OnPlayerWasted: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
No edit summary
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
This event is triggered when a player dies.
This event is triggered when a player is killed or dies.


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
void onPlayerWasted ( int totalammo, player killer, int killerweapon, int bodypart )         
void onPlayerWasted ( int totalAmmo, element killer, int killerWeapon, int bodypart )         
</syntaxhighlight>  
</syntaxhighlight>  


==Variables==
==Parameters==
* The source of this event refers to the player who died.
* The '''source''' of this event refers to the player who died.
*'''totalammo''': An integer representing the total ammo the player had when he died
*'''totalAmmo''': an integer representing the total ammo the victim had when he died.
*'''killer''': A player element representing the player who was the killer.  If there was no killer this returns false.
*'''killer''': an [[element]] representing the player or vehicle who was the killer.  If there was no killer this is ''false''.
*'''killerweapon''': An integer representing the weapon the killer used to kill the player
*'''killerWeapon''': an integer representing the weapon the killer used to kill the player.
*'''bodypart''': An integer representing the bodypart ID the player was hit on when he died.
*'''bodypart''': an integer representing the bodypart ID the victim was hit on when he died.
{{BodyParts}}
{{BodyParts}}


==Example==  
==Example==  
This example prints the killer and body part to the chat on the wasted/kill event.
This example prints the killer and bodypart to the chat when a player dies.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
-- register player_Wasted as a handler for onPlayerWasted
addEventHandler ( "onPlayerWasted", getElementRoot(), "player_Wasted" )
addEventHandler ( "onPlayerWasted", getElementRoot(), "player_Wasted" )
function player_Wasted ( ammo, attacker, weapon, bodypart )
function player_Wasted ( ammo, attacker, weapon, bodypart )
  if ( attacker ) then -- if we have an attacker
-- if there was an attacker
    if ( getElementType ( attacker ) == "player" ) then -- make sure the element that killed him was a player
if ( attacker ) then
      tempString = getClientName ( attacker ).." killed "..getClientName ( source ).." ("..getWeaponNameFromID ( weapon )..")"
-- we declare our variable outside the following checks
      if ( bodypart == 9 ) then -- if he was shot in the head
local tempString
        tempString = tempString.." (HEADSHOT!)"
-- if the element that killed him was a player,
      else
if ( getElementType ( attacker ) == "player" ) then
        tempString = tempString.." ("..getBodyPartName ( bodypart )..")"
-- put the attacker, victim and weapon info in the string
      end
tempString = getClientName ( attacker ).." killed "..getClientName ( source ).." ("..getWeaponNameFromID ( weapon )..")"
      chat ( tempString )
-- else, if it was a vehicle,
    else
elseif ( getElementType ( attacker ) == "vehicle" ) then
      chat ( getClientName ( source ).." died. ("..getWeaponNameFromID ( weapon )..") ("..getBodyPartName ( bodypart )..")" )
-- we'll get the name from the attacker vehicle's driver
    end
local tempString = getClientName ( getVehicleController ( attacker ) ).." killed "..getClientName ( source ).." ("..getWeaponNameFromID ( weapon )..")"
  else
end
    chat ( getClientName ( source ).." died. ("..getWeaponNameFromID ( weapon )..") ("..getBodyPartName ( bodypart )..")" )
-- if the victim was shot in the head, append a special message
  end
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 ( getClientName ( source ).." died. ("..getWeaponNameFromID ( weapon )..") ("..getBodyPartName ( bodypart )..")" )
end
end
end
</syntaxhighlight>
</syntaxhighlight>
==See also==
{{Event functions}}

Revision as of 19:21, 22 April 2007

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

Syntax

void onPlayerWasted ( int totalAmmo, element killer, int killerWeapon, int bodypart )        

Parameters

  • The source of this event refers to the player who died.
  • totalAmmo: an integer representing the total ammo the victim had when he died.
  • killer: an element representing the player or vehicle who was the killer. If there was no killer this is false.
  • killerWeapon: an integer representing the weapon the killer used to kill the player.
  • bodypart: an integer representing the bodypart ID the victim was hit on when he died.
  • 3: Torso
  • 4: Ass
  • 5: Left Arm
  • 6: Right Arm
  • 7: Left Leg
  • 8: Right Leg
  • 9: Head

Example

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

-- register player_Wasted as a handler for onPlayerWasted
addEventHandler ( "onPlayerWasted", getElementRoot(), "player_Wasted" )
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 = getClientName ( attacker ).." killed "..getClientName ( 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
			local tempString = getClientName ( getVehicleController ( attacker ) ).." killed "..getClientName ( 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 ( getClientName ( source ).." died. ("..getWeaponNameFromID ( weapon )..") ("..getBodyPartName ( bodypart )..")" )
	end
end

See also