KillPed: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(New page: {{Server function}} __NOTOC__ This function kills the specified ped. ==Syntax== <syntaxhighlight lang="lua">bool killPed ( ped thePed, [ ped theKiller = nil, int weapon=255, int bodyPart=255, bool steal...)
 
m (→‎Optional Arguments: dp3 -> 1.0)
Line 13: Line 13:
* '''weapon:''' The ID of the weapon that should appear to have killed the ped (doesn't affect how they die)
* '''weapon:''' The ID of the weapon that should appear to have killed the ped (doesn't affect how they die)
* '''bodyPart:''' The ID of the body part that should appear to have been hit by the weapon (doesn't affect how they die)
* '''bodyPart:''' The ID of the body part that should appear to have been hit by the weapon (doesn't affect how they die)
* '''stealth:''' Boolean value, representing whether or not this a stealth kill ('''From DP3''')
* '''stealth:''' Boolean value, representing whether or not this a stealth kill ('''From 1.0''')


===Returns===
===Returns===

Revision as of 07:55, 19 March 2009

This function kills the specified ped.

Syntax

bool killPed ( ped thePed, [ ped theKiller = nil, int weapon=255, int bodyPart=255, bool stealth ] )

Required Arguments

  • thePed: The ped to kill

Optional Arguments

  • theKiller: The ped responsible for the kill
  • weapon: The ID of the weapon that should appear to have killed the ped (doesn't affect how they die)
  • bodyPart: The ID of the body part that should appear to have been hit by the weapon (doesn't affect how they die)
  • stealth: Boolean value, representing whether or not this a stealth kill (From 1.0)

Returns

Returns true if the ped was killed, false if the ped specified could not be killed or is invalid.

Example

Example 1: This simple example adds a kill command to commit suicide.

function commitSuicide ( sourcePlayer )
	-- kill the player and make him responsible for it
	killPed ( sourcePlayer, sourcePlayer )
end
-- attach our handler to the "kill" command
addCommandHandler ( "kill", commitSuicide )

Example 2: This example enables 1 hit kills if a player is shot in the head.

function headshotKill ( attacker, attackerweapon, bodypart, loss )
	if bodypart == 9 then --if the bodypart is the head
		--kill the player, emulating the correct killer, weapon and bodypart.
		killPed ( source, attacker, attackerweapon, bodypart )
	end
end
addEventHandler ( "onPlayerDamage", getRootElement(), headshotKill )

See Also