SetWeaponFlags: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Added an example section and added this function to "Needs Example" template.)
(Improved the page a lot)
Line 2: Line 2:
{{Client function}}
{{Client function}}
{{Needs_Example}}
{{Needs_Example}}
Set a custom weapons flags.
This function sets a [[Element/Weapon|custom weapon]] flags, used to change how it behaves or finds a possible target to shoot.
 
{{Note|Do not confuse this function with [[setWeaponProperty]]. Although [[setWeaponProperty]] works with player-held weapons and custom weapons (in a limited extent), this function does not work with player-held weapons.}}
'''Note:''' This is not the same as [[setWeaponProperty]]. These flags are different and can only be set for custom weapon types. You cannot set these flags for 'normal' weapons. This is true despite the ability in setWeaponProperty to set any number of supported [[Weapon Flags]].


==Syntax==
==Syntax==
<syntaxhighlight lang="lua">bool setWeaponFlags ( weapon theWeapon, string theFlag, value theValue )</syntaxhighlight>
<syntaxhighlight lang="lua">bool setWeaponFlags ( weapon theWeapon, string theFlag, boolean enable )</syntaxhighlight>
{{OOP||[[Element/Weapon|weapon]]:setFlags||getWeaponFlags}}


===Required Arguments===
===Required Arguments===
* '''theWeapon:''' the weapon to set the flag of
* '''theWeapon:''' the [[Element/Weapon|weapon element]] to set the flag of.
* '''theFlag:''' the weapon flag to set:
* '''theFlag:''' the weapon flag to change (all of them can be ''true'' or ''false''):
** bool disable_model disable the weapon model of the weapon
** '''disable_model''': makes the weapon and muzzle effect invisible or not.
** flags edit the processLineOfSight flags used to find the hit position
** '''flags''': configures the flags used to get where the gun shoots at. They are based on [[processLineOfSight]]'s. You have to specify all the eight flags for the function to succeed. These flags are (by order):
** bool checkBuildings
*** '''checkBuildings''': allows the shoot to be blocked by GTA's internally placed buildings, i.e. the world map.
** bool checkCarTires
*** '''checkCarTires''': allows the shoot to be blocked by [[vehicle]] tires.
** bool checkDummies
*** '''checkDummies''': allows the shoot to be blocked by GTA's internal dummies. These are not used in the current MTA version so this argument can be set to ''false''.
** bool checkObjects
*** '''checkObjects''': allows the shoot to be blocked by [[object|objects]].
** bool checkPeds
*** '''checkPeds''': allosw the shoot to be blocked by [[ped|peds]] and [[player|players]].
** bool checkVehicles
*** '''checkVehicles''': allows the shoot to be blocked by [[vehicle|vehicles]].
** bool checkSeeThroughStuff
*** '''checkSeeThroughStuff''': allows the shoot to be blocked by translucent game objects, e.g. glass.
** bool checkShootThroughStuff
*** '''checkShootThroughStuff''': allows the shoot to be blocked by things that can be shot through.
** bool instant_reload reload the weapon instantly rather than doing a reload
** '''instant_reload''': if enabled, the weapon will reload instantly rather than waiting the reload time until shooting again.
** bool shoot_if_out_of_range shoot the target position if out of weapon range
** '''shoot_if_out_of_range''': if enabled, the weapon will still fire its target beyond the weapon range distance.
** bool shoot_if_blocked shoot the target position if blocked
** '''shoot_if_blocked''': is enabled, the weapon will still fire its target even if it's blocked by something.
* '''theValue:''' the value to set
* '''enable''': whether to enable or disable the specified flag.


===Returns===
===Returns===
Returns ''true'' on success (flags have 8 values), ''false'' otherwise.
Returns ''true'' if all arguments are valid and the flags where changed; ''false'' otherwise.


