Recently I’ve been testing the gameEventTriggered - Cfx.re Docs event. In theory, this event should be able to take care of game checks, like entity damage, “ped entered vehicle” or “vehicle is destroyed / undrivable”.
In fact, I’m gonna show you how to set up some cool event triggers.
These are some easy to implement
AddEventHandler('gameEventTriggered', function (name, args)
if name == "CEventNetworkPlayerEnteredVehicle" then
TriggerEvent('gameEvent:NetworkPlayerEnteredVehicle', args[1], args[2])
elseif name == 'CEventNetworkVehicleUndrivable' then
TriggerEvent('gameEvent:NetworkVehicleIsUndrivable', args[1], args[2], args[3])
elseif name == 'CEventNetworkEntityDamage' then
if args[6] == 1 then --damage leads to entity death
if IsEntityAPed(args[1]) and IsEntityAPed(args[2]) then --both victim and killer are peds.
TriggerEvent('gameEvent:PedDied', args[1], args[2], args[7])
end
end
end
end)
AddEventHandler('gameEvent:PlayerEnteredVehicle', function(netID, vehicleid) --Player entered vehicle
print('Player entered vehicle id ~y~'..vehicleid..'~s~ with network id of ~y~'..netID..'~s~')
--netID is different than server id. 128 = your client.
end)
AddEventHandler('gameEvent:VehicleIsUndrivable', function(vehicleid, killerid, weaponHash) --Vehicle becomes undrivable
print('Vehicle '..vehicleid.." got destroyed by ped id "..killerid.." using weapon hash "..weaponHash)
--killerid is a ped entity id. weaponhash can also show the death by grenade explosion, or by going underwater.
end)
AddEventHandler('gameEvent:PedDied', function(victimid, killerid, weaponHash)
print('Ped '..victimid.." got killed by ped id "..killerid.." using weapon hash "..weaponHash)
end)
Let’s talk a bit about about CEventNetworkEntityDamage
. This event outputs 13 arguments!
From my testing, I found the following:
args[1] --entity that received the damage.
args[2] --entity (or -1 for falling or drowning) that caused the damage.
args[3] --unknown, but it looks like a hash
args[4] --unknown, always 0
args[5] --unknown, always 0
args[6] --damage caused entity to die. Boolean.
args[7] --weapon hash. This can be a pistol, a grenade, unarmed, drowned, drowned in vehicle, fallen, etc. There's a lot of them, but it works with already known player weapon hashes.
args[8] --sometimes this is a hash, but usually 0. Something to do with vehicle collision?
args[9] --sometimes this is a hash, but usually 0. Something to do with vehicle collision?
args[10] --unk, always 0 in my testing
args[11] --unk, sometimes 1, but mostly 0. I think something to do with cops.
args[12] --always 1 if you hit a parked car. Otherwise 0
args[13] --some sort of flag. parked cars is 116. Otherwise mostly 0.
Some notes:
-
Only network game events are triggered. (for now?)(single player events added in server version 5182) - Game the entity damage event might be of better use rather than always looping ped damage / death natives.
- There are some other events that I caught, like
CEventNetworkPlayerCollectedAmbientPickup
, that triggers every time you pickup something from the ground. I haven’t tested it that much, which is why I haven’t included it here, yet!