Restrict weapon equip

I want to be able to set up a script that isn’t a blacklist of a weapon, but more of a restriction. Is it possible to stop someone from equipping a weapon based on criteria?

Maybe something like this will help?

local restrictedWeapons = {
	"WEAPON_RPG"
}
local currentWeapon = GetHashKey("WEAPON_UNARMED")

Citizen.CreateThread(function()
	while true do
		local ped = GetPlayerPed(PlayerId())
		local weapon = GetCurrentPedWeapon(ped, false)
		if weapon ~= currentWeapon then
			if isWeaponRestricted(weapon) then
				SetCurrentPedWeapon(ped, currentWeapon, true)
				print("Weapon Restricted... Going back to last weapon!")
			else
				currentWeapon = weapon
				print("Weapon switch accepted... Switching weapons!")
			end
		end
		Citizen.Wait(250)
	end
end)

function isWeaponRestricted(weapon)
	for a = 1, #restrictedWeapons do
		if GetHashKey(restrictedWeapons[a]) == weapon then
			return true
		end
	end
	return false
end

That should do exactly what i need! Thanks for the help! you are awesome

I haven’t tested it so no idea if there is gonna be an error or not. Just wrote it and pasted it.

Well for what i’m doing i was mainly unsure the right syntax for the SetCurrentPedWeapon. what you posted should help me figure out what i’m doing. If i have any problems i’ll let you know :slight_smile:

1 Like

The only difference i needed was to use GetSelectedPedWeapon() instead of GetCurrentPedWeapon()

1 Like

Cool.