SetWeaponAmmo: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(Remove obsolete Requirements section)
Tag: Manual revert
 
(27 intermediate revisions by 15 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
{{Server function}}  
{{Server client function}}  
{{Needs_Checking|I cant actually think of a use for this function anymore.  giveWeapon is capable of doing everything this function does - and from my testing this function doesnt allow giving ammo to a weapon that shares ammo with another, e.g. giving AK-47 ammo when a player has M4 will not work. --[[User:Talidan2|Talidan2]] 17:06, 29 July 2007 (CDT)}}
<section name="setWeaponAmmo" class="server" show="true">
Sets the ammo to a certain amount for a specified weapon (if they already have it), regardless of current ammo.
Sets the ammo to a certain amount for a specified weapon (if they already have it), regardless of current ammo.


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">bool setWeaponAmmo ( player thePlayer, int weapon, int ammo )</syntaxhighlight>  
<syntaxhighlight lang="lua">bool setWeaponAmmo ( player thePlayer, int weapon, int totalAmmo [, int ammoInClip = 0 ] )</syntaxhighlight>  


===Required Arguments===  
===Required Arguments===  
*'''thePlayer:''' A [[player]] object referencing the specified player   
*'''thePlayer:''' A [[player]] object referencing the specified player   
*'''weapon:''' A whole number integer that refers to a [[weapon]] ID.
*'''weapon:''' A whole number integer that refers to a [[weapon]] ID.
*'''ammo:''' A whole number integer serving as the ammo amount for the given weapon
*'''totalAmmo:''' A whole number integer serving as the total ammo amount for the given weapon (including ammo in clip).
 
===Optional Arguments===
{{OptionalArg}}
*'''ammoInClip:''' The amount of ammo to set in the player's clip.  This will be taken from the main ammo.  If left unspecified or set to 0, the current clip will remain.


==Returns==
==Returns==
Line 16: Line 20:


==Example==   
==Example==   
<section name="Server" class="server" show="true">
This example will give players an M4 weapon with 200 ammo followed by 5 more ammo when they spawn.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function scriptOnSpawnpointUse ( thePlayer )
local randPlayer = getRandomPlayer() -- Get a random player
    giveWeapon ( thePlayer, 31, 200 ) -- Gives the M4 weapon with 200 ammo to any player when they use a spawnpoint
giveWeapon(randPlayer,35,100) -- Give them a rocket launcher with 100 rockets.
    setWeaponAmmo ( thePlayer, 31, 50 ) -- Sets ammo to 50 for the M4
setWeaponAmmo(randPlayer,35,50) -- Decide we're only going to give them 50 rockets.
end
</syntaxhighlight>
addEventHandler ( "onSpawnpointUse", root, scriptOnSpawnpointUse )
</section>
 
<section name="setWeaponAmmo (custom weapons)" class="client" show="true">
Set the ammo of a custom weapon which was created through [[createWeapon]]. By default, a custom weapon has 9999 ammo (which means infinite ammo).
 
==Syntax==
<syntaxhighlight lang="lua">bool setWeaponAmmo ( weapon theWeapon, int ammo )</syntaxhighlight>
{{OOP||[[Element/Weapon|weapon]]:setAmmo|ammo|getWeaponAmmo}}
 
===Required arguments===
* '''theWeapon:''' The weapon to set the ammo of.
* '''ammo:''' The total ammo amount for the given weapon (including ammo in clip).
 
==Returns==
Returns ''true'' on success, ''false'' otherwise.
 
==Example== 
<syntaxhighlight lang="lua">
local weapon = createWeapon ("deagle",0, 0, 10) -- Create the weapon
setWeaponAmmo(weapon,5000)  
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>


==See Also==
==See also==
{{Weapon functions}}
{{Weapon functions}}
{{Client weapon creation functions}}
[[ru:setWeaponAmmo]]

Latest revision as of 15:32, 7 November 2024

Click to collapse [-]
setWeaponAmmo

Sets the ammo to a certain amount for a specified weapon (if they already have it), regardless of current ammo.

Syntax

bool setWeaponAmmo ( player thePlayer, int weapon, int totalAmmo [, int ammoInClip = 0 ] )

Required Arguments

  • thePlayer: A player object referencing the specified player
  • weapon: A whole number integer that refers to a weapon ID.
  • totalAmmo: A whole number integer serving as the total ammo amount for the given weapon (including ammo in clip).

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.

  • ammoInClip: The amount of ammo to set in the player's clip. This will be taken from the main ammo. If left unspecified or set to 0, the current clip will remain.

Returns

Returns a boolean value true or false that tells you if it was successful or not.

Example

local randPlayer = getRandomPlayer() -- Get a random player
giveWeapon(randPlayer,35,100) -- Give them a rocket launcher with 100 rockets.
setWeaponAmmo(randPlayer,35,50) -- Decide we're only going to give them 50 rockets.
Click to collapse [-]
setWeaponAmmo (custom weapons)

Set the ammo of a custom weapon which was created through createWeapon. By default, a custom weapon has 9999 ammo (which means infinite ammo).

Syntax

bool setWeaponAmmo ( weapon theWeapon, int ammo )

OOP Syntax Help! I don't understand this!

Method: weapon:setAmmo(...)
Variable: .ammo
Counterpart: getWeaponAmmo


Required arguments

  • theWeapon: The weapon to set the ammo of.
  • ammo: The total ammo amount for the given weapon (including ammo in clip).

Returns

Returns true on success, false otherwise.

Example

local weapon = createWeapon ("deagle",0, 0, 10) -- Create the weapon
setWeaponAmmo(weapon,5000) 

See also