GetBodyPartName: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(9 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{{Server client function}}
__NOTOC__
__NOTOC__
This function is used to get the name of a body part on a player.
This function is used to get the name of a body part on a player.
Line 8: Line 9:


===Required Arguments===
===Required Arguments===
*'''bodyPartID''': An interger representing the body part ID you wish to retrieve the name of.
*'''bodyPartID''': An integer representing the body part ID you wish to retrieve the name of.
{{BodyParts}}
{{BodyParts}}


==Returns==
==Returns==
This function returns a string containing the body part name if the ID is valid, 'false' otherwise.
This function returns a string containing the body part name if the ID is valid, ''false'' otherwise.


==Example==
==Example==
This example prints the killer and body part to the chat on the wasted/kill event.
This example prints the killer and body part to the chat on the wasted/kill event.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addEventHandler ( "onPlayerWasted", root, "onPlayerWasted" )
function deathMessageOnWasted ( ammo, attacker, weapon, bodypart )
function onPlayerWasted ( ammo, attacker, weapon, bodypart )
   if ( attacker ) then                                   -- if we have an attacker
   if ( attacker ) then -- if we have an attacker
     if ( getElementType ( attacker ) == "player" ) then   -- make sure the element that killed him was a player
     if ( getElementType ( attacker ) == "player" ) then -- make sure the element that killed him was a player
       tempString = getPlayerName ( attacker ) .. " killed " .. getPlayerName ( source ) .. " (" .. getWeaponNameFromID ( weapon ) .. ")"
       tempString = getClientName ( attacker ).." killed "..getClientName ( source ).." ("..getWeaponNameFromID ( weapon )..")"
       if ( bodypart == 9 ) then -- if he was shot in the head
       if ( bodypart == 9 ) then -- if he was shot in the head
         tempString = tempString.." (HEADSHOT!)"
         tempString = tempString .. " (HEADSHOT!)"
       else
       else
         tempString = tempString.." ("..getBodyPartName ( bodypart )..")"
         tempString = tempString .. " (" .. getBodyPartName ( bodypart ) .. ")"
       end
       end
       chat ( tempString )
       outputChatBox ( tempString )
     else
     else
       chat ( getClientName ( source ).." died. ("..getWeaponNameFromID ( weapon )..") ("..getBodyPartName ( bodypart )..")" )
       outputChatBox ( getPlayerName ( source ) .. " died. (" .. getWeaponNameFromID ( weapon ) .. ") (" .. getBodyPartName ( bodypart ) .. ")" )
     end
     end
   else
   else
     chat ( getClientName ( source ).." died. ("..getWeaponNameFromID ( weapon )..") ("..getBodyPartName ( bodypart )..")" )
     outputChatBox ( getPlayerName ( source ) .. " died. (" .. getWeaponNameFromID ( weapon ) .. ") (" .. getBodyPartName ( bodypart ) .. ")" )
   end
   end
end
end
addEventHandler ( "onPlayerWasted", root, deathMessageOnWasted )
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{Clothes and body functions}}
{{Clothes and body functions}}
[[hu:getBodyPartName]]
[[PL:GetBodyPartName]]

Latest revision as of 21:42, 17 September 2018

This function is used to get the name of a body part on a player.

Syntax

string getBodyPartName ( int bodyPartID )

Required Arguments

  • bodyPartID: An integer representing the body part ID you wish to retrieve the name of.
  • 3: Torso
  • 4: Ass
  • 5: Left Arm
  • 6: Right Arm
  • 7: Left Leg
  • 8: Right Leg
  • 9: Head

Returns

This function returns a string containing the body part name if the ID is valid, false otherwise.

Example

This example prints the killer and body part to the chat on the wasted/kill event.

function deathMessageOnWasted ( 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 = getPlayerName ( attacker ) .. " killed " .. getPlayerName ( source ) .. " (" .. getWeaponNameFromID ( weapon ) .. ")"
      if ( bodypart == 9 ) then -- if he was shot in the head
        tempString = tempString .. " (HEADSHOT!)"
      else
        tempString = tempString .. " (" .. getBodyPartName ( bodypart ) .. ")"
      end
      outputChatBox ( tempString )
    else
      outputChatBox ( getPlayerName ( source ) .. " died. (" .. getWeaponNameFromID ( weapon ) .. ") (" .. getBodyPartName ( bodypart ) .. ")" )
    end
  else
    outputChatBox ( getPlayerName ( source ) .. " died. (" .. getWeaponNameFromID ( weapon ) .. ") (" .. getBodyPartName ( bodypart ) .. ")" )
  end
end
addEventHandler ( "onPlayerWasted", root, deathMessageOnWasted )

See Also