Difference between revisions of "KillPlayer"

From Multi Theft Auto: Wiki
(Removed 'DP3' things)
Line 5: Line 5:
  
 
==Syntax==
 
==Syntax==
<syntaxhighlight lang="lua">bool killPlayer ( player thePlayer, [ player theKiller = nil, int weapon=255, int bodyPart=255, bool stealth ] )</syntaxhighlight>
+
<syntaxhighlight lang="lua">bool killPlayer ( player thePlayer, [ player theKiller = nil, int weapon=255, int bodyPart=255 ] )</syntaxhighlight>
  
 
===Required Arguments===
 
===Required Arguments===
Line 14: Line 14:
 
* '''weapon:''' The ID of the weapon that should appear to have killed the player (doesn't affect how they die)
 
* '''weapon:''' The ID of the weapon that should appear to have killed the player (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''')
 
  
 
===Returns===
 
===Returns===

Revision as of 07:09, 13 April 2009


Emblem-important.png This function is deprecated. This means that its use is discouraged and that it might not exist in future versions, but there should be a more generic way to perform what it does.

This function kills the specified player.

Syntax

bool killPlayer ( player thePlayer, [ player theKiller = nil, int weapon=255, int bodyPart=255 ] )

Required Arguments

Optional Arguments

  • theKiller: The player responsible for the kill
  • weapon: The ID of the weapon that should appear to have killed the player (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)

Returns

Returns true if the player was killed, false if the player 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
	killPlayer(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.
		killPlayer ( source, attacker, attackerweapon, bodypart )
	end
end
addEventHandler ( "onPlayerDamage", getRootElement(), headshotKill )

See Also

FROM VERSION 1.5.7 r19626 ONWARDS
FROM VERSION 1.5.7 r19626 ONWARDS