SetJetpackWeaponEnabled: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(Remove obsolete Requirements section)
 
(5 intermediate revisions by 4 users not shown)
Line 2: Line 2:
{{Server function}}
{{Server function}}
This function sets a weapon usable while using the Jetpack.
This function sets a weapon usable while using the Jetpack.
{{Note|colt 45, sawed-off, tec-9 and uzi are always enabled for the Jetpack and are not affected by this function}}
{{Note|colt 45, sawed-off, tec-9 and uzi are always enabled for the Jetpack and are not affected by this function.}}
==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">bool setJetpackWeaponEnabled(string weapon, bool enabled)</syntaxhighlight>  
<syntaxhighlight lang="lua">bool setJetpackWeaponEnabled ( int weaponID/string weaponName, bool enabled )</syntaxhighlight>  


===Required Arguments===  
===Required Arguments===  
*'''weapon''' The weapon that's being set usable on a Jetpack. Names can be: (Case is ignored)
*'''weaponID/weaponName:''' The ID or weapon name that's being set usable on a Jetpack. Names can be: (Case is ignored)
{{All Weapon Types}}
{{All Weapon Types}}
*'''enabled''' A bool representing whether the weapon is enabled or disabled.
*'''enabled:''' A [[boolean]] representing whether the weapon is enabled or disabled.


===Returns===
===Returns===
Returns true, else false if invalid arguments are passed.
Returns true if successful, or false if invalid arguments are passed.


==Example==
==Example==
This example enables the M4 to be fired while using a jetpack and announces it in the chat.
<syntaxhighlight lang="lua">addEventHandler("onResourceStart",resourceRoot,function()
<syntaxhighlight lang="lua">addEventHandler("onResourceStart",resourceRoot,function()
     if setJetpackWeaponEnabled("31",true) then
     if setJetpackWeaponEnabled("31",true) then
Line 21: Line 22:
end)</syntaxhighlight>
end)</syntaxhighlight>


== Issues ==
This example enables the M4, sniper rifle and country rifle to be fired while using a jetpack and announces it in the chat.
{{Issues|
<syntaxhighlight lang="lua">
{{Issue|8827|If you use setJetpackWeaponEnabled to make weapons usable on jetpack and then wield them on jetpack, the weapon can become invisible.}}
local weapons = {
}}
    31,
    34,
    33,
}
 
addEventHandler("onResourceStart",resourceRoot,function()
    for i,v in ipairs(weapons) do
        if setJetpackWeaponEnabled(v,true) then
            outputChatBox(getWeaponNameFromID(v).." is now enabled for jetpacks!")
        end
    end
end
)</syntaxhighlight>


==Requirements==
{{Requirements|1.3.1|n/a|}}
==See Also==
==See Also==
{{World_functions}}
{{World_functions|server}}

Latest revision as of 17:05, 7 November 2024

This function sets a weapon usable while using the Jetpack.

[[{{{image}}}|link=|]] Note: colt 45, sawed-off, tec-9 and uzi are always enabled for the Jetpack and are not affected by this function.

Syntax

bool setJetpackWeaponEnabled ( int weaponID/string weaponName, bool enabled )

Required Arguments

  • weaponID/weaponName: The ID or weapon name that's being set usable on a Jetpack. Names can be: (Case is ignored)
  • brassknuckle
  • golfclub
  • nightstick
  • knife
  • bat
  • shovel
  • poolstick
  • katana
  • chainsaw
  • dildo
  • vibrator
  • flower
  • cane
  • 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
  • nightvision
  • infrared
  • parachute
  • enabled: A boolean representing whether the weapon is enabled or disabled.

Returns

Returns true if successful, or false if invalid arguments are passed.

Example

This example enables the M4 to be fired while using a jetpack and announces it in the chat.

addEventHandler("onResourceStart",resourceRoot,function()
     if setJetpackWeaponEnabled("31",true) then
          outputChatBox(getWeaponNameFromID(31).." is now enabled for jetpacks!")
     end
end)

This example enables the M4, sniper rifle and country rifle to be fired while using a jetpack and announces it in the chat.

local weapons = {
    31,
    34,
    33,
}

addEventHandler("onResourceStart",resourceRoot,function()
    for i,v in ipairs(weapons) do
        if setJetpackWeaponEnabled(v,true) then
            outputChatBox(getWeaponNameFromID(v).." is now enabled for jetpacks!")
        end
    end
end
)

See Also