From 64d61345d456350ce831255cf7e99fa6de3e86c6 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKeown" Date: Mon, 25 Oct 2021 06:39:28 -0400 Subject: [PATCH] Fix "attempt to index a nil value" error when purchasing jerry can with ESX disabled. --- source/fuel_client.lua | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/source/fuel_client.lua b/source/fuel_client.lua index df886e7..ae4b99a 100644 --- a/source/fuel_client.lua +++ b/source/fuel_client.lua @@ -236,19 +236,19 @@ Citizen.CreateThread(function() 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 Config.UseESX then + 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) + if IsControlJustReleased(0, 38) then + GiveWeaponToPed(ped, 883325847, 4500, false, true) - TriggerServerEvent('fuel:pay', Config.JerryCanCost) + TriggerServerEvent('fuel:pay', Config.JerryCanCost) - currentCash = ESX.GetPlayerData().money - end - else - if Config.UseESX then + currentCash = ESX.GetPlayerData().money + end + else local refillCost = Round(Config.RefillCost * (1 - GetAmmoInPedWeapon(ped, 883325847) / 4500)) if refillCost > 0 then @@ -266,16 +266,28 @@ Citizen.CreateThread(function() else DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.JerryCanFull) end - else + end + else + DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.NotEnoughCash) + end + else + 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) + end + else + if GetAmmoInPedWeapon(ped, 883325847) < 4500 then DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.RefillJerryCan) if IsControlJustReleased(0, 38) then SetPedAmmo(ped, 883325847, 4500) end + else + DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.JerryCanFull) end end - else - DrawText3Ds(stringCoords.x, stringCoords.y, stringCoords.z + 1.2, Config.Strings.NotEnoughCash) end else Citizen.Wait(250)