GetWeaponIDFromName: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
Line 17: Line 17:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
-- Define our function that will handle this command
-- Define our function that will handle this command
function consoleGiveWeapon ( playerSource, commandName, params)
function consoleGiveWeapon ( playerSource, commandName, weapName )
-- If a player triggered it (rather than the admin) then
-- If a player triggered it (rather than the admin) then
if ( playerSource )
if ( playerSource )
-- Get the weapon ID from the name
-- Get the weapon ID from the name
weapid = getWeaponIDFromName ( params )
weapID = getWeaponIDFromName ( weapName )
                 -- Give the weapon to the player
                 -- Give the weapon to the player
                 giveWeapon ( playerSource, weapid, 20 )
                 giveWeapon ( playerSource, weapID, 20 )
-- Output it in the chat box
-- Output it in the chat box
outputChatBox ( "You got a " .. params, playerSource )
outputChatBox ( "You got a " .. weapName, playerSource )
end
end
end
end

Revision as of 11:13, 31 July 2007

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 20 ammo whenever they type "weapon name" into the console.

-- 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 )
		-- Get the weapon ID from the name
		weapID = getWeaponIDFromName ( weapName )
                -- Give the weapon to the player
                giveWeapon ( playerSource, weapID, 20 )
		-- Output it in the chat box
		outputChatBox ( "You got a " .. weapName, playerSource )
	end
end
-- Register the command handler and attach it to the 'consoleGiveWeapon' function
addCommandHandler ( "weapon", consoleGiveWeapon )

See Also