-
Notifications
You must be signed in to change notification settings - Fork 14
/
server.lua
73 lines (62 loc) · 2.48 KB
/
server.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
-- DMV School
-- Tech Development - https://discord.gg/tHAbhd94vS
local ESX = exports.es_extended:getSharedObject()
ESX.RegisterServerCallback('ricky-dmv:getData', function(source, cb)
local licenses = Config.License
local xPlayer = ESX.GetPlayerFromId(source)
local result = MySQL.Sync.fetchAll("SELECT * FROM user_licenses WHERE owner = @identifier", {
['@identifier'] = xPlayer.identifier,
})
for k,v in pairs(licenses) do
v.theory = false
v.practice = false
for i=1, #result, 1 do
local coso = result[i]
if coso.type == v.id then
v.theory = true
v.practice = true
elseif coso.type == v.id.."dmv" then
v.theory = true
v.practice = false
end
end
end
cb(licenses, xPlayer.getAccount('money').money, xPlayer.getAccount('bank').money)
end)
AddEventHandler('onResourceStart', function(resource)
if resource == GetCurrentResourceName() then
for k,v in pairs(Config.License) do
local result = MySQL.Sync.fetchAll("SELECT * FROM licenses WHERE type = @type", {
['@type'] = v.id,
})
if result == nil or result[1] == nil then
MySQL.Async.execute("INSERT INTO licenses (type, label) VALUES (@type, @label)", {
['@type'] = v.id,
['@label'] = v.label,
})
end
end
for k,v in pairs(Config.License) do
local result = MySQL.Sync.fetchAll("SELECT * FROM licenses WHERE type = @type", {
['@type'] = v.id.."dmv",
})
if result == nil or result[1] == nil then
MySQL.Async.execute("INSERT INTO licenses (type, label) VALUES (@type, @label)", {
['@type'] = v.id.."dmv",
['@label'] = v.label.." DMV",
})
end
end
end
end)
RegisterServerEvent('ricky-dmv:givelicense')
AddEventHandler('ricky-dmv:givelicense', function(license)
TriggerEvent('esx_license:addLicense', source, license)
TriggerClientEvent('ricky-dmv:updateLicense', source)
end)
RegisterServerEvent('ricky-dmv:removeMoney')
AddEventHandler('ricky-dmv:removeMoney', function(account, money)
local src = source
local xPlayer = ESX.GetPlayerFromId(src)
xPlayer.removeAccountMoney(account, money)
end)