KillPlayer: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(17 intermediate revisions by 12 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
This function kills the specified player. It returns a boolean value (true or false) depending on whether the function passed or failed.
{{Server function}}
{{Deprecated|killPed|}}
 
This function kills the specified player.


==Syntax==
==Syntax==
<syntaxhighlight lang="lua">bool killPlayer ( player thePlayer )</syntaxhighlight>
<syntaxhighlight lang="lua">bool killPlayer ( player thePlayer, [ player theKiller = nil, int weapon=255, int bodyPart=255 ] )</syntaxhighlight>


===Required Arguments===
===Required Arguments===
* '''thePlayer''': A [[player]] object referencing the specified player.
* '''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===
Line 12: Line 20:


==Example==
==Example==
'''Example 1:''' This simple example adds a '''kill''' command to commit suicide.
<syntaxhighlight lang="lua">
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)
</syntaxhighlight>
'''Example 2:''' This example enables 1 hit kills if a player is shot in the head.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
-- Get the player with an ID of 1
function headshotKill ( attacker, attackerweapon, bodypart, loss )
player = getPlayerFromID ( 1 )
if bodypart == 9 then --if the bodypart is the head
-- If a player was found with an ID of 1 then
--kill the player, emulating the correct killer, weapon and bodypart.
if ( player )
killPlayer ( source, attacker, attackerweapon, bodypart )
-- Kill the player
if ( killPlayer ( player ) ) then
-- Inform everyone that they were killed.
outputChatBox ( ( getPlayerName ( player ), " was eliminated." ) )
end
end
end
end
addEventHandler ( "onPlayerDamage", root, headshotKill )
</syntaxhighlight>
</syntaxhighlight>


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

Latest revision as of 07:08, 4 November 2020

Emblem-important.png This function is deprecated. This means that its use is discouraged and that it might not exist in future versions.

Please use killPed instead.


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", root, headshotKill )

See Also