Server Open Files
Open Source Files
if Framework.ESX() then
return
end
exports['nf-core']:CheckVersion("nf-skin")
local QBCore = exports['qb-core']:GetCoreObject()
lib.callback.register('nf-skin:server:getSkin', function(source, citizen_id)
local currentSkin = MySQL.single.await('SELECT * FROM `playerskins` WHERE citizenid = ?', {
citizen_id or QBCore.Functions.GetPlayer(source).PlayerData.citizenid
})
return currentSkin.model, json.decode(currentSkin.skin)
end)
RegisterNetEvent('qb-clothes:loadPlayerSkin', function()
local _source = source
if not _source then
return
end
local citizen_id = QBCore.Functions.GetPlayer(_source).PlayerData.citizenid
local currentSkin = MySQL.single.await('SELECT * FROM `playerskins` WHERE citizenid = ?', {
citizen_id
})
if currentSkin then
TriggerClientEvent('nf-skin:client:loadSkin', _source, currentSkin.model, json.decode(currentSkin.skin))
elseif not currentSkin then
TriggerClientEvent('nf-skin:client:loadSkin', _source, false)
end
end)
RegisterNetEvent('nf-skin:server:loadPlayerSkin', function()
local _source = source
if not _source then
return
end
local citizen_id = QBCore.Functions.GetPlayer(_source).PlayerData.citizenid
local currentSkin = MySQL.single.await('SELECT * FROM `playerskins` WHERE citizenid = ?', {
citizen_id
})
if currentSkin then
TriggerClientEvent('nf-skin:client:loadSkin', _source, currentSkin.model, json.decode(currentSkin.skin))
elseif not currentSkin then
TriggerClientEvent('nf-skin:client:loadSkin', _source, false)
end
end)
RegisterNetEvent('nf-skin:server:saveSkin', function(outfitname, model, skinData)
local _source = source
if not _source then
return
end
local citizen_id = QBCore.Functions.GetPlayer(_source).PlayerData.citizenid
if outfitname then
MySQL.insert.await(
'INSERT INTO `player_outfits` (citizenid, model, skin, outfitname) VALUES (?, ?, ?, ?)', {
citizen_id,
model,
json.encode({
components = skinData.components,
props = skinData.props
}),
outfitname
})
end
local skin_exists = MySQL.single.await('SELECT `id` FROM `playerskins` WHERE citizenid = ?',
{ citizen_id })
if skin_exists then
MySQL.update.await('UPDATE `playerskins` SET model = ?, skin = ? WHERE citizenid = ?', {
model,
json.encode(skinData),
citizen_id
})
else
MySQL.insert.await(
'INSERT INTO `playerskins` (citizenid, model, skin) VALUES (?, ?, ?)', {
citizen_id,
model,
json.encode(skinData)
})
end
end)
local function getOutfits(source, citizen_id)
return MySQL.query.await(
'SELECT `id`, `outfitname`, `outfitId` FROM `player_outfits` WHERE citizenid = ?', {
citizen_id or QBCore.Functions.GetPlayer(source).PlayerData.citizenid
})
end
lib.callback.register('nf-skin:server:getOutfits', function(source, citizen_id)
return getOutfits(source, citizen_id)
end)
lib.callback.register('nf-skin:server:addOutfit', function(source, outfitname, model, skinData)
local citizen_id = QBCore.Functions.GetPlayer(source).PlayerData.citizenid
MySQL.insert.await('INSERT INTO `player_outfits` (citizenid, model, skin, outfitname) VALUES (?, ?, ?, ?)', {
citizen_id,
model,
json.encode({
components = skinData.components,
props = skinData.props
}),
outfitname
})
return getOutfits(source, citizen_id)
end)
lib.callback.register('nf-skin:server:renameOutfit', function(source, outfit)
MySQL.update.await('UPDATE `player_outfits` SET outfitname = ? WHERE id = ?', {
outfit.outfitname,
outfit.id
})
return getOutfits(source)
end)
lib.callback.register('nf-skin:server:deleteOutfit', function(source, outfit_id)
MySQL.query.await('DELETE FROM `player_outfits` WHERE id = ?', {
outfit_id
})
return getOutfits(source)
end)
lib.callback.register('nf-skin:server:importOutfit', function(_, outfitId)
local outfit = MySQL.single.await('SELECT * FROM `player_outfits` WHERE outfitId = ?', {
outfitId
})
if not outfit then
return nil
end
return json.decode(outfit.skin)
end)
lib.callback.register('nf-skin:server:updateOutfit', function(source, outfit_id, skinData)
MySQL.update.await('UPDATE `player_outfits` SET skin = ? WHERE id = ?', {
json.encode({
components = skinData.components,
props = skinData.props
}),
outfit_id
})
return getOutfits(source)
end)
lib.callback.register('nf-skin:server:wearOutfit', function(source, outfit_id)
local wantedOutfit = MySQL.single.await('SELECT * FROM `player_outfits` WHERE id = ? LIMIT 1', {
outfit_id
})
wantedOutfit.skin = json.decode(wantedOutfit.skin)
if not wantedOutfit then
return nil, nil
end
local citizen_id = QBCore.Functions.GetPlayer(source).PlayerData.citizenid
local playerSkin = MySQL.single.await('SELECT * FROM `playerskins` WHERE citizenid = ? LIMIT 1', {
citizen_id
})
playerSkin.skin = json.decode(playerSkin.skin)
if not playerSkin then
return nil, nil
end
playerSkin.skin.components = wantedOutfit.skin.components
playerSkin.skin.props = wantedOutfit.skin.props
MySQL.update.await('UPDATE `playerskins` SET model = ?, skin = ? WHERE citizenid = ?', {
wantedOutfit.model,
json.encode(playerSkin.skin),
citizen_id
})
return wantedOutfit.model, wantedOutfit.skin
end)
local function GetRoomOutfits(source, edit, type)
local xPlayer = QBCore.Functions.GetPlayer(source).PlayerData
local response = {}
if edit then
response = MySQL.query.await(
'SELECT `id`, `outfitname`, `grades` FROM `workoutfits` WHERE gender = ? AND job = ?',
{
xPlayer.charinfo.gender,
xPlayer[type].name
})
else
response = MySQL.query.await(
'SELECT `id`, `outfitname`, `grades` FROM `workoutfits` WHERE gender = ? AND job = ? AND grades LIKE ?',
{
xPlayer.charinfo.gender,
xPlayer[type].name,
'%' .. xPlayer[type].grade.level .. '%'
})
end
for i = 1, #response do
response[i].skin = json.decode(response[i].skin)
response[i].grades = json.decode(response[i].grades)
end
return response
end
lib.callback.register('nf-skin:server:getRoomOutfits', function(source, edit, type)
return GetRoomOutfits(source, edit, type)
end)
lib.callback.register('nf-skin:server:wearRoomOutfit', function(_, outfit_id)
local row = MySQL.single.await('SELECT `skin` FROM `workoutfits` WHERE `id` = ? LIMIT 1', {
outfit_id
})
return json.decode(row.skin)
end)
lib.callback.register('nf-skin:server:addRoomOutfit', function(source, outfit, skinData, type)
local xPlayer = QBCore.Functions.GetPlayer(source).PlayerData
MySQL.insert.await(
'INSERT INTO `workoutfits` (`gender`, `job`, `grades`, `outfitname`, `skin`) VALUES (?, ?, ?, ?, ?)', {
xPlayer.charinfo.gender,
xPlayer.job.name,
json.encode(outfit.grades),
outfit.outfitname,
json.encode({
components = skinData.components,
props = skinData.props
})
})
return GetRoomOutfits(source, true, type)
end)
lib.callback.register('nf-skin:server:updateRoomOutfit', function(source, outfit_id, skinData, type)
MySQL.update.await('UPDATE `workoutfits` SET skin = ? WHERE id = ?', {
json.encode({
components = skinData.components,
props = skinData.props
}),
outfit_id
})
return GetRoomOutfits(source, true, type)
end)
lib.callback.register('nf-skin:server:renameRoomOutfit', function(source, outfit, type)
MySQL.update.await('UPDATE `workoutfits` SET outfitname = ?, grades = ? WHERE id = ?', {
outfit.outfitname,
json.encode(outfit.grades),
outfit.id
})
return GetRoomOutfits(source, true, type)
end)
lib.callback.register('nf-skin:server:deleteRoomOutfit', function(source, outfit_id, type)
MySQL.query.await('DELETE FROM `workoutfits` WHERE id = ?', {
outfit_id
})
return GetRoomOutfits(source, true, type)
end)
lib.callback.register("nf-skin:server:getPlayerAces", function(source)
local allowedAces = {}
for i = 1, #Config.Aces do
local ace = Config.Aces[i]
if IsPlayerAceAllowed(source, ace) then
allowedAces[#allowedAces + 1] = ace
end
end
return allowedAces
end)
if Framework.QBCore() then
return
end
exports['nf-core']:CheckVersion("nf-skin")
local ESX = exports["es_extended"]:getSharedObject()
lib.callback.register('nf-skin:server:getSkin', function(source, identifier)
local currentSkin = MySQL.single.await('SELECT `skin` FROM `users` WHERE identifier = ?', {
identifier or ESX.GetPlayerFromId(source).identifier
})
local skinDecoded = json.decode(currentSkin.skin)
return skinDecoded.model, skinDecoded
end)
lib.callback.register('nf-skin:server:getJobs', function()
local formatedJobs = {}
local jobs = MySQL.query.await('SELECT * FROM `jobs`')
for i = 1, #jobs do
local job_grades = MySQL.query.await('SELECT * FROM `job_grades` WHERE `job_name` = ?', {
jobs[i].name
})
formatedJobs[jobs[i].name] = {
label = jobs[i].label,
grades = {}
}
for j = 1, #job_grades do
formatedJobs[jobs[i].name].grades[tostring(job_grades[j].grade)] = {
name = job_grades[j].label,
}
end
end
return formatedJobs
end)
RegisterNetEvent('nf-skin:server:loadPlayerSkin', function()
local _source = source
if not _source then
return
end
local xPlayer = ESX.GetPlayerFromId(source)
local currentSkin = MySQL.single.await('SELECT `skin` FROM `users` WHERE identifier = ?', {
xPlayer.identifier
})
if currentSkin then
local skinDecoded = json.decode(currentSkin.skin)
TriggerClientEvent('nf-skin:client:loadSkin', _source, skinDecoded.model, skinDecoded)
elseif not currentSkin then
TriggerClientEvent('nf-skin:client:loadSkin', _source, false)
end
end)
RegisterNetEvent('nf-skin:server:saveSkin', function(outfitname, model, skinData)
local _source = source
if not _source then
return
end
local xPlayer = ESX.GetPlayerFromId(source)
if outfitname then
MySQL.insert.await(
'INSERT INTO `player_outfits` (identifier, model, skin, outfitname) VALUES (?, ?, ?, ?)', {
xPlayer.identifier,
model,
json.encode({
components = skinData.components,
props = skinData.props
}),
outfitname
})
end
MySQL.update.await('UPDATE `users` SET skin = ? WHERE identifier = ?', {
json.encode(skinData),
xPlayer.identifier
})
end)
lib.callback.register('nf-skin:server:getPlayerSkin', function(source)
local xPlayer = ESX.GetPlayerFromId(source)
MySQL.single('SELECT `skin` FROM `users` WHERE identifier = ?', {
xPlayer.identifier
}, function(userData)
local skin = nil
if userData.skin then
skin = json.decode(userData.skin)
end
return skin
end)
end)
local function getOutfits(source, identifier)
return MySQL.query.await(
'SELECT `id`, `outfitname`, `outfitId` FROM `player_outfits` WHERE identifier = ?', {
identifier or ESX.GetPlayerFromId(source).identifier
})
end
lib.callback.register('nf-skin:server:getOutfits', function(source, identifier)
return getOutfits(source, identifier)
end)
lib.callback.register('nf-skin:server:addOutfit', function(source, outfitname, model, skinData)
local identifier = ESX.GetPlayerFromId(source).identifier
MySQL.insert.await('INSERT INTO `player_outfits` (identifier, model, skin, outfitname) VALUES (?, ?, ?, ?)', {
identifier,
model,
json.encode({
components = skinData.components,
props = skinData.props
}),
outfitname
})
return getOutfits(source, identifier)
end)
lib.callback.register('nf-skin:server:renameOutfit', function(source, outfit)
MySQL.update.await('UPDATE `player_outfits` SET outfitname = ? WHERE id = ?', {
outfit.outfitname,
outfit.id
})
return getOutfits(source)
end)
lib.callback.register('nf-skin:server:deleteOutfit', function(source, outfit_id)
MySQL.query.await('DELETE FROM `player_outfits` WHERE id = ?', {
outfit_id
})
return getOutfits(source)
end)
lib.callback.register('nf-skin:server:importOutfit', function(_, outfitId)
local outfit = MySQL.single.await('SELECT * FROM `player_outfits` WHERE outfitId = ?', {
outfitId
})
if not outfit then
return nil
end
return json.decode(outfit.skin)
end)
lib.callback.register('nf-skin:server:updateOutfit', function(source, outfit_id, skinData)
MySQL.update.await('UPDATE `player_outfits` SET skin = ? WHERE id = ?', {
json.encode({
components = skinData.components,
props = skinData.props
}),
outfit_id
})
return getOutfits(source)
end)
lib.callback.register('nf-skin:server:wearOutfit', function(source, outfit_id)
local wantedOutfit = MySQL.single.await('SELECT * FROM `player_outfits` WHERE id = ? LIMIT 1', {
outfit_id
})
wantedOutfit.skin = json.decode(wantedOutfit.skin)
if not wantedOutfit then
return nil, nil
end
local identifier = ESX.GetPlayerFromId(source).identifier
local playerSkin = MySQL.single.await('SELECT `skin` FROM `users` WHERE identifier = ? LIMIT 1', {
identifier
})
playerSkin.skin = json.decode(playerSkin.skin)
if not playerSkin then
return nil, nil
end
playerSkin.skin.components = wantedOutfit.skin.components
playerSkin.skin.props = wantedOutfit.skin.props
MySQL.update.await('UPDATE `users` SET skin = ? WHERE identifier = ?', {
json.encode(playerSkin.skin),
identifier
})
return wantedOutfit.model, wantedOutfit.skin
end)
local function GetRoomOutfits(source, edit, type)
local xPlayer = ESX.GetPlayerFromId(source)
local response = {}
if edit then
response = MySQL.query.await(
'SELECT `id`, `outfitname`, `grades` FROM `workoutfits` WHERE gender = ? AND job = ?',
{
xPlayer.get('sex') == 'f' and 1 or 0,
xPlayer.job.name
})
else
response = MySQL.query.await(
'SELECT `id`, `outfitname`, `grades` FROM `workoutfits` WHERE gender = ? AND job = ? AND grades LIKE ?',
{
xPlayer.get('sex') == 'f' and 1 or 0,
xPlayer.job.name,
'%' .. xPlayer.job.grade .. '%'
})
end
for i = 1, #response do
response[i].skin = json.decode(response[i].skin)
response[i].grades = json.decode(response[i].grades)
end
return response
end
lib.callback.register('nf-skin:server:getRoomOutfits', function(source, edit, type)
return GetRoomOutfits(source, edit, type)
end)
lib.callback.register('nf-skin:server:wearRoomOutfit', function(_, outfit_id)
local row = MySQL.single.await('SELECT `skin` FROM `workoutfits` WHERE `id` = ? LIMIT 1', {
outfit_id
})
return json.decode(row.skin)
end)
lib.callback.register('nf-skin:server:addRoomOutfit', function(source, outfit, skinData, type)
local xPlayer = ESX.GetPlayerFromId(source)
MySQL.insert.await(
'INSERT INTO `workoutfits` (`gender`, `job`, `grades`, `outfitname`, `skin`) VALUES (?, ?, ?, ?, ?)', {
xPlayer.get('sex') == 'f' and 1 or 0,
xPlayer.job.name,
json.encode(outfit.grades),
outfit.outfitname,
json.encode({
components = skinData.components,
props = skinData.props
})
})
return GetRoomOutfits(source, true, type)
end)
lib.callback.register('nf-skin:server:updateRoomOutfit', function(source, outfit_id, skinData, type)
MySQL.update.await('UPDATE `workoutfits` SET skin = ? WHERE id = ?', {
json.encode({
components = skinData.components,
props = skinData.props
}),
outfit_id
})
return GetRoomOutfits(source, true, type)
end)
lib.callback.register('nf-skin:server:renameRoomOutfit', function(source, outfit, type)
MySQL.update.await('UPDATE `workoutfits` SET outfitname = ?, grades = ? WHERE id = ?', {
outfit.outfitname,
json.encode(outfit.grades),
outfit.id
})
return GetRoomOutfits(source, true, type)
end)
lib.callback.register('nf-skin:server:deleteRoomOutfit', function(source, outfit_id, type)
MySQL.query.await('DELETE FROM `workoutfits` WHERE id = ?', {
outfit_id
})
return GetRoomOutfits(source, true, type)
end)
lib.callback.register("nf-skin:server:getPlayerAces", function(source)
local allowedAces = {}
for i = 1, #Config.Aces do
local ace = Config.Aces[i]
if IsPlayerAceAllowed(source, ace) then
allowedAces[#allowedAces + 1] = ace
end
end
return allowedAces
end)
Last updated