Eventos de Dano do Jogo
Entenda o payload do gameEventTriggered / CEventNetworkEntityDamage e crie eventos limpos de onPlayerKilled, onPlayerDied e veículo destruído no seu próprio resource.
Por enquanto, esta ferramenta e as notas dela estão em inglês.
damage:onPlayerDied
The local player died, whatever the cause. Fires once per death, even when the game skipped the damage event (a watchdog thread checks IsEntityDead).
| # | Arg | Type | Description |
|---|---|---|---|
| 1 | cause | string | "player", "ped", "vehicle", "suicide" or "environment". |
| 2 | killerServerId | number|nil | Server id of the killer when cause is "player". |
| 3 | weaponHash | hash | Weapon or cause of damage. |
| 4 | killerEntity | entity | Killer ped or vehicle handle, 0 when none. |
AddEventHandler("damage:onPlayerDied", function(cause, killerServerId, weaponHash, killerEntity)
print("onPlayerDied", cause, killerServerId, weaponHash, killerEntity)
end)damage:onPlayerKilledByPlayer
The local player was killed by another player (also when run over by a car a player drives).
| # | Arg | Type | Description |
|---|---|---|---|
| 1 | killerServerId | number | Server id of the killer. |
| 2 | weaponHash | hash | Weapon or cause of damage. |
| 3 | isMelee | boolean | Weapon is in the melee or unarmed group. |
| 4 | isHeadshot | boolean | Last damaged bone was the head (SKEL_Head). |
| 5 | distance | number | Distance to the killer in metres. |
AddEventHandler("damage:onPlayerKilledByPlayer", function(killerServerId, weaponHash, isMelee, isHeadshot, distance)
print("onPlayerKilledByPlayer", killerServerId, weaponHash, isMelee, isHeadshot, distance)
end)damage:onPlayerKilledByPed
The local player was killed by an NPC.
| # | Arg | Type | Description |
|---|---|---|---|
| 1 | killerPed | entity | The NPC ped. |
| 2 | weaponHash | hash | Weapon or cause of damage. |
| 3 | isMelee | boolean | Weapon is in the melee or unarmed group. |
AddEventHandler("damage:onPlayerKilledByPed", function(killerPed, weaponHash, isMelee)
print("onPlayerKilledByPed", killerPed, weaponHash, isMelee)
end)damage:onPlayerKilledByVehicle
The local player was run over or crushed by a vehicle with no player driver.
| # | Arg | Type | Description |
|---|---|---|---|
| 1 | vehicle | entity | The vehicle. |
| 2 | weaponHash | hash | Weapon or cause of damage. |
AddEventHandler("damage:onPlayerKilledByVehicle", function(vehicle, weaponHash)
print("onPlayerKilledByVehicle", vehicle, weaponHash)
end)damage:onPlayerKilled
The local player killed another player (killer side). Use it for kill feeds, streaks and rewards.
| # | Arg | Type | Description |
|---|---|---|---|
| 1 | victimServerId | number | Server id of the victim. |
| 2 | weaponHash | hash | Weapon or cause of damage. |
| 3 | isMelee | boolean | Weapon is in the melee or unarmed group. |
| 4 | isHeadshot | boolean | Last damaged bone was the head (SKEL_Head). |
| 5 | distance | number | Distance to the victim in metres. |
AddEventHandler("damage:onPlayerKilled", function(victimServerId, weaponHash, isMelee, isHeadshot, distance)
print("onPlayerKilled", victimServerId, weaponHash, isMelee, isHeadshot, distance)
end)damage:onPlayerDamaged
The local player took damage and survived.
| # | Arg | Type | Description |
|---|---|---|---|
| 1 | attacker | entity | Attacker ped or vehicle, 0 / -1 when none. |
| 2 | weaponHash | hash | Weapon or cause of damage. |
| 3 | isMelee | boolean | Weapon is in the melee or unarmed group. |
| 4 | attackerServerId | number|nil | Server id when the attacker is a player. |
AddEventHandler("damage:onPlayerDamaged", function(attacker, weaponHash, isMelee, attackerServerId)
print("onPlayerDamaged", attacker, weaponHash, isMelee, attackerServerId)
end)damage:onPedKilledByPlayer
The local player killed an NPC ped.
| # | Arg | Type | Description |
|---|---|---|---|
| 1 | ped | entity | The dead ped. |
| 2 | weaponHash | hash | Weapon or cause of damage. |
| 3 | isMelee | boolean | Weapon is in the melee or unarmed group. |
| 4 | isHeadshot | boolean | Last damaged bone was the head (SKEL_Head). |
AddEventHandler("damage:onPedKilledByPlayer", function(ped, weaponHash, isMelee, isHeadshot)
print("onPedKilledByPlayer", ped, weaponHash, isMelee, isHeadshot)
end)damage:onPedDied
An NPC ped died and the local player was not the killer.
| # | Arg | Type | Description |
|---|---|---|---|
| 1 | ped | entity | The dead ped. |
| 2 | attacker | entity | Killer entity, 0 / -1 when none. |
| 3 | weaponHash | hash | Weapon or cause of damage. |
AddEventHandler("damage:onPedDied", function(ped, attacker, weaponHash)
print("onPedDied", ped, attacker, weaponHash)
end)damage:onVehicleDestroyed
A vehicle was destroyed (blew up or was wrecked).
| # | Arg | Type | Description |
|---|---|---|---|
| 1 | vehicle | entity | The vehicle. |
| 2 | attacker | entity | Entity that destroyed it. |
| 3 | weaponHash | hash | Weapon or cause of damage. |
| 4 | byLocalPlayer | boolean | The local player (or their vehicle) did it. |
AddEventHandler("damage:onVehicleDestroyed", function(vehicle, attacker, weaponHash, byLocalPlayer)
print("onVehicleDestroyed", vehicle, attacker, weaponHash, byLocalPlayer)
end)damage:onVehicleDamaged
A vehicle took damage but was not destroyed.
| # | Arg | Type | Description |
|---|---|---|---|
| 1 | vehicle | entity | The vehicle. |
| 2 | attacker | entity | Entity that damaged it. |
| 3 | weaponHash | hash | Weapon or cause of damage. |
AddEventHandler("damage:onVehicleDamaged", function(vehicle, attacker, weaponHash)
print("onVehicleDamaged", vehicle, attacker, weaponHash)
end)damage:onEntityDamaged
Every CEventNetworkEntityDamage, untouched. Handy for debugging new builds.
| # | Arg | Type | Description |
|---|---|---|---|
| 1 | victim | entity | args[1] |
| 2 | attacker | entity | args[2] |
| 3 | weaponHash | hash | Weapon or cause of damage. |
| 4 | fatal | boolean | args[6] == 1 |
| 5 | args | table | The raw args table. |
AddEventHandler("damage:onEntityDamaged", function(victim, attacker, weaponHash, fatal, args)
print("onEntityDamaged", victim, attacker, weaponHash, fatal, args)
end)gameEventTriggered and CEventNetworkEntityDamage
FiveM forwards low-level game events to scripts through the client event gameEventTriggered. Every time a networked entity takes damage, the game raises CEventNetworkEntityDamage and you get its payload as a flat array of integers:
AddEventHandler("gameEventTriggered", function(name, args)
if name == "CEventNetworkEntityDamage" then
local victim = args[1]
local attacker = args[2]
local fatal = args[6] == 1
local weapon = args[7]
end
end)The array has no names and its layout changed over time: game build 2060 and 2189 each inserted an extra value before fatal, which is why old snippets read args[4] and args[5] and silently break. Victim, attacker, fatal and weapon are reliable on current builds. The values after the weapon move around, so the generated code works out melee from the weapon group and headshots fromGetPedLastDamageBone instead of trusting those slots.
Why wrap it in cleaner events
- One handler does the parsing, every other script just listens to
damage:onPlayerKilledByPlayerand friends. - The event fires on every client that knows the victim, not only on the victim and the killer. The generated events filter on the local player where it matters, so a kill is only reported once.
- Deaths are de-duplicated: shooting a body again does not fire a second death, and a small watchdog catches deaths that never raised a damage event (fall damage on some builds,
SetEntityHealth(ped, 0)).
Server relay
The server does not get CEventNetworkEntityDamage. The relay lets the victim report its own death, which is the least abusable direction: a cheater can only lie about their own death. The server side still checks the payload type, rate limits reports, verifies the killer is another connected player and (with OneSync) drops kills from further than the max distance. Treat it as a kill feed source, not as proof for bans.
Credits
The idea of turning the raw damage event into named events comes from Vespura'sDamageEvents resource (C#, DamageEvents:PedKilledByPlayer etc.). The Lua generated here is a separate implementation written for current game builds.
Mais ferramentas de referências
Navegador de Modelos e Hashes
Busque mais de 900 veículos, mais de 1.100 peds e todas as armas, com fotos, spawn names e hashes.
Mapa Interativo
O mapa inteiro do GTA V no navegador: um mapa 2D com coordenadas e um mundo 3D para voar ou andar.
Blips, Markers e Checkpoints
Todos os sprites e cores de blip, todos os tipos de marker e de checkpoint. Com busca e cópia em um clique.
