SetWeaponProperty: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
No edit summary
Line 48: Line 48:
This example makes the silenced pistol dual wielded at pro skill level
This example makes the silenced pistol dual wielded at pro skill level
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
setWeaponProperty(23, "pro", "flags", 0x000800)
setWeaponProperty(23, "pro", "flags", 0x000800) -- Warning - Depends on the current flag setting
setWeaponProperty(23, "pro", "flags", 0x000002)
setWeaponProperty(23, "pro", "flags", 0x000002) -- Warning - Depends on the current flag setting
setWeaponProperty(23, "pro", "maximum_clip_ammo", 34)
setWeaponProperty(23, "pro", "maximum_clip_ammo", 34)
</syntaxhighlight>
</syntaxhighlight>
Line 63: Line 63:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
setWeaponProperty("minigun", "pro", "maximum_clip_ammo", 1000)
setWeaponProperty("minigun", "pro", "maximum_clip_ammo", 1000)
</syntaxhighlight>
This turns off auto aim for all weapons
<syntaxhighlight lang="lua">
function setAutoAimForAllWeapons( bEnable )
    weaponList = { "colt 45", "silenced", "deagle", "shotgun", "sawed-off", "combat shotgun", "uzi", "mp5", "ak-47", "m4", "tec-9", "rifle", "sniper", "minigun" }
    for _,weapon in ipairs( weaponList ) do
        for _,skill in ipairs( { "poor", "std", "pro" } ) do
            setWeaponPropertyFlag( weapon, skill, 0x0001, not bEnable )
        end
    end
end
-- Set or clear an individual weapon flag bit
function setWeaponPropertyFlag( weapon, skill, flagBit, bSet )
    local bIsSet = bitAnd( getWeaponProperty(weapon, skill, "flags"), flagBit ) ~= 0
    if bIsSet ~= bSet then
        setWeaponProperty(weapon, skill, "flags", flagBit)
    end
end
-- Turn off auto aim
setAutoAimForAllWeapons( false )
</syntaxhighlight>
</syntaxhighlight>



Revision as of 04:22, 12 February 2014

Click to collapse [-]
setWeaponProperty

This function sets the weapon property of the specified weapons specified weapon type. See lower down the page for documentation related to weapon creation.

Syntax

bool setWeaponProperty ( int weaponID/string weaponName, string weaponSkill, string property, int/float theValue )

Required Arguments

  • weaponID: The ID or name of the weapon you want to set a property of. Names can be:
  • grenade
  • teargas
  • molotov
  • colt 45
  • silenced
  • deagle
  • shotgun
  • sawed-off
  • combat shotgun
  • uzi
  • mp5
  • ak-47
  • m4
  • tec-9
  • rifle
  • sniper
  • rocket launcher
  • rocket launcher hs
  • flamethrower
  • minigun
  • satchel
  • bomb
  • spraycan
  • fire extinguisher
  • camera
  • weaponSkill: Either: "pro", "std" or "poor". The player must have this skill level set to have the effect.
  • property: The property you want to set the value of:
    • "weapon_range" - float
    • "target_range" - float
    • "accuracy" - float
    • "damage" - int Note: Changing the standard M4 stat will change how much damage vehicle guns (e.g: Rustler) do.
    • "maximum_clip_ammo" - int
    • "move_speed" - float
    • "flags" - int (specify a flag to toggle it on/off) See Weapon Flags
    • "anim_loop_start" - float
    • "anim_loop_stop" - float
    • "anim_loop_bullet_fire" - float
    • "anim2_loop_start" - float
    • "anim2_loop_stop" - float
    • "anim2_loop_bullet_fire" - float
    • "anim_breakout_time" - float
  • theValue: The value to set the property to.

Returns

On success:

bool: Returns true if the weapon property was successfully set

On failure:

bool: Returns false if the weapon property was unable to be set

Example

This example sets the weapon range of the M4 at poor skill level to 75

local rangeSet = setWeaponProperty(31, "poor", "weapon_range", 75)
if (rangeSet) then
    outputChatBox("M4 range at poor skill is set now 75!")
end

This example makes the silenced pistol dual wielded at pro skill level

setWeaponProperty(23, "pro", "flags", 0x000800) -- Warning - Depends on the current flag setting
setWeaponProperty(23, "pro", "flags", 0x000002) -- Warning - Depends on the current flag setting
setWeaponProperty(23, "pro", "maximum_clip_ammo", 34)

This examples doubles the range of the colt 45 hand gun

setWeaponProperty(22, "poor", "weapon_range", 70)
setWeaponProperty(22, "std", "weapon_range", 70)
setWeaponProperty(22, "pro", "weapon_range", 70)

This example makes the minigun able to fire all its ammo without the short reload time

setWeaponProperty("minigun", "pro", "maximum_clip_ammo", 1000)

This turns off auto aim for all weapons


function setAutoAimForAllWeapons( bEnable )
    weaponList = { "colt 45", "silenced", "deagle", "shotgun", "sawed-off", "combat shotgun", "uzi", "mp5", "ak-47", "m4", "tec-9", "rifle", "sniper", "minigun" }
    for _,weapon in ipairs( weaponList ) do
        for _,skill in ipairs( { "poor", "std", "pro" } ) do
            setWeaponPropertyFlag( weapon, skill, 0x0001, not bEnable )
        end
    end
end

-- Set or clear an individual weapon flag bit
function setWeaponPropertyFlag( weapon, skill, flagBit, bSet )
    local bIsSet = bitAnd( getWeaponProperty(weapon, skill, "flags"), flagBit ) ~= 0
    if bIsSet ~= bSet then
        setWeaponProperty(weapon, skill, "flags", flagBit)
    end
end

-- Turn off auto aim
setAutoAimForAllWeapons( false )

Requirements

Minimum server version 1.3
Minimum client version n/a
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 server="1.3" />
Click to collapse [-]
setWeaponProperty

Syntax (weapon creation)

bool setWeaponProperty ( weapon theWeapon, string strProperty, value theValue )

Required Arguments

  • theWeapon: the weapon to change the property of.
  • strProperty: the property to edit such as damage per hit ( "damage" ):
    • "weapon_range" - float
    • "target_range" - float
    • "accuracy" - float
    • "damage" - int
    • "maximum_clip_ammo" - int
    • "move_speed" - float
    • "flags" - int (specify a flag to toggle it on/off) See Weapon Flags
    • "anim_loop_start" - float
    • "anim_loop_stop" - float
    • "anim_loop_bullet_fire" - float
    • "anim2_loop_start" - float
    • "anim2_loop_stop" - float
    • "anim2_loop_bullet_fire" - float
    • "anim_breakout_time" - float
  • theValue: whatever you wish to set it to ( different properties use different data types so damage could be an int where as accuracy is a float ).

Sets an individual weapons property. Only a handful of useful properties are supported now and it uses the same property names as setWeaponProperty server side.

Returns true if the property was set.

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