RU/GetWeaponIDFromName: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
m (Redirected page to RU/getWeaponIDFromName)
 
Line 1: Line 1:
__NOTOC__
#REDIRECT [[RU/getWeaponIDFromName]]
{{RU/Server client function}}
This function will obtain the ID of a particular weapon from its name.
 
==Syntax==
<syntaxhighlight lang="lua">
int getWeaponIDFromName ( string name )           
</syntaxhighlight>
 
===Required Arguments===
*'''name:''' A [[string]] containing the name of the weapon.
 
===Returns===
Returns an [[int]] if the name matches that of a weapon, ''false'' otherwise.
 
==Example==
<section name="Server" class="server" show="true">
This example will give the player the weapon they specify 20 ammo whenever they type "weapon ''name''" into the console.
<syntaxhighlight lang="lua">
-- Define our function that will handle this command
function consoleGiveWeapon ( playerSource, commandName, weapName )
-- If a player triggered it (rather than the admin) then
if ( playerSource ) then
-- Get the weapon ID from the name
local weapID = getWeaponIDFromName ( weapName )
-- If it's a valid weapon
if ( weapID ) then
-- Give the weapon to the player
giveWeapon ( playerSource, weapID, 20 )
-- Output it in the chat box
outputChatBox ( "You got a " .. weapName, playerSource )
else outputChatBox ( "Invalid weapon name." )
end
end
end
-- Register the command handler and attach it to the 'consoleGiveWeapon' function
addCommandHandler ( "weapon", consoleGiveWeapon )
</syntaxhighlight>
</section>
 
==See Also==
{{RU/Weapon functions}}

Latest revision as of 08:46, 30 September 2014