109 lines
3.3 KiB
Lua
109 lines
3.3 KiB
Lua
-- client/atm_blips.lua
|
|
print("^2[turfwar]^7 atm_blips.lua loaded")
|
|
|
|
if IsDuplicityVersion() then
|
|
print("^1[turfwar]^7 atm_blips.lua loaded on SERVER by mistake!")
|
|
return
|
|
end
|
|
|
|
Config = Config or {}
|
|
Config.Finance = Config.Finance or {}
|
|
|
|
-- =========================
|
|
-- Config defaults (blips)
|
|
-- =========================
|
|
Config.Finance.ATM_BLIPS_ENABLED = (Config.Finance.ATM_BLIPS_ENABLED ~= false)
|
|
Config.Finance.ATM_BLIP_SPRITE = Config.Finance.ATM_BLIP_SPRITE or 277
|
|
Config.Finance.ATM_BLIP_SCALE = Config.Finance.ATM_BLIP_SCALE or 0.55
|
|
Config.Finance.ATM_BLIP_COLOR = Config.Finance.ATM_BLIP_COLOR or 2
|
|
Config.Finance.ATM_BLIP_SHORT_RANGE = (Config.Finance.ATM_BLIP_SHORT_RANGE ~= false)
|
|
|
|
-- =========================
|
|
-- State
|
|
-- =========================
|
|
local ATM_BLIPS = {} -- array for easy cleanup
|
|
local ATM_BY_KEY = {} -- coordKey -> blip
|
|
|
|
-- =========================
|
|
-- Helpers
|
|
-- =========================
|
|
local function coordKey(x, y, z)
|
|
-- round to 0.5m to dedupe close matches
|
|
local rx = math.floor((x * 2.0) + 0.5) / 2.0
|
|
local ry = math.floor((y * 2.0) + 0.5) / 2.0
|
|
local rz = math.floor((z * 2.0) + 0.5) / 2.0
|
|
return (("%0.1f|%0.1f|%0.1f"):format(rx, ry, rz))
|
|
end
|
|
|
|
local function ClearATMBlips()
|
|
for _, b in ipairs(ATM_BLIPS) do
|
|
if DoesBlipExist(b) then RemoveBlip(b) end
|
|
end
|
|
ATM_BLIPS = {}
|
|
ATM_BY_KEY = {}
|
|
end
|
|
|
|
local function AddATMBlip(coords)
|
|
local key = coordKey(coords.x, coords.y, coords.z)
|
|
if ATM_BY_KEY[key] and DoesBlipExist(ATM_BY_KEY[key]) then return end
|
|
|
|
local blip = AddBlipForCoord(coords.x, coords.y, coords.z)
|
|
SetBlipSprite(blip, Config.Finance.ATM_BLIP_SPRITE)
|
|
SetBlipScale(blip, Config.Finance.ATM_BLIP_SCALE)
|
|
SetBlipColour(blip, Config.Finance.ATM_BLIP_COLOR)
|
|
SetBlipDisplay(blip, 4)
|
|
SetBlipAsShortRange(blip, Config.Finance.ATM_BLIP_SHORT_RANGE)
|
|
|
|
BeginTextCommandSetBlipName("STRING")
|
|
AddTextComponentString("ATM")
|
|
EndTextCommandSetBlipName(blip)
|
|
|
|
ATM_BLIPS[#ATM_BLIPS + 1] = blip
|
|
ATM_BY_KEY[key] = blip
|
|
end
|
|
|
|
local function BuildATMBlips(atms)
|
|
ClearATMBlips()
|
|
|
|
if not atms or #atms == 0 then
|
|
print("^1[turfwar]^7 atm_blips.lua: Config.Finance.ATMS is empty (0) -> no ATM blips.")
|
|
return
|
|
end
|
|
|
|
for _, c in ipairs(atms) do
|
|
if type(c) == "vector3" then
|
|
AddATMBlip(c)
|
|
elseif type(c) == "table" and c.x and c.y and c.z then
|
|
AddATMBlip(vector3(c.x, c.y, c.z))
|
|
end
|
|
end
|
|
|
|
print(("^2[turfwar]^7 ATM blips created: %d"):format(#ATM_BLIPS))
|
|
end
|
|
|
|
-- If you still have an atm_coords.lua that fires this:
|
|
AddEventHandler("turfwar:atm:listReady", function(atms)
|
|
if not Config.Finance.ATM_BLIPS_ENABLED then return end
|
|
BuildATMBlips(atms)
|
|
end)
|
|
|
|
-- Boot: Mode B static list from config.lua
|
|
CreateThread(function()
|
|
Wait(500)
|
|
|
|
if not Config.Finance.ATM_BLIPS_ENABLED then
|
|
print("^3[turfwar]^7 ATM blips disabled in config")
|
|
return
|
|
end
|
|
|
|
local atms = Config.Finance.ATMS or {}
|
|
print(("^3[turfwar]^7 atm_blips.lua: boot -> ATMS=%d"):format(#atms))
|
|
|
|
BuildATMBlips(atms)
|
|
end)
|
|
|
|
AddEventHandler("onClientResourceStop", function(res)
|
|
if res ~= GetCurrentResourceName() then return end
|
|
ClearATMBlips()
|
|
end)
|