-
Notifications
You must be signed in to change notification settings - Fork 3
/
sv_garage.lua
66 lines (58 loc) · 2.66 KB
/
sv_garage.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
QBCore = nil
NumberCharset = {}
Charset = {}
for i = 48, 57 do table.insert(NumberCharset, 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
TriggerEvent("QBCore:GetObject", function(obj) QBCore = obj end)
RegisterServerEvent('qb-policegarage:server:takemoney', function(data)
xPlayer = QBCore.Functions.GetPlayer(source)
if xPlayer.PlayerData.money['cash'] >= data.price then
xPlayer.Functions.RemoveMoney('cash', data.price)
TriggerClientEvent('qb-policegarage:client:spawn', source, data.model, vector3(443.1918, -1022.256, 28.567802), 93.38)
elseif xPlayer.PlayerData.money['bank'] >= data.price then
xPlayer.Functions.RemoveMoney('bank', data.price)
TriggerClientEvent('qb-policegarage:client:spawn', source, data.model, vector3(443.1918, -1022.256, 28.567802), 93.38)
else
TriggerClientEvent('chatMessage', source, "Insufficient Funds", "error", "You don't have enough money..")
end
end)
RegisterNetEvent('qb-policegarage:server:AddGarage')
AddEventHandler('qb-policegarage:server:AddGarage', function(vehmodel, hash)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if Player ~= nil then
local newplate = GeneratePlate()
newplate = newplate:gsub("%s+", "")
QBCore.Functions.ExecuteSql(false, "INSERT INTO `player_vehicles` (`steam`, `citizenid`, `vehicle`, `hash`, `mods`, `plate`, `state`) VALUES ('"..Player.PlayerData.steam.."', '"..Player.PlayerData.citizenid.."', '"..vehmodel.."', '"..hash.."', '{}', '"..newplate.."', 0)")
TriggerClientEvent('qb-policegarage:client:AddGarage', src, newplate)
end
end)
function GeneratePlate()
local plate = tostring(GetRandomNumber(1)) .. GetRandomLetter(2) .. tostring(GetRandomNumber(3)) .. GetRandomLetter(2)
QBCore.Functions.ExecuteSql(true, "SELECT * FROM `player_vehicles` WHERE `plate` = '"..plate.."'", function(result)
while (result[1] ~= nil) do
plate = tostring(GetRandomNumber(1)) .. GetRandomLetter(2) .. tostring(GetRandomNumber(3)) .. GetRandomLetter(2)
end
return plate
end)
return plate:upper()
end
function GetRandomNumber(length)
Citizen.Wait(1)
math.randomseed(GetGameTimer())
if length > 0 then
return GetRandomNumber(length - 1) .. NumberCharset[math.random(1, #NumberCharset)]
else
return ''
end
end
function GetRandomLetter(length)
Citizen.Wait(1)
math.randomseed(GetGameTimer())
if length > 0 then
return GetRandomLetter(length - 1) .. Charset[math.random(1, #Charset)]
else
return ''
end
end