Hello i try to make AFK Zone for my server. But how can i disable certain commands like /carry (carry people script) in my AFK zone? And any notification that stay on the screen if we are in the AFK Zone?
My AFK Zone Client Lua.
client.lua (3.5 KB)
you should add export like > isInAFKSite and in commands you want check player in AFK zone or not.
for adding export you should add
export 'isInAFKSite'
in __resource.lua and add replace bellow code to client.lua
local isInAfkZone = false
local notifIn = false
local notifOut = false
local zones = {
{ ['x'] = 1079.94, ['y'] = -694.71, ['z'] = 58.01}
}
function isInAFKSite()
return isInAfkZone
end
Citizen.CreateThread(function()
for k,zone in pairs(Config.CircleZones) do
CreateBlipCircle(zone.coords, zone.name, zone.radius, zone.color, zone.sprite)
end
end)
Citizen.CreateThread(function()
while not NetworkIsPlayerActive(PlayerId()) do
Citizen.Wait(100)
end
while true do
local playerPed = GetPlayerPed(-1)
local x, y, z = table.unpack(GetEntityCoords(playerPed, true))
local minDistance = 100000
for i = 1, #zones, 1 do
dist = Vdist(zones[i].x, zones[i].y, zones[i].z, x, y, z)
if dist < minDistance then
minDistance = dist
closestZone = i
end
end
Citizen.Wait(100)
end
end)
Citizen.CreateThread(function()
while not NetworkIsPlayerActive(PlayerId()) do
Citizen.Wait(100)
end
while true do
Citizen.Wait(100)
local player = GetPlayerPed(-1)
local x,y,z = table.unpack(GetEntityCoords(player, true))
local veh = GetVehiclePedIsUsing(ped)
local dist = Vdist(zones[closestZone].x, zones[closestZone].y, zones[closestZone].z, x, y, z)
if dist <= 25.0 then
isInAfkZone = true
if not notifOut then
SetPlayerInvincible(GetPlayerIndex(),true)
SetEntityHealth(player, 2000)
SetCurrentPedWeapon(player,GetHashKey("WEAPON_UNARMED"),true)
SetEntityProofs(GetPlayerPed(-1), true, true, true, true, true, true, true, true)
SetEntityOnlyDamagedByPlayer(GetPlayerPed(-1), false)
SetEntityCanBeDamaged(GetPlayerPed(-1), false)
notifIn = true
notifOut = false
end
else
isInAfkZone = false
if not notifIn then
SetPlayerInvincible(GetPlayerIndex(),false)
notifOut = true
notifIn = false
end
end
if notifIn then
DisableControlAction(2, 37, true) -- disable weapon wheel (Tab)
DisablePlayerFiring(player,true) -- Disables firing all together if they somehow bypass inzone Mouse Disable
DisableControlAction(0, 106, true) -- Disable in-game mouse controls
if IsDisabledControlJustPressed(2, 37) then --if Tab is pressed, send error message
SetCurrentPedWeapon(player,GetHashKey("WEAPON_UNARMED"),true) -- if tab is pressed it will set them to unarmed (this is to cover the vehicle glitch until I sort that all out)
TriggerEvent("pNotify:SendNotification",{
text = "<b style='color:#1E90FF'>You can not use weapons in a AFK Zone</b>",
type = "error",
timeout = (3000),
layout = "bottomcenter",
queue = "global"
})
end
if IsDisabledControlJustPressed(0, 106) then --if LeftClick is pressed, send error message
SetCurrentPedWeapon(player,GetHashKey("WEAPON_UNARMED"),true) -- If they click it will set them to unarmed
TriggerEvent("pNotify:SendNotification",{
text = "<b style='color:#1E90FF'>You can not do that in a AFK Zone</b>",
type = "error",
timeout = (3000),
layout = "bottomcenter",
queue = "global"
})
end
end
end
end)
function CreateBlipCircle(coords, text, radius, color, sprite)
local blip = AddBlipForRadius(coords, radius)
SetBlipHighDetail(blip, true)
SetBlipColour(blip, 2)
SetBlipAlpha (blip, 128)
-- create a blip in the middle
blip = AddBlipForCoord(coords)
SetBlipHighDetail(blip, true)
SetBlipSprite (blip, sprite)
SetBlipScale (blip, 0.7)
SetBlipColour (blip, color)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString(text)
EndTextCommandSetBlipName(blip)
end
in other client files that you want to disable command or player task you should add
if not exports[' {NAME OF AFK ZONE RESOURCE} ']:isInAFKSite() then
-- add code you want to player can do out of the zone
end
for other question please say more details
1 Like
where can i get the afkzone script
need a config.lua for this?
how to make player will not get kicked when afk at the afk zone ?.. im using afkkick script too