GetWeaponState: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(Added OOP syntax and improved the example)
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 ( weapon theWeapon )</syntaxhighlight>
<syntaxhighlight lang="lua">string getWeaponState ( weapon theWeapon )</syntaxhighlight>


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


===Returns===
===Returns===
* A [[string]] indicating the weapon state.
* 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 will constantly fire (unless any shooting blocking flags are set) according to its assigned firing rate.
** '''ready''': the weapon is idle
** '''ready''': the weapon is idle.
* ''false'' otherwise.
* ''false'' if an error occured or the [[Element/Weapon|weapon]] is invalid.
 
==Example==
==Example==
This command will block players from reloading while they are still reloading
This example creates a gun where the local player is and informs any player about its state.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">local function testWeaponState()
addCommandHandler ( "reload",
    local weapon = createWeapon("m4", getElementPosition(localPlayer)) -- Create the weapon
    function ( thePlayer )
    outputChatBox("The weapon that has just been created state is " .. getWeaponState(weapon) .. ".") -- Tell the player its state
        if ( getWeaponState ( getPedWeapon ( thePlayer ) ) == "reloading" ) then
end
            outputChatBox ( "You are still reloading...", thePlayer )
addEventHandler("onClientResourceStart", resourceRoot, testWeaponState)
            return
        end
        reloadPedWeapon ( thePlayer )
    end
)
</syntaxhighlight>
</syntaxhighlight>


Line 32: Line 28:
{{Requirements|n/a|1.3.0-9.04555|}}
{{Requirements|n/a|1.3.0-9.04555|}}


==See Also==
==See also==
{{Client weapon creation functions}}
{{Client weapon creation functions}}

Revision as of 16:22, 23 December 2014

This function gets the state of a custom weapon.

Syntax

string getWeaponState ( weapon theWeapon )

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 will constantly fire (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

This template will be deleted.

See also