diff --git a/README.md b/README.md index 86b926c..7713a8e 100644 --- a/README.md +++ b/README.md @@ -1,32 +1,10 @@ ### About -Started off as my first script, and for whatever reason, I decided to release it. As it was pretty badly created, I felt like I should rewrite it and make a better version, so ended up spending a few hours doing so. +My Forked version of LegacyFuel all rights belong to the owner. +this is my version and its NUI based +![image](https://user-images.githubusercontent.com/82306584/134341351-46b14e43-986a-4f26-9e7b-37eac8516f1e.png) ### Installation 1) Download the latest version in the "code" tab on GitHub. 2) Drag & drop the folder into your `resources` server folder. 3) Configure the config file to your liking. -4) Add `start LegacyFuel` to your server config. - -### Exports -There are currently two (client-sided) exports available, which should help you control the fuel level for vehicles whenever needed. - -``` -SetFuel(vehicle --[[ Vehicle ]], value --[[ Number: (0-100) ]]) -GetFuel(vehicle --[[ Vehicle ]]) -- Returns the vehicle's fuel level. -``` - -**Example usage:** -``` -function SpawnVehicle(modelHash) - local vehicle = CreateVehicle(modelHash, coords.x, coords.y, coords.z, true, false) - - exports["LegacyFuel"]:SetFuel(vehicle, 100) -end - -function StoreVehicleInGarage(vehicle) - local plate = GetVehicleNumberPlateText(vehicle) - local fuelLevel = exports["LegacyFuel"]:GetFuel(vehicle) - - TriggerServerEvent('vehiclesStored', plate, fuelLevel) -end -``` +4) Add `start renzu_fuel` to your server config. diff --git a/client.lua b/client.lua new file mode 100644 index 0000000..c8e3e10 --- /dev/null +++ b/client.lua @@ -0,0 +1,369 @@ +local isNearPump = false +local pumpLocation = nil +local isFueling = false +local currentFuel = 0.0 +local currentFuel2 = 0.0 +local currentCost = 0.0 + +local output = { + ['price'] = Config.stock.default_price, + ['stock'] = Config.stock.default_stock, +} + +function close() + SetNuiFocus(false, false) + SendNUIMessage({ action = false }) + isFueling = false +end + +function open(vehicle,data) + SetNuiFocus(true, true) + SendNUIMessage({ action = true, fuel = GetVehicleFuelLevel(vehicle), data = data }) +end + +RegisterNetEvent('renzu_fuel:open') +AddEventHandler('renzu_fuel:open',function(vehicle,data) + open(vehicle,data) +end) + +AddEventHandler('onResourceStart', function(name) + if GetCurrentResourceName() ~= name then return end + close() +end) + +RegisterNUICallback('escape', function(data, cb) + close() +end) + +RegisterNetEvent('renzu_fuel:close') +AddEventHandler('renzu_fuel:close',function() + close() +end) + +function ManageFuelUsage(vehicle) + if IsVehicleEngineOn(vehicle) then + SetVehicleFuelLevel(vehicle,GetVehicleFuelLevel(vehicle) - Config.FuelUsage[Round(GetVehicleCurrentRpm(vehicle),1)] * (Config.Classes[GetVehicleClass(vehicle)] or 1.0) / 10) + DecorSetFloat(vehicle,Config.FuelDecor,GetVehicleFuelLevel(vehicle)) + end +end + +Citizen.CreateThread(function() + if Config.Managefuel then + DecorRegister(Config.FuelDecor,1) + while true do + Citizen.Wait(2000) + local ped = PlayerPedId() + if IsPedInAnyVehicle(ped) then + local vehicle = GetVehiclePedIsIn(ped) + if GetPedInVehicleSeat(vehicle,-1) == ped then + ManageFuelUsage(vehicle) + end + end + end + end +end) + +function FindNearestFuelPump() + local coords = GetEntityCoords(PlayerPedId()) + local fuelPumps = {} + local handle,object = FindFirstObject() + local success + for k,v in pairs(GetGamePool('CObject')) do + if Config.PumpModels[GetEntityModel(v)] then + table.insert(fuelPumps,v) + end + end + + local pumpObject = 0 + local pumpDistance = 1000 + + for k,v in pairs(fuelPumps) do + local dstcheck = #(coords - GetEntityCoords(v)) + + if dstcheck < pumpDistance then + pumpDistance = dstcheck + pumpObject = v + end + end + return pumpObject,pumpDistance +end + +RegisterNetEvent("renzu_fuel:syncfuel") +AddEventHandler("renzu_fuel:syncfuel",function(index,change,FuelDecor) + if NetworkDoesNetworkIdExist(index) then + local v = NetToVeh(index) + if DoesEntityExist(v) then + SetVehicleFuelLevel(v,(GetVehicleFuelLevel(v) + change)) + DecorSetFloat(v,FuelDecor,GetVehicleFuelLevel(v)) + end + end +end) + +RegisterNetEvent('renzu_fuel:jerrycan') +AddEventHandler('renzu_fuel:jerrycan',function() + GiveWeaponToPed(PlayerPedId(),883325847,4500,false,true) +end) + +function Round(num,numDecimalPlaces) + local mult = 10^(numDecimalPlaces or 0) + return math.floor(num*mult+0.5) / mult +end + +--[[ Creates gas station and blips ]]-- +Citizen.CreateThread(function() + Wait(1000) + local blip = {} + for k,v in pairs(Config.GasStation) do + if not DoesBlipExist(blip[k]) then + local x,y,z = table.unpack(v) + blip[k] = AddBlipForCoord(x,y,z) + SetBlipSprite(blip[k], 361) + SetBlipDisplay(blip[k], 5) + SetBlipScale(blip[k], 0.5) + SetBlipColour(blip[k], 1) + SetBlipAsShortRange(blip[k], true) + + BeginTextCommandSetBlipName('Gas Station') + AddTextEntry(k, 'Gas Station') + EndTextCommandSetBlipName(blip[k]) + end + end +end) + +RegisterNetEvent('renzu_fuel:refuelFromPump') +AddEventHandler('renzu_fuel:refuelFromPump',function(pumpObject,ped,vehicle) + currentFuel = GetVehicleFuelLevel(vehicle) + TaskTurnPedToFaceEntity(ped,vehicle,5000) + LoadAnimDict("timetable@gardener@filling_can") + TaskPlayAnim(ped,"timetable@gardener@filling_can","gar_ig_5_filling_can",2.0,8.0,-1,50,0,0,0,0) + isFueling = true + while isFueling do + Citizen.Wait(4) + local oldFuel = DecorGetFloat(vehicle,Config.FuelDecor)+0.0 + local fuelToAdd = math.random(1,2) / 100.0 + + for k,v in pairs(Config.DisableKeys) do + DisableControlAction(0,v) + end + + local vehicleCoords = GetEntityCoords(vehicle) + if not pumpObject then + DrawText3Ds(vehicleCoords.x,vehicleCoords.y,vehicleCoords.z + 0.5,"PRESS ~g~E ~w~TO CANCEL") + DrawText3Ds(vehicleCoords.x,vehicleCoords.y,vehicleCoords.z + 0.34,"GALLON: ~b~"..Round(GetAmmoInPedWeapon(ped,883325847) / 4500 * 100,1).."%~w~ TANK: ~y~"..Round(currentFuel,1).."%") + if GetAmmoInPedWeapon(ped,883325847) - fuelToAdd * 100 >= 0 then + currentFuel = currentFuel + fuelToAdd + SetPedAmmo(ped,883325847,math.floor(GetAmmoInPedWeapon(ped,883325847) - fuelToAdd * 100)) + else + isFueling = false + end + end + + if not IsEntityPlayingAnim(ped,"timetable@gardener@filling_can","gar_ig_5_filling_can",3) then + TaskPlayAnim(ped,"timetable@gardener@filling_can","gar_ig_5_filling_can",2.0,8.0,-1,50,0,0,0,0) + end + + if currentFuel > 100.0 then + currentFuel = 100.0 + isFueling = false + end + + SetVehicleFuelLevel(vehicle,currentFuel) + + if IsControlJustReleased(0,38) or DoesEntityExist(GetPedInVehicleSeat(vehicle,-1)) then + isFueling = false + end + end + DecorSetFloat(vehicle,Config.FuelDecor,GetVehicleFuelLevel(vehicle)+0.0) + + ClearPedTasks(ped) + RemoveAnimDict("timetable@gardener@filling_can") +end) + +RegisterNetEvent('renzu_fuel:fuelevent') +AddEventHandler('renzu_fuel:fuelevent',function(pumpObject,ped,vehicle) + local vehicle = GetPlayersLastVehicle() + local vehicleCoords = GetEntityCoords(vehicle) + local ped = PlayerPedId() + if DoesEntityExist(vehicle) and GetDistanceBetweenCoords(GetEntityCoords(ped),vehicleCoords) < 3.5 then + if isNearPump then + open(vehicle,output) + isFueling = true + paid = false + else + isFueling = true + TriggerEvent('renzu_fuel:refuelFromPump',isNearPump,ped,vehicle) + end + end +end) + +function PopUI(name,v,reqdist,event,arg,server) + if reqdist == nil then reqdist = 5 end + local table = { + ['event'] = event, + ['title'] = name, + ['server_event'] = server, + ['unpack_arg'] = true, + ['invehicle_title'] = 'Get out to vehicle', + ['confirm'] = '[ENTER]', + ['fa'] = '', + ['reject'] = '[CLOSE]', + ['custom_arg'] = arg, -- example: {1,2,3,4} + ['use_cursor'] = false, -- USE MOUSE CURSOR INSTEAD OF INPUT (ENTER) + } + TriggerEvent('renzu_popui:showui',table) + local dist = #(v - GetEntityCoords(PlayerPedId())) + while dist < reqdist and isNearPump do + dist = #(v - GetEntityCoords(PlayerPedId())) + Wait(100) + end + TriggerEvent('renzu_popui:closeui') +end + +function DrawtextUI(name,v,reqdist,event,arg,server,invehicle,key) + if reqdist == nil then reqdist = 5 end + local table = { + ['key'] = key or 'backspace', + ['event'] = event, + ['title'] = name, + ['invehicle_title'] = name, + ['server_event'] = server, + ['unpack_arg'] = true, + ['fa'] = '', + ['custom_arg'] = arg, -- example: {1,2,3,4} + } + TriggerEvent('renzu_popui:drawtextuiwithinput',table) + local dist = #(v - GetEntityCoords(PlayerPedId())) + while dist < reqdist and isNearPump and not IsPedInAnyVehicle(PlayerPedId()) do + dist = #(v - GetEntityCoords(PlayerPedId())) + Wait(100) + end + if invehicle then + while dist < reqdist and isNearPump and IsPedInAnyVehicle(PlayerPedId()) do + dist = #(v - GetEntityCoords(PlayerPedId())) + Wait(100) + end + end + TriggerEvent('renzu_popui:closeui') +end + +Citizen.CreateThread(function() + while true do + Citizen.Wait(2000) + local ped = PlayerPedId() + local sleep = 2000 + local pumpObject,pumpDistance = FindNearestFuelPump() + if pumpDistance < 3.0 then + isNearPump = pumpObject + else + isNearPump = false + Citizen.Wait(math.ceil(pumpDistance*5)) + end + Citizen.Wait(2000) + end +end) + +Citizen.CreateThread(function() + while true do + Citizen.Wait(2000) + local ped = PlayerPedId() + local sleep = 2000 + while not isFueling and ((isNearPump and GetEntityHealth(isNearPump) > 0) or (GetSelectedPedWeapon(ped) == 883325847 and not isNearPump)) do + if isNearPump then + sleep = 1000 + end + if IsPedInAnyVehicle(ped) and GetPedInVehicleSeat(GetVehiclePedIsIn(ped),-1) == ped then + local pumpCoords = GetEntityCoords(isNearPump) + DrawtextUI("Get Out of Vehicle",pumpCoords,3.5,'dummyevent',{},false,true) + else + local vehicle = GetPlayersLastVehicle() + local vehicleCoords = GetEntityCoords(vehicle) + if DoesEntityExist(vehicle) and GetDistanceBetweenCoords(GetEntityCoords(ped),vehicleCoords) < 3.5 then + if not DoesEntityExist(GetPedInVehicleSeat(vehicle,-1)) then + local stringCoords = GetEntityCoords(isNearPump) + local canFuel = true + if GetSelectedPedWeapon(ped) == 883325847 then + stringCoords = vehicleCoords + if GetAmmoInPedWeapon(ped,883325847) < 100 then + canFuel = false + end + end + + if GetVehicleFuelLevel(vehicle) < 99 and canFuel and isNearPump then + DrawtextUI("Press [E] to Re Fuel Vehicle",stringCoords,3.5,'renzu_fuel:open',{vehicle,output},false,false,'E') + --PopUI("Re Fuel Vehicle",stringCoords,3.5,'renzu_fuel:open',{vehicle,output},false) + elseif canFuel and GetVehicleFuelLevel(vehicle) < 99 then + DrawtextUI("Press [E] to Re Fuel Vehicle (PETROL CAN)",stringCoords,3.5,'renzu_fuel:refuelFromPump',{false,ped,vehicle},false,false,'E') + elseif not canFuel then + DrawtextUI("Cant Fuel",stringCoords,3.5,'dummyevent',{},false,false) + else + DrawtextUI("FULL TANK",stringCoords,3.5,'dummyevent',{},false,false) + end + end + elseif isNearPump then + local stringCoords = GetEntityCoords(isNearPump) + DrawtextUI("Press [E] to Buy Jerry Can",stringCoords,3.5,'renzu_fuel:payfuel',{10000,true},true,false,'E') + --PopUI("Buy Jerry Can",stringCoords,3.5,'renzu_fuel:payfuel',{10000,true},true) + end + end + Citizen.Wait(sleep) + end + end +end) + +function ShowHelpNotification(msg, thisFrame, beep, duration) + AddTextEntry('notify_gas', msg) + DisplayHelpTextThisFrame('notify_gas', thisFrame) +end + +RegisterNetEvent('renzu_fuel:Notify') +AddEventHandler('renzu_fuel:Notify',function(msg) + ShowHelpNotification(msg, false) +end) + +RegisterNUICallback('pay', function(data, cb) + local vehicle = GetPlayersLastVehicle() + local new_perc = tonumber(data.new_perc) + if not paid then + if DoesEntityExist(vehicle) and GetDistanceBetweenCoords(GetEntityCoords(PlayerPedId()),GetEntityCoords(vehicle)) < 5 then + TriggerServerEvent('renzu_fuel:payfuel',math.floor(new_perc),false,VehToNet(vehicle),math.floor(new_perc),Config.FuelDecor,pumpLocation) + paid = true + end + end +end) + +RegisterNUICallback('startanim',function(data,cb) + local ped = PlayerPedId() + local vehicle = GetPlayersLastVehicle() + TaskTurnPedToFaceEntity(ped,vehicle,5000) + LoadAnimDict("timetable@gardener@filling_can") + TaskPlayAnim(ped,"timetable@gardener@filling_can","gar_ig_5_filling_can",2.0,8.0,-1,50,0,0,0,0) +end) + +RegisterNUICallback('removeanim',function(data,cb) + local ped = PlayerPedId() + ClearPedTasks(ped) + RemoveAnimDict("timetable@gardener@filling_can") +end) + +function DrawText3Ds(x,y,z,text) + local onScreen,_x,_y = World3dToScreen2d(x,y,z) + + SetTextFont(4) + SetTextScale(0.35,0.35) + SetTextColour(255,255,255,150) + SetTextEntry("STRING") + SetTextCentre(1) + AddTextComponentString(text) + DrawText(_x,_y) + local factor = (string.len(text))/370 + DrawRect(_x,_y+0.0125,0.01+factor,0.03,0,0,0,80) +end + +function LoadAnimDict(dict) + if not HasAnimDictLoaded(dict) then + RequestAnimDict(dict) + while not HasAnimDictLoaded(dict) do + Citizen.Wait(10) + end + end +end \ No newline at end of file diff --git a/config.lua b/config.lua index 8e4ec39..bcde04c 100644 --- a/config.lua +++ b/config.lua @@ -1,48 +1,17 @@ Config = {} --- Are you using ESX? Turn this to true if you would like fuel & jerry cans to cost something. -Config.UseESX = true - --- What should the price of jerry cans be? -Config.JerryCanCost = 100 -Config.RefillCost = 50 -- If it is missing half of it capacity, this amount will be divided in half, and so on. - --- Fuel decor - No need to change this, just leave it. -Config.FuelDecor = "_FUEL_LEVEL" - --- What keys are disabled while you're fueling. -Config.DisableKeys = {0, 22, 23, 24, 29, 30, 31, 37, 44, 56, 82, 140, 166, 167, 168, 170, 288, 289, 311, 323} - --- Want to use the HUD? Turn this to true. -Config.EnableHUD = true - --- Configure blips here. Turn both to false to disable blips all together. -Config.ShowNearestGasStationOnly = true -Config.ShowAllGasStations = false - --- Modify the fuel-cost here, using a multiplier value. Setting the value to 2.0 would cause a doubled increase. -Config.CostMultiplier = 1.0 +Config.ESX = { + ['ESXSHAREDOBJECT'] = "esx:getSharedObject", +} --- Configure the strings as you wish here. -Config.Strings = { - ExitVehicle = "Exit the vehicle to refuel", - EToRefuel = "Press ~g~E ~w~to refuel vehicle", - JerryCanEmpty = "Jerry can is empty", - FullTank = "Tank is full", - PurchaseJerryCan = "Press ~g~E ~w~to purchase a jerry can for ~g~$" .. Config.JerryCanCost, - CancelFuelingPump = "Press ~g~E ~w~to cancel the fueling", - CancelFuelingJerryCan = "Press ~g~E ~w~to cancel the fueling", - NotEnoughCash = "Not enough cash", - RefillJerryCan = "Press ~g~E ~w~ to refill the jerry can for ", - NotEnoughCashJerryCan = "Not enough cash to refill jerry can", - JerryCanFull = "Jerry can is full", - TotalCost = "Cost", +Config.stock = { + ['default_price'] = 7.00, + ['default_stock'] = 9999 } +Config.Managefuel = false -- enable disable managefuel, disable if you only want gas station function +Config.FuelDecor = "_FUEL_LEVEL" -if not Config.UseESX then - Config.Strings.PurchaseJerryCan = "Press ~g~E ~w~to grab a jerry can" - Config.Strings.RefillJerryCan = "Press ~g~E ~w~ to refill the jerry can" -end +Config.DisableKeys = { 0,22,23,24,29,30,31,37,44,56,82,140,166,167,168,170,288,289,311,323 } Config.PumpModels = { [-2007231801] = true, @@ -54,83 +23,71 @@ Config.PumpModels = { [-164877493] = true } --- Blacklist certain vehicles. Use names or hashes. https://wiki.gtanet.work/index.php?title=Vehicle_Models -Config.Blacklist = { - --"Adder", - --276773164 +Config.GasStation = { + ["gas_station_1"] = {264.95275878906,-1259.4567871094,29.142911911011,30}, + ["gas_station_2"] = {819.61047363281,-1028.2071533203,26.404321670532,30}, + ["gas_station_3"] = {1208.6068115234,-1402.2863769531,35.224140167236,30}, + ["gas_station_4"] = {1180.9593505859,-329.84280395508,69.316436767578,30}, + ["gas_station_5"] = {620.80499267578,268.73849487305,103.08948516846,30}, + ["gas_station_6"] = {2581.1779785156,362.01254272461,108.46883392334,30}, + ["gas_station_7"] = {175.55857849121,-1562.2135009766,29.264209747314,30}, + ["gas_station_8"] = {-319.42581176758,-1471.8182373047,30.548692703247,30}, + ["gas_station_9"] = {1785.9000244141,3330.9035644531,41.377250671387,30}, + ["gas_station_10"] = {49.802303314209,2779.318359375,58.043937683105,30}, + ["gas_station_11"] = {263.92358398438,2607.4140625,44.983062744141,30}, + ["gas_station_12"] = {1039.1220703125,2671.30859375,39.550872802734,30}, + ["gas_station_13"] = {1208.0380859375,2660.4892578125,37.899772644043,30}, + ["gas_station_14"] = {2539.3337402344,2594.61328125,37.944820404053,30}, + ["gas_station_15"] = {2679.9396972656,3264.0981445313,55.240585327148,30}, + ["gas_station_16"] = {2005.0074462891,3774.2006835938,32.40393447876,30}, + ["gas_station_17"] = {1687.263671875,4929.6328125,42.078086853027,30}, + ["gas_station_18"] = {1702.0052490234,6416.9975585938,32.763767242432,30}, + ["gas_station_19"] = {179.82470703125,6602.8408203125,31.868196487427,30}, + ["gas_station_20"] = {-94.206100463867,6419.4975585938,31.489490509033,30}, + ["gas_station_21"] = {-2555.1257324219,2334.2705078125,33.078022003174,30}, + ["gas_station_22"] = {-1799.4152832031,802.8154296875,138.65368652344,30}, + ["gas_station_23"] = {-1436.9724121094,-276.55426025391,46.207653045654,30}, + ["gas_station_24"] = {-2096.5913085938,-321.48611450195,13.168619155884,30}, + ["gas_station_25"] = {-723.298828125,-935.55322265625,19.213928222656,30}, + ["gas_station_26"] = {-525.35266113281,-1211.3215332031,18.184829711914,30}, + ["gas_station_27"] = {-70.514175415039,-1761.2590332031,29.655626296997,30}, } --- Do you want the HUD removed from showing in blacklisted vehicles? -Config.RemoveHUDForBlacklistedVehicle = true - --- Class multipliers. If you want SUVs to use less fuel, you can change it to anything under 1.0, and vise versa. Config.Classes = { - [0] = 1.0, -- Compacts - [1] = 1.0, -- Sedans - [2] = 1.0, -- SUVs - [3] = 1.0, -- Coupes - [4] = 1.0, -- Muscle - [5] = 1.0, -- Sports Classics - [6] = 1.0, -- Sports - [7] = 1.0, -- Super - [8] = 1.0, -- Motorcycles - [9] = 1.0, -- Off-road - [10] = 1.0, -- Industrial - [11] = 1.0, -- Utility - [12] = 1.0, -- Vans + [0] = 0.6, -- Compacts + [1] = 0.6, -- Sedans + [2] = 0.6, -- SUVs + [3] = 0.6, -- Coupes + [4] = 0.6, -- Muscle + [5] = 0.6, -- Sports Classics + [6] = 0.6, -- Sports + [7] = 0.6, -- Super + [8] = 0.6, -- Motorcycles + [9] = 0.6, -- Off-road + [10] = 0.6, -- Industrial + [11] = 0.6, -- Utility + [12] = 0.6, -- Vans [13] = 0.0, -- Cycles - [14] = 1.0, -- Boats - [15] = 1.0, -- Helicopters - [16] = 1.0, -- Planes - [17] = 1.0, -- Service - [18] = 1.0, -- Emergency - [19] = 1.0, -- Military - [20] = 1.0, -- Commercial - [21] = 1.0, -- Trains + [14] = 0.0, -- Boats + [15] = 0.0, -- Helicopters + [16] = 0.0, -- Planes + [17] = 0.3, -- Service + [18] = 0.3, -- Emergency + [19] = 0.6, -- Military + [20] = 0.6, -- Commercial + [21] = 0.6, -- Trains } --- The left part is at percentage RPM, and the right is how much fuel (divided by 10) you want to remove from the tank every second Config.FuelUsage = { - [1.0] = 1.4, - [0.9] = 1.2, - [0.8] = 1.0, - [0.7] = 0.9, - [0.6] = 0.8, - [0.5] = 0.7, - [0.4] = 0.5, - [0.3] = 0.4, - [0.2] = 0.2, - [0.1] = 0.1, + [1.0] = 2.0, + [0.9] = 1.8, + [0.8] = 1.6, + [0.7] = 1.4, + [0.6] = 1.2, + [0.5] = 1.0, + [0.4] = 0.8, + [0.3] = 0.6, + [0.2] = 0.4, + [0.1] = 0.2, [0.0] = 0.0, -} - -Config.GasStations = { - vector3(49.4187, 2778.793, 58.043), - vector3(263.894, 2606.463, 44.983), - vector3(1039.958, 2671.134, 39.550), - vector3(1207.260, 2660.175, 37.899), - vector3(2539.685, 2594.192, 37.944), - vector3(2679.858, 3263.946, 55.240), - vector3(2005.055, 3773.887, 32.403), - vector3(1687.156, 4929.392, 42.078), - vector3(1701.314, 6416.028, 32.763), - vector3(179.857, 6602.839, 31.868), - vector3(-94.4619, 6419.594, 31.489), - vector3(-2554.996, 2334.40, 33.078), - vector3(-1800.375, 803.661, 138.651), - vector3(-1437.622, -276.747, 46.207), - vector3(-2096.243, -320.286, 13.168), - vector3(-724.619, -935.1631, 19.213), - vector3(-526.019, -1211.003, 18.184), - vector3(-70.2148, -1761.792, 29.534), - vector3(265.648, -1261.309, 29.292), - vector3(819.653, -1028.846, 26.403), - vector3(1208.951, -1402.567,35.224), - vector3(1181.381, -330.847, 69.316), - vector3(620.843, 269.100, 103.089), - vector3(2581.321, 362.039, 108.468), - vector3(176.631, -1562.025, 29.263), - vector3(176.631, -1562.025, 29.263), - vector3(-319.292, -1471.715, 30.549), - vector3(1784.324, 3330.55, 41.253) -} +} \ No newline at end of file diff --git a/functions/functions_client.lua b/functions/functions_client.lua deleted file mode 100644 index 37ba151..0000000 --- a/functions/functions_client.lua +++ /dev/null @@ -1,88 +0,0 @@ -function GetFuel(vehicle) - return DecorGetFloat(vehicle, Config.FuelDecor) -end - -function SetFuel(vehicle, fuel) - if type(fuel) == 'number' and fuel >= 0 and fuel <= 100 then - SetVehicleFuelLevel(vehicle, fuel + 0.0) - DecorSetFloat(vehicle, Config.FuelDecor, GetVehicleFuelLevel(vehicle)) - end -end - -function LoadAnimDict(dict) - if not HasAnimDictLoaded(dict) then - RequestAnimDict(dict) - - while not HasAnimDictLoaded(dict) do - Citizen.Wait(1) - end - end -end - -function DrawText3Ds(x, y, z, text) - local onScreen,_x,_y=World3dToScreen2d(x,y,z) - - if onScreen then - SetTextScale(0.35, 0.35) - SetTextFont(4) - SetTextProportional(1) - SetTextColour(255, 255, 255, 215) - SetTextEntry("STRING") - SetTextCentre(1) - AddTextComponentString(text) - DrawText(_x,_y) - end -end - -function Round(num, numDecimalPlaces) - local mult = 10^(numDecimalPlaces or 0) - - return math.floor(num * mult + 0.5) / mult -end - -function CreateBlip(coords) - local blip = AddBlipForCoord(coords) - - SetBlipSprite(blip, 361) - SetBlipScale(blip, 0.9) - SetBlipColour(blip, 4) - SetBlipDisplay(blip, 4) - SetBlipAsShortRange(blip, true) - - BeginTextCommandSetBlipName("STRING") - AddTextComponentString("Gas Station") - EndTextCommandSetBlipName(blip) - - return blip -end - -function FindNearestFuelPump() - local coords = GetEntityCoords(PlayerPedId()) - local fuelPumps = {} - local handle, object = FindFirstObject() - local success - - repeat - if Config.PumpModels[GetEntityModel(object)] then - table.insert(fuelPumps, object) - end - - success, object = FindNextObject(handle, object) - until not success - - EndFindObject(handle) - - local pumpObject = 0 - local pumpDistance = 1000 - - for _, fuelPumpObject in pairs(fuelPumps) do - local dstcheck = GetDistanceBetweenCoords(coords, GetEntityCoords(fuelPumpObject)) - - if dstcheck < pumpDistance then - pumpDistance = dstcheck - pumpObject = fuelPumpObject - end - end - - return pumpObject, pumpDistance -end diff --git a/fxmanifest.lua b/fxmanifest.lua index 9103586..6565ebc 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -1,23 +1,23 @@ -fx_version 'bodacious' -game 'gta5' +fx_version "adamant" +game "gta5" -author 'InZidiuZ' -description 'Legacy Fuel' -version '1.3' - --- What to run -client_scripts { - 'config.lua', - 'functions/functions_client.lua', - 'source/fuel_client.lua' -} +ui_page 'html/ui.html' server_scripts { - 'config.lua', - 'source/fuel_server.lua' + "@mysql-async/lib/MySQL.lua", + "config.lua", + "server.lua" } -exports { - 'GetFuel', - 'SetFuel' +client_scripts { + "config.lua", + "client.lua" } + +dependency 'renzu_popui' +files { + 'html/ui.html', + 'html/ui.css', + 'html/ui.js', + 'html/logo.png' +} \ No newline at end of file diff --git a/html/logo.png b/html/logo.png new file mode 100644 index 0000000..aab682b Binary files /dev/null and b/html/logo.png differ diff --git a/html/ui.css b/html/ui.css new file mode 100644 index 0000000..e537b72 --- /dev/null +++ b/html/ui.css @@ -0,0 +1,280 @@ +@import url('https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,300;0,500;1,200&display=swap'); +body { + display: flex; + align-items: center; + justify-content: center; + display: none; + margin-top: -20%; + margin-left: 40%; +} + +* { + user-select: none; + box-sizing: border-box; + font-family: 'Raleway', sans-serif; +} + +.container { + position: relative; + width: 400px; + height: 400px; + padding-top: 8px; + padding-left: 15px; + background-color: rgb(8 8 8 / 50%); + border-top-right-radius: 10px; + border-bottom-right-radius: 10px; +} + +.container small { + position: relative; + top: 5px; + color: rgb(241 251 250); + font-size: 9px; + font-size: 15px; + font-weight: 300; + letter-spacing: 1px; + text-transform: uppercase; + font-family: 'Poppins', sans-serif; +} + +.container span img { + max-width: 18px; +} + +.container span { + color: rgb(209 225 255); + font-size: 25px; + margin-bottom: 10px; + text-transform: uppercase; +} + +.container .box { + margin-top: 10px; +} + +.container .box:nth-child(2) { + margin-top: 20px; +} + +.container .box:nth-child(3) { + margin-top: 20px; +} + +.container .box #title { + font-size: 13px; +} + +.container .item { + position: relative; + width: 94%; + height: 60px; + display: flex; + color: #fff; + margin-top: 10px; + text-align: center; + align-items: center; + justify-content: center; + border-width: 2px; + border-style: solid; + border-image: linear-gradient( + to bottom, + #000000, + #22a7f4 + ) 1 100%; + text-transform: uppercase; + background: #00000052; + border-radius: 10px; +} + +.container .item .litro { + position: relative; + color: #fff; + font-size: 20px; + font-family: 'Poppins', sans-serif; + font-weight: 200; +} + +#amount { + border: 0; + color: #fff; + outline: none; + text-align: center; + font-size: 16px; + font-family: 'Poppins', sans-serif; + font-weight: 150; + background: transparent; +} + +#minus { +} + +#plus { +} + +.modal { + position: absolute; + top:50%; + left: 50%; + width: 300px; + height: 120px; + color: #ffff; + padding: 14px; + font-size: 11px; + font-weight: 600; + text-align: center; + border-radius: .3rem; + text-transform: uppercase; + /* backdrop-filter: blur(20px); */ + transform: translate(-50%,-50%); + background-color: rgb(0 0 0 / 64%); + border-radius: 10px; +} + +.modal b { + position: relative; + top: 6px; + font-size: 20px; + font-weight: 200; + font-family: 'Poppins', sans-serif; +} + +.modal .accept { + position: absolute; + border: 0; + left: 15px; + width: 120px; + bottom: 30px; + outline: none; + color: #fff; + font-size: 12px; + font-weight: 200; + padding: 5px 7px; + border-radius: 30px; + text-transform: uppercase; + font-family: 'Poppins', sans-serif; + background-color: rgba(13, 17, 19, 0.938); + height: 40px; +} + +.modal .recuse { + position: absolute; + border: 0; + right: 15px; + width: 120px; + bottom: 30px; + outline: none; + color: #fff; + font-size: 12px; + padding: 5px 7px; + font-weight: 200; + border-radius: 30px; + text-transform: uppercase; + font-family: 'Poppins', sans-serif; + background-color: rgba(13, 17, 19, 0.938); + height: 40px; +} + +.modal .btninfo:hover { + background-color: rgba(24, 36, 43, 0.938); +} + +.container .item button { + position: absolute; + display: flex; + top: 46%; + border: 0; + width: 20px; + height: 20px; + color: #fff; + padding-top: 3px; + font-weight: 100; + border-radius: 100%; + align-items: center; + justify-content: center; + transform: translate(0,-50%); + font-family: 'Poppins', sans-serif; + background: linear-gradient(to right, #2367a0ea, #003a92); +} + +.container .item button:nth-child(1) { + left: 5px; +} + +left { + position: relative; + display: flex; + width: 200px; + height: 400px; + padding: 15px; + color: #fff; + font-size: 7px; + line-height: 15px; + margin-right: 10px; + text-align: center; + flex-direction: column; + text-transform: uppercase; + background-color: rgb(14 14 14 / 56%); + border-top-left-radius: 10px; + border-bottom-left-radius: 10px; +} + +left img { + position: absolute; + left: 50%; + max-height: 200px; + max-width: 120px; + transform: translate(-50%,0); + top: 10%; +} + +left p { + font-size: 13px; + margin-top: 70px; + letter-spacing: 1px; +} + +.act { + position: absolute; + width: 100%; + bottom: 0; + left: 0; +} + +left .act button { + border: 0; + opacity: .9; + width: 100%; + height: 60px; + outline: none; + color: #fff; + font-weight: 300; + letter-spacing: 1px; + background-color: transparent; + border-top: 1px solid rgb(240 240 241 / 22%); + border-bottom: 1px solid rgb(101 117 128 / 38%); +} + +left .act button:hover { + opacity: 1; + color: #252525; + font-weight: 400; + background-color: #f3f3f3; +} + +left .act button:active { + background: linear-gradient(to right, #f3f3f3, #C5C6C8); +} + +left .act button:last-child { + border-top: 0px; +} + +input[type=number]::-webkit-inner-spin-button { + -webkit-appearance: none; + +} +input[type=number] { + -moz-appearance: textfield; + appearance: textfield; + +} \ No newline at end of file diff --git a/html/ui.html b/html/ui.html new file mode 100644 index 0000000..56862cd --- /dev/null +++ b/html/ui.html @@ -0,0 +1,51 @@ + + + + + + + + + + + + +
+ + + +
+
+
+ To fuel
+ Vehicle +
+ Price to Pay +
+ + + +
+
+
+ Vehicle fuel +
+
+ $ 0.00 +
+
+
+
+ Price per liter +
+ $ 1.00 +
+
+
+ + + diff --git a/html/ui.js b/html/ui.js new file mode 100644 index 0000000..f90acd0 --- /dev/null +++ b/html/ui.js @@ -0,0 +1,196 @@ +$(document).ready(function(){ + window.addEventListener('message', function( event ) { + if (event.data.action == true) { + + fuel = event.data.fuel; + datafuel = event.data.fuel + dataGas = event.data.data + + + $('#fuel-price').empty(); + $('#fuel-price').append(new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD'}).format(dataGas.price)); + $('#stock').empty(); + if (dataGas.stock == 0) { + $('#stock').append("OUT OF STOCK
" + "NO PETROL
"); + $('.act').fadeOut(); + } else { + $('#stock').append("Fuel in stock:
" + dataGas.stock + " Litres
"); + $('.act').fadeIn(300); + } + + $('body').css('display','flex'); + $('.modal').css('display','none'); + $('.litro').text(Math.round(event.data.fuel) + ' Liters'); + $("#amount").val("") + + $(document).keyup(function(e) { + if (!counting) { + if (e.key === "Escape") { + myStop(); + $("#amount").val("") + counting; + inv; + price; + perc_new; + totalPercent; + guardar; + completar; + maxFuel; + $.post('http://renzu_fuel/escape', JSON.stringify({})); + } + } + }); + } else { + $('body').fadeOut(); + } + }); + function close() {} + + var counting; + var completar; + var guardar; + var price; + var inv; + var totalPercent; + var perc_new; + var maxFuel; + + + function myStart() { + if (inv == undefined) { inv = setInterval(increase,1000); } + } + + function myStop() { + if (inv !== undefined) { clearInterval(inv); inv = undefined; } + } + + function increase() { + if (counting) { + if (fuel < maxFuel) { + fuel++; + totalPercent = Math.round(fuel) + '%' + $('.litro').text(totalPercent); + } else { + $.post('http://renzu_fuel/removeanim', JSON.stringify({})); + if (completar) { + console.log(perc_new*dataGas.price) + console.log(price) + $.post('http://renzu_fuel/pay', JSON.stringify({ new_perc: perc_new*dataGas.price })); + perc_new; + completar = !completar; + } else if (guardar) { + console.log(perc_new*dataGas.price) + console.log(price) + $.post('http://renzu_fuel/pay', JSON.stringify({ new_perc: price })); + price; + guardar = !guardar; + } + counting = !counting; + inv; + totalPercent; + maxFuel; + myStop(); + $.post('http://renzu_fuel/escape', JSON.stringify({})); + } + } + } + + $( "#retirar" ).click(function() { + if (!counting) { + perc_new = 100 - Math.round(datafuel); + $.post('http://renzu_fuel/checkpay', JSON.stringify({ new_perc: perc_new })); + counting = !counting; + completar = !completar; + maxFuel = 99 + $('.modal span').text("Do you want to fill the tank at $"+(perc_new*dataGas.price).toFixed(2)); + $('.modal').fadeIn(300); + $('.container').fadeOut(); + $('left').fadeOut(); + $('.act').fadeOut(); + } + }); + + $( "#guardar" ).click(function() { + if (!counting) { + price = Math.round($("#amount").val()); + if (price > dataGas.price) { + console.log(price) + console.log(((100-Math.round(datafuel))*dataGas.price)) + if (price <= ((100-Math.round(datafuel))*dataGas.price)) { + $.post('http://renzu_fuel/checkpay', JSON.stringify({ new_perc: price })); + counting = !counting; + guardar = !guardar; + maxFuel = (Math.floor(price/dataGas.price)+Math.round(datafuel))-1 + $('.modal span').text("Do you want to fill the tank at $ "+price); + $('.modal').fadeIn(300); + $('.container').fadeOut(); + $('left').fadeOut(); + $('.act').fadeOut(); + } else { + var texto = "The maximum value to fill the tank is $"+((100-Math.round(datafuel))*dataGas.price)+"!" + $.post('http://renzu_fuel/notifytext', JSON.stringify({ text: texto })); + } + } else { + var texto = "The price must be greater than $" + dataGas.price + "!" + $.post('http://renzu_fuel/notifytext', JSON.stringify({ text: texto })); + } + } + }); + + $( "#close" ).click(function() { + $("#amount").val("") + counting; + inv; + price; + perc_new; + totalPercent; + guardar; + completar; + maxFuel; + $.post('http://renzu_fuel/escape', JSON.stringify({})); + }) + + $( "#plus" ).click(function() { + if (!counting) { + if (Math.round($("#amount").val()) < 100) { + $("#amount").val(Math.round($("#amount").val())+1) + price = $("#amount").val() + } + } + }); + + $( "#minus" ).click(function() { + if (!counting) { + if (Math.round($("#amount").val()) > 0) { + $("#amount").val(Math.round($("#amount").val())-1) + price = $("#amount").val() + } + } + }); + + $(".accept").click(function() { + if (counting) { + $('.modal').fadeOut(); + $('.container').fadeIn(300); + $('left').fadeIn(300); + $('.act').fadeIn(300); + $.post('http://renzu_fuel/startanim', JSON.stringify({})); + myStop(); + myStart(); + } + }) + + $(".recuse").click(function() { + $('.modal').fadeOut(); + $('.container').fadeIn(300); + $('left').fadeIn(300); + $('.act').fadeIn(300); + if (completar) { + counting = !counting; + completar = !completar; + } else if (guardar) { + counting = !counting; + guardar = !guardar; + } + }) +}); \ No newline at end of file diff --git a/server.lua b/server.lua new file mode 100644 index 0000000..4387501 --- /dev/null +++ b/server.lua @@ -0,0 +1,32 @@ +ESX = nil +TriggerEvent(Config.ESX.ESXSHAREDOBJECT, function(obj) ESX = obj end) + +RegisterServerEvent("renzu_fuel:payfuel") +AddEventHandler("renzu_fuel:payfuel",function(price,jeryycan,vehicle,fuel,fuel2,key) + local source = source + local output = {} + output = { + ['price'] = Config.stock.default_price, + } + local xPlayer = ESX.GetPlayerFromId(source) + if price > 0 then + local amount = 0 + money = xPlayer.getMoney() + if money >= price then + xPlayer.removeMoney(price) + if jeryycan then + xPlayer.removeWeapon('WEAPON_PETROLCAN') + Wait(500) + xPlayer.addWeapon('WEAPON_PETROLCAN',4500) + else + amount = math.floor(price/output.price) + fuel = math.floor(fuel/output.price) + TriggerClientEvent('renzu_fuel:syncfuel',-1,vehicle,fuel) + TriggerClientEvent("renzu_fuel:Notify",source,"Paid $"..price.." in "..amount.." liters.") + end + else + TriggerClientEvent('renzu_fuel:insuficiente',source,vehicle,fuel2) + TriggerClientEvent("renzu_fuel:Notify",source,"Insuficient money.") + end + end +end) \ No newline at end of file diff --git a/source/fuel_client.lua b/source/fuel_client.lua deleted file mode 100644 index df886e7..0000000 --- a/source/fuel_client.lua +++ /dev/null @@ -1,388 +0,0 @@ -if Config.UseESX then - Citizen.CreateThread(function() - while not ESX do - TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) - - Citizen.Wait(500) - end - end) -end - -local isNearPump = false -local isFueling = false -local currentFuel = 0.0 -local currentCost = 0.0 -local currentCash = 1000 -local fuelSynced = false -local inBlacklisted = false - -function ManageFuelUsage(vehicle) - if not DecorExistOn(vehicle, Config.FuelDecor) then - SetFuel(vehicle, math.random(200, 800) / 10) - elseif not fuelSynced then - SetFuel(vehicle, GetFuel(vehicle)) - - fuelSynced = true - end - - if IsVehicleEngineOn(vehicle) then - SetFuel(vehicle, GetVehicleFuelLevel(vehicle) - Config.FuelUsage[Round(GetVehicleCurrentRpm(vehicle), 1)] * (Config.Classes[GetVehicleClass(vehicle)] or 1.0) / 10) - end -end - -Citizen.CreateThread(function() - DecorRegister(Config.FuelDecor, 1) - - for index = 1, #Config.Blacklist do - if type(Config.Blacklist[index]) == 'string' then - Config.Blacklist[GetHashKey(Config.Blacklist[index])] = true - else - Config.Blacklist[Config.Blacklist[index]] = true - end - end - - for index = #Config.Blacklist, 1, -1 do - table.remove(Config.Blacklist, index) - end - - while true do - Citizen.Wait(1000) - - local ped = PlayerPedId() - - if IsPedInAnyVehicle(ped) then - local vehicle = GetVehiclePedIsIn(ped) - - if Config.Blacklist[GetEntityModel(vehicle)] then - inBlacklisted = true - else - inBlacklisted = false - end - - if not inBlacklisted and GetPedInVehicleSeat(vehicle, -1) == ped then - ManageFuelUsage(vehicle) - end - else - if fuelSynced then - fuelSynced = false - end - - if inBlacklisted then - inBlacklisted = false - end - end - end -end) - -Citizen.CreateThread(function() - while true do - Citizen.Wait(250) - - local pumpObject, pumpDistance = FindNearestFuelPump() - - if pumpDistance < 2.5 then - isNearPump = pumpObject - - if Config.UseESX then - local playerData = ESX.GetPlayerData() - for i=1, #playerData.accounts, 1 do - if playerData.accounts[i].name == 'money' then - currentCash = playerData.accounts[i].money - break - end - end - end - else - isNearPump = false - - Citizen.Wait(math.ceil(pumpDistance * 20)) - end - end -end) - -AddEventHandler('fuel:startFuelUpTick', function(pumpObject, ped, vehicle) - currentFuel = GetVehicleFuelLevel(vehicle) - - while isFueling do - Citizen.Wait(500) - - local oldFuel = DecorGetFloat(vehicle, Config.FuelDecor) - local fuelToAdd = math.random(10, 20) / 10.0 - local extraCost = fuelToAdd / 1.5 * Config.CostMultiplier - - if not pumpObject then - if GetAmmoInPedWeapon(ped, 883325847) - fuelToAdd * 100 >= 0 then - currentFuel = oldFuel + fuelToAdd - - SetPedAmmo(ped, 883325847, math.floor(GetAmmoInPedWeapon(ped, 883325847) - fuelToAdd * 100)) - else - isFueling = false - end - else - currentFuel = oldFuel + fuelToAdd - end - - if currentFuel > 100.0 then - currentFuel = 100.0 - isFueling = false - end - - currentCost = currentCost + extraCost - - if currentCash >= currentCost then - SetFuel(vehicle, currentFuel) - else - isFueling = false - end - end - - if pumpObject then - TriggerServerEvent('fuel:pay', currentCost) - end - - currentCost = 0.0 -end) - -AddEventHandler('fuel:refuelFromPump', function(pumpObject, ped, vehicle) - TaskTurnPedToFaceEntity(ped, vehicle, 1000) - Citizen.Wait(1000) - SetCurrentPedWeapon(ped, -1569615261, true) - LoadAnimDict("timetable@gardener@filling_can") - TaskPlayAnim(ped, "timetable@gardener@filling_can", "gar_ig_5_filling_can", 2.0, 8.0, -1, 50, 0, 0, 0, 0) - - TriggerEvent('fuel:startFuelUpTick', pumpObject, ped, vehicle) - - while isFueling do - for _, controlIndex in pairs(Config.DisableKeys) do - DisableControlAction(0, controlIndex) - end - - local vehicleCoords = GetEntityCoords(vehicle) - - if pumpObject then - local stringCoords = GetEntityCoords(pumpObject) - local extraString = "" - - if Config.UseESX then - extraString = "\n" .. Config.Strings.TotalCost .. ": ~g~$" .. Round(currentCost, 1) - end - - DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.CancelFuelingPump .. extraString) - DrawText3Ds(vehicleCoords.x, vehicleCoords.y, vehicleCoords.z + 0.5, Round(currentFuel, 1) .. "%") - else - DrawText3Ds(vehicleCoords.x, vehicleCoords.y, vehicleCoords.z + 0.5, Config.Strings.CancelFuelingJerryCan .. "\nGas can: ~g~" .. Round(GetAmmoInPedWeapon(ped, 883325847) / 4500 * 100, 1) .. "% | Vehicle: " .. Round(currentFuel, 1) .. "%") - end - - if not IsEntityPlayingAnim(ped, "timetable@gardener@filling_can", "gar_ig_5_filling_can", 3) then - TaskPlayAnim(ped, "timetable@gardener@filling_can", "gar_ig_5_filling_can", 2.0, 8.0, -1, 50, 0, 0, 0, 0) - end - - if IsControlJustReleased(0, 38) or DoesEntityExist(GetPedInVehicleSeat(vehicle, -1)) or (isNearPump and GetEntityHealth(pumpObject) <= 0) then - isFueling = false - end - - Citizen.Wait(0) - end - - ClearPedTasks(ped) - RemoveAnimDict("timetable@gardener@filling_can") -end) - -Citizen.CreateThread(function() - while true do - local ped = PlayerPedId() - - if not isFueling and ((isNearPump and GetEntityHealth(isNearPump) > 0) or (GetSelectedPedWeapon(ped) == 883325847 and not isNearPump)) then - if IsPedInAnyVehicle(ped) and GetPedInVehicleSeat(GetVehiclePedIsIn(ped), -1) == ped then - local pumpCoords = GetEntityCoords(isNearPump) - - DrawText3Ds(pumpCoords.x, pumpCoords.y, pumpCoords.z + 1.2, Config.Strings.ExitVehicle) - else - local vehicle = GetPlayersLastVehicle() - local vehicleCoords = GetEntityCoords(vehicle) - - if DoesEntityExist(vehicle) and GetDistanceBetweenCoords(GetEntityCoords(ped), vehicleCoords) < 2.5 then - if not DoesEntityExist(GetPedInVehicleSeat(vehicle, -1)) then - local stringCoords = GetEntityCoords(isNearPump) - local canFuel = true - - if GetSelectedPedWeapon(ped) == 883325847 then - stringCoords = vehicleCoords - - if GetAmmoInPedWeapon(ped, 883325847) < 100 then - canFuel = false - end - end - - if GetVehicleFuelLevel(vehicle) < 95 and canFuel then - if currentCash > 0 then - DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.EToRefuel) - - if IsControlJustReleased(0, 38) then - isFueling = true - - TriggerEvent('fuel:refuelFromPump', isNearPump, ped, vehicle) - LoadAnimDict("timetable@gardener@filling_can") - end - else - DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.NotEnoughCash) - end - elseif not canFuel then - DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.JerryCanEmpty) - else - DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.FullTank) - end - end - elseif isNearPump then - local stringCoords = GetEntityCoords(isNearPump) - - if currentCash >= Config.JerryCanCost then - if not HasPedGotWeapon(ped, 883325847) then - DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.PurchaseJerryCan) - - if IsControlJustReleased(0, 38) then - GiveWeaponToPed(ped, 883325847, 4500, false, true) - - TriggerServerEvent('fuel:pay', Config.JerryCanCost) - - currentCash = ESX.GetPlayerData().money - end - else - if Config.UseESX then - local refillCost = Round(Config.RefillCost * (1 - GetAmmoInPedWeapon(ped, 883325847) / 4500)) - - if refillCost > 0 then - if currentCash >= refillCost then - DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.RefillJerryCan .. refillCost) - - if IsControlJustReleased(0, 38) then - TriggerServerEvent('fuel:pay', refillCost) - - SetPedAmmo(ped, 883325847, 4500) - end - else - DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.NotEnoughCashJerryCan) - end - else - DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.JerryCanFull) - end - else - DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.RefillJerryCan) - - if IsControlJustReleased(0, 38) then - SetPedAmmo(ped, 883325847, 4500) - end - end - end - else - DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.NotEnoughCash) - end - else - Citizen.Wait(250) - end - end - else - Citizen.Wait(250) - end - - Citizen.Wait(0) - end -end) - -if Config.ShowNearestGasStationOnly then - Citizen.CreateThread(function() - local currentGasBlip = 0 - - while true do - local coords = GetEntityCoords(PlayerPedId()) - local closest = 1000 - local closestCoords - - for _, gasStationCoords in pairs(Config.GasStations) do - local dstcheck = GetDistanceBetweenCoords(coords, gasStationCoords) - - if dstcheck < closest then - closest = dstcheck - closestCoords = gasStationCoords - end - end - - if DoesBlipExist(currentGasBlip) then - RemoveBlip(currentGasBlip) - end - - currentGasBlip = CreateBlip(closestCoords) - - Citizen.Wait(10000) - end - end) -elseif Config.ShowAllGasStations then - Citizen.CreateThread(function() - for _, gasStationCoords in pairs(Config.GasStations) do - CreateBlip(gasStationCoords) - end - end) -end - -if Config.EnableHUD then - local function DrawAdvancedText(x,y ,w,h,sc, text, r,g,b,a,font,jus) - SetTextFont(font) - SetTextProportional(0) - SetTextScale(sc, sc) - N_0x4e096588b13ffeca(jus) - SetTextColour(r, g, b, a) - SetTextDropShadow(0, 0, 0, 0,255) - SetTextEdge(1, 0, 0, 0, 255) - SetTextDropShadow() - SetTextOutline() - SetTextEntry("STRING") - AddTextComponentString(text) - DrawText(x - 0.1+w, y - 0.02+h) - end - - local mph = 0 - local kmh = 0 - local fuel = 0 - local displayHud = false - - local x = 0.01135 - local y = 0.002 - - Citizen.CreateThread(function() - while true do - local ped = PlayerPedId() - - if IsPedInAnyVehicle(ped) and not (Config.RemoveHUDForBlacklistedVehicle and inBlacklisted) then - local vehicle = GetVehiclePedIsIn(ped) - local speed = GetEntitySpeed(vehicle) - - mph = tostring(math.ceil(speed * 2.236936)) - kmh = tostring(math.ceil(speed * 3.6)) - fuel = tostring(math.ceil(GetVehicleFuelLevel(vehicle))) - - displayHud = true - else - displayHud = false - - Citizen.Wait(500) - end - - Citizen.Wait(50) - end - end) - - Citizen.CreateThread(function() - while true do - if displayHud then - DrawAdvancedText(0.130 - x, 0.77 - y, 0.005, 0.0028, 0.6, mph, 255, 255, 255, 255, 6, 1) - DrawAdvancedText(0.174 - x, 0.77 - y, 0.005, 0.0028, 0.6, kmh, 255, 255, 255, 255, 6, 1) - DrawAdvancedText(0.2195 - x, 0.77 - y, 0.005, 0.0028, 0.6, fuel, 255, 255, 255, 255, 6, 1) - DrawAdvancedText(0.148 - x, 0.7765 - y, 0.005, 0.0028, 0.4, "mp/h km/h Fuel", 255, 255, 255, 255, 6, 1) - else - Citizen.Wait(750) - end - - Citizen.Wait(0) - end - end) -end diff --git a/source/fuel_server.lua b/source/fuel_server.lua deleted file mode 100644 index 5a61c65..0000000 --- a/source/fuel_server.lua +++ /dev/null @@ -1,15 +0,0 @@ -ESX = nil - -if Config.UseESX then - TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) - - RegisterServerEvent('fuel:pay') - AddEventHandler('fuel:pay', function(price) - local xPlayer = ESX.GetPlayerFromId(source) - local amount = ESX.Math.Round(price) - - if price > 0 then - xPlayer.removeMoney(amount) - end - end) -end