This repository has been archived by the owner on Apr 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
client_functions.lua
177 lines (142 loc) · 4.43 KB
/
client_functions.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
function CanPumpRefuelPetrolCan()
local petrolCan = GetCurrentGasCanDurability()
if petrolCan == nil then return false end
if petrolCan >= 100 then return false end
return true
end
--Checks if the supplied vehicle can have fuel siphoned from it
function IsSiphonFuelAllowed(vehicle)
if GetVehicleEngineHealth(entity) <= 0 then return false end
if isFueling then return false end
local curGasCanDurability = GetCurrentGasCanDurability()
if curGasCanDurability == nil then return false end
if curGasCanDurability >= 100 then return false end
return Config.AllowFuelSiphoning
end
--Checks if the vehicle passed in can be refuelled by petrol can
function IsPetrolCanRefuelAllowed(vehicle)
if GetVehicleEngineHealth(entity) <= 0 then return false end
if isFueling then return false end
local curGasCanDurability = GetCurrentGasCanDurability()
if curGasCanDurability == nil then return false end
if curGasCanDurability <= 0 then return false end
return Config.AllowPetrolCanRefuelCar
end
--If the player has a gas can equiped it gets the durability of the can
--nil if no can is equiped
function GetCurrentGasCanDurability()
local ammo = GetAmmoInPedWeapon(PlayerPedId(), `weapon_petrolcan`)
local weapon, hash = GetCurrentPedWeapon(PlayerPedId())
local percentageFull = (ammo / 4000) * 100
if weapon then
return percentageFull
-- if hash == `weapon_petrolcan` then
-- -- if ammo > 4000 then
-- -- print("Ammo over 4000")
-- -- ammo = 4000
-- -- SetPedAmmo(PlayerPedId(), `weapon_petrolcan`, ammo)
-- -- ammo = GetAmmoInPedWeapon(PlayerPedId(), `weapon_petrolcan`)
-- -- end
-- return percentageFull
-- else
-- return nil
-- end
else
return nil
end
end
--Sets the ammo contained the petrol can
function SetPetrolCanDurability(percentageFull)
if percentageFull > 100 then percentageFull = 100 end
if percentageFull < 0 then percentageFull = 0 end
local ammo = (4000 / 100) * percentageFull
if ammo > 4000 then ammo = 100 end
if ammo < 0 then ammo = 0 end
SetPedAmmo(PlayerPedId(),`weapon_petrolcan`,ammo)
TriggerServerEvent("weapons:server:UpdateWeaponAmmo",CurrentWeaponData,ammo)
end
--Returns true if the vehicle passed in is able to be fueled
function CanFuelVehicle(Vehicle)
if Vehicle then
local fuelLevel = GetFuel(Vehicle)
if fuelLevel == 100 then
return false
end
return true
end
return false
end
function GetFuel(vehicle)
if vehicle == 0 or vehicle == nil then return 0 end
return DecorGetFloat(vehicle, Config.FuelDecor)
end
function SetFuel(vehicle, fuel)
if vehicle == 0 or vehicle == nil then print("nil vehicle") return end
if type(fuel) == 'number' and fuel >= 0 and fuel <= 100 then
SetVehicleFuelLevel(vehicle, fuel)
DecorSetFloat(vehicle, Config.FuelDecor, fuel + 0.0)
end
end
function LoadAnimDict(dict)
if not HasAnimDictLoaded(dict) then
RequestAnimDict(dict)
while not HasAnimDictLoaded(dict) do
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.6)
SetBlipColour(blip, 4)
SetBlipDisplay(blip, 4)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString("Gas Station")
EndTextCommandSetBlipName(blip)
return blip
end
function GetGasPumpModels()
return Config.GasPumpModels
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 = #(coords - GetEntityCoords(fuelPumpObject))
if dstcheck < pumpDistance then
pumpDistance = dstcheck
pumpObject = fuelPumpObject
end
end
return pumpObject, pumpDistance
end