-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsv_garageelicotteri.lua
86 lines (72 loc) · 2.78 KB
/
sv_garageelicotteri.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
local ESX = exports.es_extended:getSharedObject()
RegisterNetEvent('royal_garageelicotteri:SalvaGarage', function(plate, garage)
MySQL.Async.execute('UPDATE owned_elicotteri SET `garage` = @garage WHERE `plate` = @plate', {
['@plate'] = plate,
['@garage'] = garage
}, function(rowsChanged)
end)
end)
ESX.RegisterServerCallback('royal_garageelicotteri:isOwned', function(source, cb, plate)
local s = source
local x = ESX.GetPlayerFromId(s)
local s = source
local x = ESX.GetPlayerFromId(s)
MySQL.Async.fetchAll('SELECT `vehicle` FROM owned_elicotteri WHERE `plate` = @plate AND `owner` = @owner', {['@plate'] = plate, ['@owner'] = x.identifier}, function(vehicle)
if next(vehicle) then
cb(true)
else
cb(false)
end
end)
end)
RegisterNetEvent('royal_garageelicotteri:changeState')
AddEventHandler('royal_garageelicotteri:changeState', function(plate, state)
if state == false then
state = 0
else
state = 1
end
MySQL.Sync.execute("UPDATE owned_elicotteri SET `stored` = @state WHERE `plate` = @plate",
{
['@state'] = state,
['@plate'] = plate
})
end)
Citizen.CreateThread(function()
MySQL.Async.execute('UPDATE owned_elicotteri SET `stored` = true WHERE `stored` = @stored', {
['@stored'] = false
}, function(rowsChanged)
if rowsChanged > 0 then
print(('ELICOTTERI: %s sono stati rimessi nel garage!'):format(rowsChanged))
end
end)
end)
ESX.RegisterServerCallback('royalgarage:veicolisequestrati', function(source, cb)
local ownedCars = {}
local s = source
local x = ESX.GetPlayerFromId(s)
MySQL.Async.fetchAll('SELECT * FROM veicoli_sequestrati WHERE `owner` = @owner ', {['@owner'] = x.identifier}, function(vehicles)
for _,v in pairs(vehicles) do
local vehicle = json.decode(v.vehicle)
table.insert(ownedCars, {vehicle = vehicle, plate = v.plate, label = v.vehiclename, modelname = v.modelname})
end
cb(ownedCars)
end)
end)
ESX.RegisterServerCallback('royal_garageelicotteri:loadVehicles', function(source, cb)
local ownedCars = {}
local s = source
local x = ESX.GetPlayerFromId(s)
MySQL.Async.fetchAll('SELECT * FROM owned_elicotteri WHERE `owner` = @owner AND `stored` = 1', {['@owner'] = x.identifier}, function(vehicles)
for _,v in pairs(vehicles) do
local vehicle = json.decode(v.vehicle)
table.insert(ownedCars, {vehicle = vehicle, stored = v.stored, plate = v.plate, label = v.vehiclename, modelname = v.modelname})
end
cb(ownedCars)
end)
end)
RegisterNetEvent('royal_garageelicotteri:saveProps')
AddEventHandler('royal_garageelicotteri:saveProps', function(plate, props)
local xProps = json.encode(props)
MySQL.Sync.execute("UPDATE owned_elicotteri SET `vehicle` = @props WHERE `plate` = @plate", {['@plate'] = plate, ['@props'] = xProps})
end)