<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.multitheftauto.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Mab</id>
	<title>Multi Theft Auto: Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.multitheftauto.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Mab"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/wiki/Special:Contributions/Mab"/>
	<updated>2026-05-23T14:54:20Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=GiveWeapon&amp;diff=24520</id>
		<title>GiveWeapon</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=GiveWeapon&amp;diff=24520"/>
		<updated>2010-11-11T13:34:54Z</updated>

		<summary type="html">&lt;p&gt;Mab: /* Required Arguments */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__ &lt;br /&gt;
{{Server function}}&lt;br /&gt;
giveWeapon gives a specified weapon to a certain player or ped. There is an optional argument to specify ammunition. For example, a melee weapon doesn't need an ammo argument.&lt;br /&gt;
&lt;br /&gt;
==Syntax== &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;bool giveWeapon ( player thePlayer, int weapon [, int ammo=30, bool setAsCurrent=false ] )&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
===Required Arguments=== &lt;br /&gt;
*'''thePlayer:''' A [[player]] or [[ped]] object referencing the specified player (or [[ped]])&lt;br /&gt;
*'''weapon:''' A whole number integer that refers to a [[Weapon]] ID. Click [[Weapon|here]] for a list of possible weapon IDs.&lt;br /&gt;
&lt;br /&gt;
===Optional Arguments=== &lt;br /&gt;
{{OptionalArg}} &lt;br /&gt;
*'''ammo:''' A whole number integer serving as the ammo amount for the given weapon.  For weapons that do not require ammo, such as melee, this should be at least 1.&lt;br /&gt;
*'''setAsCurrent:''' A boolean value determining whether or not the weapon will be set as the players current.&lt;br /&gt;
&lt;br /&gt;
===Returns=== &lt;br /&gt;
Returns ''true'' if weapon was successfully acquired, ''false'' otherwise.&lt;br /&gt;
&lt;br /&gt;
==Example== &lt;br /&gt;
'''Example 1:''' This example gives a player an M4 with 200 ammo whenever they spawn.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function giveWeaponsOnSpawn ( theSpawnpont, theTeam )&lt;br /&gt;
    giveWeapon ( source, 31, 200 ) -- Gives the M4 weapon with 200 ammo&lt;br /&gt;
end&lt;br /&gt;
addEventHandler ( &amp;quot;onPlayerSpawn&amp;quot;, getRootElement(), giveWeaponsOnSpawn ) -- attach the event handler&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example 2:''' This example adds a &amp;quot;give&amp;quot; command in console which allows giving of any weapon by entering &amp;quot;give &amp;lt;id&amp;gt; &amp;lt;amount&amp;gt;&amp;quot;.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function consoleGive ( thePlayer, commandName, weaponID, ammo )&lt;br /&gt;
	local status = giveWeapon ( thePlayer, weaponID, ammo, true )   -- attempt to give the weapon, forcing it as selected weapon&lt;br /&gt;
	if ( not status ) then                                          -- if it was unsuccessful&lt;br /&gt;
		outputConsole ( &amp;quot;Failed to give weapon.&amp;quot;, thePlayer )   -- tell the player&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
addCommandHandler ( &amp;quot;give&amp;quot;, consoleGive )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example 3:''' This example creates a ped in certain coordinates. You can give him a weapon with &amp;quot;give &amp;lt;weaponID&amp;gt; &amp;lt;amount&amp;gt;&amp;quot; command in console.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
ped = createPed( 19, -1634.5775, 1203.85, 7.1796 );&lt;br /&gt;
&lt;br /&gt;
addCommandHandler( &amp;quot;give&amp;quot;,&lt;br /&gt;
  function ( player, command, id, amount )&lt;br /&gt;
    if not id then return end&lt;br /&gt;
    giveWeapon( ped, id, amount, true )&lt;br /&gt;
  end&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
{{Weapon functions}}&lt;br /&gt;
[[ru:giveWeapon]]&lt;/div&gt;</summary>
		<author><name>Mab</name></author>
	</entry>
</feed>