I have used polyzone to create the zones, but the problem comes when I add more than one weapon to the allowed weapons table, when I only have one weapon the script works correctly, but when I put more than one it stops working, does anyone know why? it is?
Config.lua
Settings = {}
Settings.Zones = {
{
name = "Cannabis",
allowedWeapons = {
"WEAPON_PISTOL",
"WEAPON_PISTOL_MK2",
},
}
}
client.lua
local Cannabis = PolyZone:Create({
vector2(-489.82, -1766.53),
vector2(-507.92, -1762.84),
vector2(-525.63, -1753.71),
vector2(-638.49, -1669.42),
vector2(-661.96, -1643.68),
vector2(-622.69, -1589.12),
vector2(-597.88, -1581.37),
vector2(-576.93, -1583.83),
vector2(-397.84, -1674.78),
vector2(-429.4, -1756.9)
}, {
name="cannabis",
minZ=17.0,
maxZ=36.0,
debugGrid=true,
gridDivisions=25
})
local insideCannabis = false
CreateThread(function()
while true do
SetCurrentPedWeapon(player,GetHashKey("WEAPON_UNARMED"),true)
local plyPed = PlayerPedId()
local coord = GetEntityCoords(plyPed)
insideCannabis= Cannabis:isPointInside(coord)
if insideCannabis then
for k, v in pairs(Settings.Zones) do
if v.name == "Cannabis" then
for i = 1, #v.allowedWeapons do
local weapon = v.allowedWeapons[i]
if HasPedGotWeapon(PlayerPedId(), GetHashKey(weapon), false) then
print("Esta dentro de la zona y tiene el arma")
else
SetCurrentPedWeapon(plyPed,GetHashKey("WEAPON_UNARMED"),true)
end
end
end
end
end
Citizen.Wait(1000)
end
end)