OnPlayerWasted: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
(Add beta header)
 
(11 intermediate revisions by 9 users not shown)
Line 4: Line 4:


==Parameters==
==Parameters==
{{New feature/item|3|1.0||<syntaxhighlight lang="lua">
{{New feature/item|3.0161|1.6.0|22620|
<syntaxhighlight lang="lua">
int totalAmmo, element killer, int killerWeapon, int bodypart, bool stealth, int animGroup, int animID
</syntaxhighlight>
}}
 
{{Deprecated_feature|3|1.0|<syntaxhighlight lang="lua">
int totalAmmo, element killer, int killerWeapon, int bodypart, bool stealth
int totalAmmo, element killer, int killerWeapon, int bodypart, bool stealth
</syntaxhighlight>}}
</syntaxhighlight>}}
Line 12: Line 18:
</syntaxhighlight>}}
</syntaxhighlight>}}


*'''totalAmmo''': an integer representing the total ammo the victim had when he died.
*'''totalAmmo''': an [[int]] representing the total ammo the victim had when they died.
*'''killer''': an [[element]] representing the player or vehicle who was the killer. If there was no killer this is ''false''.
*'''killer''': an [[element]] representing the [[player]], [[ped]], [[vehicle]] or [[object]] who was the killer. Deaths resulting from fall damage provide the [[vehicle]] or [[object]] landed on as the killer. If there is no killer this is ''false''.
*'''killerWeapon''': an integer representing the [[Weapons|killer weapon]] or the [[Damage Types|damage type]].
*'''killerWeapon''': an [[int]] representing the [[Weapons|killer weapon]] or the [[Damage Types|damage type]].
*'''bodypart''': an integer representing the bodypart ID the victim was hit on when he died.
*'''bodypart''': an [[int]] representing the bodypart ID the victim was hit on when they died.
{{BodyParts}}
{{BodyParts}}
*{{New feature/item|3|1.0||'''stealth''': boolean value representing whether or not this was a stealth kill}}
*'''stealth''': a [[boolean]] value representing whether or not this was a stealth kill.
{{New feature/item|3.0161|1.6.0|22620|
*'''animGroup''': an [[int|integer]] representing the player's current animation group.
}}
{{New feature/item|3.0161|1.6.0|22620|
*'''animID''': an [[int|integer]] representing the player's current animation ID.
}}
 


==Source==
==Source==
Line 55: Line 68:
end
end
end
end
addEventHandler ( "onPlayerWasted", getRootElement(), player_Wasted )
addEventHandler ( "onPlayerWasted", root, player_Wasted )
</syntaxhighlight>
</syntaxhighlight>


Line 61: Line 74:
And another example, this will spawn you in the middle of GTA SA world (x=0, y=0, z=3) after 2 seconds of your death
And another example, this will spawn you in the middle of GTA SA world (x=0, y=0, z=3) after 2 seconds of your death
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addEventHandler( "onPlayerWasted", getRootElement( ),
addEventHandler( "onPlayerWasted", root,
function()
function()
setTimer( spawnPlayer, 2000, 1, source, 0, 0, 3 )
setTimer( spawnPlayer, 2000, 1, source, 0, 0, 3 )
Line 67: Line 80:
)
)
</syntaxhighlight>
</syntaxhighlight>
<section name="Example 1" class="server" show="true">
This Example is a script for Tactics Servers , the script giving the killer health as a reward for killing.
<syntaxhighlight lang="lua">
function GiveHealth(ammo, killer, killerweapon, bodypart)
if ( killer ) and ( killer ~= source ) and ( (getElementHealth(killer)) ~= 100 ) --Here we have selcted that who will be gave a health is the killer
setElementHealth(killer, (getElementHealth(killer)) + 20) --He will get +20 health, if you want to reward him by sitting him health 100 you can just type 100 after (killer,
outputChatBox("#ff0000[ Server ] : #ffff00You Have Got Health +20",killer,255,0,0,true) --out put chat box for the killer
end      --End if
end      --End function
addEventHandler("onPlayerWasted", getRootElement(), GiveHealth)
</syntaxhighlight>
</section>


{{See also/Server event|Player events}}
{{See also/Server event|Player events}}
[[ru:onPlayerWasted]]

Latest revision as of 21:00, 15 July 2024

This event is triggered when a player is killed or dies.

Parameters

ADDED/UPDATED IN VERSION 1.6.0 r22620:
int totalAmmo, element killer, int killerWeapon, int bodypart, bool stealth, int animGroup, int animID
  • totalAmmo: an int representing the total ammo the victim had when they died.
  • killer: an element representing the player, ped, vehicle or object who was the killer. Deaths resulting from fall damage provide the vehicle or object landed on as the killer. If there is no killer this is false.
  • killerWeapon: an int representing the killer weapon or the damage type.
  • bodypart: an int representing the bodypart ID the victim was hit on when they died.
  • 3: Torso
  • 4: Ass
  • 5: Left Arm
  • 6: Right Arm
  • 7: Left Leg
  • 8: Right Leg
  • 9: Head
  • stealth: a boolean value representing whether or not this was a stealth kill.
ADDED/UPDATED IN VERSION 1.6.0 r22620:
  • animGroup: an integer representing the player's current animation group.
ADDED/UPDATED IN VERSION 1.6.0 r22620:
  • animID: an integer representing the player's current animation ID.


Source

The source of this event is the player that died or got killed.

Example

This example prints the killer and bodypart to the chat when a player dies.

-- register player_Wasted as a handler for onPlayerWasted
function player_Wasted ( ammo, attacker, weapon, bodypart )
	-- if there was an attacker
	if ( attacker ) then
		-- we declare our variable outside the following checks
		local tempString
		-- if the element that killed him was a player,
		if ( getElementType ( attacker ) == "player" ) then
			-- put the attacker, victim and weapon info in the string
			tempString = getPlayerName ( attacker ).." killed "..getPlayerName ( source ).." ("..getWeaponNameFromID ( weapon )..")"
		-- else, if it was a vehicle,
		elseif ( getElementType ( attacker ) == "vehicle" ) then
			-- we'll get the name from the attacker vehicle's driver
			tempString = getPlayerName ( getVehicleController ( attacker ) ).." killed "..getPlayerName ( source ).." ("..getWeaponNameFromID ( weapon )..")"
		end
		-- if the victim was shot in the head, append a special message
		if ( bodypart == 9 ) then
			tempString = tempString.." (HEADSHOT!)"
		-- else, just append the bodypart name
		else
			tempString = tempString.." ("..getBodyPartName ( bodypart )..")"
		end
		-- display the message
		outputChatBox ( tempString )
	-- if there was no attacker,
	else
		-- output a death message without attacker info
		outputChatBox ( getPlayerName ( source ).." died. ("..getWeaponNameFromID ( weapon )..") ("..getBodyPartName ( bodypart )..")" )
	end
end
addEventHandler ( "onPlayerWasted", root, player_Wasted )


And another example, this will spawn you in the middle of GTA SA world (x=0, y=0, z=3) after 2 seconds of your death

addEventHandler( "onPlayerWasted", root,
	function()
		setTimer( spawnPlayer, 2000, 1, source, 0, 0, 3 )
	end
)

See Also

Player events


Event functions