Lifecycle Events
One event name per lifecycle moment, regardless of which framework is running underneath. No more if framework == 'vorp' then ... else ... end blocks scattered through your resources.
OnPlayerLoaded(callback)server
Fires once a player finishes loading into the server.
| Param | Type | Description |
|---|---|---|
| callback | function(source) | Runs when the player loads in. |
internally listens to —
vorp_core events
'vorp_CharSelectedCharacter' -- existing character selected
'vorp_NewCharacter' -- new character created
rsg-core event
'RSGCore:Server:OnPlayerLoaded'
example
wc:OnPlayerLoaded(function(source)
print("Player loaded:", source)
end)
OnPlayerUnload(callback)server
Fires when a player logs out or returns to character select.
VORP gap. There's no confirmed dedicated server-side "player unload" event for VORP in the docs this lib was built against. On RSG this fires reliably via
RSGCore:Server:OnPlayerUnload; on VORP it currently registers but never fires, with a console warning on startup explaining why. Extend it in _custom/server.lua if your VORP build exposes a usable event.
OnJobUpdate(callback)server
Fires when a player's job changes.
| Param | Type | Description |
|---|---|---|
| callback | function(source, newJob, oldJob) | Runs on job change. |
example
wc:OnJobUpdate(function(source, newJob, oldJob)
wc:Notify(source, { title = "Job updated" })
end)
Real Wild County example — stagecoach job list refresh
wc_stagecoach rebuilds a driver's available missions the moment their job changes, instead of waiting for the player to relog.
wc_stagecoach/server/main.lua
wc:OnPlayerLoaded(function(source)
RefreshStagecoachMissions(source)
end)
wc:OnJobUpdate(function(source, newJob, oldJob)
if newJob == 'stagecoach_driver' or oldJob == 'stagecoach_driver' then
RefreshStagecoachMissions(source)
end
end)
Common mistakes
- Registering
OnPlayerLoadedinside a client-facing event handler — it's server-only. Register it once at server resource start, not per-player. - Relying on
OnPlayerUnloadto clean up VORP-side state — it's a documented gap and never fires on VORP. UseAddEventHandler('playerDropped', ...)as your cleanup hook there instead. - Relying on
OnJobUpdatefiring on RSG — RSG has no confirmed server-side job-update event, so this callback registers but never runs there. Listen to your own job resource's event on RSG if you need this. - Doing expensive work (database writes, webhook calls) directly inside the callback for every player on every server restart — batch or debounce if you have a large player base.
Troubleshooting
- If
OnPlayerLoadednever fires: confirm wc_libs started before your resource (checkfxmanifest.luadependency order) and that a framework was actually detected. - If it fires twice for the same player on VORP: that's expected if both
vorp_CharSelectedCharacterandvorp_NewCharacterapply — guard your handler to be idempotent if that matters for your logic. - If
OnJobUpdatenever fires on RSG: this is the documented RSG gap above, not a bug — hook your own job resource's server event directly viaWCLib.Raw.RSG().