From bf973de31c8b663b9fa622efc77b865962e3b754 Mon Sep 17 00:00:00 2001 From: Corey McCown Date: Mon, 2 Apr 2018 10:21:11 -0400 Subject: [PATCH 1/7] Update server.lua Added ESX. Switched from .txt storage to MySQL. --- clothing/server.lua | 77 +++++++++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 34 deletions(-) diff --git a/clothing/server.lua b/clothing/server.lua index ccdde8c..82a273f 100644 --- a/clothing/server.lua +++ b/clothing/server.lua @@ -1,30 +1,43 @@ +ESX = nil +TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) + models = {} + RegisterServerEvent("clothes:firstspawn") AddEventHandler("clothes:firstspawn",function() - local source = source - local identifier = getID("steam",source) - print(identifier) - if models[identifier] then - TriggerClientEvent("clothes:spawn", source, models[identifier]) - else - local default_models = {1413662315,-781039234,1077785853,2021631368,1423699487,1068876755,2120901815,-106498753,131961260,-1806291497,1641152947,115168927,330231874,-1444213182,1809430156,1822107721,2064532783,-573920724,-782401935,808859815,-1106743555,-1606864033,1004114196,532905404,1699403886,-1656894598,1674107025,-88831029,-1244692252,951767867,1388848350,1090617681,379310561,-569505431,-1332260293,-840346158} - models[identifier] = { - model = default_models[math.random(1,tonumber(#default_models))], - new = true, - clothing = {drawables = {0,0,0,0,0,0,0,0,0,0,0,0},textures = {2,0,1,1,0,0,0,0,0,0,0,0},palette = {0,0,0,0,0,0,0,0,0,0,0,0}}, - props = {drawables = {-1,-1,-1,-1,-1,-1,-1,-1}, textures = {-1,-1,-1,-1,-1,-1,-1,-1}}, - overlays = {drawables = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}, opacity = {1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0}, colours = {{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0}}}, - } - saveModels() - TriggerClientEvent("clothes:spawn", source, models[identifier]) + local _source = source + local xPlayer = ESX.GetPlayerFromId(_source) + if xPlayer ~= nil then + local identifier = xPlayer.identifier + MySQL.Async.fetchAll("SELECT * FROM users WHERE identifier = @identifier", { + ['@identifier'] = identifier + },function(result) + local user = result[1] + local skin = user['skin'] + + if skin == "" or skin == nil then + local default_models = {1413662315,-781039234,1077785853,2021631368,1423699487,1068876755,2120901815,-106498753,131961260,-1806291497,1641152947,115168927,330231874,-1444213182,1809430156,1822107721,2064532783,-573920724,-782401935,808859815,-1106743555,-1606864033,1004114196,532905404,1699403886,-1656894598,1674107025,-88831029,-1244692252,951767867,1388848350,1090617681,379310561,-569505431,-1332260293,-840346158} + models[identifier] = { + model = default_models[math.random(1,tonumber(#default_models))], + new = true, + clothing = {drawables = {0,0,0,0,0,0,0,0,0,0,0,0},textures = {2,0,1,1,0,0,0,0,0,0,0,0},palette = {0,0,0,0,0,0,0,0,0,0,0,0}}, + props = {drawables = {-1,-1,-1,-1,-1,-1,-1,-1}, textures = {-1,-1,-1,-1,-1,-1,-1,-1}}, + overlays = {drawables = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}, opacity = {1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0}, colours = {{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0}}}, + } + TriggerClientEvent("clothes:spawn", _source, models[identifier]) + else + models[identifier] = json.decode(skin) + TriggerClientEvent("clothes:spawn", _source, json.decode(skin)) + end + end) end end) RegisterServerEvent("clothes:spawn") AddEventHandler("clothes:spawn",function() - local source = source - local identifier = getID("steam",source) - TriggerClientEvent("clothes:spawn", source, models[identifier]) + local _source = source + local identifier = getID("steam",_source) + TriggerClientEvent("clothes:spawn", _source, models[identifier]) end) RegisterServerEvent("clothes:loaded") @@ -34,22 +47,20 @@ end) RegisterServerEvent("clothes:save") AddEventHandler("clothes:save",function(player_data) - local source = source - local identifier = getID("steam",source) - models[identifier] = player_data - saveModels() + local _source = source + local xPlayer = ESX.GetPlayerFromId(_source) + if xPlayer ~= nil then + local identifier = xPlayer.identifier + MySQL.Async.execute("UPDATE users SET skin = @skin WHERE identifier = @identifier", { + ['@skin'] = tostring(json.encode(player_data)), + ['@identifier'] = identifier + }) + models[identifier] = player_data + end + -- Give weapons etc end) -function loadModels() - models = LoadResourceFile(GetCurrentResourceName(), "models.txt") or "[]" - models = json.decode(models) -end - -function saveModels() - SaveResourceFile(GetCurrentResourceName(), "models.txt", json.encode(models), -1) -end - function getID(type, source) for k,v in ipairs(GetPlayerIdentifiers(source)) do if string.sub(tostring(v), 1, string.len("steam:")) == "steam:" and (type == "steam" or type == 1) then @@ -62,5 +73,3 @@ function getID(type, source) end return nil end - -loadModels() \ No newline at end of file From a945ee261a4ba9220dacbad42c2b2ab2a2865f3f Mon Sep 17 00:00:00 2001 From: Corey McCown Date: Mon, 2 Apr 2018 10:22:21 -0400 Subject: [PATCH 2/7] Update __resource.lua Added MySQL resource. --- clothing/__resource.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/clothing/__resource.lua b/clothing/__resource.lua index ca5755f..d230b0f 100644 --- a/clothing/__resource.lua +++ b/clothing/__resource.lua @@ -6,4 +6,7 @@ client_scripts { 'config.lua', } -server_script 'server.lua' \ No newline at end of file +server_scripts { + '@mysql-async/lib/MySQL.lua', + 'server.lua' +} From e4871048c6bdb5d20e5f9840198654aaf2825039 Mon Sep 17 00:00:00 2001 From: Corey McCown Date: Mon, 2 Apr 2018 10:24:29 -0400 Subject: [PATCH 3/7] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 63189be..82025d9 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,10 @@ A Menu that: ---------- ## Latest change(s) +**My Fork** +* REQUIRES MySQL-Async and EssentialMode Extended +* Added MySQL support instead of .txt file + **Version 3** * Rebuilt from the ground up * New UI Modified version of @MrDaGree 's menu From e4a3983a538a5320fdacb385494c19da64d5c3be Mon Sep 17 00:00:00 2001 From: Corey McCown Date: Mon, 2 Apr 2018 10:25:01 -0400 Subject: [PATCH 4/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 82025d9..73848c0 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ A Menu that: * Can be opened and closed using E in a clothing shop * lets you choose from every working model * lets you fully customise models -* Loads/Saves models to a textfile +* Loads/Saves models to a MySQL database From ac5369c53e87d64c0cabfde31cd1a5e409e58bee Mon Sep 17 00:00:00 2001 From: Corey McCown Date: Tue, 3 Apr 2018 16:49:14 -0400 Subject: [PATCH 5/7] Update server.lua Added save to SQL database on first spawn. --- clothing/server.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/clothing/server.lua b/clothing/server.lua index 82a273f..cc5a93e 100644 --- a/clothing/server.lua +++ b/clothing/server.lua @@ -25,6 +25,7 @@ AddEventHandler("clothes:firstspawn",function() overlays = {drawables = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}, opacity = {1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0}, colours = {{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0}}}, } TriggerClientEvent("clothes:spawn", _source, models[identifier]) + TriggerEvent("clothes:save", _source, models[identifier]) else models[identifier] = json.decode(skin) TriggerClientEvent("clothes:spawn", _source, json.decode(skin)) From fc3557bec75819bcec539a0a5def135c2cdfd241 Mon Sep 17 00:00:00 2001 From: Corey McCown Date: Mon, 2 Jul 2018 15:33:17 -0400 Subject: [PATCH 6/7] Remove ESX Dependency Removed ESX dependency --- clothing/server.lua | 67 ++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 38 deletions(-) diff --git a/clothing/server.lua b/clothing/server.lua index cc5a93e..2882973 100644 --- a/clothing/server.lua +++ b/clothing/server.lua @@ -1,37 +1,31 @@ -ESX = nil -TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) - models = {} RegisterServerEvent("clothes:firstspawn") AddEventHandler("clothes:firstspawn",function() local _source = source - local xPlayer = ESX.GetPlayerFromId(_source) - if xPlayer ~= nil then - local identifier = xPlayer.identifier - MySQL.Async.fetchAll("SELECT * FROM users WHERE identifier = @identifier", { - ['@identifier'] = identifier - },function(result) - local user = result[1] - local skin = user['skin'] - - if skin == "" or skin == nil then - local default_models = {1413662315,-781039234,1077785853,2021631368,1423699487,1068876755,2120901815,-106498753,131961260,-1806291497,1641152947,115168927,330231874,-1444213182,1809430156,1822107721,2064532783,-573920724,-782401935,808859815,-1106743555,-1606864033,1004114196,532905404,1699403886,-1656894598,1674107025,-88831029,-1244692252,951767867,1388848350,1090617681,379310561,-569505431,-1332260293,-840346158} - models[identifier] = { - model = default_models[math.random(1,tonumber(#default_models))], - new = true, - clothing = {drawables = {0,0,0,0,0,0,0,0,0,0,0,0},textures = {2,0,1,1,0,0,0,0,0,0,0,0},palette = {0,0,0,0,0,0,0,0,0,0,0,0}}, - props = {drawables = {-1,-1,-1,-1,-1,-1,-1,-1}, textures = {-1,-1,-1,-1,-1,-1,-1,-1}}, - overlays = {drawables = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}, opacity = {1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0}, colours = {{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0}}}, - } - TriggerClientEvent("clothes:spawn", _source, models[identifier]) - TriggerEvent("clothes:save", _source, models[identifier]) - else - models[identifier] = json.decode(skin) - TriggerClientEvent("clothes:spawn", _source, json.decode(skin)) - end - end) - end + local identifier = getID("steam",_source) + MySQL.Async.fetchAll("SELECT * FROM users WHERE identifier = @identifier", { + ['@identifier'] = identifier + },function(result) + local user = result[1] + local skin = user['skin'] + + if skin == "" or skin == nil then + local default_models = {1413662315,-781039234,1077785853,2021631368,1423699487,1068876755,2120901815,-106498753,131961260,-1806291497,1641152947,115168927,330231874,-1444213182,1809430156,1822107721,2064532783,-573920724,-782401935,808859815,-1106743555,-1606864033,1004114196,532905404,1699403886,-1656894598,1674107025,-88831029,-1244692252,951767867,1388848350,1090617681,379310561,-569505431,-1332260293,-840346158} + models[identifier] = { + model = default_models[math.random(1,tonumber(#default_models))], + new = true, + clothing = {drawables = {0,0,0,0,0,0,0,0,0,0,0,0},textures = {2,0,1,1,0,0,0,0,0,0,0,0},palette = {0,0,0,0,0,0,0,0,0,0,0,0}}, + props = {drawables = {-1,-1,-1,-1,-1,-1,-1,-1}, textures = {-1,-1,-1,-1,-1,-1,-1,-1}}, + overlays = {drawables = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}, opacity = {1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0}, colours = {{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0},{colourType = 0, colour = 0}}}, + } + TriggerClientEvent("clothes:spawn", _source, models[identifier]) + TriggerEvent("clothes:save", _source, models[identifier]) + else + models[identifier] = json.decode(skin) + TriggerClientEvent("clothes:spawn", _source, json.decode(skin)) + end + end) end) RegisterServerEvent("clothes:spawn") @@ -49,15 +43,12 @@ end) RegisterServerEvent("clothes:save") AddEventHandler("clothes:save",function(player_data) local _source = source - local xPlayer = ESX.GetPlayerFromId(_source) - if xPlayer ~= nil then - local identifier = xPlayer.identifier - MySQL.Async.execute("UPDATE users SET skin = @skin WHERE identifier = @identifier", { - ['@skin'] = tostring(json.encode(player_data)), - ['@identifier'] = identifier - }) - models[identifier] = player_data - end + local identifier = getID("steam",_source) + MySQL.Async.execute("UPDATE users SET skin = @skin WHERE identifier = @identifier", { + ['@skin'] = tostring(json.encode(player_data)), + ['@identifier'] = identifier + }) + models[identifier] = player_data -- Give weapons etc end) From b7d2f927f4b9fe98a234f8ac3b6783814179a60a Mon Sep 17 00:00:00 2001 From: Corey McCown Date: Mon, 2 Jul 2018 15:35:06 -0400 Subject: [PATCH 7/7] Update client.lua https://github.com/FrazzIe/model-menu/commit/29a83e1f0cebdec7818348e44423de3df1a6b1eb --- clothing/client.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clothing/client.lua b/clothing/client.lua index b941d56..e641880 100644 --- a/clothing/client.lua +++ b/clothing/client.lua @@ -154,7 +154,7 @@ function accessories(title) end end) Menu.addOption("clothing_accessories", function() - if(Menu.ScrollBarInt("Textures", textureScroller, GetNumberOfPedTextureVariations(GetPlayerPed(-1), componentScroller, subComponentScroller), function(cb) textureScroller = cb end)) then + if(Menu.ScrollBarInt("Textures", textureScroller, GetNumberOfPedPropTextureVariations(GetPlayerPed(-1), componentScroller, subComponentScroller), function(cb) textureScroller = cb end)) then SetPedPropIndex(GetPlayerPed(-1), componentScroller, subComponentScroller, textureScroller, false) end end) @@ -372,4 +372,4 @@ AddEventHandler("playerSpawned", function() else TriggerServerEvent("clothes:spawn") end -end) \ No newline at end of file +end)