diff --git a/server-data/resources/[ox]/ox_fuel/client.lua b/server-data/resources/[ox]/ox_fuel/client.lua deleted file mode 100644 index 0950b759e..000000000 --- a/server-data/resources/[ox]/ox_fuel/client.lua +++ /dev/null @@ -1,500 +0,0 @@ -if not lib.checkDependency('ox_lib', '3.0.0', true) then return end - -if not lib.checkDependency('ox_inventory', '2.28.4', true) then return end - -lib.locale() - -local fuelingCan = exports.ox_inventory:getCurrentWeapon() - -AddEventHandler('ox_inventory:currentWeapon', function(currentWeapon) - fuelingCan = currentWeapon?.name == 'WEAPON_PETROLCAN' and currentWeapon -end) - -local function getVehicleInFront() - local coords = GetEntityCoords(cache.ped) - local destination = GetOffsetFromEntityInWorldCoords(cache.ped, 0.0, 2.2, -0.25) - local handle = StartShapeTestCapsule(coords.x, coords.y, coords.z, destination.x, destination.y, destination.z, 2.2, 2, cache.ped, 4) - - while true do - Wait(0) - local retval, _, _, _, entityHit = GetShapeTestResult(handle) - - if retval ~= 1 then - return entityHit ~= 0 and entityHit - end - end -end - -local function setFuel(state, vehicle, fuel, replicate) - if DoesEntityExist(vehicle) then - if fuel < 0 then fuel = 0 end - - SetVehicleFuelLevel(vehicle, fuel) - - if not state.fuel then - TriggerServerEvent('ox_fuel:createStatebag', NetworkGetNetworkIdFromEntity(vehicle), fuel) - else - state:set('fuel', fuel, replicate) - end - end -end - -local lastVehicle = cache.vehicle or GetPlayersLastVehicle() - -lib.onCache('seat', function(seat) - if cache.vehicle then - lastVehicle = cache.vehicle - end - - if not NetworkGetEntityIsNetworked(lastVehicle) then return end - - if seat == -1 then - SetTimeout(0, function() - local vehicle = cache.vehicle - local multiplier = Config.classUsage[GetVehicleClass(vehicle)] or 1.0 - - -- Vehicle doesn't use fuel - if multiplier == 0.0 then return end - - local state = Entity(vehicle).state - - if not state.fuel then - TriggerServerEvent('ox_fuel:createStatebag', NetworkGetNetworkIdFromEntity(vehicle), GetVehicleFuelLevel(vehicle)) - while not state.fuel do Wait(0) end - end - - SetVehicleFuelLevel(vehicle, state.fuel) - - local fuelTick = 0 - - while cache.seat == -1 do - local fuel = state.fuel - local newFuel = fuel - - if fuel > 0 then - if GetIsVehicleEngineRunning(vehicle) then - local usage = Config.rpmUsage[math.floor(GetVehicleCurrentRpm(vehicle) * 10) / 10] - newFuel -= usage * multiplier - end - - if GetVehiclePetrolTankHealth(vehicle) < 700 then - newFuel -= math.random(10, 20) * 0.01 - end - - if fuel ~= newFuel then - if fuelTick == 15 then - fuelTick = 0 - end - - setFuel(state, vehicle, newFuel, fuelTick == 0) - fuelTick += 1 - end - end - - Wait(1000) - end - - setFuel(state, vehicle, state.fuel, true) - end) - end -end) - -local isFueling = false -local nearestPump - -AddTextEntry('ox_fuel_station', locale('fuel_station_blip')) - -local function createBlip(station) - local blip = AddBlipForCoord(station.x, station.y, station.z) - SetBlipSprite(blip, 361) - SetBlipDisplay(blip, 4) - SetBlipScale(blip, 0.8) - SetBlipColour(blip, 6) - SetBlipAsShortRange(blip, true) - BeginTextCommandSetBlipName('ox_fuel_station') - EndTextCommandSetBlipName(blip) - - return blip -end - -CreateThread(function() - local blip - - if Config.ox_target and Config.showBlips ~= 1 then return end - - while true do - local playerCoords = GetEntityCoords(cache.ped) - - for station, pumps in pairs(stations) do - local stationDistance = #(playerCoords - station) - if stationDistance < 60 then - if Config.showBlips == 1 and not blip then - blip = createBlip(station) - end - - if not Config.ox_target then - repeat - if stationDistance < 15 then - local pumpDistance - - repeat - playerCoords = GetEntityCoords(cache.ped) - for i = 1, #pumps do - local pump = pumps[i] - pumpDistance = #(playerCoords - pump) - - if pumpDistance < 3 then - nearestPump = pump - - while pumpDistance < 3 do - if cache.vehicle then - DisplayHelpTextThisFrame('fuelLeaveVehicleText', false) - elseif not isFueling then - local vehicleInRange = lastVehicle ~= 0 and #(GetEntityCoords(lastVehicle) - playerCoords) <= 3 - - if vehicleInRange then - DisplayHelpTextThisFrame('fuelHelpText', false) - elseif Config.petrolCan.enabled then - DisplayHelpTextThisFrame('petrolcanHelpText', false) - end - end - - pumpDistance = #(GetEntityCoords(cache.ped) - pump) - Wait(0) - end - - nearestPump = nil - end - end - Wait(100) - until pumpDistance > 15 - break - end - - Wait(100) - stationDistance = #(GetEntityCoords(cache.ped) - station) - until stationDistance > 60 - end - end - end - - - Wait(500) - if blip then - RemoveBlip(blip) - blip = nil - end - end -end) - -if Config.showBlips == 2 then - for station in pairs(stations) do createBlip(station) end -end - -local ox_inventory = exports.ox_inventory - ----@return number -local function defaultMoneyCheck() - return ox_inventory:Search('count', 'money') -end - -local getMoneyAmount = defaultMoneyCheck - -exports('setMoneyCheck', function(fn) - getMoneyAmount = fn or defaultMoneyCheck -end) - --- fuelingMode = 1 - Pump --- fuelingMode = 2 - Can -local function startFueling(vehicle, isPump) - local Vehicle = Entity(vehicle).state - local fuel = Vehicle.fuel or GetVehicleFuelLevel(vehicle) - local duration = math.ceil((100 - fuel) / Config.refillValue) * Config.refillTick - local price, moneyAmount - local durability = 0 - - if 100 - fuel < Config.refillValue then - return lib.notify({type = 'error', description = locale('tank_full')}) - end - - if isPump then - price = 0 - moneyAmount = getMoneyAmount() - - if Config.priceTick > moneyAmount then - return lib.notify({ - type = 'error', - description = locale('not_enough_money', Config.priceTick) - }) - end - elseif not fuelingCan then - return lib.notify({type = 'error', description = locale('petrolcan_not_equipped')}) - elseif fuelingCan.metadata.ammo <= Config.durabilityTick then - return lib.notify({ - type = 'error', - description = locale('petrolcan_not_enough_fuel') - }) - end - - isFueling = true - - TaskTurnPedToFaceEntity(cache.ped, vehicle, duration) - Wait(500) - - CreateThread(function() - lib.progressCircle({ - duration = duration, - useWhileDead = false, - canCancel = true, - disable = { - move = true, - car = true, - combat = true, - }, - anim = { - dict = isPump and 'timetable@gardener@filling_can' or 'weapon@w_sp_jerrycan', - clip = isPump and 'gar_ig_5_filling_can' or 'fire', - }, - }) - - isFueling = false - end) - - while isFueling do - if isPump then - price += Config.priceTick - - if price + Config.priceTick >= moneyAmount then - lib.cancelProgress() - end - else - durability += Config.durabilityTick - - if durability >= fuelingCan.metadata.ammo then - lib.cancelProgress() - durability = fuelingCan.metadata.ammo - break - end - end - - fuel += Config.refillValue - - if fuel >= 100 then - isFueling = false - fuel = 100.0 - end - - Wait(Config.refillTick) - end - - ClearPedTasks(cache.ped) - - if isPump then - TriggerServerEvent('ox_fuel:pay', price, fuel, NetworkGetNetworkIdFromEntity(vehicle)) - else - TriggerServerEvent('ox_fuel:updateFuelCan', durability, NetworkGetNetworkIdFromEntity(vehicle), fuel) - end -end - -local function getPetrolCan(pumpCoord, refuel) - TaskTurnPedToFaceCoord(cache.ped, pumpCoord.x, pumpCoord.y, pumpCoord.z, Config.petrolCan.duration) - Wait(500) - - if lib.progressCircle({ - duration = Config.petrolCan.duration, - useWhileDead = false, - canCancel = true, - disable = { - move = true, - car = true, - combat = true, - }, - anim = { - dict = 'timetable@gardener@filling_can', - clip = 'gar_ig_5_filling_can', - flags = 49, - } - }) then - if refuel and ox_inventory:Search('count', 'WEAPON_PETROLCAN') then - return TriggerServerEvent('ox_fuel:fuelCan', true, Config.petrolCan.refillPrice) - end - - TriggerServerEvent('ox_fuel:fuelCan', false, Config.petrolCan.price) - end - - ClearPedTasks(cache.ped) -end - -local bones = { - 'petrolcap', - 'petroltank', - 'petroltank_l', - 'hub_lr', - 'engine', -} - -local function getVehiclePetrolCapBoneIndex(vehicle) - for i = 1, #bones do - local boneIndex = GetEntityBoneIndexByName(vehicle, bones[i]) - - if boneIndex ~= -1 then - -- print(boneIndex, bones[i]) - return boneIndex - end - end -end - -if not Config.ox_target then - RegisterCommand('startfueling', function() - if isFueling or cache.vehicle or lib.progressActive() then return end - - local petrolCan = Config.petrolCan.enabled and GetSelectedPedWeapon(cache.ped) == `WEAPON_PETROLCAN` - local playerCoords = GetEntityCoords(cache.ped) - - if nearestPump then - local moneyAmount = getMoneyAmount() - - if petrolCan and moneyAmount >= Config.petrolCan.refillPrice then - return getPetrolCan(nearestPump, true) - end - - local vehicleInRange = lastVehicle and #(GetEntityCoords(lastVehicle) - playerCoords) <= 3 - - if not vehicleInRange then - if not Config.petrolCan.enabled then return end - - if moneyAmount >= Config.petrolCan.price then - return getPetrolCan(nearestPump) - end - - return lib.notify({type = 'error', description = locale('petrolcan_cannot_afford')}) - elseif moneyAmount >= Config.priceTick then - return startFueling(lastVehicle, true) - else - return lib.notify({type = 'error', description = locale('refuel_cannot_afford')}) - end - - return lib.notify({type = 'error', description = locale('vehicle_far')}) - elseif petrolCan then - local vehicle = getVehicleInFront() - - if vehicle then - local hasFuel = Config.classUsage[GetVehicleClass(vehicle)] or true - - if hasFuel == 0.0 then return end - - local boneIndex = getVehiclePetrolCapBoneIndex(vehicle) - local fuelcapPosition = boneIndex and GetWorldPositionOfEntityBone(vehicle, boneIndex) - - if fuelcapPosition and #(playerCoords - fuelcapPosition) < 1.8 then - return startFueling(vehicle, false) - end - - return lib.notify({type = 'error', description = locale('vehicle_far')}) - end - end - end) - - RegisterKeyMapping('startfueling', 'Fuel vehicle', 'keyboard', 'e') - TriggerEvent('chat:removeSuggestion', '/startfueling') -end - - -if Config.ox_target then - if Config.petrolCan.enabled then - exports.ox_target:addModel(Config.pumpModels, { - { - distance = 2, - onSelect = function() - if getMoneyAmount() >= Config.priceTick then - startFueling(lastVehicle, 1) - else - lib.notify({type = 'error', description = locale('refuel_cannot_afford')}) - end - end, - icon = "fas fa-gas-pump", - label = locale('start_fueling'), - canInteract = function(entity) - if isFueling or cache.vehicle or lib.progressActive() then - return false - end - - return lastVehicle and #(GetEntityCoords(lastVehicle) - GetEntityCoords(cache.ped)) <= 3 - end - }, - { - distance = 2, - onSelect = function(data) - local petrolCan = Config.petrolCan.enabled and GetSelectedPedWeapon(cache.ped) == `WEAPON_PETROLCAN` - local moneyAmount = getMoneyAmount() - - if moneyAmount < Config.petrolCan.price then - return lib.notify({type = 'error', description = locale('petrolcan_cannot_afford')}) - end - - return getPetrolCan(data.coords, petrolCan) - end, - icon = "fas fa-faucet", - label = locale('petrolcan_buy_or_refill'), - }, - }) - else - exports.ox_target:addModel(Config.pumpModels, { - { - distance = 2, - onSelect = function() - if getMoneyAmount() >= Config.priceTick then - if GetVehicleFuelLevel(lastVehicle) >= 100 then - return lib.notify({type = 'error', description = locale('vehicle_full')}) - end - startFueling(lastVehicle, 1) - else - lib.notify({type = 'error', description = locale('refuel_cannot_afford')}) - end - end, - icon = "fas fa-gas-pump", - label = locale('start_fueling'), - canInteract = function(entity) - if isFueling or cache.vehicle then - return false - end - - return lastVehicle and #(GetEntityCoords(lastVehicle) - GetEntityCoords(cache.ped)) <= 3 - end - }, - }) - end - if Config.petrolCan.enabled then - exports.ox_target:addGlobalVehicle({ - { - distance = 2, - onSelect = function(data) - if not fuelingCan then - return lib.notify({type = 'error', description = locale('petrolcan_not_equipped')}) - end - - if fuelingCan.metadata.ammo <= Config.durabilityTick then - return lib.notify({ - type = 'error', - description = locale('petrolcan_not_enough_fuel') - }) - end - - startFueling(data.entity) - end, - icon = "fas fa-gas-pump", - label = locale('start_fueling'), - canInteract = function(entity) - if isFueling or cache.vehicle or lib.progressActive() then - return false - end - return fuelingCan and Config.petrolCan.enabled - end - } - }) - end -end - -AddTextEntry('fuelHelpText', locale('fuel_help')) -AddTextEntry('petrolcanHelpText', locale('petrolcan_help')) -AddTextEntry('fuelLeaveVehicleText', locale('leave_vehicle')) diff --git a/server-data/resources/[ox]/ox_fuel/client/fuel.lua b/server-data/resources/[ox]/ox_fuel/client/fuel.lua new file mode 100644 index 000000000..c1b68de2e --- /dev/null +++ b/server-data/resources/[ox]/ox_fuel/client/fuel.lua @@ -0,0 +1,142 @@ +local config = require("config") +local state = require("client.state") +local utils = require("client.utils") +local fuel = {} + +---@param vehState StateBag +---@param vehicle integer +---@param amount number +---@param replicate? boolean +function fuel.setFuel(vehState, vehicle, amount, replicate) + if DoesEntityExist(vehicle) then + amount = math.clamp(amount, 0, 100) + + SetVehicleFuelLevel(vehicle, amount) + vehState:set("fuel", amount, replicate) + end +end + +function fuel.getPetrolCan(coords, refuel) + TaskTurnPedToFaceCoord(cache.ped, coords.x, coords.y, coords.z, config.petrolCan.duration) + Wait(500) + + if + lib.progressCircle({ + duration = config.petrolCan.duration, + useWhileDead = false, + canCancel = true, + disable = { + move = true, + car = true, + combat = true, + }, + anim = { + dict = "timetable@gardener@filling_can", + clip = "gar_ig_5_filling_can", + flags = 49, + }, + }) + then + if refuel and exports.ox_inventory:GetItemCount("WEAPON_PETROLCAN") then + return TriggerServerEvent("ox_fuel:fuelCan", true, config.petrolCan.refillPrice) + end + + TriggerServerEvent("ox_fuel:fuelCan", false, config.petrolCan.price) + end + + ClearPedTasks(cache.ped) +end + +function fuel.startFueling(vehicle, isPump) + local vehState = Entity(vehicle).state + local fuelAmount = vehState.fuel or GetVehicleFuelLevel(vehicle) + local duration = math.ceil((100 - fuelAmount) / config.refillValue) * config.refillTick + local price, moneyAmount + local durability = 0 + + if 100 - fuelAmount < config.refillValue then + return lib.notify({ type = "error", description = locale("tank_full") }) + end + + if isPump then + price = 0 + moneyAmount = utils.getMoney() + + if config.priceTick > moneyAmount then + return lib.notify({ + type = "error", + description = locale("not_enough_money", config.priceTick), + }) + end + elseif not state.petrolCan then + return lib.notify({ type = "error", description = locale("petrolcan_not_equipped") }) + elseif state.petrolCan.metadata.ammo <= config.durabilityTick then + return lib.notify({ + type = "error", + description = locale("petrolcan_not_enough_fuel"), + }) + end + + state.isFueling = true + + TaskTurnPedToFaceEntity(cache.ped, vehicle, duration) + Wait(500) + + CreateThread(function() + lib.progressCircle({ + duration = duration, + useWhileDead = false, + canCancel = true, + disable = { + move = true, + car = true, + combat = true, + }, + anim = { + dict = isPump and "timetable@gardener@filling_can" or "weapon@w_sp_jerrycan", + clip = isPump and "gar_ig_5_filling_can" or "fire", + }, + }) + + state.isFueling = false + end) + + while state.isFueling do + if isPump then + price += config.priceTick + + if price + config.priceTick >= moneyAmount then + lib.cancelProgress() + end + elseif state.petrolCan then + durability += config.durabilityTick + + if durability >= state.petrolCan.metadata.ammo then + lib.cancelProgress() + durability = state.petrolCan.metadata.ammo + break + end + else + break + end + + fuelAmount += config.refillValue + + if fuelAmount >= 100 then + state.isFueling = false + fuelAmount = 100.0 + end + + Wait(config.refillTick) + end + + ClearPedTasks(cache.ped) + + if isPump then + TriggerServerEvent("ox_fuel:pay", price, fuelAmount, NetworkGetNetworkIdFromEntity(vehicle)) + else + TriggerServerEvent("ox_fuel:updateFuelCan", durability, NetworkGetNetworkIdFromEntity(vehicle), fuelAmount) + end +end + +return fuel diff --git a/server-data/resources/[ox]/ox_fuel/client/init.lua b/server-data/resources/[ox]/ox_fuel/client/init.lua new file mode 100644 index 000000000..6d1b10311 --- /dev/null +++ b/server-data/resources/[ox]/ox_fuel/client/init.lua @@ -0,0 +1,140 @@ +local config = require("config") + +if not config then + return +end + +SetFuelConsumptionState(true) +SetFuelConsumptionRateMultiplier(config.globalFuelConsumptionRate) + +AddTextEntry("fuelHelpText", locale("fuel_help")) +AddTextEntry("petrolcanHelpText", locale("petrolcan_help")) +AddTextEntry("fuelLeaveVehicleText", locale("leave_vehicle")) +AddTextEntry("ox_fuel_station", locale("fuel_station_blip")) + +local utils = require("client.utils") +local state = require("client.state") +local fuel = require("client.fuel") + +require("client.stations") + +local function startDrivingVehicle() + local vehicle = cache.vehicle + + if not DoesVehicleUseFuel(vehicle) then + return + end + + local vehState = Entity(vehicle).state + + if not vehState.fuel then + vehState:set("fuel", GetVehicleFuelLevel(vehicle), true) + while not vehState.fuel do + Wait(0) + end + end + + SetVehicleFuelLevel(vehicle, vehState.fuel) + + local fuelTick = 0 + + while cache.seat == -1 do + if not DoesEntityExist(vehicle) then + return + end + + local fuelAmount = tonumber(vehState.fuel) + local newFuel = GetVehicleFuelLevel(vehicle) + + if fuelAmount > 0 then + if GetVehiclePetrolTankHealth(vehicle) < 700 then + newFuel -= math.random(10, 20) * 0.01 + end + + if fuelAmount ~= newFuel then + if fuelTick == 15 then + fuelTick = 0 + end + + fuel.setFuel(vehState, vehicle, newFuel, fuelTick == 0) + fuelTick += 1 + end + end + + Wait(1000) + end + + fuel.setFuel(vehState, vehicle, vehState.fuel, true) +end + +if cache.seat == -1 then + CreateThread(startDrivingVehicle) +end + +lib.onCache("seat", function(seat) + if cache.vehicle then + state.lastVehicle = cache.vehicle + end + + if seat == -1 then + SetTimeout(0, startDrivingVehicle) + end +end) + +if config.ox_target then + return require("client.target") +end + +RegisterCommand("startfueling", function() + if state.isFueling or cache.vehicle or lib.progressActive() then + return + end + + local petrolCan = config.petrolCan.enabled and GetSelectedPedWeapon(cache.ped) == `WEAPON_PETROLCAN` + local playerCoords = GetEntityCoords(cache.ped) + local nearestPump = state.nearestPump + + if nearestPump then + local moneyAmount = utils.getMoney() + + if petrolCan and moneyAmount >= config.petrolCan.refillPrice then + return fuel.getPetrolCan(nearestPump, true) + end + + local vehicleInRange = state.lastVehicle and #(GetEntityCoords(state.lastVehicle) - playerCoords) <= 3 + + if not vehicleInRange then + if not config.petrolCan.enabled then + return + end + + if moneyAmount >= config.petrolCan.price then + return fuel.getPetrolCan(nearestPump) + end + + return lib.notify({ type = "error", description = locale("petrolcan_cannot_afford") }) + elseif moneyAmount >= config.priceTick then + return fuel.startFueling(state.lastVehicle, true) + else + return lib.notify({ type = "error", description = locale("refuel_cannot_afford") }) + end + + return lib.notify({ type = "error", description = locale("vehicle_far") }) + elseif petrolCan then + local vehicle = utils.getVehicleInFront() + + if vehicle and DoesVehicleUseFuel(vehicle) then + local boneIndex = utils.getVehiclePetrolCapBoneIndex(vehicle) + local fuelcapPosition = boneIndex and GetWorldPositionOfEntityBone(vehicle, boneIndex) + + if fuelcapPosition and #(playerCoords - fuelcapPosition) < 1.8 then + return fuel.startFueling(vehicle, false) + end + + return lib.notify({ type = "error", description = locale("vehicle_far") }) + end + end +end) + +RegisterKeyMapping("startfueling", "Fuel vehicle", "keyboard", "e") +TriggerEvent("chat:removeSuggestion", "/startfueling") diff --git a/server-data/resources/[ox]/ox_fuel/client/state.lua b/server-data/resources/[ox]/ox_fuel/client/state.lua new file mode 100644 index 000000000..0224cc393 --- /dev/null +++ b/server-data/resources/[ox]/ox_fuel/client/state.lua @@ -0,0 +1,22 @@ +---@class State +---@field petrolCan SlotWithItem? +---@field isFueling boolean +---@field nearestPump vector3? +---@field lastVehicle number? +local state = { + isFueling = false, + lastVehicle = cache.vehicle or GetPlayersLastVehicle() +} + +if state.lastVehicle == 0 then state.lastVehicle = nil end + +---@param data? SlotWithItem +local function setPetrolCan(data) + state.petrolCan = data?.name == 'WEAPON_PETROLCAN' and data or nil +end + +setPetrolCan(exports.ox_inventory:getCurrentWeapon()) + +AddEventHandler('ox_inventory:currentWeapon', setPetrolCan) + +return state diff --git a/server-data/resources/[ox]/ox_fuel/client/stations.lua b/server-data/resources/[ox]/ox_fuel/client/stations.lua new file mode 100644 index 000000000..a0890032a --- /dev/null +++ b/server-data/resources/[ox]/ox_fuel/client/stations.lua @@ -0,0 +1,81 @@ +local config = require("config") +local state = require("client.state") +local utils = require("client.utils") +local stations = lib.load("data.stations") + +if config.showBlips == 2 then + for station in pairs(stations) do + utils.createBlip(station) + end +end + +if config.ox_target and config.showBlips ~= 1 then + return +end + +---@param point CPoint +local function onEnterStation(point) + if config.showBlips == 1 and not point.blip then + point.blip = utils.createBlip(point.coords) + end +end + +---@param point CPoint +local function nearbyStation(point) + if point.currentDistance > 15 then + return + end + + local pumps = point.pumps + local pumpDistance + + for i = 1, #pumps do + local pump = pumps[i] + pumpDistance = #(cache.coords - pump) + + if pumpDistance <= 3 then + state.nearestPump = pump + + repeat + local playerCoords = GetEntityCoords(cache.ped) + pumpDistance = #(GetEntityCoords(cache.ped) - pump) + + 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 + + Wait(0) + until pumpDistance > 3 + + state.nearestPump = nil + + return + end + end +end + +---@param point CPoint +local function onExitStation(point) + if point.blip then + point.blip = RemoveBlip(point.blip) + 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 diff --git a/server-data/resources/[ox]/ox_fuel/client/target.lua b/server-data/resources/[ox]/ox_fuel/client/target.lua new file mode 100644 index 000000000..9647eed9b --- /dev/null +++ b/server-data/resources/[ox]/ox_fuel/client/target.lua @@ -0,0 +1,98 @@ +local config = require("config") +local state = require("client.state") +local utils = require("client.utils") +local fuel = require("client.fuel") + +if config.petrolCan.enabled then + exports.ox_target:addModel(config.pumpModels, { + { + distance = 2, + onSelect = function() + if utils.getMoney() >= config.priceTick then + fuel.startFueling(state.lastVehicle, 1) + else + lib.notify({ type = "error", description = locale("refuel_cannot_afford") }) + end + end, + icon = "fas fa-gas-pump", + label = locale("start_fueling"), + canInteract = function(entity) + if state.isFueling or cache.vehicle or lib.progressActive() then + return false + end + + return state.lastVehicle and #(GetEntityCoords(state.lastVehicle) - GetEntityCoords(cache.ped)) <= 3 + end, + }, + { + distance = 2, + onSelect = function(data) + local petrolCan = config.petrolCan.enabled and GetSelectedPedWeapon(cache.ped) == `WEAPON_PETROLCAN` + local moneyAmount = utils.getMoney() + + if moneyAmount < config.petrolCan.price then + return lib.notify({ type = "error", description = locale("petrolcan_cannot_afford") }) + end + + return fuel.getPetrolCan(data.coords, petrolCan) + end, + icon = "fas fa-faucet", + label = locale("petrolcan_buy_or_refill"), + }, + }) +else + exports.ox_target:addModel(config.pumpModels, { + { + distance = 2, + onSelect = function() + if utils.getMoney() >= config.priceTick then + if GetVehicleFuelLevel(state.lastVehicle) >= 100 then + return lib.notify({ type = "error", description = locale("vehicle_full") }) + end + fuel.startFueling(state.lastVehicle, 1) + else + lib.notify({ type = "error", description = locale("refuel_cannot_afford") }) + end + end, + icon = "fas fa-gas-pump", + label = locale("start_fueling"), + canInteract = function(entity) + if state.isFueling or cache.vehicle or not DoesVehicleUseFuel(state.lastVehicle) then + return false + end + + return state.lastVehicle and #(GetEntityCoords(state.lastVehicle) - GetEntityCoords(cache.ped)) <= 3 + end, + }, + }) +end + +if config.petrolCan.enabled then + exports.ox_target:addGlobalVehicle({ + { + distance = 2, + onSelect = function(data) + if not state.petrolCan then + return lib.notify({ type = "error", description = locale("petrolcan_not_equipped") }) + end + + if state.petrolCan.metadata.ammo <= config.durabilityTick then + return lib.notify({ + type = "error", + description = locale("petrolcan_not_enough_fuel"), + }) + end + + fuel.startFueling(data.entity) + end, + icon = "fas fa-gas-pump", + label = locale("start_fueling"), + canInteract = function(entity) + if state.isFueling or cache.vehicle or lib.progressActive() or not DoesVehicleUseFuel(entity) then + return false + end + return state.petrolCan and config.petrolCan.enabled + end, + }, + }) +end diff --git a/server-data/resources/[ox]/ox_fuel/client/utils.lua b/server-data/resources/[ox]/ox_fuel/client/utils.lua new file mode 100644 index 000000000..902c92e5b --- /dev/null +++ b/server-data/resources/[ox]/ox_fuel/client/utils.lua @@ -0,0 +1,63 @@ +local utils = {} + +---@param coords vector3 +---@return integer +function utils.createBlip(coords) + local blip = AddBlipForCoord(coords.x, coords.y, coords.z) + SetBlipSprite(blip, 361) + SetBlipDisplay(blip, 4) + SetBlipScale(blip, 0.8) + SetBlipColour(blip, 6) + SetBlipAsShortRange(blip, true) + BeginTextCommandSetBlipName("ox_fuel_station") + EndTextCommandSetBlipName(blip) + + return blip +end + +function utils.getVehicleInFront() + local coords = GetEntityCoords(cache.ped) + local destination = GetOffsetFromEntityInWorldCoords(cache.ped, 0.0, 2.2, -0.25) + local handle = StartShapeTestCapsule(coords.x, coords.y, coords.z, destination.x, destination.y, destination.z, 2.2, 2, cache.ped, 4) + + while true do + Wait(0) + local retval, _, _, _, entityHit = GetShapeTestResult(handle) + + if retval ~= 1 then + return entityHit ~= 0 and entityHit + end + end +end + +local bones = { + "petrolcap", + "petroltank", + "petroltank_l", + "hub_lr", + "engine", +} + +---@param vehicle integer +function utils.getVehiclePetrolCapBoneIndex(vehicle) + for i = 1, #bones do + local boneIndex = GetEntityBoneIndexByName(vehicle, bones[i]) + + if boneIndex ~= -1 then + return boneIndex + end + end +end + +---@return number +local function defaultMoneyCheck() + return exports.ox_inventory:GetItemCount("money") +end + +utils.getMoney = defaultMoneyCheck + +exports("setMoneyCheck", function(fn) + utils.getMoney = fn or defaultMoneyCheck +end) + +return utils diff --git a/server-data/resources/[ox]/ox_fuel/config.lua b/server-data/resources/[ox]/ox_fuel/config.lua index 15e0d8839..c1c801135 100644 --- a/server-data/resources/[ox]/ox_fuel/config.lua +++ b/server-data/resources/[ox]/ox_fuel/config.lua @@ -1,4 +1,7 @@ -Config = { +if not lib.checkDependency('ox_lib', '3.22.0', true) then return end +if not lib.checkDependency('ox_inventory', '2.30.0', true) then return end + +return { -- Get notified when a new version releases versionCheck = true, @@ -11,10 +14,7 @@ Config = { * 1 - Show nearest (5000ms interval check) * 2 - Show all */ - showBlips = 1, - - -- What keys to disable while fueling - disabledKeys = { 0, 22, 23, 24, 29, 30, 31, 37, 44, 56, 82, 140, 166, 167, 168, 170, 288, 289, 311, 323 }, + showBlips = 2, -- Total duration (ex. 10% missing fuel): 10 / 0.25 * 250 = 10 seconds @@ -38,44 +38,8 @@ Config = { refillPrice = 800, }, - -- Fuel usage multiplier based on class (default 1.0) - classUsage = { - [13] = 0.0, -- Cycles - }, - - -- Fuel usage per second based on vehicle RPM - rpmUsage = { - [1.0] = 0.14, - [0.9] = 0.12, - [0.8] = 0.10, - [0.7] = 0.09, - [0.6] = 0.08, - [0.5] = 0.07, - [0.4] = 0.05, - [0.3] = 0.04, - [0.2] = 0.02, - [0.1] = 0.01, - [0.0] = 0.00, - }, - - -- Electic vehicles (not currently used) - electricModels = { - [`airtug`] = true, - [`neon`] = true, - [`raiden`] = true, - [`caddy`] = true, - [`caddy2`] = true, - [`caddy3`] = true, - [`cyclone`] = true, - [`dilettante`] = true, - [`dilettante2`] = true, - [`surge`] = true, - [`tezeract`] = true, - [`imorgon`] = true, - [`khamelion`] = true, - [`voltic`] = true, - [`iwagen`] = true, - }, + ---Modifies the fuel consumption rate of all vehicles - see [`SET_FUEL_CONSUMPTION_RATE_MULTIPLIER`](https://docs.fivem.net/natives/?_0x845F3E5C). + globalFuelConsumptionRate = 10.0, -- Gas pump models pumpModels = { diff --git a/server-data/resources/[ox]/ox_fuel/data/stations.lua b/server-data/resources/[ox]/ox_fuel/data/stations.lua index dc8b3569a..95b3f39bf 100644 --- a/server-data/resources/[ox]/ox_fuel/data/stations.lua +++ b/server-data/resources/[ox]/ox_fuel/data/stations.lua @@ -1,207 +1,207 @@ -stations = { - -- Los Santos - [vec3(-71.28, -1761.16, 29.48)] = { - vec3(-63.61373901367187, -1767.937744140625, 28.26160812377929), - vec3(-61.03425216674805, -1760.8505859375, 28.30055999755859), - vec3(-69.45481872558594, -1758.018798828125, 28.54180145263672), - vec3(-72.0343017578125, -1765.10595703125, 28.52847290039062), - vec3(-80.17231750488281, -1762.143798828125, 28.79890060424804), - vec3(-77.5927505493164, -1755.056884765625, 28.80794906616211) - }, - - [vec3(264.74, -1260.98, 29.18)] = { - vec3(256.4333801269531, -1253.46142578125, 28.2867317199707), - vec3(256.4333801269531, -1261.29833984375, 28.29153060913086), - vec3(256.4333801269531, -1268.6396484375, 28.29116821289062), - vec3(265.0627136230469, -1268.6396484375, 28.29112243652343), - vec3(265.0627136230469, -1261.29833984375, 28.29272079467773), - vec3(265.0627136230469, -1253.46142578125, 28.28998565673828), - vec3(273.8385925292969, -1253.46142578125, 28.29183197021484), - vec3(273.8385925292969, -1261.29833984375, 28.2861328125), - vec3(273.8385925292969, -1268.6396484375, 28.29059982299804) - }, - - [vec3(1208.66, -1402.64, 35.22)] = { - vec3(1212.937255859375, -1404.030029296875, 34.38496017456055), - vec3(1210.064697265625, -1406.903076171875, 34.38496017456055), - vec3(1204.1953125, -1401.03369140625, 34.38496017456055), - vec3(1207.068115234375, -1398.160888671875, 34.38496017456055) - }, - - [vec3(818.83, -1029.89, 26.17)] = { - vec3(810.698974609375, -1026.247802734375, 25.43555450439453), - vec3(810.698974609375, -1030.94140625, 25.43555450439453), - vec3(818.986083984375, -1030.94140625, 25.43555450439453), - vec3(818.986083984375, -1026.247802734375, 25.43555450439453), - vec3(827.2933349609375, -1026.247802734375, 25.63511276245117), - vec3(827.2933349609375, -1030.94140625, 25.63511276245117) - }, - - [vec3(1181.27, -329.57, 69.18)] = { - vec3(1186.3909912109376, -338.2332458496094, 68.35638427734375), - vec3(1178.9632568359376, -339.5430603027344, 68.3656005859375), - vec3(1177.4598388671876, -331.0143737792969, 68.3187255859375), - vec3(1184.8870849609376, -329.7048034667969, 68.30953979492188), - vec3(1183.1292724609376, -320.9965515136719, 68.35069274902344), - vec3(1175.7015380859376, -322.3061218261719, 68.35877990722656) - }, - - [vec3(621.07, 269.52, 103.04)] = { - vec3(612.4210205078125, 273.9571533203125, 102.26951599121094), - vec3(612.4322509765625, 263.83575439453127, 102.26951599121094), - vec3(620.9901123046875, 263.8359375, 102.26951599121094), - vec3(620.986083984375, 273.96978759765627, 102.26951599121094), - vec3(629.630615234375, 273.9698486328125, 102.26951599121094), - vec3(629.634521484375, 263.835693359375, 102.26951599121094) - }, - - [vec3(-1437.58, -276.38, 46.21)] = { - vec3(-1429.075927734375, -279.15185546875, 45.40259552001953), - vec3(-1438.072021484375, -268.69781494140627, 45.40358734130859), - vec3(-1444.5035400390626, -274.23236083984377, 45.40358734130859), - vec3(-1435.5074462890626, -284.6864013671875, 45.40259552001953) - }, - - [vec3(-2096.6, -318.15, 13.02)] = { - vec3(-2088.755615234375, -327.3988037109375, 12.1609182357788), - vec3(-2088.086669921875, -321.0352478027344, 12.1609182357788), - vec3(-2087.21533203125, -312.8184814453125, 12.1609182357788), - vec3(-2096.096435546875, -311.9068908691406, 12.1609182357788), - vec3(-2096.814453125, -320.1178894042969, 12.1609182357788), - vec3(-2097.4833984375, -326.48150634765627, 12.1609182357788), - vec3(-2106.065673828125, -325.5794677734375, 12.1609182357788), - vec3(-2105.396728515625, -319.2159118652344, 12.1609182357788), - vec3(-2104.53515625, -311.01983642578127, 12.1609182357788) - }, - - [vec3(-1799.03, 803.11, 138.4)] = { - vec3(-1795.9344482421876, 811.963623046875, 137.69021606445313), - vec3(-1790.8387451171876, 806.4029541015625, 137.69512939453126), - vec3(-1797.2239990234376, 800.5526123046875, 137.65481567382813), - vec3(-1802.3189697265626, 806.1129150390625, 137.65170288085938), - vec3(-1808.7191162109376, 799.951416015625, 137.68540954589845), - vec3(-1803.6236572265626, 794.3907470703125, 137.68983459472657) - }, - - [vec3(-524.84, -1211.02, 18.18)] = { - vec3(-522.2349853515625, -1217.422119140625, 17.32516098022461), - vec3(-524.9267578125, -1216.152099609375, 17.32538604736328), - vec3(-529.51708984375, -1213.962646484375, 17.32538604736328), - vec3(-532.2852783203125, -1212.71875, 17.32538604736328), - vec3(-528.5758056640625, -1204.80126953125, 17.32538604736328), - vec3(-525.8076171875, -1206.044921875, 17.32538604736328), - vec3(-521.21728515625, -1208.234375, 17.32538604736328), - vec3(-518.525634765625, -1209.50439453125, 17.32516098022461) - }, - - [vec3(2581.56, 361.65, 108.46)] = { - vec3(2588.406005859375, 358.5595703125, 107.65083312988281), - vec3(2588.645751953125, 364.0592041015625, 107.65049743652344), - vec3(2581.173583984375, 364.3847351074219, 107.65000915527344), - vec3(2580.93408203125, 358.88507080078127, 107.6507797241211), - vec3(2573.544677734375, 359.20697021484377, 107.65115356445313), - vec3(2573.7841796875, 364.7066650390625, 107.65056610107422) - }, - - [vec3(-319.84, -1471.77, 30.55)] = { - vec3(-329.8195495605469, -1471.6396484375, 29.72901153564453), - vec3(-324.7491149902344, -1480.4140625, 29.7288589477539), - vec3(-317.2628479003906, -1476.091796875, 29.72502899169922), - vec3(-322.3332214355469, -1467.317626953125, 29.72066497802734), - vec3(-314.9219665527344, -1463.03857421875, 29.72624969482422), - vec3(-309.8515319824219, -1471.79833984375, 29.72341156005859) - }, - - [vec3(175.31, -1561.73, 29.26)] = { - vec3(181.8067169189453, -1561.9698486328126, 28.32902526855468), - vec3(174.9801483154297, -1568.4442138671876, 28.32902526855468), - vec3(169.29725646972657, -1562.2669677734376, 28.32902526855468), - vec3(176.02076721191407, -1555.9114990234376, 28.32838058471679) - }, - - [vec3(-723.72, -935.51, 19.21)] = { - vec3(-732.6458129882813, -932.5162353515625, 18.211669921875), - vec3(-732.6458129882813, -939.3216552734375, 18.211669921875), - vec3(-724.0073852539063, -939.3216552734375, 18.211669921875), - vec3(-724.0073852539063, -932.5162353515625, 18.211669921875), - vec3(-715.4374389648438, -932.5162353515625, 18.211669921875), - vec3(-715.4374389648438, -939.3216552734375, 18.211669921875) - }, - - -- Blaine County - [vec3(-2555.31, 2334.01, 33.06)] = { - vec3(-2551.396240234375, 2327.115478515625, 32.24691772460937), - vec3(-2558.021484375, 2326.704345703125, 32.25613403320312), - vec3(-2558.484619140625, 2334.1337890625, 32.2554702758789), - vec3(-2552.607177734375, 2334.467529296875, 32.254150390625), - vec3(-2552.3984375, 2341.8916015625, 32.21600341796875), - vec3(-2558.7724609375, 2341.48779296875, 32.2252197265625) - }, - - [vec3(49.69, 2778.33, 57.88)] = { - vec3(50.30570602416992, 2778.53466796875, 57.04140090942383), - vec3(48.9130973815918, 2779.58544921875, 57.04140090942383) - }, - - [vec3(264.15, 2607.05, 44.95)] = { - vec3(264.976318359375, 2607.177734375, 43.98323059082031), - vec3(263.08258056640627, 2606.794677734375, 43.98323059082031) - }, - - [vec3(1207.56, 2660.2, 37.81)] = { - vec3(1208.509765625, 2659.427978515625, 36.89814758300781), - vec3(1209.58154296875, 2658.3515625, 36.89955139160156), - vec3(1205.8997802734376, 2662.048583984375, 36.89674377441406) - }, - - [vec3(2538.0, 2593.83, 37.94)] = { - vec3(2539.79443359375, 2594.807861328125, 36.95571899414062) - }, - - [vec3(2680.01, 3265.0, 55.24)] = { - vec3(2680.90234375, 3266.40771484375, 54.39086151123047), - vec3(2678.512939453125, 3262.3369140625, 54.39086151123047) - }, - - [vec3(2005.07, 3774.33, 32.18)] = { - vec3(2009.25439453125, 3776.7734375, 31.39846420288086), - vec3(2006.205078125, 3774.95654296875, 31.39846420288086), - vec3(2003.913818359375, 3773.47607421875, 31.39846420288086), - vec3(2001.546875, 3772.20166015625, 31.39846420288086) - }, - - [vec3(1688.42, 4930.85, 42.08)] = { - vec3(1684.5911865234376, 4931.6552734375, 41.22716522216797), - vec3(1690.0948486328126, 4927.8017578125, 41.22769546508789) - }, - - [vec3(1039.34, 2671.78, 39.55)] = { - vec3(1043.2193603515626, 2674.445556640625, 38.70339202880859), - vec3(1035.4425048828126, 2674.435791015625, 38.70319366455078), - vec3(1035.4423828125, 2667.904052734375, 38.70318984985351), - vec3(1043.2196044921876, 2667.913818359375, 38.70345306396484) - }, - - [vec3(1785.58, 3330.47, 41.38)] = { - vec3(1785.032470703125, 3331.47607421875, 40.34383392333984), - vec3(1786.079833984375, 3329.853515625, 40.41194534301758) - }, - - -- Paleto bay stations - [vec3(1702.79, 6416.86, 33.64)] = { - vec3(1697.756591796875, 6418.34423828125, 31.760009765625), - vec3(1701.724365234375, 6416.48291015625, 31.760009765625), - vec3(1705.737060546875, 6414.60009765625, 31.760009765625) - }, - - [vec3(179.94, 6602.6, 31.85)] = { - vec3(186.97091674804688, 6606.2177734375, 31.0625), - vec3(179.67465209960938, 6604.9306640625, 31.0625), - vec3(172.33335876464845, 6603.6357421875, 31.0625) - }, - - [vec3(-93.98, 6420.1, 31.48)] = { - vec3(-97.06086730957031, 6416.7666015625, 30.64349365234375), - vec3(-91.29045104980469, 6422.537109375, 30.64349365234375) - }, +return { + -- Los Santos + [vec3(-71.28, -1761.16, 29.48)] = { + vec3(-63.61373901367187, -1767.937744140625, 28.26160812377929), + vec3(-61.03425216674805, -1760.8505859375, 28.30055999755859), + vec3(-69.45481872558594, -1758.018798828125, 28.54180145263672), + vec3(-72.0343017578125, -1765.10595703125, 28.52847290039062), + vec3(-80.17231750488281, -1762.143798828125, 28.79890060424804), + vec3(-77.5927505493164, -1755.056884765625, 28.80794906616211), + }, + + [vec3(264.74, -1260.98, 29.18)] = { + vec3(256.4333801269531, -1253.46142578125, 28.2867317199707), + vec3(256.4333801269531, -1261.29833984375, 28.29153060913086), + vec3(256.4333801269531, -1268.6396484375, 28.29116821289062), + vec3(265.0627136230469, -1268.6396484375, 28.29112243652343), + vec3(265.0627136230469, -1261.29833984375, 28.29272079467773), + vec3(265.0627136230469, -1253.46142578125, 28.28998565673828), + vec3(273.8385925292969, -1253.46142578125, 28.29183197021484), + vec3(273.8385925292969, -1261.29833984375, 28.2861328125), + vec3(273.8385925292969, -1268.6396484375, 28.29059982299804), + }, + + [vec3(1208.66, -1402.64, 35.22)] = { + vec3(1212.937255859375, -1404.030029296875, 34.38496017456055), + vec3(1210.064697265625, -1406.903076171875, 34.38496017456055), + vec3(1204.1953125, -1401.03369140625, 34.38496017456055), + vec3(1207.068115234375, -1398.160888671875, 34.38496017456055), + }, + + [vec3(818.83, -1029.89, 26.17)] = { + vec3(810.698974609375, -1026.247802734375, 25.43555450439453), + vec3(810.698974609375, -1030.94140625, 25.43555450439453), + vec3(818.986083984375, -1030.94140625, 25.43555450439453), + vec3(818.986083984375, -1026.247802734375, 25.43555450439453), + vec3(827.2933349609375, -1026.247802734375, 25.63511276245117), + vec3(827.2933349609375, -1030.94140625, 25.63511276245117), + }, + + [vec3(1181.27, -329.57, 69.18)] = { + vec3(1186.3909912109376, -338.2332458496094, 68.35638427734375), + vec3(1178.9632568359376, -339.5430603027344, 68.3656005859375), + vec3(1177.4598388671876, -331.0143737792969, 68.3187255859375), + vec3(1184.8870849609376, -329.7048034667969, 68.30953979492188), + vec3(1183.1292724609376, -320.9965515136719, 68.35069274902344), + vec3(1175.7015380859376, -322.3061218261719, 68.35877990722656), + }, + + [vec3(621.07, 269.52, 103.04)] = { + vec3(612.4210205078125, 273.9571533203125, 102.26951599121094), + vec3(612.4322509765625, 263.83575439453127, 102.26951599121094), + vec3(620.9901123046875, 263.8359375, 102.26951599121094), + vec3(620.986083984375, 273.96978759765627, 102.26951599121094), + vec3(629.630615234375, 273.9698486328125, 102.26951599121094), + vec3(629.634521484375, 263.835693359375, 102.26951599121094), + }, + + [vec3(-1437.58, -276.38, 46.21)] = { + vec3(-1429.075927734375, -279.15185546875, 45.40259552001953), + vec3(-1438.072021484375, -268.69781494140627, 45.40358734130859), + vec3(-1444.5035400390626, -274.23236083984377, 45.40358734130859), + vec3(-1435.5074462890626, -284.6864013671875, 45.40259552001953), + }, + + [vec3(-2096.6, -318.15, 13.02)] = { + vec3(-2088.755615234375, -327.3988037109375, 12.1609182357788), + vec3(-2088.086669921875, -321.0352478027344, 12.1609182357788), + vec3(-2087.21533203125, -312.8184814453125, 12.1609182357788), + vec3(-2096.096435546875, -311.9068908691406, 12.1609182357788), + vec3(-2096.814453125, -320.1178894042969, 12.1609182357788), + vec3(-2097.4833984375, -326.48150634765627, 12.1609182357788), + vec3(-2106.065673828125, -325.5794677734375, 12.1609182357788), + vec3(-2105.396728515625, -319.2159118652344, 12.1609182357788), + vec3(-2104.53515625, -311.01983642578127, 12.1609182357788), + }, + + [vec3(-1799.03, 803.11, 138.4)] = { + vec3(-1795.9344482421876, 811.963623046875, 137.69021606445313), + vec3(-1790.8387451171876, 806.4029541015625, 137.69512939453126), + vec3(-1797.2239990234376, 800.5526123046875, 137.65481567382813), + vec3(-1802.3189697265626, 806.1129150390625, 137.65170288085938), + vec3(-1808.7191162109376, 799.951416015625, 137.68540954589845), + vec3(-1803.6236572265626, 794.3907470703125, 137.68983459472657), + }, + + [vec3(-524.84, -1211.02, 18.18)] = { + vec3(-522.2349853515625, -1217.422119140625, 17.32516098022461), + vec3(-524.9267578125, -1216.152099609375, 17.32538604736328), + vec3(-529.51708984375, -1213.962646484375, 17.32538604736328), + vec3(-532.2852783203125, -1212.71875, 17.32538604736328), + vec3(-528.5758056640625, -1204.80126953125, 17.32538604736328), + vec3(-525.8076171875, -1206.044921875, 17.32538604736328), + vec3(-521.21728515625, -1208.234375, 17.32538604736328), + vec3(-518.525634765625, -1209.50439453125, 17.32516098022461), + }, + + [vec3(2581.56, 361.65, 108.46)] = { + vec3(2588.406005859375, 358.5595703125, 107.65083312988281), + vec3(2588.645751953125, 364.0592041015625, 107.65049743652344), + vec3(2581.173583984375, 364.3847351074219, 107.65000915527344), + vec3(2580.93408203125, 358.88507080078127, 107.6507797241211), + vec3(2573.544677734375, 359.20697021484377, 107.65115356445313), + vec3(2573.7841796875, 364.7066650390625, 107.65056610107422), + }, + + [vec3(-319.84, -1471.77, 30.55)] = { + vec3(-329.8195495605469, -1471.6396484375, 29.72901153564453), + vec3(-324.7491149902344, -1480.4140625, 29.7288589477539), + vec3(-317.2628479003906, -1476.091796875, 29.72502899169922), + vec3(-322.3332214355469, -1467.317626953125, 29.72066497802734), + vec3(-314.9219665527344, -1463.03857421875, 29.72624969482422), + vec3(-309.8515319824219, -1471.79833984375, 29.72341156005859), + }, + + [vec3(175.31, -1561.73, 29.26)] = { + vec3(181.8067169189453, -1561.9698486328126, 28.32902526855468), + vec3(174.9801483154297, -1568.4442138671876, 28.32902526855468), + vec3(169.29725646972657, -1562.2669677734376, 28.32902526855468), + vec3(176.02076721191407, -1555.9114990234376, 28.32838058471679), + }, + + [vec3(-723.72, -935.51, 19.21)] = { + vec3(-732.6458129882813, -932.5162353515625, 18.211669921875), + vec3(-732.6458129882813, -939.3216552734375, 18.211669921875), + vec3(-724.0073852539063, -939.3216552734375, 18.211669921875), + vec3(-724.0073852539063, -932.5162353515625, 18.211669921875), + vec3(-715.4374389648438, -932.5162353515625, 18.211669921875), + vec3(-715.4374389648438, -939.3216552734375, 18.211669921875), + }, + + -- Blaine County + [vec3(-2555.31, 2334.01, 33.06)] = { + vec3(-2551.396240234375, 2327.115478515625, 32.24691772460937), + vec3(-2558.021484375, 2326.704345703125, 32.25613403320312), + vec3(-2558.484619140625, 2334.1337890625, 32.2554702758789), + vec3(-2552.607177734375, 2334.467529296875, 32.254150390625), + vec3(-2552.3984375, 2341.8916015625, 32.21600341796875), + vec3(-2558.7724609375, 2341.48779296875, 32.2252197265625), + }, + + [vec3(49.69, 2778.33, 57.88)] = { + vec3(50.30570602416992, 2778.53466796875, 57.04140090942383), + vec3(48.9130973815918, 2779.58544921875, 57.04140090942383), + }, + + [vec3(264.15, 2607.05, 44.95)] = { + vec3(264.976318359375, 2607.177734375, 43.98323059082031), + vec3(263.08258056640627, 2606.794677734375, 43.98323059082031), + }, + + [vec3(1207.56, 2660.2, 37.81)] = { + vec3(1208.509765625, 2659.427978515625, 36.89814758300781), + vec3(1209.58154296875, 2658.3515625, 36.89955139160156), + vec3(1205.8997802734376, 2662.048583984375, 36.89674377441406), + }, + + [vec3(2538.0, 2593.83, 37.94)] = { + vec3(2539.79443359375, 2594.807861328125, 36.95571899414062), + }, + + [vec3(2680.01, 3265.0, 55.24)] = { + vec3(2680.90234375, 3266.40771484375, 54.39086151123047), + vec3(2678.512939453125, 3262.3369140625, 54.39086151123047), + }, + + [vec3(2005.07, 3774.33, 32.18)] = { + vec3(2009.25439453125, 3776.7734375, 31.39846420288086), + vec3(2006.205078125, 3774.95654296875, 31.39846420288086), + vec3(2003.913818359375, 3773.47607421875, 31.39846420288086), + vec3(2001.546875, 3772.20166015625, 31.39846420288086), + }, + + [vec3(1688.42, 4930.85, 42.08)] = { + vec3(1684.5911865234376, 4931.6552734375, 41.22716522216797), + vec3(1690.0948486328126, 4927.8017578125, 41.22769546508789), + }, + + [vec3(1039.34, 2671.78, 39.55)] = { + vec3(1043.2193603515626, 2674.445556640625, 38.70339202880859), + vec3(1035.4425048828126, 2674.435791015625, 38.70319366455078), + vec3(1035.4423828125, 2667.904052734375, 38.70318984985351), + vec3(1043.2196044921876, 2667.913818359375, 38.70345306396484), + }, + + [vec3(1785.58, 3330.47, 41.38)] = { + vec3(1785.032470703125, 3331.47607421875, 40.34383392333984), + vec3(1786.079833984375, 3329.853515625, 40.41194534301758), + }, + + -- Paleto bay stations + [vec3(1702.79, 6416.86, 33.64)] = { + vec3(1697.756591796875, 6418.34423828125, 31.760009765625), + vec3(1701.724365234375, 6416.48291015625, 31.760009765625), + vec3(1705.737060546875, 6414.60009765625, 31.760009765625), + }, + + [vec3(179.94, 6602.6, 31.85)] = { + vec3(186.97091674804688, 6606.2177734375, 31.0625), + vec3(179.67465209960938, 6604.9306640625, 31.0625), + vec3(172.33335876464845, 6603.6357421875, 31.0625), + }, + + [vec3(-93.98, 6420.1, 31.48)] = { + vec3(-97.06086730957031, 6416.7666015625, 30.64349365234375), + vec3(-91.29045104980469, 6422.537109375, 30.64349365234375), + }, } diff --git a/server-data/resources/[ox]/ox_fuel/fxmanifest.lua b/server-data/resources/[ox]/ox_fuel/fxmanifest.lua index e5f40bfc1..4b38492f1 100644 --- a/server-data/resources/[ox]/ox_fuel/fxmanifest.lua +++ b/server-data/resources/[ox]/ox_fuel/fxmanifest.lua @@ -1,36 +1,37 @@ ---[[ FX Information ]]-- -fx_version 'cerulean' -use_experimental_fxv2_oal 'yes' -lua54 'yes' -game 'gta5' +fx_version("cerulean") +use_experimental_fxv2_oal("yes") +lua54("yes") +game("gta5") ---[[ Resource Information ]]-- -name 'ox_fuel' -author 'Overextended' -version '1.4.0' -repository 'https://github.com/overextended/ox_fuel' -description 'Fuel management system with ox_inventory support' +name("ox_fuel") +author("Overextended") +version("1.5.1") +repository("https://github.com/overextended/ox_fuel") +description("Fuel management system with ox_inventory support") ---[[ Manifest ]]-- -dependencies { - 'ox_lib', - 'ox_inventory', -} +dependencies({ + "ox_lib", + "ox_inventory", +}) -shared_scripts { - '@ox_lib/init.lua', - 'config.lua' -} +shared_scripts({ + "@ox_lib/init.lua", + "config.lua", +}) -server_scripts { - 'server.lua' -} +server_scripts({ + "server.lua", +}) -client_scripts { - 'data/stations.lua', - 'client.lua' -} +client_script("client/init.lua") -files { - 'locales/*.json' -} +files({ + "locales/*.json", + "data/stations.lua", + "client/*.lua", +}) + +ox_libs({ + "math", + "locale", +}) diff --git a/server-data/resources/[ox]/ox_fuel/locales/cs.json b/server-data/resources/[ox]/ox_fuel/locales/cs.json index 7e3c09aa8..e97657a07 100644 --- a/server-data/resources/[ox]/ox_fuel/locales/cs.json +++ b/server-data/resources/[ox]/ox_fuel/locales/cs.json @@ -17,4 +17,4 @@ "petrolcan_cannot_carry": "Neunesete kanystr", "petrolcan_not_enough_fuel": "Kanystr nemá v sobě dostatek paliva", "petrolcan_not_equipped": "Musíš mít v ruce kanystr, aby jsi mohl natankovat" -} +} \ No newline at end of file diff --git a/server-data/resources/[ox]/ox_fuel/locales/de.json b/server-data/resources/[ox]/ox_fuel/locales/de.json index da543ada3..663b3fbb3 100644 --- a/server-data/resources/[ox]/ox_fuel/locales/de.json +++ b/server-data/resources/[ox]/ox_fuel/locales/de.json @@ -15,4 +15,4 @@ "petrolcan_refill": "Du hast $%s für das Auffüllen deines Treibstoffkanisters bezahlt", "petrolcan_buy": "Du hast $%s für einen Treibstoffkanister bezahlt", "petrolcan_cannot_carry": "Du kannst diesen Treibstoffkanister nicht tragen" -} +} \ No newline at end of file diff --git a/server-data/resources/[ox]/ox_fuel/server.lua b/server-data/resources/[ox]/ox_fuel/server.lua index 5f1c23668..f22039c13 100644 --- a/server-data/resources/[ox]/ox_fuel/server.lua +++ b/server-data/resources/[ox]/ox_fuel/server.lua @@ -1,20 +1,22 @@ -if not lib.checkDependency('ox_lib', '3.0.0', true) then return end +local config = require 'config' -if not lib.checkDependency('ox_inventory', '2.28.4', true) then return end +if not config then return end -lib.locale() - -if Config.versionCheck then lib.versionCheck('overextended/ox_fuel') end +if config.versionCheck then lib.versionCheck('overextended/ox_fuel') end local ox_inventory = exports.ox_inventory -local function setFuelState(netid, fuel) - local vehicle = NetworkGetEntityFromNetworkId(netid) - local state = vehicle and Entity(vehicle)?.state +local function setFuelState(netId, fuel) + local vehicle = NetworkGetEntityFromNetworkId(netId) - if state then - state:set('fuel', fuel, true) + if vehicle == 0 or GetEntityType(vehicle) ~= 2 then + return end + + local state = Entity(vehicle)?.state + fuel = math.clamp(fuel, 0, 100) + + state:set('fuel', fuel, true) end ---@param playerId number @@ -25,7 +27,7 @@ local function defaultPaymentMethod(playerId, price) if success then return true end - local money = ox_inventory:GetItem(source, 'money', false, true) + local money = ox_inventory:GetItemCount(source, 'money') TriggerClientEvent('ox_lib:notify', source, { type = 'error', @@ -102,12 +104,3 @@ RegisterNetEvent('ox_fuel:updateFuelCan', function(durability, netid, fuel) -- player is sus? end) - -RegisterNetEvent('ox_fuel:createStatebag', function(netid, fuel) - local vehicle = NetworkGetEntityFromNetworkId(netid) - local state = vehicle and Entity(vehicle).state - - if state and not state.fuel and GetEntityType(vehicle) == 2 and NetworkGetEntityOwner(vehicle) == source then - state:set('fuel', fuel > 100 and 100 or fuel, true) - end -end)