-
Notifications
You must be signed in to change notification settings - Fork 55
/
server.lua
104 lines (88 loc) · 3.58 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
if not ESX then TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) end
RegisterServerEvent('fivem-appearance:save')
AddEventHandler('fivem-appearance:save', function(appearance)
local xPlayer = ESX.GetPlayerFromId(source)
MySQL.update('UPDATE users SET skin = @skin WHERE identifier = @identifier', {
['@skin'] = json.encode(appearance),
['@identifier'] = xPlayer.identifier
})
end)
ESX.RegisterServerCallback('fivem-appearance:getPlayerSkin', function(source, cb)
local xPlayer = ESX.GetPlayerFromId(source)
MySQL.scalar.await('SELECT skin FROM users WHERE identifier = @identifier', {
['@identifier'] = xPlayer.identifier
}, function(users)
local user, appearance = users[1]
if user.skin then
appearance = json.decode(user.skin)
end
cb(appearance)
end)
end)
RegisterNetEvent('esx_skin:save', function(appearance, tattoos)
local xPlayer = ESX.GetPlayerFromId(source)
local identifier = xPlayer.identifier
MySQL.update('UPDATE users SET skin = ? WHERE identifier = ?', { json.encode(appearance), identifier })
if tattoos ~= nil then
MySQL.update('UPDATE users SET tattoos = ? WHERE identifier = ?', { json.encode(tattoos), identifier })
end
end)
ESX.RegisterServerCallback('esx_skin:getPlayerSkin', function(source, cb)
local xPlayer = ESX.GetPlayerFromId(source)
MySQL.query('SELECT skin FROM users WHERE identifier = @identifier', {
['@identifier'] = xPlayer.identifier
}, function(users)
local user, appearance = users[1]
if user.skin then
appearance = json.decode(user.skin)
end
cb(appearance)
end)
end)
RegisterServerEvent("fivem-appearance:saveOutfit")
AddEventHandler("fivem-appearance:saveOutfit", function(name, pedModel, pedComponents, pedProps)
local xPlayer = ESX.GetPlayerFromId(source)
MySQL.insert('INSERT INTO `outfits` (`identifier`, `name`, `ped`, `components`, `props`) VALUES (@identifier, @name, @ped, @components, @props)', {
['@ped'] = json.encode(pedModel),
['@components'] = json.encode(pedComponents),
['@props'] = json.encode(pedProps),
['@name'] = name,
['@identifier'] = xPlayer.identifier
})
end)
RegisterServerEvent("fivem-appearance:getOutfit")
AddEventHandler("fivem-appearance:getOutfit", function(name)
local xPlayer = ESX.GetPlayerFromId(source)
local oSource = source
MySQL.scalar('SELECT outfit FROM outfits WHERE identifier = @identifier AND name = @name', {
['@identifier'] = xPlayer.identifier,
['@name'] = name
}, function(outfit)
local newOutfit = outfit
if newOutfit then
newOutfit = json.decode(newOutfit)
TriggerClientEvent('fivem-appearance:setOutfit', oSource, newOutfit)
end
end)
end)
RegisterServerEvent("fivem-appearance:getOutfits")
AddEventHandler("fivem-appearance:getOutfits", function()
local xPlayer = ESX.GetPlayerFromId(source)
local oSource = source
local myOutfits = {}
MySQL.query('SELECT id, name, ped, components, props FROM outfits WHERE identifier = @identifier', {
['@identifier'] = xPlayer.identifier
}, function(result)
for i=1, #result, 1 do
table.insert(myOutfits, {id = result[i].id, name = result[i].name, ped = json.decode(result[i].ped), components = json.decode(result[i].components), props = json.decode(result[i].props)})
end
TriggerClientEvent('fivem-appearance:sendOutfits', oSource, myOutfits)
end)
end)
RegisterServerEvent("fivem-appearance:deleteOutfit")
AddEventHandler("fivem-appearance:deleteOutfit", function(id)
local xPlayer = ESX.GetPlayerFromId(source)
MySQL.update('DELETE FROM `outfits` WHERE `id` = @id', {
['@id'] = id
})
end)