Catalog npm
Back to packageRELEASE DETAILS

0.2.4

npm

5m-js

Helper package for FiveM JS

Published17 Dec 2022
Direct dependencies1
Transitive dependenciesNot calculated

README

Current package documentation

5m-js

Helper package for FiveM.

Installation

NPM

npm i 5m-js

YARN

yarn add 5m-js

Feature

  • Wrap native functions with setImmediate to avoid freezing the main thread. Ref
  • RPC to invoke functions client/server registered functions.
  • RPC to invoke native client functions from server.

Examples

JS

Wrap natives within callback

require("5m-js");

onNet("event-name", async () => {
  const serverId = source;
  const name = await I.GetPlayerName(serverId);
  I.emitNet("event-name", name)
})

RPC

Invoke server registered routine.

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())
});
Invoke client natives directly from server

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)

HTTP

Perform http request from server
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,
)

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 1

Native requirements
1 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
@types/node
Environment
{
  "local_name": "@types/node",
  "alias": false,
  "peer_metadata": null
}
^18.11.7development

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "integrity": "sha512-4m7CNWBO4hho6+7tFPrab4xmmzFvNgu3VQvFKC8M3RRt6TEo7tgbIPLqtfpoVa8O0MN1BSGpWOXjvuTNGyxUbQ==",
  "shasum": "b44ea017441876f0fde362ac5ab663fe018554eb",
  "tarball": "https://registry.npmjs.org/5m-js/-/5m-js-0.2.4.tgz",
  "fileCount": 5,
  "unpackedSize": 3741,
  "signatures": [
    {
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
      "sig": "MEUCIQDkScA521MXUPQy7TnTCML8YkoR1z1Ep0S764V4fel+kQIgbN3QCLcezhM2wWyTF8tTpedqxa84ot0aHHV7TFacSD0="
    }
  ],
  "npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjnk1GACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmp3sg//Z4jWTA6dPxr1y4rTaQvAYI8pZzL/1E9ejW5h69lGhONLa8os\r\nb2l51p0QJeZOvadqymWfrPRAJirelF92QFZDIiqs52uSoUzi+TAFMHBqizou\r\n9EW1eGXlAMhNrn7Ro/BjJIei1k6AYdX7qyhQCtAVTBLaDWfYCbIAix3YwJDW\r\n/SjapJXuiwGFVMecgKFqSY8jen2I9OmIpvk7H/SSrzw9hPupBbQthzf98TSM\r\nL+91D4kya6wa/jCFQR6HZn4eHDfeqTPi8ZHxfdVddtGtIy6TMRi70k9dLc0h\r\njVS/5fTUBRRnwVd1/YPbiy3My+O2Nja6wV8e/d7ogOu9gwoJUJcwtsbMM3sl\r\nVWXorl+Mtb6gUEAGufmfDw66VOb7TaZBKGmty91hayuQtG/vxCpARIbitB1Q\r\n6vWMF/zJhJuJ2jBptDPDPOr4ZfT5BYgnJSX41qKA4XkdqmJmDXTgJJ9DOm78\r\nj9Xl1mPoMDmMsam9R3GyRUU1xqA1OIfuN1qicrvNg8Eq7yA0cq+Iw6gJunNR\r\nvUxeJlOmCU58UsgV9V+LhcdR4fT82DLFws8Jk6oB7dy97Oq4ph/PqDmWnS8e\r\nQbelu48+VJMhlobCYcyT3EWSSIjdXbY9MQ/tEsWSvFlPesTwWmxmUWYA8/dq\r\nLFFj/ilvFfy04iZH+JDtjhOtdIstAL68c2c=\r\n=QpCs\r\n-----END PGP SIGNATURE-----\r\n"
}

Repository

PENDING
0xwaleed/5m-js

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 20:37 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:a86fbd4e7ef0880b56732515751714a79af436df64dbd0343cf79c2c686b595e

Other collected versions

0.8.112 May0.8.012 May0.7.11 May0.7.026 Apr0.6.226 Apr0.6.131 JanView all collected versions →