GiveWeapon: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(Undo revision 59055 by Lizzalka (talk))
Line 1: Line 1:
<font face="sans-serif">
__NOTOC__
<div style="background:#333;">
{{Server function}}
<div style="height:4px;background:#AAA;"></div>
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.
<font color="#FFF" size="5">
{{Note|
<p>&nbsp;Ваша версия Adobe Flash Player устарела</p>
*When setting ammo for [[Weapon|weapons in slot]] 0,1,10,11 or 12, the ammo max is 1
</font>
*When setting ammo for [[Weapon|weapons in slot]] 3,4,5, the ammo is added
<div style="background:#FFF;">
*When setting ammo for [[Weapon|weapons in slot]] 2,6,7,8,9 and the slot weapon is changing, the ammo is replaced
<font color="#F00" size="2">
}}
<p>Требуется срочное обновление до текущей версии!</p>
 
</font>
==Syntax==
<font color="#000" size="4">
<syntaxhighlight lang="lua">bool giveWeapon ( ped thePlayer, int weapon [, int ammo=30, bool setAsCurrent=false ] )</syntaxhighlight>
<p>Adobe Flash Player 30.0.0.164 <font color="#888" size="2">(~18 kB)</font></p>
 
</font>
===Required Arguments===
<font color="#444" size="2">
*'''thePlayer:''' A [[player]] or [[ped]] object referencing the specified player (or [[ped]])
<p><b>Операционная система:</b> Windows<br><b>Язык:</b> Выбирает пользователь</p>
*'''weapon:''' A whole number integer that refers to a [[Weapon]] ID. Click [[Weapon|here]] for a list of possible weapon IDs.
</font>
 
<font color="#000" size="4">
===Optional Arguments===
<p>Скачать обновление с Яндекс.Диска: yadi.sk/d/AfbiMAr1PkGdww</p>
{{OptionalArg}}
</font>
*'''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.
</div>
*'''setAsCurrent:''' A boolean value determining whether or not the weapon will be set as the players current.
</div>
 
</font>
===Returns===
Returns ''true'' if weapon was successfully acquired, ''false'' otherwise.
 
==Example==
'''Example 1:''' This example gives a player an M4 with 200 ammo whenever they spawn.
<syntaxhighlight lang="lua">
function giveWeaponsOnSpawn ( theSpawnpont, theTeam )
    giveWeapon ( source, 31, 200 ) -- Gives the M4 weapon with 200 ammo
end
addEventHandler ( "onPlayerSpawn", getRootElement(), giveWeaponsOnSpawn ) -- attach the event handler
</syntaxhighlight>
 
 
'''Example 2:''' This example adds a "give" command in console which allows giving of any weapon by entering "give <id> <amount>".
<syntaxhighlight lang="lua">
function consoleGive ( thePlayer, commandName, weaponID, ammo )
local status = giveWeapon ( thePlayer, weaponID, ammo, true )   -- attempt to give the weapon, forcing it as selected weapon
if ( not status ) then                                          -- if it was unsuccessful
outputConsole ( "Failed to give weapon.", thePlayer )  -- tell the player
end
end
addCommandHandler ( "give", consoleGive )
</syntaxhighlight>
 
 
'''Example 3:''' This example creates a ped in certain coordinates. You can give him a weapon with "give <weaponID> <amount>" command in console.
<syntaxhighlight lang="lua">
ped = createPed( 19, -1634.5775, 1203.85, 7.1796 )
 
addCommandHandler( "give",
  function ( player, command, id, amount )
    if not tonumber ( id ) then return end
 
    if not tonumber ( amount ) then
        amount = 9001
    end
 
    giveWeapon( ped, id, amount, true )
  end
)
</syntaxhighlight>
 
==See Also==
{{Weapon functions}}
[[ru:giveWeapon]]

Revision as of 06:02, 9 September 2018

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.

[[{{{image}}}|link=|]] Note:
  • When setting ammo for weapons in slot 0,1,10,11 or 12, the ammo max is 1
  • When setting ammo for weapons in slot 3,4,5, the ammo is added
  • When setting ammo for weapons in slot 2,6,7,8,9 and the slot weapon is changing, the ammo is replaced

Syntax

bool giveWeapon ( ped thePlayer, int weapon [, int ammo=30, bool setAsCurrent=false ] )

Required Arguments

  • thePlayer: A player or ped object referencing the specified player (or ped)
  • weapon: A whole number integer that refers to a Weapon ID. Click here for a list of possible weapon IDs.

Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.

  • 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.
  • setAsCurrent: A boolean value determining whether or not the weapon will be set as the players current.

Returns

Returns true if weapon was successfully acquired, false otherwise.

Example

Example 1: This example gives a player an M4 with 200 ammo whenever they spawn.

function giveWeaponsOnSpawn ( theSpawnpont, theTeam )
    giveWeapon ( source, 31, 200 ) -- Gives the M4 weapon with 200 ammo
end
addEventHandler ( "onPlayerSpawn", getRootElement(), giveWeaponsOnSpawn ) -- attach the event handler


Example 2: This example adds a "give" command in console which allows giving of any weapon by entering "give <id> <amount>".

function consoleGive ( thePlayer, commandName, weaponID, ammo )
	local status = giveWeapon ( thePlayer, weaponID, ammo, true )   -- attempt to give the weapon, forcing it as selected weapon
	if ( not status ) then                                          -- if it was unsuccessful
		outputConsole ( "Failed to give weapon.", thePlayer )   -- tell the player
	end
end
addCommandHandler ( "give", consoleGive )


Example 3: This example creates a ped in certain coordinates. You can give him a weapon with "give <weaponID> <amount>" command in console.

ped = createPed( 19, -1634.5775, 1203.85, 7.1796 )

addCommandHandler( "give",
  function ( player, command, id, amount )
    if not tonumber ( id ) then return end

    if not tonumber ( amount ) then
        amount = 9001
    end

    giveWeapon( ped, id, amount, true )
  end
)

See Also