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-BMqAqYMWuoa+JpMC3Wm7uPCxZFKWIcTPBSb7kbBtsaWQgD/1ekLMjUKGKpj/8nReBc4BptWY5TDRRHBxiqCW1w==",
"shasum": "815a803d50ed95d8f4ac71f54f20ee509ff910bc",
"tarball": "https://registry.npmjs.org/5m-js/-/5m-js-0.6.1.tgz",
"fileCount": 7,
"unpackedSize": 8571,
"signatures": [
{
"keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
"sig": "MEQCIAukZXx/bVJjJDPaRC0wMAZ4iawj6PMZqVNNWnLj1Eh/AiA6K0EWjCYr/xWtJ8THi5EWtAZr++lcjECrU9dkxplsHQ=="
}
],
"npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJj2XiXACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqAIg/9H6QB2Hn/AZg+VmlZ8Bjm1WwrF0w9JGauSnqVTmjwklq4XsL9\r\n5vmY3RgOiyu7dekTmiPlRbGqT9ny0DinCf1GWB6G01moXvCrZLCEylxvQ17e\r\nI8g+eQbf7utTMef0QDOI5784FacaSjrI9q9Cr4EqWnHnVpjsa82taRaPH/c/\r\nEBXk1EfdFeV13sX7qQUkvDaGCG5bFCVDHA1jeCwCx+YsGw2+Np1fAqXfeewt\r\nVbZ1gYLCfYwVdun1Q73DterEhG+j0p0mWUPUVbtWNbAo6gQ2bsisGeD5KvAH\r\ncseqc/0Ck468SWFL8TxATz1ouynm5e8MCH5GMifkRxo8I1w1F4kyW1aUa3Vt\r\n0kVR0XKlqxRxl6mQr2rE5QlcKfPZ7drId2KhZZSEmif7a2qfku2EhidoIh41\r\n7K5I04hj8edKRrNvpoRRIwawIzhTHv2sdXxYgV362zGCAUexvLzEuxh5Vf/v\r\n8BQbY564J2J2ka7etAwA9Wp1EqL7MRyDsHhKyRgAPNblFRENhnxwluGX5nE1\r\ns+0AwG3qGhJsrVyaNsnmg7CQKrTrInjBEQKX2yzqaiDxLzWImMkYjRtcPo7y\r\n2Ntd4i+JcpLnbpDvWP/tF2pOcpwgwiARbX81X28S2axqOSNWsaIiB8xWlXRx\r\naHQuojDcu6YHrUJIBZVu/M83yuBFdL57bhM=\r\n=3RVd\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:bf7a9405e58bf0adcc0f7aff6b34a328aac663dfbf728b76927350eaaa6cec49