Function
killPed
Instantly kills a player or an NPC: sets health to zero and fires the death event (onPlayerWasted for a player, onPedWasted for an NPC) with the given killer, weapon and body part. Scripts that count kills or hand out rewards therefore see the death as if someone really shot the ped. Nothing happens when the ped is already dead.
Syntax
bool killPed(ped ped [, element killer = false, int weapon = false, int bodyPart = false, bool stealth = false])Arguments
pedped- The player or NPC to kill.
killerelement, optional = false- Who did the killing (a player, an NPC or a vehicle). Passed to the death event as the killer.
weaponint, optional = false- Weapon or death-cause ID (e.g. 22 = pistol, 49 = rammed, 51 = explosion) passed to the event.
bodyPartint, optional = false- Body part hit: 3 torso, 4 ass, 5 left arm, 6 right arm, 7 left leg, 8 right leg, 9 head.
stealthbool, optional = falsetrue= a stealth kill (like a knife from behind); passed to the event as the last argument.
Returns
true when the ped died; false when it was already dead or an argument is wrong.
Example
addCommandHandler("zabij", function(admin, _, name)
local target = getPlayerFromName(name or "")
if target then killPed(target, admin, 0, 9) end
end)
See also
setElementHealthSets an element's health.0kills a player or ped and firesonPlayerWasted/onPedWasted.isPedDeadChecks whether a player or an NPC is dead, i.e. has zero health or is lying dead waiting to respawn. On the server it uses the state reported by the player's game; on the client it uses the health seen in this game. A dead player comes back only throughspawnPlayer.