diff --git a/README.md b/README.md index 63189be..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 @@ -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 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' +} 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) diff --git a/clothing/server.lua b/clothing/server.lua index ccdde8c..2882973 100644 --- a/clothing/server.lua +++ b/clothing/server.lua @@ -1,30 +1,38 @@ 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]) - end + local _source = source + 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") 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 +42,17 @@ end) RegisterServerEvent("clothes:save") AddEventHandler("clothes:save",function(player_data) - local source = source - local identifier = getID("steam",source) + local _source = source + 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 - saveModels() + -- 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 +65,3 @@ function getID(type, source) end return nil end - -loadModels() \ No newline at end of file