GetWeaponState: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
m (Some minor grammar fix at →‎Returns)
 
Line 13: Line 13:
* A [[string]] if the [[Element/Weapon|weapon]] is valid, indicating the weapon state, which can be:
* A [[string]] if the [[Element/Weapon|weapon]] is valid, indicating the weapon state, which can be:
** '''reloading''': the weapon is reloading.
** '''reloading''': the weapon is reloading.
** '''firing''': the weapon will constantly fire (unless any shooting blocking flags are set) according to its assigned firing rate.
** '''firing''': the weapon is constantly shooting (unless any shooting blocking flags are set) according to its assigned firing rate.
** '''ready''': the weapon is idle.
** '''ready''': the weapon is idle.
* ''false'' if an error occured or the [[Element/Weapon|weapon]] is invalid.
* ''false'' if an error occured or the [[Element/Weapon|weapon]] is invalid.

Latest revision as of 17:50, 23 December 2014

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)

Requirements

Minimum server version n/a
Minimum client version 1.3.0-9.04555

Note: Using this feature requires the resource to have the above minimum version declared in the meta.xml <min_mta_version> section. e.g. <min_mta_version client="1.3.0-9.04555" />

See also