OnPlayerWasted: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (See Also for server events)
m (→‎Parameters: linked to weapon id list)
Line 10: Line 10:
*'''totalAmmo''': an integer representing the total ammo the victim had when he 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''.
*'''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 victim was hit on when he died.
*'''bodypart''': an integer representing the bodypart ID the victim was hit on when he died.
{{BodyParts}}
{{BodyParts}}

Revision as of 08:18, 24 February 2008

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

Parameters

int totalAmmo, element killer, int killerWeapon, int bodypart
  • 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

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 = 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
addEventHandler ( "onPlayerWasted", getRootElement(), player_Wasted )

See Also

Player events


Event functions