Skip to content

Commit

Permalink
refactor(client/stations): use lib.points
Browse files Browse the repository at this point in the history
  • Loading branch information
thelindat committed Jun 3, 2024
1 parent fe0b25b commit d6c2d0b
Showing 1 changed file with 57 additions and 62 deletions.
119 changes: 57 additions & 62 deletions client/stations.lua
Original file line number Diff line number Diff line change
@@ -1,81 +1,76 @@
local config = require 'config'
local state = require 'client.state'
local utils = require 'client.utils'
local stations = lib.load 'data.stations'

CreateThread(function()
local stations = lib.load 'data.stations'
if config.showBlips == 2 then
for station in pairs(stations) do utils.createBlip(station) end
end

if config.showBlips == 2 then
for station in pairs(stations) do utils.createBlip(station) end
end

local blip

if config.ox_target and config.showBlips ~= 1 then return end
if config.ox_target and config.showBlips ~= 1 then return end

while true do
local playerCoords = GetEntityCoords(cache.ped)
---@param point CPoint
local function onEnterStation(point)
if config.showBlips == 1 and not point.blip then
point.blip = utils.createBlip(point.coords)
end
end

for station, pumps in pairs(stations) do
local stationDistance = #(playerCoords - station)
---@param point CPoint
local function nearbyStation(point)
if point.currentDistance > 15 then return end

if stationDistance < 60 then
if config.showBlips == 1 and not blip then
blip = utils.createBlip(station)
end
local pumps = point.pumps
local pumpDistance

if not config.ox_target then
repeat
if stationDistance < 15 then
local pumpDistance
for i = 1, #pumps do
local pump = pumps[i]
pumpDistance = #(cache.coords - pump)

repeat
playerCoords = GetEntityCoords(cache.ped)
for i = 1, #pumps do
local pump = pumps[i]
pumpDistance = #(playerCoords - pump)
if pumpDistance <= 3 then
state.nearestPump = pump

if pumpDistance < 3 then
state.nearestPump = pump
repeat
local playerCoords = GetEntityCoords(cache.ped)
pumpDistance = #(GetEntityCoords(cache.ped) - pump)

while pumpDistance < 3 do
if cache.vehicle then
DisplayHelpTextThisFrame('fuelLeaveVehicleText', false)
elseif not state.isFueling then
local vehicleInRange = state.lastVehicle ~= 0 and
#(GetEntityCoords(state.lastVehicle) - playerCoords) <= 3
if cache.vehicle then
DisplayHelpTextThisFrame('fuelLeaveVehicleText', false)
elseif not state.isFueling then
local vehicleInRange = state.lastVehicle ~= 0 and
#(GetEntityCoords(state.lastVehicle) - playerCoords) <= 3

if vehicleInRange then
DisplayHelpTextThisFrame('fuelHelpText', false)
elseif config.petrolCan.enabled then
DisplayHelpTextThisFrame('petrolcanHelpText', false)
end
end
if vehicleInRange then
DisplayHelpTextThisFrame('fuelHelpText', false)
elseif config.petrolCan.enabled then
DisplayHelpTextThisFrame('petrolcanHelpText', false)
end
end

pumpDistance = #(GetEntityCoords(cache.ped) - pump)
Wait(0)
end
Wait(0)
until pumpDistance > 3

state.nearestPump = nil
end
end
Wait(100)
until pumpDistance > 15
break
end
state.nearestPump = nil

Wait(100)
stationDistance = #(GetEntityCoords(cache.ped) - station)
until stationDistance > 60
end
end
return
end
end
end

Wait(500)

if blip then
RemoveBlip(blip)
blip = nil
end
---@param point CPoint
local function onExitStation(point)
if point.blip then
point.blip = RemoveBlip(point.blip)
end
end)
end

for station, pumps in pairs(stations) do
lib.points.new({
coords = station,
distance = 60,
onEnter = onEnterStation,
onExit = onExitStation,
nearby = nearbyStation,
pumps = pumps,
})
end

0 comments on commit d6c2d0b

Please sign in to comment.