forked from Musiker15/msk_givevehicle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.lua
106 lines (89 loc) · 3.15 KB
/
client.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
ESX = exports["es_extended"]:getSharedObject()
local Charset = {}
for i = 48, 57 do table.insert(Charset, string.char(i)) end
for i = 65, 90 do table.insert(Charset, string.char(i)) end
for i = 97, 122 do table.insert(Charset, string.char(i)) end
RegisterNetEvent('msk_givevehicle:spawnVehicle')
AddEventHandler('msk_givevehicle:spawnVehicle', function(props)
local playerPed = PlayerPedId()
ESX.Game.SpawnVehicle(props.model, GetEntityCoords(playerPed), GetEntityHeading(playerPed), function(vehicle)
if DoesEntityExist(vehicle) then
ESX.Game.SetVehicleProperties(vehicle, props)
Config.FuelSystem(vehicle, props.fuelLevel)
end
end)
end)
RegisterNetEvent('msk_givevehicle:giveVehicle')
AddEventHandler('msk_givevehicle:giveVehicle', function(item, veh)
local playerPed = PlayerPedId()
local playerCoords = GetEntityCoords(playerPed)
ESX.Game.SpawnVehicle(veh.model, playerCoords, 0.0, function(vehicle)
if DoesEntityExist(vehicle) then
SetEntityVisible(vehicle, false, false)
SetEntityCollision(vehicle, false)
local vehicleProps = ESX.Game.GetVehicleProperties(vehicle)
vehicleProps.plate = genPlate()
TriggerServerEvent('msk_givevehicle:setVehicle', item, vehicleProps, veh.categorie)
ESX.Game.DeleteVehicle(vehicle)
end
end)
end)
RegisterNetEvent('msk_givevehicle:giveVehicleCommand')
AddEventHandler('msk_givevehicle:giveVehicleCommand', function(target, categorie, model, plate, console, job, bool)
local playerPed = PlayerPedId()
local playerCoords = GetEntityCoords(playerPed)
local newPlate
local carExist = false
if plate then
newPlate = plate
else
newPlate = genPlate()
end
ESX.Game.SpawnVehicle(model, playerCoords, 0.0, function(vehicle)
if DoesEntityExist(vehicle) then
carExist = true
SetEntityVisible(vehicle, false, false)
SetEntityCollision(vehicle, false)
local vehicleProps = ESX.Game.GetVehicleProperties(vehicle)
vehicleProps.plate = newPlate
TriggerServerEvent('msk_givevehicle:setVehicleCommand', target, categorie, model, newPlate, vehicleProps, console, job, bool)
ESX.Game.DeleteVehicle(vehicle)
logging('debug', 'Vehicle registered with plate ' .. newPlate)
end
end)
Wait(2000)
if not carExist then
Config.Notification(source, nil, Translation[Config.Locale]['clientCommand'] .. model .. Translation[Config.Locale]['clientCommand2'])
end
end)
genPlate = function()
local plate
if Config.Plate.format:match('XXX XXX') then
plate = string.upper(GetRandomLetter(3)) .. ' ' .. math.random(001, 999)
elseif Config.Plate.format:match('XX XXXX') then
if Config.Plate.enablePrefix then
plate = Config.Plate.prefix .. ' ' .. math.random(0001, 9999)
else
plate = string.upper(GetRandomLetter(2)) .. ' ' .. math.random(0001, 9999)
end
end
return plate
end
GetRandomLetter = function(length)
Wait(0)
if length > 0 then
return GetRandomLetter(length - 1) .. Charset[math.random(1, #Charset)]
else
return ''
end
end
logging = function(code, ...)
if Config.Debug then
local script = "[^2"..GetCurrentResourceName().."^0]"
if code == 'error' then
print(script, '[^1ERROR^0]', ...)
elseif code == 'debug' then
print(script, '[^3DEBUG^0]', ...)
end
end
end