SHARE
TWEET

Untitled

a guest Oct 15th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ESX = nil
  2.  
  3. TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
  4.  
  5. RegisterServerEvent('esx_skin:save')
  6. AddEventHandler('esx_skin:save', function(skin)
  7.  
  8.   local xPlayer = ESX.GetPlayerFromId(source)
  9.  
  10.   MySQL.Async.execute(
  11.     'UPDATE users SET `skin` = @skin WHERE identifier = @identifier',
  12.     {
  13.       ['@skin']       = json.encode(skin),
  14.       ['@identifier'] = xPlayer.identifier
  15.     }
  16.   )
  17.  
  18. end)
  19.  
  20. RegisterServerEvent('esx_skin:responseSaveSkin')
  21. AddEventHandler('esx_skin:responseSaveSkin', function(skin)
  22.  
  23.   local file = io.open('resources/[esx]/esx_skin/skins.txt', "a")
  24.  
  25.   file:write(json.encode(skin) .. "\n\n")
  26.   file:flush()
  27.   file:close()
  28.  
  29. end)
  30.  
  31. ESX.RegisterServerCallback('esx_skin:getPlayerSkin', function(source, cb)
  32.  
  33.   local xPlayer = ESX.GetPlayerFromId(source)
  34.  
  35.   MySQL.Async.fetchAll(
  36.     'SELECT * FROM users WHERE identifier = @identifier',
  37.     {
  38.       ['@identifier'] = xPlayer.identifier
  39.     },
  40.     function(users)
  41.  
  42.       local user = users[1]
  43.       local skin = nil
  44.  
  45.       local jobSkin = {
  46.         skin_male   = xPlayer.job.skin_male,
  47.         skin_female = xPlayer.job.skin_female
  48.       }
  49.  
  50.       if user.skin ~= nil then
  51.         skin = json.decode(user.skin)
  52.       end
  53.  
  54.       cb(skin, jobSkin)
  55.  
  56.     end
  57.   )
  58.  
  59. end)
  60.  
  61. -- Commands
  62. TriggerEvent('es:addGroupCommand', 'skin', 'admin', function(source, args, user)
  63.   TriggerClientEvent('esx_skin:openSaveableMenu', source)
  64. end, function(source, args, user)
  65.   TriggerClientEvent('chatMessage', source, "SYSTEM", {255, 0, 0}, 'Insufficient permissions!')
  66. end, {help = _U('skin')})
  67.  
  68. TriggerEvent('es:addGroupCommand', 'saveskin', 'admin', function(source, args, user)
  69.   TriggerClientEvent('esx_skin:requestSaveSkin', source)
  70. end, function(source, args, user)
  71.   TriggerClientEvent('chatMessage', source, "SYSTEM", {255, 0, 0}, "Insufficient Permissions.")
  72. end, {help = _U('saveskin')})
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top