esx_accessories
client/main.lua (Add)
local spawned = false
AddEventHandler('playerSpawned', function()
Wait(2500)
if not spawned then
spawned = true
TriggerEvent('skinchanger:getSkin', function(skin)
TriggerServerEvent("esx_accessories:save", skin, "ears")
TriggerServerEvent("esx_accessories:save", skin, "glasses")
TriggerServerEvent("esx_accessories:save", skin, "helmet")
TriggerServerEvent("esx_accessories:save", skin, "mask")
end)
end
end)
AddEventHandler("rcore_clothes:clothesUpdate", function()
TriggerEvent('skinchanger:getSkin', function(skin)
TriggerServerEvent("esx_accessories:save", skin, "ears")
TriggerServerEvent("esx_accessories:save", skin, "glasses")
TriggerServerEvent("esx_accessories:save", skin, "helmet")
TriggerServerEvent("esx_accessories:save", skin, "mask")
end)
end)
server/main.lua (change/update)
RegisterServerEvent('esx_accessories:save')
AddEventHandler('esx_accessories:save', function(skin, accessory)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
accessory = string.lower(accessory)
TriggerEvent('esx_datastore:getDataStore', 'user_' .. accessory, xPlayer.identifier, function(store)
store.set('has' .. accessory, true)
local itemSkin = {}
local item1 = string.lower(accessory) .. '_1'
local item2 = string.lower(accessory) .. '_2'
itemSkin[item1] = skin[item1]
itemSkin[item2] = skin[item2]
store.set('skin', itemSkin)
end)
end)
ESX.RegisterServerCallback('esx_accessories:get', function(source, cb, accessory)
local xPlayer = ESX.GetPlayerFromId(source)
accessory = string.lower(accessory)
TriggerEvent('esx_datastore:getDataStore', 'user_' .. accessory, xPlayer.identifier, function(store)
local hasAccessory = (store.get('has' .. accessory) and store.get('has' .. accessory) or false)
local skin = (store.get('skin') and store.get('skin') or {})
cb(hasAccessory, skin)
end)
end)
Last updated