GetWeaponState: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(Remove obsolete Requirements section)
 
(22 intermediate revisions by 9 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Client function}}
{{Client function}}
Get the state of the custom weapon.
This function gets the state of a [[Element/Weapon|custom weapon]].


==Syntax==
==Syntax==
<syntaxhighlight lang="lua">string getWeaponState ( theWeapon )</syntaxhighlight>
<syntaxhighlight lang="lua">string getWeaponState ( weapon theWeapon )</syntaxhighlight>
{{OOP||[[Element/Weapon|weapon]]:getState|state|setWeaponState}}


===Required Arguments===
===Required arguments===
* '''theWeapon:''' The weapon to get the target of.
* '''theWeapon:''' the [[Element/Weapon|weapon]] to get the state of.


===Returns===
===Returns===
Returns the ''state'' of the custom weapon, ''false'' otherwise.
* A [[string]] if the [[Element/Weapon|weapon]] is valid, indicating the weapon state, which can be:
** '''reloading''': the weapon is reloading.
** '''firing''': the weapon is constantly shooting (unless any shooting blocking flags are set) according to its assigned firing rate.
** '''ready''': the weapon is idle.
* ''false'' if an error occured or the [[Element/Weapon|weapon]] is invalid.


'''States:'''
==Example==
"reloading" - the weapon is reloading
This example creates a gun where the local player is and informs any player about its state.
** "firing" - the weapon will constantly fire ( unless any shooting blocking flags are set ) according to its assigned firing rate
<syntaxhighlight lang="lua">local function testWeaponState()
** "ready" - the weapon is idle
    local weapon = createWeapon("m4", getElementPosition(localPlayer)) -- Create the weapon
    outputChatBox("The weapon that has just been created state is " .. getWeaponState(weapon) .. ".") -- Tell the player its state
end
addEventHandler("onClientResourceStart", resourceRoot, testWeaponState)
</syntaxhighlight>


==Requirements==
==See also==
{{Requirements|1.3.0-4555|1.3.0-4555|}}
 
==See Also==
{{Client weapon creation functions}}
{{Client weapon creation functions}}

Latest revision as of 17:08, 7 November 2024

This function gets the state of a custom weapon.

Syntax

string getWeaponState ( weapon theWeapon )

OOP Syntax Help! I don't understand this!

Method: weapon:getState(...)
Variable: .state
Counterpart: setWeaponState


Required arguments

  • theWeapon: the weapon to get the state of.

Returns

  • A string if the weapon is valid, indicating the weapon state, which can be:
    • reloading: the weapon is reloading.
    • firing: the weapon is constantly shooting (unless any shooting blocking flags are set) according to its assigned firing rate.
    • ready: the weapon is idle.
  • false if an error occured or the weapon is invalid.

Example

This example creates a gun where the local player is and informs any player about its state.

local function testWeaponState()
    local weapon = createWeapon("m4", getElementPosition(localPlayer)) -- Create the weapon
    outputChatBox("The weapon that has just been created state is " .. getWeaponState(weapon) .. ".") -- Tell the player its state
end
addEventHandler("onClientResourceStart", resourceRoot, testWeaponState)

See also