OnClientPlayerWasted: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Killer element type)
m (Using predefined variables in "Example" code)
 
Line 20: Line 20:
This example outputs a mocking message when the local player dies.
This example outputs a mocking message when the local player dies.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
messages = {  
local messages = {
"Better luck next time",
"Better luck next time",
"Don't think you're so cool now, do you?",
"Don't think you're so cool now, do you?",
"Nice one, pal",
"Nice one, pal",
"Your opinion is void"  
"Your opinion is void"
}
}


function wastedMessage ( killer, weapon, bodypart )
-- add an event for the local player only
local randomID = math.random ( 1, #messages ) --get a random ID from the table
addEventHandler("onClientPlayerWasted", localPlayer, function(killer, weapon, bodyPart)
local randomMessage = messages[randomID] --use that to retrieve a message
local randomMessage = messages[math.random(#messages)] -- get a random message from the table
outputChatBox ( randomMessage, 255, 0, 0 ) --output the message
outputChatBox(randomMessage, 255, 0, 0) -- output the message
end
end)
addEventHandler ( "onClientPlayerWasted", getLocalPlayer(), wastedMessage ) --add an event for the local player only
</syntaxhighlight>
</syntaxhighlight>



Latest revision as of 11:22, 27 June 2023

This event is triggered whenever a player, including those remote, dies.

Parameters

element killer, int weapon, int bodypart, bool stealth
  • 3: Torso
  • 4: Ass
  • 5: Left Arm
  • 6: Right Arm
  • 7: Left Leg
  • 8: Right Leg
  • 9: Head
  • stealth: A boolean representing whether or not this was a stealth kill.

Source

The source of this event is the player that died.

Example

This example outputs a mocking message when the local player dies.

local messages = {
	"Better luck next time",
	"Don't think you're so cool now, do you?",
	"Nice one, pal",
	"Your opinion is void"
}

-- add an event for the local player only
addEventHandler("onClientPlayerWasted", localPlayer, function(killer, weapon, bodyPart)
	local randomMessage = messages[math.random(#messages)] -- get a random message from the table
	outputChatBox(randomMessage, 255, 0, 0) -- output the message
end)

See Also

Client player events


Client event functions

Shared