Skip to content

Ground rules ​

Three rules come before everything else: the server decides, every resource survives a restart, and every script is cheap to run. A change that breaks any of them gets sent back.

Security first ​

  • The server decides money, items, jobs, task state, prices, and positions where it can. The client only displays and asks.
  • Validate every net event and callback on the server: types, ranges, ownership, state, distance and cooldowns. Nothing the client triggers grants anything on its say-so.
  • Assume every player dumps everything their client downloads: files{} entries, client JS, NUI, state bags and events. Locations, spawn pools, loot tables, rates, prices, admin lists and other players' info stay in server-only config and code.
  • Send each client only what that player needs right now, and re-check every interaction on the server.

Restart-safe ​

  • No dependency or dependencies in fxmanifest.lua (asset-only resources like raze_mlo are the exception). Load order comes from the ensure order in server/server.cfg.
  • Providers call announceReady() from @raze/shared/ready once they've fully started.
  • Anything you register into another resource goes inside whenReady('<provider>', fn), and fn must be safe to run twice. Never use onResourceStart plus setTimeout.
  • <resource>:ready belongs to the ready system, so never name a net event ready. onClient and onServer refuse it. A client asking the server for its state again (after a restart) sends clientReady.
  • Loops over players already online use untilReady('raze_core').then(...). Per-second loops that call raze_core start with if (!isReady('raze_core')) return;.
  • A raze_core restart keeps players in their character, and raze_jobs keeps duty. Never clear per-player state on onResourceStop('raze_core'); use raze_core:characterUnloaded.
  • A resource restarting mid-task cleans up its own entities and state, never pays twice, and leaves nothing behind.
ts
import { announceReady, whenReady } from '@raze/shared/ready';

whenReady('raze_interact', () => {
  // register points here; this may run again after raze_interact restarts
});

announceReady();

Performance first ​

Every script is built to be cheap: near 0.00 ms in resmon when idle, and no hitches on the server thread. Treat a cost you could have avoided as a bug.

  • Client setTick runs only while it's needed (the player is nearby, a screen is open) and is cleared afterwards. Anything that doesn't need every frame uses an interval or an event.
  • Proximity checks walk a short list of nearby points refreshed every second or so, never every point on the map each frame.
  • Send the least you can over the network: only to the players who need it, and only what changed. Nothing goes out every frame or as an every-second broadcast. Use state bags only for what other clients must see.
  • No database queries in loops or per-player timers. Cache read-mostly data in memory, write once per action, and index the columns you look things up by.
  • Release whatever you load and create: call SetModelAsNoLongerNeeded after spawning, delete entities, and clear ticks and timers when you're done and when the resource stops.
  • NUI renders only while it's open and never polls.
  • Measure before you hand work in: resmon on the client, and razecost (or the admin Performance page) on the server.
ts
// Draw only while someone is near: the tick starts and stops with distance.
let tick: number | null = null;
setInterval(() => {
  const near = isNearAny(); // checks a short nearby list, not the whole map
  if (near && tick === null) tick = setTick(draw);
  else if (!near && tick !== null) { clearTick(tick); tick = null; }
}, 1000);

Private. Do not share outside the team.