OnPlayerWasted: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 8: Line 8:


==Variables==
==Variables==
* 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 player had when he died
*'''killer''': A player element representing the player who was the killer.  If there was no killer this returns false.
*'''killer''': A player element representing the player who was the killer.  If there was no killer this returns false.

Revision as of 15:27, 2 December 2006

This event is triggered when a player dies.

Syntax

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

Variables

  • The source of this event refers to the player who died.
  • 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