GetWeaponIDFromName: Difference between revisions
Jump to navigation
Jump to search
JonChappell (talk | contribs) mNo edit summary |
JonChappell (talk | contribs) No edit summary |
||
Line 14: | Line 14: | ||
==Example== | ==Example== | ||
This example | This example will give the player the weapon they specify with 20 ammo whenever they type "weapon ''name''" into the console. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
-- | -- Register the command handler and attach it to the 'consoleGiveWeapon' function | ||
addCommandHandler ( "weapon", "consoleGiveWeapon" ) | |||
-- | -- Define our function that will handle this command | ||
function consoleGiveWeapon ( playerSource, commandName, params) | |||
-- If a player triggered it (rather than the admin) then | |||
if ( playerSource ) | |||
-- Get the weapon ID from the name | |||
weapid = getWeaponIDFromName ( params ) | |||
-- Give the weapon to the player | |||
giveWeapon ( playerSource, weapid, 20 ) | |||
-- Output it in the chat box | |||
outputChatBox ( "You got a " .. params, playerSource ) | |||
end | |||
end | |||
</syntaxhighlight> | </syntaxhighlight> | ||
==See Also== | ==See Also== | ||
{{Weapon functions}} | {{Weapon functions}} | ||
Revision as of 06:02, 3 October 2006
This function will obtain the ID of a particular weapon from its name.
Syntax
int getWeaponIDFromName ( string name )
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
This example will give the player the weapon they specify with 20 ammo whenever they type "weapon name" into the console.
-- Register the command handler and attach it to the 'consoleGiveWeapon' function addCommandHandler ( "weapon", "consoleGiveWeapon" ) -- Define our function that will handle this command function consoleGiveWeapon ( playerSource, commandName, params) -- If a player triggered it (rather than the admin) then if ( playerSource ) -- Get the weapon ID from the name weapid = getWeaponIDFromName ( params ) -- Give the weapon to the player giveWeapon ( playerSource, weapid, 20 ) -- Output it in the chat box outputChatBox ( "You got a " .. params, playerSource ) end end
See Also
- getWeaponProperty
- getPickupWeapon
- getOriginalWeaponProperty
- getSlotFromWeapon
- getWeaponIDFromName
- getWeaponNameFromID
- setWeaponAmmo
- setWeaponProperty