Hey everyone, i’m trying to make it so when a player is in usable range of a bank, they will receive a notification. What would be the proper way to do this (without running a loop that constantly checks the player location and compares it to the location of a specified coordinate)? Is there a way that I can call a function if a player walks within range of said coordinate? Thanks for any help.
Config.Zones = {
zone1 = {
Pos = { x = 123.456, y = -123.456, z = 12.3 },
Size = { x = 1.5, y = 1.5, z = 0.4 },
Type = 1
},
zone2 = {
Pos = { x = -123.456, y = 123.456, z = 12.3 },
Size = { x = 1.5, y = 1.5, z = 0.4 },
Type = 1
},
Citizen.CreateThread(function()
while true do
Wait(0)
local coords = GetEntityCoords(GetPlayerPed(-1))
for k,v in pairs(Config.Zones) do
if(v.Type ~= -1 and GetDistanceBetweenCoords(coords, v.Pos.x, v.Pos.y, v.Pos.z, true) < Config.DrawDistance) then
DrawMarker(v.Type, v.Pos.x, v.Pos.y, v.Pos.z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, v.Size.x, v.Size.y, v.Size.z, Config.MarkerColor.r, Config.MarkerColor.g, Config.MarkerColor.b, 100, false, true, 2, false, false, false, false)
end
end
end
end)
Citizen.CreateThread(function()
while true do
Wait(0)
local coords = GetEntityCoords(GetPlayerPed(-1))
local isInMarker = false
local currentZone = nil
for k,v in pairs(Config.Zones) do
if(GetDistanceBetweenCoords(coords, v.Pos.x, v.Pos.y, v.Pos.z, true) < v.Size.x) then
isInMarker = true
currentZone = k
end
end
if isInMarker and not hasAlreadyEnteredMarker then
hasAlreadyEnteredMarker = true
lastZone = currentZone
TriggerEvent('notificationevent', currentZone)
end
if not isInMarker and hasAlreadyEnteredMarker then
hasAlreadyEnteredMarker = false
TriggerEvent('notificationevent', lastZone)
end
end
end)
1 Like