ServersYour serverFor creatorsForumFAQDocumentationSecurity
Download the launcher
  1. Documentation
  2. Server events
  3. onPlayerWasted

Event

onPlayerWasted

A player died: from a weapon, in an accident, an explosion or by a script.

Handler

addEventHandler("onPlayerWasted", root, function(ammo, killer, weapon, bodypart, stealth) ... end)

Parameters

ammoint
How much ammo the player had at the moment of death.
killerelement
Who killed: a player, a vehicle or false if nobody.
weaponint
Weapon number or cause of death.
bodypartint
The body part hit by the last shot.
stealthbool
true for a silent knife kill from behind.

Differences from MTA:SA

  • These MTA:SA parameters are not here: int animGroup, int animID

In MTA:SA

function(int totalAmmo, element killer, int killerWeapon, int bodypart, bool stealth, int animGroup, int animID)

Source

source is the player who died.

Example

A kill message in chat and back into the game after 5 seconds.

addEventHandler("onPlayerWasted", root, function(ammo, killer, weapon)
    local victim = getPlayerName(source)
    if killer and getElementType(killer) == "player" and killer ~= source then
        outputChatBox(getPlayerName(killer) .. " killed " .. victim .. ".")
        givePlayerMoney(killer, 100)
    else
        outputChatBox(victim .. " died.")
    end
    setTimer(spawnPlayer, 5000, 1, source, 2495.3, -1687.0, 13.5)
end)

Notes

Also after a scripted death. The event also arrives after killPed(player) and setElementHealth(player, 0).

See also