==Example==
==Example==
<syntaxhighlight lang="lua">--TODO</syntaxhighlight>
This example creates a minigun that will kill any player who approaches the center of the map, no matter if he takes cover or not.
<syntaxhighlight lang="lua">local function setupDeadlyWeapon()
    local weapon = createWeapon("minigun", 0, 0, 10) -- Create the minigun
    setWeaponTarget(weapon, localPlayer, 8) -- Set the weapon target to the head of the local player
    setWeaponFlags(weapon, "flags", false, false, false, false, false, false, false, false) -- Allow the weapon to shoot through everything
end
addEventHandler("onClientResourceStart", resourceRoot, setupDeadlyWeapon)</syntaxhighlight>


==Requirements==
==Requirements==
{{Requirements|n/a|1.3.0-9.04555|}}
{{Requirements|n/a|1.3.0-9.04555|}}


==See Also==
==Issues==
{{Deprecated items|3.0141|1.4.1|{{Issues|{{Issue|8686|setWeaponFlags(weapon, "flags") always returns false, but getWeaponFlags(weapon, "flags") works correctly}}}}}}
 
==See also==
{{Client weapon creation functions}}
{{Client weapon creation functions}}
sets the flags of the weapon ( used to determine what to hit )

Revision as of 15:53, 23 December 2014

Accessories-text-editor.png Script Example Missing Function SetWeaponFlags needs a script example, help out by writing one.

Before submitting check out Editing Guidelines Script Examples.

This function sets a custom weapon flags, used to change how it behaves or finds a possible target to shoot.

[[{{{image}}}|link=|]] Note: Do not confuse this function with setWeaponProperty. Although setWeaponProperty works with player-held weapons and custom weapons (in a limited extent), this function does not work with player-held weapons.

Syntax

bool setWeaponFlags ( weapon theWeapon, string theFlag, boolean enable )

OOP Syntax Help! I don't understand this!

Method: weapon:setFlags(...)
Counterpart: getWeaponFlags


Required Arguments

  • theWeapon: the weapon element to set the flag of.
  • theFlag: the weapon flag to change (all of them can be true or false):
    • disable_model: makes the weapon and muzzle effect invisible or not.
    • flags: configures the flags used to get where the gun shoots at. They are based on processLineOfSight's. You have to specify all the eight flags for the function to succeed. These flags are (by order):
      • checkBuildings: allows the shoot to be blocked by GTA's internally placed buildings, i.e. the world map.
      • checkCarTires: allows the shoot to be blocked by vehicle tires.
      • checkDummies: allows the shoot to be blocked by GTA's internal dummies. These are not used in the current MTA version so this argument can be set to false.
      • checkObjects: allows the shoot to be blocked by objects.
      • checkPeds: allosw the shoot to be blocked by peds and players.
      • checkVehicles: allows the shoot to be blocked by vehicles.
      • checkSeeThroughStuff: allows the shoot to be blocked by translucent game objects, e.g. glass.
      • checkShootThroughStuff: allows the shoot to be blocked by things that can be shot through.
    • instant_reload: if enabled, the weapon will reload instantly rather than waiting the reload time until shooting again.
    • shoot_if_out_of_range: if enabled, the weapon will still fire its target beyond the weapon range distance.
    • shoot_if_blocked: is enabled, the weapon will still fire its target even if it's blocked by something.
  • enable: whether to enable or disable the specified flag.

Returns

Returns true if all arguments are valid and the flags where changed; false otherwise.

Example

This example creates a minigun that will kill any player who approaches the center of the map, no matter if he takes cover or not.

local function setupDeadlyWeapon()
    local weapon = createWeapon("minigun", 0, 0, 10) -- Create the minigun
    setWeaponTarget(weapon, localPlayer, 8) -- Set the weapon target to the head of the local player
    setWeaponFlags(weapon, "flags", false, false, false, false, false, false, false, false) -- Allow the weapon to shoot through everything
end
addEventHandler("onClientResourceStart", resourceRoot, setupDeadlyWeapon)

Requirements

This template will be deleted.

Issues

BEFORE VERSION 1.4.1 :
Issue ID Description
#8686 setWeaponFlags(weapon, "flags") always returns false, but getWeaponFlags(weapon, "flags") works correctly

See also