-
Notifications
You must be signed in to change notification settings - Fork 115
Expand file tree
/
Copy pathserver.lua
More file actions
70 lines (62 loc) · 2.42 KB
/
server.lua
File metadata and controls
70 lines (62 loc) · 2.42 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
local QBCore = exports['qb-core']:GetCoreObject({ 'Functions' })
local sharedItems = exports['qb-core']:GetShared('Items')
CreateThread(function()
while true do
Wait(1000)
GenerateVehicleList()
Wait((1000 * 60) * 60)
end
end)
RegisterNetEvent('qb-scrapyard:server:LoadVehicleList', function()
local src = source
TriggerClientEvent('qb-scapyard:client:setNewVehicles', src, Config.CurrentVehicles)
end)
QBCore.Functions.CreateCallback('qb-scrapyard:checkOwnerVehicle', function(_, cb, plate)
local result = MySQL.scalar.await('SELECT `plate` FROM `player_vehicles` WHERE `plate` = ?', { plate })
if result then
cb(false)
else
cb(true)
end
end)
RegisterNetEvent('qb-scrapyard:server:ScrapVehicle', function(listKey)
local src = source
if Config.CurrentVehicles[listKey] ~= nil then
for _ = 1, math.random(2, 4), 1 do
local item = Config.Items[math.random(1, #Config.Items)]
exports['qb-inventory']:AddItem(src, item, math.random(25, 45), false, false, 'qb-scrapyard:server:ScrapVehicle')
TriggerClientEvent('qb-inventory:client:ItemBox', src, sharedItems[item], 'add')
Wait(500)
end
local Luck = math.random(1, 8)
local Odd = math.random(1, 8)
if Luck == Odd then
local random = math.random(10, 20)
exports['qb-inventory']:AddItem(src, 'rubber', random, false, false, 'qb-scrapyard:server:ScrapVehicle')
TriggerClientEvent('qb-inventory:client:ItemBox', src, sharedItems['rubber'], 'add')
end
Config.CurrentVehicles[listKey] = nil
TriggerClientEvent('qb-scapyard:client:setNewVehicles', -1, Config.CurrentVehicles)
end
end)
function GenerateVehicleList()
Config.CurrentVehicles = {}
for i = 1, Config.VehicleCount, 1 do
local randVehicle = Config.Vehicles[math.random(1, #Config.Vehicles)]
if not IsInList(randVehicle) then
Config.CurrentVehicles[i] = randVehicle
end
end
TriggerClientEvent('qb-scapyard:client:setNewVehicles', -1, Config.CurrentVehicles)
end
function IsInList(name)
local retval = false
if Config.CurrentVehicles ~= nil and next(Config.CurrentVehicles) ~= nil then
for k in pairs(Config.CurrentVehicles) do
if Config.CurrentVehicles[k] == name then
retval = true
end
end
end
return retval
end