KillPlayer: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(Replaced example)
Line 18: Line 18:


==Example==
==Example==
This simple example adds a '''kill''' command to commit suicide.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
-- Get the player with an ID of 1
function commitSuicide(sourcePlayer)
thePlayer = getPlayerFromID ( 1 )
-- kill the player and make him responsible for it
-- If a player was found with an ID of 1 then
killPlayer(sourcePlayer, sourcePlayer)
if ( thePlayer ) then
-- Kill the player
if ( killPlayer ( thePlayer ) ) then
-- Inform everyone that they were killed.
outputChatBox ( getPlayerName ( thePlayer ) .. " was eliminated." )
end
end
end
-- attach our handler to the "kill" command
addCommandHandler("kill", commitSuicide)
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{Player functions}}
{{Player functions}}

Revision as of 17:33, 26 August 2007

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

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)

See Also