Scripting/Server/Events
Contents
Define any of these as a global function in a server script. All are optional. Types in the signatures: player/killer/victim are Player handles, vehicle is a Vehicle handle, other names are plain integers, floats, strings or bools.
Lifecycle and connection
- onScriptLoad – Called once after every server script file has been loaded.
- onPlayerConnect – A player has connected.
- onPlayerJoin – The player finished loading and joined.
- onPlayerPart – The player left.
- onConsoleInput – A line was typed in the server console.
Spawning, deaths and combat
- onPlayerRequestSpawn – The player pressed spawn on the class-selection screen.
- onPlayerSpawn – The player spawned (normal spawn or player.Spawn()).
- onPlayerDeath – The player died.
- onPlayerBusted – A cop busted the player.
- onPlayerShoot – The player's weapon fired - on foot, in a vehicle, anywhere (gun ammo going down; thrown weapons too).
- onPlayerActionChange – (v0.3-r2+) The player's ped changed what it is doing: jumping, falling, staggering, getting up, aiming, entering / leaving a vehicle, dying ... Values...
- onPlayerKill – One player killed another.
- onPlayerShotPlayer – Fires for every hit one player lands on another (not just kills).
- onPlayerWeaponChange – The weapon in the player's hands changed.
- onPlayerUseDetonator – The player triggered the detonator (remote bombs).
- onPlayerShootObject – A player shot a script-created object.
- onPlayerCheat – (v0.4.9+) Anti-cheat: a detection fired for this player, and YOU decide what happens (KickPlayer, BanPlayer, a warning, nothing).
- onPlayerCLEO – Old name of CLEO detection 1, still called when the script has NO onPlayerCheat.
- onPlayerFileHash – Answer to player.CheckFileHash(file).
Chat and commands
function onPlayerCommand(player, cmd, params)
{
if (cmd == "give") // /give 5 100 -> weapon 5, 100 ammo
{
if (NumTok(params, " ") < 2)
return MessagePlayer("Usage: /give <weapon> <ammo>", player);
local weapon = GetTok(params, " ", 1).tointeger();
local ammo = GetTok(params, " ", 2).tointeger();
player.SetWeapon(weapon, ammo);
}
}- onPlayerChat – A player sent a normal chat line (not starting with /).
- onPlayerCommand – The player typed /cmd params.
Vehicles
Seat numbers: 0 is the driver, 1..8 are passengers. "Entering/Exiting" fire before the state changes; "Entered/Exited" fire after.
- onPlayerEnteringVehicle – The player started to get into a vehicle.
- onPlayerEnteredVehicle – The player is seated.
- onPlayerExitingVehicle – The player started to get out.
- onPlayerExitedVehicle – The player is out.
- onPlayerEnteredTrain – Convenience event for model 124.
- onPlayerExitedTrain – Convenience event for model 124.
- onVehicleWrecked – The vehicle was destroyed.
- onVehicleRespawn – The vehicle respawned (after being wrecked, or the idle respawn timer).
- onVehicleHealthChange – Vehicle health changed (1000 = full).
- onVehicleDamage – Vehicle health went down.
- onVehicleUpdate – Fires for every sync packet of a driven vehicle.
World
- onPlayerEnterSphere – The player walked/drove into a sphere created with CreateSphere.
- onPlayerExitSphere – The player left the sphere.
- onPlayerEnterCheckpoint – The player walked/drove into a checkpoint created with CreateCheckpoint or CreateClientCheckpoint.
- onPlayerExitCheckpoint – The player left the checkpoint (or changed virtual world).
- onPickupPickedUp – A player collected a pickup.
- onPickupRespawn – A pickup came back after its respawn time.
- onPlayerIslandChange – The player crossed to another island.
Input and sync
- onPlayerKeyStateChange – key is a KEY_ONFOOT_* or KEY_INCAR_* bit mask and down is true on press, false on release.
- onPlayerUpdate – Fires for every on-foot sync packet the server receives from a player.
NPC events
- onPlayerShootNPC – A player shot an NPC. For instant-hit weapons (Colt-45, Uzi, AK-47, M16) the body part is reported as the torso.
- onNPCDeath – reason is the player id credited with the killing blow, or -1 if the damage came from the world or a script.
- onNPCKillPlayer – (0.5.4+) An NPC killed the player.
- onPedKillPlayer – (0.5.4+) A pedestrian (gang member, cop, street ped) killed the player.
- onNPCRespawn – Fired by npc.Respawn().
Traffic events
Only fire when traffic_sync on. See the Traffic chapter for the handles.
- onTrafficPedCreated – A traffic pedestrian appeared.
- onTrafficVehicleCreated – A traffic vehicle appeared.
- onTrafficPedRemoved – The ped is gone.
- onTrafficVehicleRemoved – The traffic vehicle is gone.
- onPlayerShootTrafficPed – A player shot a traffic ped.
- onTrafficPedDeath – killer is the player who last hurt the ped within 10 seconds, otherwise null (traffic, fire, other peds).
- onTrafficVehicleWrecked – A traffic car was destroyed.
- onPlayerTakeOverTrafficVehicle – A player got into a traffic car.
- onPlayerCommitCrime – The player's game was about to give them wanted stars (v0.1.9+).
- onDialogResponse – The player answered a dialog opened with ShowPlayerDialog (v0.2.3+, see section 4.9).
- onPlayerEditObject – Result of the object editor opened with EditObject (v0.3+).
- onPlayerSelectObject – The player clicked an object after SelectObject(player) (v0.3+).
- onPlayerEditGraffiti – Result of the editor opened with EditGraffiti (v0.5-beta).
Bot events
- onBotDeath – A bot made with CreateBot ran out of health (v0.5-beta).
Categories: Server events