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
dependencyordependenciesinfxmanifest.lua(asset-only resources likeraze_mloare the exception). Load order comes from theensureorder inserver/server.cfg. - Providers call
announceReady()from@raze/shared/readyonce they've fully started. - Anything you register into another resource goes inside
whenReady('<provider>', fn), andfnmust be safe to run twice. Never useonResourceStartplussetTimeout. <resource>:readybelongs to the ready system, so never name a net eventready.onClientandonServerrefuse it. A client asking the server for its state again (after a restart) sendsclientReady.- Loops over players already online use
untilReady('raze_core').then(...). Per-second loops that callraze_corestart withif (!isReady('raze_core')) return;. - A
raze_corerestart keeps players in their character, andraze_jobskeeps duty. Never clear per-player state ononResourceStop('raze_core'); useraze_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
setTickruns 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
SetModelAsNoLongerNeededafter 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:
resmonon the client, andrazecost(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);