Catalog npm
Back to packageRELEASE DETAILS

0.1.1

npm

5m-js

Helper package for FiveM JS

Published30 Oct 2022
Direct dependencies2
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 2

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

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "shasum": "1605b5b0d6763a5e124f7fb5fcf443f2382f00e5",
  "integrity": "sha512-YBOyBW2ylNTVWELrmDyEdk0nOMeeEvvBvjUXcjapLCYZtdSnYaYdNJSPbCddwqiZSE7efSgs5RLo7IHvbu6QDA==",
  "tarball": "https://registry.npmjs.org/5m-js/-/5m-js-0.1.1.tgz",
  "fileCount": 7,
  "unpackedSize": 1552,
  "signatures": [
    {
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
      "sig": "MEUCIESbIILRxxMAp/Gdr+zRSwcp97JQLoRdNoUMBXphhOu9AiEA9s3MEaZrgsc2IXvQ/rtep1+3jWxh4TpoNyHSmaJuM4g="
    }
  ],
  "npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjXpDxACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrGcQ/8DLgfeJAYJHk69aAVXyT7ihG8LcEA6gDmBrfUX7BYpLttlr4v\r\nIUcIxSb+UmBdx1AOPFecAZzb/3wjSmLz61bVV92xy+dQR96CpNoaovJIVQVD\r\nR/Cz+lOC/hIV8fYimM94mLQAPoURwSMSEZcOdezGfqCNuh9QgmiRP2uBmqN9\r\nBvx6KhgTyh7iGohkrYb/mQb7UOCWykwvgdOvHkJWFTqQkNEftK3NPprUCOTq\r\njdr5usF2kRfdj/MaRhLx2ktHw8fBUU0Y1sz+doH4vZOr7C1pTKzQIDw51WYi\r\nHWagp4cP/lh4SOmk55O2GgqAVLrNuG7EYmQ//S5Zvpwh9fdzzehiOiZKUDri\r\nB4rj0aa6S4X2A5jx6OcbR079ArfVl5pQkPhZitpG7j+7xTHMhyDfA3gVSOLw\r\nBaxNMY6hycL0+Ucy51ijRk6j5UuQN7+wWQpCTnuWnS7pRL4YVC5TSuH/8PsJ\r\nPTvqAygEbZwhkb3ilvsPSlSnESNns14++TdSWOjE09NHnDvD52vangYLEX0x\r\ntfxIQj5CGQxeUh/diDYYDSYJ5hXEz5c2tCDyVsv3iScc250RU2g8XGMPq6sQ\r\nvZy+OpXmcH6zZ3TKEjgflyxP3fSOy7hL2xSZvTh2lZvNI0yqIvrl+pq+TrzG\r\nEMM7y4Q/vclPUiIi0rtDRWplD9ndcMEsre0=\r\n=JAq9\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:1926c318bb049168feb4e4c035338fe0292be151b2cadd4d25b0b6b25ae2dbe2

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 →