SetWeaponProperty: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(Remove obsolete Requirements section)
 
(14 intermediate revisions by 7 users not shown)
Line 1: Line 1:
{{Server client function}}
{{Server client function}}
__NOTOC__
__NOTOC__
<section name="setWeaponProperty" class="server" show="true">
<section name="Server" class="server" show="true">
This function sets the weapon property of the specified weapons specified weapon type. See lower down the page for documentation related to weapon creation.
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==
==Syntax==
<syntaxhighlight lang="lua">bool setWeaponProperty ( int weaponID/string weaponName, string weaponSkill, string property/int property, int/float theValue )</syntaxhighlight>
<syntaxhighlight lang="lua">bool setWeaponProperty ( int weaponID/string weaponName, string weaponSkill, string property, int/float theValue )</syntaxhighlight>


==Required Arguments==
==Required Arguments==
*'''weaponID:''' The ID or name of the [[Weapons|weapon]] you want to set a property of. Names can be:
*'''weaponID:''' The ID or name of the [[Weapons|weapon]] you want to set a property of. Names can be:
{{Weapon Types}}
{{Some Weapon Types}}
*'''weaponSkill:''' Either: "pro", "std" or "poor". The player must have this skill level set to have the effect.
*'''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:
*'''property:''' The property you want to set the value of:
** "weapon_range" - float
{{Weapon Properties Writable}}
** "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:''' The value to set the property to.
*'''theValue:''' The value to set the property to.


Line 36: Line 23:


'''bool:''' Returns false if the weapon property was unable to be set
'''bool:''' Returns false if the weapon property was unable to be set
</section>
<section name="Client" class="client" show="true">
<p>The client side function only applies to custom weapons created client sided.</p>
==Syntax==
<syntaxhighlight lang="lua">bool setWeaponProperty ( weapon theWeapon, string strProperty, value theValue )</syntaxhighlight>
{{OOP||[[Element/Weapon|weapon]]:setProperty||getWeaponProperty}}
==Required Arguments==
* '''theWeapon:''' the weapon to change the property of.
* '''strProperty:''' the property to edit:
{{Custom Weapon Properties Writable}}
* '''theValue:''' The value to set the property to.
==Returns==
Returns ''true'' if the property was set.
</section>


==Example==
==Example==
<section name="Server" class="server" show="true">
This example sets the weapon range of the M4 at poor skill level to 75
This example sets the weapon range of the M4 at poor skill level to 75
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
Line 48: Line 56:
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 65: Line 73:
</syntaxhighlight>
</syntaxhighlight>


==Requirements==
This example turns off auto aim for all weapons
{{Requirements|1.3|n/a|}}
<syntaxhighlight lang="lua">
</section>
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


<section name="setWeaponProperty" class="client" show="true">
-- Set or clear an individual weapon flag bit
==Syntax (weapon creation)==
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


<syntaxhighlight lang="lua">bool setWeaponProperty ( weapon theWeapon, string strProperty, value theValue )</syntaxhighlight>
-- Turn off auto aim
setAutoAimForAllWeapons( false )
</syntaxhighlight>


==Required Arguments==
</section>
 
* theWeapon the weapon to change the property of
* strProperty the property to edit such as damage per hit ( "damage" )
* 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==
==Changelog==
{{Requirements|n/a|1.3.0-9.04555|}}
{{ChangelogHeader}}
 
{{ChangelogItem|1.4.0-9.06339|Added 'fire_rotation' property}}
</section>


==See Also==
==See also==
{{Weapon functions}}
{{Weapon functions}}

Latest revision as of 15:36, 7 November 2024

Click to collapse [-]
Server

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 - Max targeting range
  • "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 - How fast player can move with weapon
  • "flags" - int - (specify a flag to toggle it on/off) See Weapon Flags
  • "flag_aim_no_auto" - bool - Disable auto up/down for non-aimed firing
  • "flag_aim_arm" - bool - Uses other arm for aiming
  • "flag_aim_1st_person" - bool - Uses 1st person aim
  • "flag_aim_free" - bool - Can only use free aiming
  • "flag_move_and_aim" - bool - Can move and aim at same time
  • "flag_move_and_shoot" - bool - Can move and fire at same time
  • "flag_type_throw" - bool - Is a throwing weapon
  • "flag_type_heavy" - bool - Can't jump
  • "flag_type_constant" - bool - Fires every frame within loop (ie paint spray)
  • "flag_type_dual" - bool - Can use 2x guns at same time
  • "flag_anim_reload" - bool - Weapon has reload anims
  • "flag_anim_crouch" - bool - Has crouching anims
  • "flag_anim_reload_loop" - bool - Loop from end of reload to fire loop start
  • "flag_anim_reload_long" - bool - Force a longer reload time
  • "flag_shot_slows" - bool - Slows down (area effect)
  • "flag_shot_rand_speed" - bool - Random speed (area effect)
  • "flag_shot_anim_abrupt" - bool - Force the anim to finish player after aim/fire rather than blending out (area effect)
  • "flag_shot_expands" - bool - Expands (area effect)
  • "anim_loop_start" - float - Start of aimed firing animation loop
  • "anim_loop_stop" - float - End of aimed firing animation loop (Reduce to increase firing rate)
  • "anim_loop_bullet_fire" - float - Time in aimed firing animation when weapon should be fired (Must be between Start and End)
  • "anim2_loop_start" - float - Start of non-aimed firing animation2 loop
  • "anim2_loop_stop" - float - End of non-aimed firing animation2 loop (Reduce to increase crouch firing rate)
  • "anim2_loop_bullet_fire" - float - Time in non-aimed firing animation2 when weapon should be fired (Must be between Start and End)
  • "anim_breakout_time" - float - Time after which player can break out of attack and run off
  • 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


Click to collapse [-]
Client

The client side function only applies to custom weapons created client sided.

Syntax

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

OOP Syntax Help! I don't understand this!

Method: weapon:setProperty(...)
Counterpart: getWeaponProperty


Required Arguments

  • theWeapon: the weapon to change the property of.
  • strProperty: the property to edit:
  • "weapon_range" - float
  • "target_range" - float
  • "accuracy" - float
  • "damage" - int
ADDED/UPDATED IN VERSION 1.4 r6693:
  • "fire_rotation" - vector - For aligning fire direction with model
  • theValue: The value to set the property to.

Returns

Returns true if the property was set.

Example

Click to collapse [-]
Server

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 example 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 )

Changelog

Version Description
1.4.0-9.06339 Added 'fire_rotation' property

See also