KillPlayer: Difference between revisions
Jump to navigation
Jump to search
(Replaced example) |
(added another example) |
||
Line 18: | Line 18: | ||
==Example== | ==Example== | ||
This simple example adds a '''kill''' command to commit suicide. | '''Example 1:''' This simple example adds a '''kill''' command to commit suicide. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function commitSuicide(sourcePlayer) | function commitSuicide(sourcePlayer) | ||
Line 26: | Line 26: | ||
-- attach our handler to the "kill" command | -- attach our handler to the "kill" command | ||
addCommandHandler("kill", commitSuicide) | addCommandHandler("kill", commitSuicide) | ||
</syntaxhighlight> | |||
'''Example 2:''' This example enables 1 hit kills if a player is shot in the head. | |||
<syntaxhighlight lang="lua"> | |||
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 ) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
==See Also== | ==See Also== | ||
{{Player functions}} | {{Player functions}} |
Revision as of 16:47, 29 August 2007
This function kills the specified player.
Syntax
bool killPlayer ( player thePlayer, [ player theKiller = nil, int weapon=255, int bodyPart=255 ] )
Required Arguments
- thePlayer: The player to kill
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
- getPlayerTeam
- getPlayerBlurLevel
- setPlayerBlurLevel
- getPlayerSerial
- forcePlayerMap
- getPlayerScriptDebugLevel
- getPlayerFromName
- getPlayerMoney
- getPlayerName
- getPlayerNametagColor
- getPlayerNametagText
- getPlayerPing
- getPlayerWantedLevel
- givePlayerMoney
- isPlayerMapForced
- isPlayerNametagShowing
- setPlayerHudComponentVisible
- setPlayerMoney
- setPlayerNametagColor
- setPlayerNametagShowing
- setPlayerNametagText
- takePlayerMoney
- countPlayersInTeam
- getPlayersInTeam
- isVoiceEnabled
- setControlState
- getControlState