-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(client/stations): use lib.points
- Loading branch information
Showing
1 changed file
with
57 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |