Skip to content
This repository was archived by the owner on Apr 19, 2025. It is now read-only.

Commit d6c2d0b

Browse files
committed
refactor(client/stations): use lib.points
1 parent fe0b25b commit d6c2d0b

File tree

1 file changed

+57
-62
lines changed

1 file changed

+57
-62
lines changed

client/stations.lua

Lines changed: 57 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,76 @@
11
local config = require 'config'
22
local state = require 'client.state'
33
local utils = require 'client.utils'
4+
local stations = lib.load 'data.stations'
45

5-
CreateThread(function()
6-
local stations = lib.load 'data.stations'
6+
if config.showBlips == 2 then
7+
for station in pairs(stations) do utils.createBlip(station) end
8+
end
79

8-
if config.showBlips == 2 then
9-
for station in pairs(stations) do utils.createBlip(station) end
10-
end
11-
12-
local blip
13-
14-
if config.ox_target and config.showBlips ~= 1 then return end
10+
if config.ox_target and config.showBlips ~= 1 then return end
1511

16-
while true do
17-
local playerCoords = GetEntityCoords(cache.ped)
12+
---@param point CPoint
13+
local function onEnterStation(point)
14+
if config.showBlips == 1 and not point.blip then
15+
point.blip = utils.createBlip(point.coords)
16+
end
17+
end
1818

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

22-
if stationDistance < 60 then
23-
if config.showBlips == 1 and not blip then
24-
blip = utils.createBlip(station)
25-
end
23+
local pumps = point.pumps
24+
local pumpDistance
2625

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

32-
repeat
33-
playerCoords = GetEntityCoords(cache.ped)
34-
for i = 1, #pumps do
35-
local pump = pumps[i]
36-
pumpDistance = #(playerCoords - pump)
30+
if pumpDistance <= 3 then
31+
state.nearestPump = pump
3732

38-
if pumpDistance < 3 then
39-
state.nearestPump = pump
33+
repeat
34+
local playerCoords = GetEntityCoords(cache.ped)
35+
pumpDistance = #(GetEntityCoords(cache.ped) - pump)
4036

41-
while pumpDistance < 3 do
42-
if cache.vehicle then
43-
DisplayHelpTextThisFrame('fuelLeaveVehicleText', false)
44-
elseif not state.isFueling then
45-
local vehicleInRange = state.lastVehicle ~= 0 and
46-
#(GetEntityCoords(state.lastVehicle) - playerCoords) <= 3
37+
if cache.vehicle then
38+
DisplayHelpTextThisFrame('fuelLeaveVehicleText', false)
39+
elseif not state.isFueling then
40+
local vehicleInRange = state.lastVehicle ~= 0 and
41+
#(GetEntityCoords(state.lastVehicle) - playerCoords) <= 3
4742

48-
if vehicleInRange then
49-
DisplayHelpTextThisFrame('fuelHelpText', false)
50-
elseif config.petrolCan.enabled then
51-
DisplayHelpTextThisFrame('petrolcanHelpText', false)
52-
end
53-
end
43+
if vehicleInRange then
44+
DisplayHelpTextThisFrame('fuelHelpText', false)
45+
elseif config.petrolCan.enabled then
46+
DisplayHelpTextThisFrame('petrolcanHelpText', false)
47+
end
48+
end
5449

55-
pumpDistance = #(GetEntityCoords(cache.ped) - pump)
56-
Wait(0)
57-
end
50+
Wait(0)
51+
until pumpDistance > 3
5852

59-
state.nearestPump = nil
60-
end
61-
end
62-
Wait(100)
63-
until pumpDistance > 15
64-
break
65-
end
53+
state.nearestPump = nil
6654

67-
Wait(100)
68-
stationDistance = #(GetEntityCoords(cache.ped) - station)
69-
until stationDistance > 60
70-
end
71-
end
55+
return
7256
end
57+
end
58+
end
7359

74-
Wait(500)
75-
76-
if blip then
77-
RemoveBlip(blip)
78-
blip = nil
79-
end
60+
---@param point CPoint
61+
local function onExitStation(point)
62+
if point.blip then
63+
point.blip = RemoveBlip(point.blip)
8064
end
81-
end)
65+
end
66+
67+
for station, pumps in pairs(stations) do
68+
lib.points.new({
69+
coords = station,
70+
distance = 60,
71+
onEnter = onEnterStation,
72+
onExit = onExitStation,
73+
nearby = nearbyStation,
74+
pumps = pumps,
75+
})
76+
end

0 commit comments

Comments
 (0)