-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.lua
More file actions
173 lines (156 loc) · 6.32 KB
/
Copy pathserver.lua
File metadata and controls
173 lines (156 loc) · 6.32 KB
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
ESX = nil
QBCore = nil
RegisterServerCallBack_ = nil
RegisterUsableItem = nil
Initialized()
turbos = {}
RegisterCommand("changeturbo", function(source, args, rawCommand)
local source = source
local xPlayer = GetPlayerFromId(source)
local veh = GetVehiclePedIsIn(GetPlayerPed(source),false)
print(veh,GetPlayerPed(source))
if xPlayer.getGroup() ~= 'user' and Config.turbos[args[1]] and args[1] ~= nil and veh ~= 0 then
plate = GetVehicleNumberPlateText(veh)
if turbos[plate] == nil then
turbos[plate] = {}
end
turbos[plate].turbo = args[1]
turbos[plate].plate = plate
turbos[plate].durability = 100.0
local ent = Entity(veh).state
ent:set('turbo',turbos[plate], true)
SaveTurbo(plate,args[1])
end
end, false)
GetTurboType = function(type)
for k,v in pairs(Config.turbos) do
if v.item == type then
return k
end
end
return false
end
AddTurbo = function(net,type)
local vehicle = NetworkGetEntityFromNetworkId(net)
local turbo = GetTurboType(type)
if not DoesEntityExist(vehicle) or not turbo then return end
local plate = string.gsub(GetVehicleNumberPlateText(vehicle), '^%s*(.-)%s*$', '%1'):upper()
if turbos[plate] == nil then
turbos[plate] = {}
end
turbos[plate].turbo = turbo
turbos[plate].plate = plate
turbos[plate].durability = 100.0
local ent = Entity(vehicle).state
ent:set('turbo',turbos[plate], true)
SaveTurbo(plate,turbo)
end
exports('AddTurbo', AddTurbo)
RegisterNetEvent('renzu_turbo:AddTurbo', AddTurbo)
Citizen.CreateThread(function()
Wait(1000)
local ret = json.decode(GetResourceKvpString('renzu_turbo') or '[]') or {}
for k,v in pairs(ret) do
if not turbos[k] then turbos[k] = {} end
turbos[k].plate = k
turbos[k].turbo = v.turbo
turbos[k].durability = v.durability or 100.0
end
for k,v in ipairs(GetAllVehicles()) do
local plate = GetVehicleNumberPlateText(v)
if turbos[plate] and plate == turbos[plate].plate then
local ent = Entity(v).state
if turbos[plate].durability == nil then
turbos[plate].durability = 100.0
end
ent:set('turbo',turbos[plate], true)
end
end
while true do
Wait(60000)
local turbodata = {}
for k,v in pairs(turbos) do
turbodata[v.plate] = v
end
SetResourceKvp('renzu_turbo',json.encode(turbodata))
end
end)
function SaveTurbo(plate,turbo)
local data = json.decode(GetResourceKvpString('renzu_turbo') or '[]') or {}
data[plate] = turbo
SetResourceKvp('renzu_turbo',json.encode(data))
end
function firstToUpper(str)
return (str:gsub("^%l", string.upper))
end
Citizen.CreateThread(function()
for v, k in pairs(Config.turbos) do
local turboname = string.lower(v)
print("register item", v)
RegisterUsableItem("turbo"..turboname.."", function(source)
local xPlayer = GetPlayerFromId(source)
if Config.jobonly and xPlayer.job.name ~= tostring(Config.turbojob) then print("not mech") return end
xPlayer.removeInventoryItem("turbo"..turboname.."", 1)
local veh = GetVehiclePedIsIn(GetPlayerPed(source),false)
local turbo = turboname
if turbo ~= nil and veh ~= 0 then
plate = GetVehicleNumberPlateText(veh)
if turbos[plate] == nil then
turbos[plate] = {}
end
turbos[plate].current = turbos[plate].turbo or v
turbos[plate].turbo = v
turbos[plate].plate = plate
local ent = Entity(veh).state
ent:set('turbo',turbos[plate],true)
SaveTurbo(plate,v)
end
end)
end
print(" TURBO LOADED ")
end)
AddStateBagChangeHandler('bov' --[[key filter]], nil --[[bag filter]], function(bagName, key, value, _unused, replicated)
Wait(0)
local net = tonumber(bagName:gsub('entity:', ''), 10)
if not value then return end
local entity = NetworkGetEntityFromNetworkId(net)
if DoesEntityExist(entity) then
local ent = Entity(entity).state
local plate = GetVehicleNumberPlateText(entity)
local state = ent.turbo or {}
if not state.durability then
state.durability = 100.0
end
state.durability -= (0.05) * value.boost
if state then
ent:set('turbo',state,true)
turbos[plate].durability = state.durability
end
Wait(0)
ent:set('bov',false,true)
end
end)
SetTurbo = function(entity)
if DoesEntityExist(entity) and GetEntityPopulationType(entity) == 7 and GetEntityType(entity) == 2 then
local plate = GetVehicleNumberPlateText(entity)
if turbos[plate] and turbos[plate].turbo then
local ent = Entity(entity).state
ent:set('turbo',turbos[plate],true)
end
end
end
AddStateBagChangeHandler('VehicleProperties' --[[key filter]], nil --[[bag filter]], function(bagName, key, value, _unused, replicated)
Wait(0)
local net = tonumber(bagName:gsub('entity:', ''), 10)
if not value then return end
local entity = NetworkGetEntityFromNetworkId(net)
Wait(1000)
if DoesEntityExist(entity) then
SetTurbo(entity) -- compatibility with ESX onesync server setter vehicle spawn
end
end)
AddEventHandler('entityCreated', function(entity)
local entity = entity
Wait(2000)
SetTurbo(entity)
end)