GetWeaponNameFromID: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Updated issues)
 
(11 intermediate revisions by 8 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
This function allows you to retrieve the name of a weapon from an ID. Note it also allows you to retrieve the name of other methods of death, such as ''Fall'' and ''Rammed''.
{{Server client function}}
This function allows you to retrieve the name of a weapon from an ID.
{{Note|You can also retrieve the name of other methods of death, such as Fall and Rammed.}}


==Syntax==  
==Syntax==  
Line 11: Line 13:


===Returns===
===Returns===
Returns a string of the name of the weapon, ''false'' otherwise.
Returns a string of the name of the weapon or death type, ''false'' otherwise. Names will be like these: (Ignoring case)
{{All Weapon Types}}


==Example==  
==Example==  
<section name="Server" class="server" show="true">
This example displays a death message in the format of "* ''Killer'' killed ''dead'' (''Weapon'')"
This example displays a death message in the format of "* ''Killer'' killed ''dead'' (''Weapon'')"
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addEventHandler ( "onPlayerWasted", root, "onPlayerWasted" ) --add an event handler for onPlayerWasted
function scriptOnPlayerWasted ( totalammo, killer, killerweapon, bodypart ) --when a player dies
function onPlayerWasted ( totalammo, killer, killerweapon, bodypart ) --when a player dies
local causeOfDeath = getWeaponNameFromID ( killerweapon ) --get the name of 'killerweapon' and define it as 'causeOfDeath'
k3 = getWeaponNameFromID ( killerweapon ) --get the name of the weapon of the 'killerweapon' and define it as 'k3'
local killedPerson = getPlayerName ( source ) --get the name of the player who died and define it as 'killedPerson'
k2 = getClientName ( source ) --get the name of the player who died and define it as 'k2'
if ( killer ) then --if there was a killer
if ( killer ) then --if there was a killer
k1 = getClientName ( killer ) --get the name of the killer and define it as 'k1'
local killerPerson = getPlayerName ( killer ) --get the name of the killer and define it as 'killerPerson'
if killer == source then --if the killer is the same as the person who died i.e. he killed himself
if ( killer == source ) then --if the killer is the same as the person who died i.e. he killed himself
outputChatBox ( "* "..k1.." died ("..k3..")", root, 255, 100, 100 ) --output in the chatbox that  he died and the method he died in the brackets
outputChatBox ( "* "..killerPerson.." died ("..causeOfDeath..")", root, 255, 100, 100 ) --output in the chatbox that  he died and the method he died in the brackets
else --if the killer is not the same as the person who died
else --if the killer is not the same as the person who died
outputChatBox ( "* "..k1.." killed "..k2.." ("..k3..")", root, 255, 100, 100 ) --output in the chatbox that he was killed by the killer and the method in brackets
outputChatBox ( "* "..killerPerson.." killed "..killedPerson.." ("..causeOfDeath..")", root, 255, 100, 100 ) --output in the chatbox that he was killed by the killer and the method in brackets
end
end
else --if there was no killer
else --if there was no killer
outputChatBox ( "* "..k2 .. " died (" ..k3..")", root, 255, 100, 100 ) --output in the chatbox that the dead person died and how he died
outputChatBox ( "* "..killedPerson .. " died (" ..causeOfDeath..")", root, 255, 100, 100 ) --output in the chatbox that the person died and how he died
end
end
end
end
addEventHandler ( "onPlayerWasted", root, scriptOnPlayerWasted ) --add an event handler for onPlayerWasted
</syntaxhighlight>
</syntaxhighlight>
</section>
== Issues ==
{{Issues|
{{Issue|514|getWeaponNameFromID() returns duplicate ID's for 10/11 and 12/13}}
}}


==See Also==
==See Also==
{{Weapon functions}}
{{Weapon functions}}
[[ru:getWeaponNameFromID]]

Latest revision as of 10:19, 30 January 2022

This function allows you to retrieve the name of a weapon from an ID.

[[{{{image}}}|link=|]] Note: You can also retrieve the name of other methods of death, such as Fall and Rammed.

Syntax

string getWeaponNameFromID ( int id )            

Required Arguments

  • id: The ID you wish to retrieve the name of

Returns

Returns a string of the name of the weapon or death type, false otherwise. Names will be like these: (Ignoring case)

  • brassknuckle
  • golfclub
  • nightstick
  • knife
  • bat
  • shovel
  • poolstick
  • katana
  • chainsaw
  • dildo
  • vibrator
  • flower
  • cane
  • grenade
  • teargas
  • molotov
  • colt 45
  • silenced
  • deagle
  • shotgun
  • sawed-off
  • combat shotgun
  • uzi
  • mp5
  • ak-47
  • m4
  • tec-9
  • rifle
  • sniper
  • rocket launcher
  • rocket launcher hs
  • flamethrower
  • minigun
  • satchel
  • bomb
  • spraycan
  • fire extinguisher
  • camera
  • nightvision
  • infrared
  • parachute

Example

Click to collapse [-]
Server

This example displays a death message in the format of "* Killer killed dead (Weapon)"

function scriptOnPlayerWasted ( totalammo, killer, killerweapon, bodypart ) --when a player dies
	local causeOfDeath = getWeaponNameFromID ( killerweapon ) --get the name of 'killerweapon' and define it as 'causeOfDeath'
	local killedPerson = getPlayerName ( source ) --get the name of the player who died and define it as 'killedPerson'
	if ( killer ) then --if there was a killer
	local killerPerson = getPlayerName ( killer ) --get the name of the killer and define it as 'killerPerson'
		if ( killer == source ) then --if the killer is the same as the person who died i.e. he killed himself
			outputChatBox ( "* "..killerPerson.." died ("..causeOfDeath..")", root, 255, 100, 100 ) --output in the chatbox that  he died and the method he died in the brackets
		else --if the killer is not the same as the person who died
			outputChatBox ( "* "..killerPerson.." killed "..killedPerson.." ("..causeOfDeath..")", root, 255, 100, 100 ) --output in the chatbox that he was killed by the killer and the method in brackets
		end
	else --if there was no killer
		outputChatBox ( "* "..killedPerson .. " died (" ..causeOfDeath..")", root, 255, 100, 100 ) --output in the chatbox that the person died and how he died
	end
end
addEventHandler ( "onPlayerWasted", root, scriptOnPlayerWasted ) --add an event handler for onPlayerWasted

Issues

Issue ID Description
#514 getWeaponNameFromID() returns duplicate ID's for 10/11 and 12/13

See Also