Events
List of all events that can be used to listen for events. For usage details and more events, see Events.
Connection Events
OnClientJoin()
Called when the local client joins the server.
Example:
Event.Add("OnClientJoin", function()
print("Connected to server!")
end)
Render Events
OnRender()
Called every frame. Use the Render
event to draw elements to the screen underneath the JC4MP UI, such as the chat window. Learn more here.
Example:
Event.Add("OnRender", function()
Render.DrawText(vec2(100, 100), "Hello World!", 1.0, vec4(1, 1, 1, 1))
end)
OnPostRender()
Called every frame. Use the PostRender
event to draw elements to the screen on top of the JC4MP UI, such as the chat window. This is good for full-screen overlays, such as fading to black for transitions. Learn more here.
Example:
Event.Add("OnPostRender", function()
Render.DrawBox(vec2(0, 0), vec2(100, 100), vec4(0, 0, 0, 0.5))
end)
OnUpdate()
Thread-safe per-frame update, called every frame. Prefer this over OnRender
for game logic that must be thread-safe.
Example:
Event.Add("OnUpdate", function()
-- Update game logic here
end)
OnPostUpdate()
Thread-safe per-frame update that runs after OnUpdate
. Prefer this over OnPostRender
for logic that must be thread-safe.
Example:
Event.Add("OnPostUpdate", function()
-- Late update logic here
end)
Vehicle Events
OnVehicleExplode(vehicle: NetVehicle)
This event fires when a vehicle explodes. Only available on the client side.
Parameters:
vehicle: NetVehicle
- The vehicle that exploded
Example:
Event.Add("OnVehicleExplode", function(vehicle)
print("Vehicle " .. vehicle:GetId() .. " exploded!")
end)
OnVehiclePartChangedState(vehicle: NetVehicle, part: VehiclePart, state: VehiclePartState)
This event is called when a part of a vehicle changes state, such as the door opening on the carrier plane.
Parameters:
vehicle: NetVehicle
- The vehicle whose part changedpart: VehiclePart
- The part that changed statestate: VehiclePartState
- The new state of the part
Example:
Event.Add("OnVehiclePartChangedState", function(vehicle, part, state)
print("Vehicle " .. vehicle:GetId() .. " part " .. tostring(part) .. " changed to state " .. tostring(state))
end)
OnVehicleNitrousUse(vehicle: NetVehicle)
This event fires when a vehicle uses nitrous boost.
Parameters:
vehicle: NetVehicle
- The vehicle using nitrous
Example:
Event.Add("OnVehicleNitrousUse", function(vehicle)
print("Vehicle " .. vehicle:GetId() .. " used nitrous!")
end)
OnVehicleTurboJump(vehicle: NetVehicle)
This event fires when a vehicle performs a turbo jump.
Parameters:
vehicle: NetVehicle
- The vehicle performing the turbo jump
Example:
Event.Add("OnVehicleTurboJump", function(vehicle)
print("Vehicle " .. vehicle:GetId() .. " performed a turbo jump!")
end)
OnVehicleCollision(vehicle: NetVehicle, position: vec3, normal: vec3, impulse: float)
This event fires when a vehicle collides with something, providing collision details including position, surface normal, and impact impulse.
Parameters:
vehicle: NetVehicle
- The vehicle that collidedposition: vec3
- The collision positionnormal: vec3
- The surface normal at the collision pointimpulse: float
- The impact impulse
Example:
Event.Add("OnVehicleCollision", function(vehicle, position, normal, impulse)
print("Vehicle collision at " .. tostring(position) .. " with impulse " .. impulse)
end)
OnVehicleRender(vehicle: NetVehicle)
This function is called when the game updates/renders all vehicles, one call per vehicle.
Parameters:
vehicle: NetVehicle
- The vehicle whose lights are being updated
Example:
Event.Add("OnVehicleRender", function(vehicle)
print("Updating vehicle " .. vehicle:GetId())
end)
OnVehicleHornPlay(vehicle: NetVehicle)
This event fires when a vehicle's horn starts playing.
Parameters:
vehicle: NetVehicle
- The vehicle whose horn started playing
Example:
Event.Add("OnVehicleHornPlay", function(vehicle)
print("Vehicle " .. vehicle:GetId() .. " started honking")
end)
OnVehicleHornStop(vehicle: NetVehicle)
This event fires when a vehicle's horn stops playing.
Parameters:
vehicle: NetVehicle
- The vehicle whose horn stopped playing
Example:
Event.Add("OnVehicleHornStop", function(vehicle)
print("Vehicle " .. vehicle:GetId() .. " stopped honking")
end)
Player Events
OnPlayerRagdollStart(player: NetPlayer)
This event fires when a player starts ragdolling (enters ragdoll state).
Parameters:
player: NetPlayer
- The player that started ragdolling
Example:
Event.Add("OnPlayerRagdollStart", function(player)
print("Player " .. player:GetNick() .. " started ragdolling")
end)
OnPlayerRagdollEnd(player: NetPlayer)
This event fires when a player stops ragdolling (exits ragdoll state).
Parameters:
player: NetPlayer
- The player that stopped ragdolling
Example:
Event.Add("OnPlayerRagdollEnd", function(player)
print("Player " .. player:GetNick() .. " stopped ragdolling")
end)
OnPlayerKicked(player: NetPlayer)
This event fires when a player is kicked using the grapple reeling.
Parameters:
player: NetPlayer
- The player that was kicked
Example:
Event.Add("OnPlayerKicked", function(player)
print("Player " .. player:GetNick() .. " was kicked")
end)
OnPlayerGrappleHit(player: NetPlayer, position: vec3, direction: vec3)
This event fires when a player is grappled by another player.
Parameters:
player: NetPlayer
- The player that was grappledposition: vec3
- The position where the grapple hitdirection: vec3
- The direction of the grapple
Example:
Event.Add("OnPlayerGrappleHit", function(player, position, direction)
print("Player " .. player:GetNick() .. " was grappled at " .. tostring(position))
end)
Navigation Events
OnWaypointPlace()
This event fires when a waypoint is placed. This event is cancellable with Event.Cancel().
Parameters:
position: vec3
- The position of the waypoint
Example:
Event.Add("OnWaypointPlace", function(position)
print("Waypoint placed at " .. tostring(position))
-- Cancel waypoint placement
Event.Cancel()
end)
OnWaypointRemove(reached: bool)
This event fires when a waypoint is removed. The reached parameter indicates if the waypoint was removed when the local player reached it (true) or for another reason (false). This event is cancellable with Event.Cancel().
Parameters:
reached: bool
- Whether the waypoint was reached by the player
Example:
Event.Add("OnWaypointRemove", function(reached)
if reached then
print("Waypoint reached!")
else
print("Waypoint removed for other reason")
end
-- Cancel waypoint removal
Event.Cancel()
end)
OnScanStart()
This event fires when a scan starts (default tab key). This event is cancellable with Event.Cancel().
OnScanEnd()
This event fires when a scan ends (default tab key). This event is cancellable with Event.Cancel().