OnPlayerWasted: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
(14 intermediate revisions by 10 users not shown) | |||
Line 3: | Line 3: | ||
This event is triggered when a player is killed or dies. | This event is triggered when a player is killed or dies. | ||
==Parameters== | |||
{{New feature/item|3|1.0||<syntaxhighlight lang="lua"> | |||
int totalAmmo, element killer, int killerWeapon, int bodypart, bool stealth | |||
</syntaxhighlight>}} | |||
{{Deprecated_feature|3|1.0|<syntaxhighlight lang="lua"> | |||
int totalAmmo, element killer, int killerWeapon, int bodypart | |||
</syntaxhighlight>}} | |||
*'''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''. | |||
*'''killerWeapon''': an [[int]] representing the [[Weapons|killer weapon]] or the [[Damage Types|damage type]]. | |||
*'''bodypart''': an [[int]] representing the bodypart ID the victim was hit on when they died. | |||
{{BodyParts}} | |||
*'''stealth''': a [[boolean]] value representing whether or not this was a stealth kill. | |||
==Source== | ==Source== | ||
The [[event system#Event source|source]] of this event is the [[player]] that died or got killed. | The [[event system#Event source|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. | |||
<syntaxhighlight lang="lua"> | |||
-- 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", getRootElement(), player_Wasted ) | |||
</syntaxhighlight> | |||
end | |||
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"> | |||
addEventHandler( "onPlayerWasted", getRootElement( ), | |||
function() | |||
setTimer( spawnPlayer, 2000, 1, source, 0, 0, 3 ) | |||
end | |||
) | |||
</syntaxhighlight> | |||
{{See also/Server event|Player events}} |
Revision as of 03:03, 27 September 2018
This event is triggered when a player is killed or dies.
Parameters
int totalAmmo, element killer, int killerWeapon, int bodypart, bool stealth
- 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.
- 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.
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", getRootElement(), 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", getRootElement( ), function() setTimer( spawnPlayer, 2000, 1, source, 0, 0, 3 ) end )
See Also
Player events
- onPlayerACInfo
- onPlayerBan
- onPlayerChangeNick
- onPlayerChat
- onPlayerClick
- onPlayerCommand
- onPlayerConnect
- onPlayerContact
- onPlayerDamage
- onPlayerJoin
- onPlayerLogin
- onPlayerLogout
- onPlayerMarkerHit
- onPlayerMarkerLeave
- onPlayerModInfo
- onPlayerMute
- onPlayerNetworkStatus
- onPlayerPickupHit
- onPlayerPickupLeave
- onPlayerPickupUse
- onPlayerPrivateMessage
- onPlayerQuit
- onPlayerScreenShot
- onPlayerSpawn
- onPlayerStealthKill
- onPlayerTarget
- onPlayerUnmute
- onPlayerVehicleEnter
- onPlayerVehicleExit
- onPlayerVoiceStart
- onPlayerVoiceStop
- onPlayerWasted
- onPlayerWeaponFire
- onPlayerWeaponSwitch
Event functions
- addEvent
- addEventHandler
- cancelEvent
- cancelLatentEvent
- getCancelReason
- getEventHandlers
- getLatentEventHandles
- getLatentEventStatus
- removeEventHandler
- triggerEvent
- triggerClientEvent
- triggerLatentClientEvent
- wasEventCancelled