Current collected state Current
Observed since 20 Oct, 20:37 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
5m-js
Helper package for FiveM JS
Helper package for FiveM.
npm i 5m-js
yarn add 5m-js
setImmediate to avoid freezing the main
thread. Refrequire("5m-js");
onNet("event-name", async () => {
const serverId = source;
const name = await I.GetPlayerName(serverId);
I.emitNet("event-name", name)
})
server.js
require("5m-js");
// calculate will be the rpc name
// when passing function, it will be registered as the rpc routine
rpc.calculate(function (playerServerId, op, x, y) {
// `playerServerId` will always passed to the rpc routine when registered in server side.
// And the rest will be the arguments passed to the rpc invocation from client.
switch (op) {
case "+":
return x + y;
case "-":
return x - y;
default:
return 0;
}
});
RegisterCommand("get-player-health", async function () {
const playerServerId = 1;
// invoking client registered rpc routine from server, playerServerId is the target player
const health = await rpc.getPlayerHealth(playerServerId)
console.log(health)
}, true);
client.js
require("5m-js");
RegisterCommand("calculate-from-server", async function () {
const r = await rpc.calculate("+", 2, 3);
console.log(r); // 5
}, false);
// registering rpc routine in clinet to be invoked from server side.
rpc.getPlayerHealth(function () {
return GetEntityHealth(PlayerPedId())
});
server.js
require("5m-js");
RegisterCommand("kill-all-players", async function() {
const players = getPlayers();
for (const p of players) {
// we need to pass the player server id (source) then the native arguments according to fivem natives.
const ped = await rpc.native.PlayerPedId(p);
await rpc.native.SetEntityHealth(p, ped, 0);
}
}, true)
let r = await httpRequest("https://httpbin.org/anything", {
method: "POST",
data: "name=5m-js",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
}
})
console.log(
r.statusCode, r.body, r.headers,
)
r = await httpRequsetJson("https://httpbin.org/anything", {
method: "POST",
data: {name: "5m-js"},
headers: {
"X-Token": "123"
}
})
console.log(
r.statusCode, r.body, r.headers,
)
Download counts and popularity will appear here as the collector receives them.
| Package / target | Requirement | Relationship |
|---|---|---|
@types/nodeEnvironment{
"local_name": "@types/node",
"alias": false,
"peer_metadata": null
} | ^18.11.7 | development |
Source distribution
{
"integrity": "sha512-cLEKu1n5Fl71R172NhbPxe+u2mF6xS218JwFpFoYKT82fgAgUSR3ECXfJt1r6MtUKHfooC/BeZdtrlubYw1y+g==",
"shasum": "9c1aaf04bfd0ac62a27c87d601f900bf46c69049",
"tarball": "https://registry.npmjs.org/5m-js/-/5m-js-0.5.3.tgz",
"fileCount": 7,
"unpackedSize": 8372,
"signatures": [
{
"keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
"sig": "MEYCIQD4G0+tmNokmTcwcOea+tfPkfODcibk+p7/PWDptRNB/AIhAJU+56PB6jYzta0znIikSuXW45lRS2JGuucsIYaJEkUL"
}
],
"npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJj0wApACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoROg/5ADuolGZX4C9aGqGX5ExcyDG7YPXxFChSbNCEEJ0HV99K9KWx\r\nWomyn/cHKmKcBcqnhsC+VJewhU56QAGWcXexelD/Iah1w4a/WQUkOa7XLg0p\r\nbQqI93ph90LVOPAXgW7Ckk5697cYPDpGgJo0P+0EBA7DZooCn+6/OQii569V\r\nIRG/vA92t5ZUhD5218CsIvnqFrHOyqdKgwG8iIwsBPQVe82UYyr8Sp41bdDV\r\nyFS6AF9gwj8z4oxImWHUJ1tPZsCczIoWZ3zqacsngo07oXu0qq8Ai4BOmNny\r\nmV8RUD7KlZNy5eCf3JV1phYpk7Fne/fMjfsP7NU8h8rWt1/vVMUYh1S2dbuE\r\nfVqgFUzJGc/6U4gg/7Ww0Guquzmw+/XlmgClElCZFCHuO2AdWJXI15GMrw92\r\nDpq5vaGtviuwqS9D2QtG/fdouyTyAMiUcoAbbUhhZrnkeOes3f1j9zMyOxD/\r\nBXQxoRMe2k9Ud9f4cAc+hr0G7gZQfSmu6O6rfa5BDmBC6Lp3CL+hl8fVJ4wP\r\nRmo5HfbwDhL5IQb7u5S5S4S7SU5r/yuAUQSj6sfnt/rOw7AwpGoUHNowwTdP\r\npl3Yzy/a7470FZo0JZaR+xuYTZELzWJhe5ki3ytM7ZSj7tanYQz1lTBdA73B\r\nzEAmRlOM0wPqVTJSAoMwsJsNhPR+RJLx878=\r\n=w2yZ\r\n-----END PGP SIGNATURE-----\r\n"
}Observed since 20 Oct, 20:37 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package_version:7e197c01a39df5165526225e7577100322b5a3dff463dbdc516b76ea799d35f7