← All articles · Dev · 3 min read

Making civilian roleplay jobs hands-on in s&box

Civilian jobs with real work instead of passive income: C# components, Razor panels in the world, and economy checks on the host.

Players in a small apartment on a roleplay server. A vote in the corner asks whether one of them may become a police officer.
A job vote on a roleplay server: one player asks to become a police officer, and the others vote yes or no.

On classic roleplay servers in older sandbox games, criminal roles often got active play, such as combat and break-ins. The plainest civilian role often had little to do except wait for the next payday.

Breaking out of the passive income loop

When income comes from passive sources, server economies tend to inflate unless money sinks keep pace. Player interaction can shrink to isolated bases guarding money printers. Many players then pick civilian roles mainly to fund criminal loadouts, not to engage with the city.

In s&box, which is built on Valve's Source 2, game modes are written as C# components. UI can be built from Razor panels. Together, these let developers turn everyday civilian and municipal roles into hands-on interactive loops. Client frame rates still depend on your code, so keep per-frame work small. A Razor panel rebuilds when its BuildHash() value changes or when you call StateHasChanged(). It also rebuilds when the cursor enters, leaves or clicks a panel that has pointer-events.

Hands-on jobs with C# components and Razor panels

With these tools, a game mode could add a tow-truck or mechanic role. The player could open a vehicle hood and inspect individual wear components. A city maintenance role could trace and repair fault nodes in a power grid. Shopkeepers could manage live supply orders that the host keeps and saves in its own code.

WorldPanels in s&box render Razor UI as panels placed in the 3D scene. The panels use web-style CSS with flex layout, though not every web CSS property is implemented. Cash registers, diagnostic oscilloscopes, medical monitors and dispatch terminals can then work in first-person view without immersion-breaking modal popups. For input, add a WorldInput component to the player's camera and enable pointer-events in the panel's style.

Economy checks on the host, and money sinks

Route client requests for wallet transfers, shop purchases and job payouts through C# methods marked [Rpc.Host]. These methods run only on the host. Flags such as NetFlags.OwnerOnly limit who may call a method, but each handler should still check every request. Resolve the player from Rpc.Caller.SteamId and check that the player is near the workstation. Only then change the balances, in the same handler and without an await in between.

On a dedicated server, these checks run on the server. In a peer-to-peer game, one player hosts, so the checks run on that player's machine. If that player leaves normally, another player takes over as host by default. If the host crashes, the game ends for everyone. Code and plain fields on the old host do not carry over, so keep balances in [Sync] properties or other snapshot state.

Pair skill-based civilian payouts with recurring money sinks. Examples are maintenance parts bought from the game, property upkeep and fees on player-to-player trades. Sinks help keep server currency valuable across multi-month seasons, as long as they keep pace with payouts.

When jobs pay for active play, AFK farming earns less. Host-side checks can make the economy harder to exploit. Together with money sinks, this can help keep players engaged for longer.

See Facepunch's documentation at sbox.game/dev/doc for the current API.

Related: netcode generator.

Comments

No comments yet.

All news · Guides · Follow @sboxlist on Instagram and TikTok.