SetWeaponFlags: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (Removed Needs example template)
 
(3 intermediate revisions by the same user not shown)
Line 5: Line 5:


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


Line 17: Line 17:
*** '''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''.
*** '''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 [[object|objects]].  
*** '''checkObjects''': allows the shoot to be blocked by [[object|objects]].  
*** '''checkPeds''': allosw the shoot to be blocked by [[ped|peds]] and [[player|players]].  
*** '''checkPeds''': allows the shoot to be blocked by [[ped|peds]] and [[player|players]].  
*** '''checkVehicles''': allows the shoot to be blocked by [[vehicle|vehicles]].  
*** '''checkVehicles''': allows the shoot to be blocked by [[vehicle|vehicles]].  
*** '''checkSeeThroughStuff''': allows the shoot to be blocked by translucent game objects, e.g. glass.  
*** '''checkSeeThroughStuff''': allows the shoot to be blocked by translucent game objects, e.g. glass.  
Line 23: Line 23:
** '''instant_reload''': if enabled, the weapon will reload instantly rather than waiting the reload time until shooting again.
** '''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_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.
** '''shoot_if_blocked''': if enabled, the weapon will still fire its target even if it's blocked by something.
* '''enable''': whether to enable or disable the specified flag.
* '''enable''': whether to enable or disable the specified flag.


Line 33: Line 33:
<syntaxhighlight lang="lua">local function setupDeadlyWeapon()
<syntaxhighlight lang="lua">local function setupDeadlyWeapon()
     local weapon = createWeapon("minigun", 0, 0, 10) -- Create the minigun
     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
     setWeaponTarget(weapon, localPlayer) -- Set the weapon target to the local player
     setWeaponFlags(weapon, "flags", false, false, false, false, false, false, false, false) -- Allow the weapon to shoot through everything
     setWeaponFlags(weapon, "flags", false, false, false, false, false, false, false, false) -- Allow the weapon to shoot through everything
end
end

Latest revision as of 18:21, 23 December 2014

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, bool 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: allows 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: if 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) -- Set the weapon target to 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

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" />

Issues

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

See also