forked from wasabirobby/fivem-appearance
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.lua
More file actions
98 lines (88 loc) · 3.4 KB
/
Copy pathserver.lua
File metadata and controls
98 lines (88 loc) · 3.4 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
88
89
90
91
92
93
94
95
96
97
98
-----------------For support, scripts, and more----------------
----------------- https://discord.gg/XJFNyMy3Bv ---------------
---------------------------------------------------------------
if Config.OlderESX then
if not ESX then TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) end
end
RegisterServerEvent('fivem-appearance:save')
AddEventHandler('fivem-appearance:save', function(appearance)
local source = source
local xPlayer = ESX.GetPlayerFromId(source)
MySQL.Async.execute('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.Async.fetchAll('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 source = source
local xPlayer = ESX.GetPlayerFromId(source)
MySQL.Async.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)
ESX.RegisterServerCallback('fivem-appearance:getOutfits', function(source, cb)
local xPlayer = ESX.GetPlayerFromId(source)
local outfits = {}
MySQL.Async.fetchAll('SELECT id, name, ped, components, props FROM outfits WHERE identifier = @identifier', {
['@identifier'] = xPlayer.identifier
}, function(result)
for i=1, #result, 1 do
table.insert(outfits, {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
if outfits then
cb(outfits)
else
cb(false)
end
end)
end)
RegisterServerEvent("fivem-appearance:deleteOutfit")
AddEventHandler("fivem-appearance:deleteOutfit", function(id)
local source = source
local xPlayer = ESX.GetPlayerFromId(source)
MySQL.Async.execute('DELETE FROM `outfits` WHERE `id` = @id', {
['@id'] = id
})
end)
-- ESX Skin Compatibility
getGender = function(model)
if model == 'mp_f_freemode_01' then
return 1
else
return 0
end
end
ESX.RegisterServerCallback('esx_skin:getPlayerSkin', function(source, cb)
local xPlayer = ESX.GetPlayerFromId(source)
MySQL.Async.fetchAll('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
appearance.sex = getGender(user.skin.model)
cb(appearance)
end)
end)
ESX.RegisterCommand('skin', 'admin', function(xPlayer, args, showError)
args.playerId.triggerEvent('fivem-appearance:skinCommand')
end, false, {help = 'Change Skin', validate = true, arguments = {
{name = 'playerId', help = 'Player ID', type = 'player'}}})