I’ll say first off that I am VERY new to scripting… So go easy on me. This will be a walk in the park for a lot of you.
I want to know how to make these two commands into one as a toggle for an Action Menu button.
–Add–
RegisterNetEvent("UnlockCarbine")
AddEventHandler("UnlockCarbine", function()
local weapon = GetHashKey("WEAPON_CARBINERIFLE")
local ped = GetPlayerPed(PlayerId())
GiveWeaponToPed(ped, weapon, 1000, false, true)
end)
–Remove–
RegisterNetEvent("LockCarbine")
AddEventHandler("LockCarbine", function()
local weapon = GetHashKey("WEAPON_CARBINERIFLE")
local ped = GetPlayerPed(PlayerId())
RemoveWeaponFromPed(ped, weapon)
end)
They each work individually, but it requires two buttons at the moment, and would be ideal to streamline it down to one toggle button.
My guess is some kind of native that checks to see if that weapon is currently equipped, then an “else” function of sorts, but what I tried broke the client.lua file 
First make this at the start of your code:
local carbine = false
Then change your 2 events into this one event:
RegisterNetEvent("UnlockCarbine")
AddEventHandler("UnlockCarbine", function()
local weapon = GetHashKey("WEAPON_CARBINERIFLE")
local ped = GetPlayerPed(PlayerId())
carbine = not carbine
if carbine then
GiveWeaponToPed(ped, weapon, 1000, false, true)
else
RemoveWeaponFromPed(ped, weapon)
end
end)
That should work, have not tested it though.
Works like a dream! Thank you very much good sir!
1 Like