Skip to content

Commit

Permalink
Merge pull request #1 from thelindat/main
Browse files Browse the repository at this point in the history
Support for esx_multicharacter
  • Loading branch information
ZiggyJoJo authored Jul 30, 2021
2 parents fe61b40 + 3ada2a9 commit 03f2812
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 27 deletions.
66 changes: 42 additions & 24 deletions client.lua
Original file line number Diff line number Diff line change
@@ -1,35 +1,21 @@
local Keys = {
["ESC"] = 322, ["F1"] = 288, ["F2"] = 289, ["F3"] = 170, ["F5"] = 166, ["F6"] = 167, ["F7"] = 168, ["F8"] = 169, ["F9"] = 56, ["F10"] = 57,
["~"] = 243, ["1"] = 157, ["2"] = 158, ["3"] = 160, ["4"] = 164, ["5"] = 165, ["6"] = 159, ["7"] = 161, ["8"] = 162, ["9"] = 163, ["-"] = 84, ["="] = 83, ["BACKSPACE"] = 177,
["TAB"] = 37, ["Q"] = 44, ["W"] = 32, ["E"] = 38, ["R"] = 45, ["T"] = 245, ["Y"] = 246, ["U"] = 303, ["P"] = 199, ["["] = 39, ["]"] = 40, ["ENTER"] = 18,
["CAPS"] = 137, ["A"] = 34, ["S"] = 8, ["D"] = 9, ["F"] = 23, ["G"] = 47, ["H"] = 74, ["K"] = 311, ["L"] = 182,
["LEFTSHIFT"] = 21, ["Z"] = 20, ["X"] = 73, ["C"] = 26, ["V"] = 0, ["B"] = 29, ["N"] = 249, ["M"] = 244, [","] = 82, ["."] = 81,
["LEFTCTRL"] = 36, ["LEFTALT"] = 19, ["SPACE"] = 22, ["RIGHTCTRL"] = 70,
["HOME"] = 213, ["PAGEUP"] = 10, ["PAGEDOWN"] = 11, ["DELETE"] = 178,
["LEFT"] = 174, ["RIGHT"] = 175, ["TOP"] = 27, ["DOWN"] = 173,
["NENTER"] = 201, ["N4"] = 108, ["N5"] = 60, ["N6"] = 107, ["N+"] = 96, ["N-"] = 97, ["N7"] = 117, ["N8"] = 61, ["N9"] = 118
}

ESX = nil
local playerLoaded
local firstSpawn = true
local skinLoaded = false
local LastZone = nil
local CurrentAction = nil
local CurrentActionMsg = ''
local hasAlreadyEnteredMarker = false
local allMyOutfits = {}

Citizen.CreateThread(function()
while ESX == nil do
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
Citizen.Wait(0)
end
end)
if not ESX then
Citizen.CreateThread(function()
while ESX == nil do
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
Citizen.Wait(0)
end
end)
end

RegisterNetEvent('esx:playerLoaded')
AddEventHandler('esx:playerLoaded', function(xPlayer)
playerLoaded = true
ESX.PlayerLoaded = true
end)

-- RegisterCommand('reloadskin', function()
Expand Down Expand Up @@ -152,7 +138,7 @@ Citizen.CreateThread(function()

if CurrentAction ~= nil then

if IsControlPressed(1, Keys['E']) then
if IsControlPressed(1, 38) then
Citizen.Wait(500)

if CurrentAction == 'clothingMenu' then
Expand Down Expand Up @@ -370,4 +356,36 @@ end)
RegisterNetEvent('fivem-appearance:deleteOutfit')
AddEventHandler('fivem-appearance:deleteOutfit', function(id)
TriggerServerEvent('fivem-appearance:deleteOutfit', id)
end)


-- Add compatibility with skinchanger and esx_skin TriggerEvents
RegisterNetEvent('skinchanger:loadSkin')
AddEventHandler('skinchanger:loadSkin', function(skin, cb)
if not skin.model then skin.model = 'mp_m_freemode_01' end
exports['fivem-appearance']:setPlayerAppearance(skin)
if cb ~= nil then
cb()
end
end)

RegisterNetEvent('esx_skin:openSaveableMenu')
AddEventHandler('esx_skin:openSaveableMenu', function(submitCb, cancelCb)
local config = {
ped = true,
headBlend = false,
faceFeatures = false,
headOverlays = false,
components = true,
props = true
}

exports['fivem-appearance']:startPlayerCustomization(function (appearance)
if (appearance) then
TriggerServerEvent('fivem-appearance:save', appearance)
submitCb()
else
cancelCb()
end
end, config)
end)
5 changes: 5 additions & 0 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ files {
'peds.json'
}

provides {
'skinchanger',
'esx_skin'
}

ui_page 'ui/build/index.html'
18 changes: 15 additions & 3 deletions server.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
ESX = nil

TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
if not ESX then TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) end

RegisterServerEvent('fivem-appearance:save')
AddEventHandler('fivem-appearance:save', function(appearance)
Expand All @@ -26,6 +24,20 @@ ESX.RegisterServerCallback('fivem-appearance:getPlayerSkin', function(source, cb
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
cb(appearance)
end)
end)

RegisterServerEvent("fivem-appearance:saveOutfit")
AddEventHandler("fivem-appearance:saveOutfit", function(name, pedModel, pedComponents, pedProps)
local xPlayer = ESX.GetPlayerFromId(source)
Expand Down

0 comments on commit 03f2812

Please sign in to comment.