|
1 | 1 | local config = require 'config' |
2 | 2 | local state = require 'client.state' |
3 | 3 | local utils = require 'client.utils' |
| 4 | +local stations = lib.load 'data.stations' |
4 | 5 |
|
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 |
7 | 9 |
|
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 |
15 | 11 |
|
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 |
18 | 18 |
|
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 |
21 | 22 |
|
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 |
26 | 25 |
|
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) |
31 | 29 |
|
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 |
37 | 32 |
|
38 | | - if pumpDistance < 3 then |
39 | | - state.nearestPump = pump |
| 33 | + repeat |
| 34 | + local playerCoords = GetEntityCoords(cache.ped) |
| 35 | + pumpDistance = #(GetEntityCoords(cache.ped) - pump) |
40 | 36 |
|
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 |
47 | 42 |
|
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 |
54 | 49 |
|
55 | | - pumpDistance = #(GetEntityCoords(cache.ped) - pump) |
56 | | - Wait(0) |
57 | | - end |
| 50 | + Wait(0) |
| 51 | + until pumpDistance > 3 |
58 | 52 |
|
59 | | - state.nearestPump = nil |
60 | | - end |
61 | | - end |
62 | | - Wait(100) |
63 | | - until pumpDistance > 15 |
64 | | - break |
65 | | - end |
| 53 | + state.nearestPump = nil |
66 | 54 |
|
67 | | - Wait(100) |
68 | | - stationDistance = #(GetEntityCoords(cache.ped) - station) |
69 | | - until stationDistance > 60 |
70 | | - end |
71 | | - end |
| 55 | + return |
72 | 56 | end |
| 57 | + end |
| 58 | +end |
73 | 59 |
|
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) |
80 | 64 | 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