OnPlayerWasted: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
Body part IDs:
__NOTOC__
* '''3:''' torso
This event is triggered when a player dies.
* '''4:''' between legs and belt
 
* '''5:''' left arm
==Syntax==
* '''6:''' right arm
<syntaxhighlight lang="lua">
* '''7:''' left foot
void onPlayerWasted ( int totalammo, player killer, int killerweapon, int bodypart )       
* '''8:''' right foot
</syntaxhighlight>
* '''9:''' head
 
==Variables==
*'''totalammo''': An integer representing the total ammo the player had when he died
*'''killer''': A player element representing the player who was the killer.  If there was no killer this returns false.
*'''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.
{{BodyParts}}
 
==Example==
This example prints the killer and body part to the chat on the wasted/kill event.
<syntaxhighlight lang="lua">
addEventHandler ( "onPlayerWasted", getElementRoot(), "onPlayerWasted" )
function onPlayerWasted ( ammo, attacker, weapon, bodypart )
  if ( attacker ) then -- if we have an attacker
    if ( getElementType ( attacker ) == "player" ) then -- make sure the element that killed him was a player
      tempString = getClientName ( attacker ).." killed "..getClientName ( source ).." ("..getWeaponNameFromID ( weapon )..")"
      if ( bodypart == 9 ) then -- if he was shot in the head
        tempString = tempString.." (HEADSHOT!)"
      else
        tempString = tempString.." ("..getBodyPartName ( bodypart )..")"
      end
      chat ( tempString )
    else
      chat ( getClientName ( source ).." died. ("..getWeaponNameFromID ( weapon )..") ("..getBodyPartName ( bodypart )..")" )
    end
  else
    chat ( getClientName ( source ).." died. ("..getWeaponNameFromID ( weapon )..") ("..getBodyPartName ( bodypart )..")" )
  end
end
</syntaxhighlight>

Revision as of 23:14, 17 November 2006

This event is triggered when a player dies.

Syntax

void onPlayerWasted ( int totalammo, player killer, int killerweapon, int bodypart )        

Variables

  • totalammo: An integer representing the total ammo the player had when he died
  • killer: A player element representing the player who was the killer. If there was no killer this returns false.
  • 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.
  • 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 body part to the chat on the wasted/kill event.

addEventHandler ( "onPlayerWasted", getElementRoot(), "onPlayerWasted" )
function onPlayerWasted ( ammo, attacker, weapon, bodypart )
  if ( attacker ) then -- if we have an attacker
    if ( getElementType ( attacker ) == "player" ) then -- make sure the element that killed him was a player
      tempString = getClientName ( attacker ).." killed "..getClientName ( source ).." ("..getWeaponNameFromID ( weapon )..")"
      if ( bodypart == 9 ) then -- if he was shot in the head
        tempString = tempString.." (HEADSHOT!)"
      else
        tempString = tempString.." ("..getBodyPartName ( bodypart )..")"
      end
      chat ( tempString )
    else
      chat ( getClientName ( source ).." died. ("..getWeaponNameFromID ( weapon )..") ("..getBodyPartName ( bodypart )..")" )
    end
  else
    chat ( getClientName ( source ).." died. ("..getWeaponNameFromID ( weapon )..") ("..getBodyPartName ( bodypart )..")" )
  end
end