Repository navigation
Expand file tree
/
Copy pathmain.lua
More file actions
87 lines (81 loc) · 3.5 KB
/
Copy pathmain.lua
File metadata and controls
87 lines (81 loc) · 3.5 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
local QBCore = exports['qb-core']:GetCoreObject()
RegisterServerEvent("qb-clothing:saveSkin")
AddEventHandler('qb-clothing:saveSkin', function(model, skin)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if model ~= nil and skin ~= nil then
-- TODO: Update primary key to be citizenid so this can be an insert on duplicate update query
MySQL.Async.execute('DELETE FROM playerskins WHERE citizenid = ?', { Player.PlayerData.citizenid }, function()
MySQL.Async.insert('INSERT INTO playerskins (citizenid, model, skin, active) VALUES (?, ?, ?, ?)', {
Player.PlayerData.citizenid,
model,
skin,
1
})
end)
end
end)
RegisterServerEvent("qb-clothes:loadPlayerSkin")
AddEventHandler('qb-clothes:loadPlayerSkin', function()
local src = source
local Player = QBCore.Functions.GetPlayer(src)
local result = MySQL.Sync.fetchAll('SELECT * FROM playerskins WHERE citizenid = ? AND active = ?', { Player.PlayerData.citizenid, 1 })
if result[1] ~= nil then
TriggerClientEvent("qb-clothes:loadSkin", src, false, result[1].model, result[1].skin)
else
TriggerClientEvent("qb-clothes:loadSkin", src, true)
end
end)
RegisterServerEvent("qb-clothes:saveOutfit")
AddEventHandler("qb-clothes:saveOutfit", function(outfitName, model, skinData)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if model ~= nil and skinData ~= nil then
local outfitId = "outfit-"..math.random(1, 10).."-"..math.random(1111, 9999)
MySQL.Async.insert('INSERT INTO player_outfits (citizenid, outfitname, model, skin, outfitId) VALUES (?, ?, ?, ?, ?)', {
Player.PlayerData.citizenid,
outfitName,
model,
json.encode(skinData),
outfitId
}, function()
local result = MySQL.Sync.fetchAll('SELECT * FROM player_outfits WHERE citizenid = ?', { Player.PlayerData.citizenid })
if result[1] ~= nil then
TriggerClientEvent('qb-clothing:client:reloadOutfits', src, result)
else
TriggerClientEvent('qb-clothing:client:reloadOutfits', src, nil)
end
end)
end
end)
RegisterServerEvent("qb-clothing:server:removeOutfit")
AddEventHandler("qb-clothing:server:removeOutfit", function(outfitName, outfitId)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
MySQL.Async.execute('DELETE FROM player_outfits WHERE citizenid = ? AND outfitname = ? AND outfitId = ?', {
Player.PlayerData.citizenid,
outfitName,
outfitId
}, function()
local result = MySQL.Sync.fetchAll('SELECT * FROM player_outfits WHERE citizenid = ?', { Player.PlayerData.citizenid })
if result[1] ~= nil then
TriggerClientEvent('qb-clothing:client:reloadOutfits', src, result)
else
TriggerClientEvent('qb-clothing:client:reloadOutfits', src, nil)
end
end)
end)
QBCore.Functions.CreateCallback('qb-clothing:server:getOutfits', function(source, cb)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
local anusVal = {}
local result = MySQL.Sync.fetchAll('SELECT * FROM player_outfits WHERE citizenid = ?', { Player.PlayerData.citizenid })
if result[1] ~= nil then
for k, v in pairs(result) do
result[k].skin = json.decode(result[k].skin)
anusVal[k] = v
end
cb(anusVal)
end
cb(anusVal)
end)