ServersYour serverFor creatorsForumFAQDocumentationSecurity
Download the launcher
  1. Documentation
  2. Server functions
  3. killPed

Function

killPed

ServerPedsIdentical to MTA:SA

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 = false
true = 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