diff --git a/server-data/resources/[esx]/esx_menu_default/client/main.lua b/server-data/resources/[esx]/esx_menu_default/client/main.lua index 486729539..873b5a9e0 100644 --- a/server-data/resources/[esx]/esx_menu_default/client/main.lua +++ b/server-data/resources/[esx]/esx_menu_default/client/main.lua @@ -1,132 +1,132 @@ -local GUI, MenuType, OpenedMenus, CurrentNameSpace = {}, 'default', 0, nil +local GUI, MenuType, OpenedMenus, CurrentNameSpace = {}, "default", 0, nil GUI.Time = 0 local function openMenu(namespace, name, data) - CurrentNameSpace = namespace - OpenedMenus = OpenedMenus + 1 - SendNUIMessage({ - action = 'openMenu', - namespace = namespace, - name = name, - data = data - }) + CurrentNameSpace = namespace + OpenedMenus = OpenedMenus + 1 + SendNUIMessage({ + action = "openMenu", + namespace = namespace, + name = name, + data = data, + }) end local function closeMenu(namespace, name) - CurrentNameSpace = namespace - OpenedMenus = OpenedMenus - 1 - if OpenedMenus < 0 then - OpenedMenus = 0 - end - SendNUIMessage({ - action = 'closeMenu', - namespace = namespace, - name = name - }) + CurrentNameSpace = namespace + OpenedMenus = OpenedMenus - 1 + if OpenedMenus < 0 then + OpenedMenus = 0 + end + SendNUIMessage({ + action = "closeMenu", + namespace = namespace, + name = name, + }) end -AddEventHandler('onResourceStop', function(resource) - if GetCurrentResourceName() == resource and OpenedMenus > 0 then - ESX.UI.Menu.CloseAll() - elseif CurrentNameSpace ~= nil and CurrentNameSpace == resource and OpenedMenus > 0 then - ESX.UI.Menu.CloseAll() - end +AddEventHandler("onResourceStop", function(resource) + if GetCurrentResourceName() == resource and OpenedMenus > 0 then + ESX.UI.Menu.CloseAll() + elseif CurrentNameSpace ~= nil and CurrentNameSpace == resource and OpenedMenus > 0 then + ESX.UI.Menu.CloseAll() + end end) ESX.UI.Menu.RegisterType(MenuType, openMenu, closeMenu) -RegisterNUICallback('menu_submit', function(data, cb) - local menu = ESX.UI.Menu.GetOpened(MenuType, data._namespace, data._name) - if menu.submit ~= nil then - menu.submit(data, menu) - end - cb('OK') +RegisterNUICallback("menu_submit", function(data, cb) + local menu = ESX.UI.Menu.GetOpened(MenuType, data._namespace, data._name) + if menu.submit ~= nil then + menu.submit(data, menu) + end + cb("OK") end) -RegisterNUICallback('menu_cancel', function(data, cb) - local menu = ESX.UI.Menu.GetOpened(MenuType, data._namespace, data._name) +RegisterNUICallback("menu_cancel", function(data, cb) + local menu = ESX.UI.Menu.GetOpened(MenuType, data._namespace, data._name) - if menu.cancel ~= nil then - menu.cancel(data, menu) - end - cb('OK') + if menu.cancel ~= nil then + menu.cancel(data, menu) + end + cb("OK") end) -RegisterNUICallback('menu_change', function(data, cb) - local menu = ESX.UI.Menu.GetOpened(MenuType, data._namespace, data._name) +RegisterNUICallback("menu_change", function(data, cb) + local menu = ESX.UI.Menu.GetOpened(MenuType, data._namespace, data._name) - for i = 1, #data.elements, 1 do - menu.setElement(i, 'value', data.elements[i].value) + for i = 1, #data.elements, 1 do + menu.setElement(i, "value", data.elements[i].value) - if data.elements[i].selected then - menu.setElement(i, 'selected', true) - else - menu.setElement(i, 'selected', false) - end - end + if data.elements[i].selected then + menu.setElement(i, "selected", true) + else + menu.setElement(i, "selected", false) + end + end - if menu.change ~= nil then - menu.change(data, menu) - end - cb('OK') + if menu.change ~= nil then + menu.change(data, menu) + end + cb("OK") end) -ESX.RegisterInput('menu_default_enter', 'Submit menu item', 'keyboard', 'RETURN', function() - if OpenedMenus > 0 and (GetGameTimer() - GUI.Time) > 200 then - SendNUIMessage({ - action = 'controlPressed', - control = 'ENTER' - }) - GUI.Time = GetGameTimer() - end +ESX.RegisterInput("menu_default_enter", "Submit menu item", "keyboard", "RETURN", function() + if OpenedMenus > 0 and (GetGameTimer() - GUI.Time) > 200 then + SendNUIMessage({ + action = "controlPressed", + control = "ENTER", + }) + GUI.Time = GetGameTimer() + end end) -ESX.RegisterInput('menu_default_backspace', 'Close menu', 'keyboard', 'BACK', function() - if OpenedMenus > 0 then - SendNUIMessage({ - action = 'controlPressed', - control = 'BACKSPACE' - }) - GUI.Time = GetGameTimer() - end +ESX.RegisterInput("menu_default_backspace", "Close menu", "keyboard", "BACK", function() + if OpenedMenus > 0 then + SendNUIMessage({ + action = "controlPressed", + control = "BACKSPACE", + }) + GUI.Time = GetGameTimer() + end end) -ESX.RegisterInput('menu_default_top', 'Change menu focus to top item', 'keyboard', 'UP', function() - if OpenedMenus > 0 then - SendNUIMessage({ - action = 'controlPressed', - control = 'TOP' - }) - GUI.Time = GetGameTimer() - end +ESX.RegisterInput("menu_default_top", "Change menu focus to top item", "keyboard", "UP", function() + if OpenedMenus > 0 then + SendNUIMessage({ + action = "controlPressed", + control = "TOP", + }) + GUI.Time = GetGameTimer() + end end) -ESX.RegisterInput('menu_default_down', 'Change menu focus to down item', 'keyboard', 'DOWN', function() - if OpenedMenus > 0 then - SendNUIMessage({ - action = 'controlPressed', - control = 'DOWN' - }) - GUI.Time = GetGameTimer() - end +ESX.RegisterInput("menu_default_down", "Change menu focus to down item", "keyboard", "DOWN", function() + if OpenedMenus > 0 then + SendNUIMessage({ + action = "controlPressed", + control = "DOWN", + }) + GUI.Time = GetGameTimer() + end end) -ESX.RegisterInput('menu_default_left', 'Change menu slider to left', 'keyboard', 'LEFT', function() - if OpenedMenus > 0 then - SendNUIMessage({ - action = 'controlPressed', - control = 'LEFT' - }) - GUI.Time = GetGameTimer() - end +ESX.RegisterInput("menu_default_left", "Change menu slider to left", "keyboard", "LEFT", function() + if OpenedMenus > 0 then + SendNUIMessage({ + action = "controlPressed", + control = "LEFT", + }) + GUI.Time = GetGameTimer() + end end) -ESX.RegisterInput('menu_default_right', 'Change menu slider to right', 'keyboard', 'RIGHT', function() - if OpenedMenus > 0 then - SendNUIMessage({ - action = 'controlPressed', - control = 'RIGHT' - }) - GUI.Time = GetGameTimer() - end -end) \ No newline at end of file +ESX.RegisterInput("menu_default_right", "Change menu slider to right", "keyboard", "RIGHT", function() + if OpenedMenus > 0 then + SendNUIMessage({ + action = "controlPressed", + control = "RIGHT", + }) + GUI.Time = GetGameTimer() + end +end) diff --git a/server-data/resources/[esx]/esx_menu_default/fxmanifest.lua b/server-data/resources/[esx]/esx_menu_default/fxmanifest.lua index 4e4b6542e..9cea64063 100644 --- a/server-data/resources/[esx]/esx_menu_default/fxmanifest.lua +++ b/server-data/resources/[esx]/esx_menu_default/fxmanifest.lua @@ -1,15 +1,15 @@ -fx_version 'adamant' +fx_version("adamant") -game 'gta5' +game("gta5") -description 'Menu Default' -lua54 'yes' -version '1.0.0' +description("Menu Default") +lua54("yes") +version("1.0.0") -client_scripts {'@es_extended/imports.lua', 'client/main.lua'} +client_scripts({ "@es_extended/imports.lua", "client/main.lua" }) -ui_page {'html/ui.html'} +ui_page({ "html/ui.html" }) -files {'html/ui.html', 'html/css/app.css', 'html/js/mustache.min.js', 'html/js/app.js'} +files({ "html/ui.html", "html/css/app.css", "html/js/mustache.min.js", "html/js/app.js" }) -dependencies {'es_extended'} +dependencies({ "es_extended" }) diff --git a/server-data/resources/[esx]/esx_menu_default/html/js/app.js b/server-data/resources/[esx]/esx_menu_default/html/js/app.js index 9ee22bc7e..33c888bc0 100644 --- a/server-data/resources/[esx]/esx_menu_default/html/js/app.js +++ b/server-data/resources/[esx]/esx_menu_default/html/js/app.js @@ -18,143 +18,143 @@ ESX_MENU.pos = {}; ESX_MENU.open = function (namespace, name, data) { - if (typeof ESX_MENU.opened[namespace] === "undefined") { - ESX_MENU.opened[namespace] = {}; - } + if (typeof ESX_MENU.opened[namespace] === "undefined") { + ESX_MENU.opened[namespace] = {}; + } - if (typeof ESX_MENU.opened[namespace][name] != "undefined") { - ESX_MENU.close(namespace, name); - } + if (typeof ESX_MENU.opened[namespace][name] != "undefined") { + ESX_MENU.close(namespace, name); + } - if (typeof ESX_MENU.pos[namespace] === "undefined") { - ESX_MENU.pos[namespace] = {}; - } + if (typeof ESX_MENU.pos[namespace] === "undefined") { + ESX_MENU.pos[namespace] = {}; + } - for (let i = 0; i < data.elements.length; i++) { - if (typeof data.elements[i].type === "undefined") { - data.elements[i].type = "default"; - } + for (let i = 0; i < data.elements.length; i++) { + if (typeof data.elements[i].type === "undefined") { + data.elements[i].type = "default"; } + } - data._index = ESX_MENU.focus.length; - data._namespace = namespace; - data._name = name; + data._index = ESX_MENU.focus.length; + data._namespace = namespace; + data._name = name; - for (let i = 0; i < data.elements.length; i++) { - data.elements[i]._namespace = namespace; - data.elements[i]._name = name; - } + for (let i = 0; i < data.elements.length; i++) { + data.elements[i]._namespace = namespace; + data.elements[i]._name = name; + } - ESX_MENU.opened[namespace][name] = data; - ESX_MENU.pos[namespace][name] = 0; + ESX_MENU.opened[namespace][name] = data; + ESX_MENU.pos[namespace][name] = 0; - for (let i = 0; i < data.elements.length; i++) { - if (data.elements[i].selected) { - ESX_MENU.pos[namespace][name] = i; - } else { - data.elements[i].selected = false; - } + for (let i = 0; i < data.elements.length; i++) { + if (data.elements[i].selected) { + ESX_MENU.pos[namespace][name] = i; + } else { + data.elements[i].selected = false; } + } - ESX_MENU.focus.push({ - namespace: namespace, - name: name, - }); + ESX_MENU.focus.push({ + namespace: namespace, + name: name, + }); - ESX_MENU.render(); - $("#menu_" + namespace + "_" + name) - .find(".menu-item.selected")[0] - .scrollIntoView(); + ESX_MENU.render(); + $("#menu_" + namespace + "_" + name) + .find(".menu-item.selected")[0] + .scrollIntoView(); }; ESX_MENU.close = function (namespace, name) { delete ESX_MENU.opened[namespace][name]; - for (let i = 0; i < ESX_MENU.focus.length; i++) { - if (ESX_MENU.focus[i].namespace === namespace && ESX_MENU.focus[i].name === name) { - ESX_MENU.focus.splice(i, 1); - break; - } + for (let i = 0; i < ESX_MENU.focus.length; i++) { + if (ESX_MENU.focus[i].namespace === namespace && ESX_MENU.focus[i].name === name) { + ESX_MENU.focus.splice(i, 1); + break; } + } ESX_MENU.render(); }; ESX_MENU.render = function () { - let menuContainer = document.getElementById("menus"); - let focused = ESX_MENU.getFocused(); - menuContainer.innerHTML = ""; - $(menuContainer).hide(); + let menuContainer = document.getElementById("menus"); + let focused = ESX_MENU.getFocused(); + menuContainer.innerHTML = ""; + $(menuContainer).hide(); - for (let namespace in ESX_MENU.opened) { - for (let name in ESX_MENU.opened[namespace]) { - let menuData = ESX_MENU.opened[namespace][name]; - let view = JSON.parse(JSON.stringify(menuData)); + for (let namespace in ESX_MENU.opened) { + for (let name in ESX_MENU.opened[namespace]) { + let menuData = ESX_MENU.opened[namespace][name]; + let view = JSON.parse(JSON.stringify(menuData)); - for (let i = 0; i < menuData.elements.length; i++) { - let element = view.elements[i]; + for (let i = 0; i < menuData.elements.length; i++) { + let element = view.elements[i]; - switch (element.type) { - case "default": - break; - - case "slider": { - element.isSlider = true; - element.sliderLabel = typeof element.options === "undefined" ? element.value : element.options[element.value]; + switch (element.type) { + case "default": + break; - break; - } + case "slider": { + element.isSlider = true; + element.sliderLabel = typeof element.options === "undefined" ? element.value : element.options[element.value]; - default: - break; - } + break; + } - if (i === ESX_MENU.pos[namespace][name]) { - element.selected = true; - } - } + default: + break; + } - let menu = $(Mustache.render(MenuTpl, view))[0]; - $(menu).hide(); - menuContainer.appendChild(menu); + if (i === ESX_MENU.pos[namespace][name]) { + element.selected = true; } - } + } - if (typeof focused != "undefined") { - $("#menu_" + focused.namespace + "_" + focused.name).show(); + let menu = $(Mustache.render(MenuTpl, view))[0]; + $(menu).hide(); + menuContainer.appendChild(menu); } + } - $(menuContainer).show(); + if (typeof focused != "undefined") { + $("#menu_" + focused.namespace + "_" + focused.name).show(); + } + + $(menuContainer).show(); }; ESX_MENU.submit = function (namespace, name, data) { - $.post("http://" + ESX_MENU.ResourceName + "/menu_submit", - JSON.stringify({ - _namespace: namespace, - _name: name, - current: data, - elements: ESX_MENU.opened[namespace][name].elements, - }) - ); + $.post("http://" + ESX_MENU.ResourceName + "/menu_submit", + JSON.stringify({ + _namespace: namespace, + _name: name, + current: data, + elements: ESX_MENU.opened[namespace][name].elements, + }) + ); }; ESX_MENU.cancel = function (namespace, name) { - $.post("http://" + ESX_MENU.ResourceName + "/menu_cancel", - JSON.stringify({ - _namespace: namespace, - _name: name, - }) - ); + $.post("http://" + ESX_MENU.ResourceName + "/menu_cancel", + JSON.stringify({ + _namespace: namespace, + _name: name, + }) + ); }; ESX_MENU.change = function (namespace, name, data) { $.post("http://" + ESX_MENU.ResourceName + "/menu_change", - JSON.stringify({ - _namespace: namespace, - _name: name, - current: data, - elements: ESX_MENU.opened[namespace][name].elements, - })); + JSON.stringify({ + _namespace: namespace, + _name: name, + current: data, + elements: ESX_MENU.opened[namespace][name].elements, + })); }; ESX_MENU.getFocused = function () { @@ -162,196 +162,196 @@ }; window.onData = (data) => { - switch (data.action) { - case "openMenu": { - ESX_MENU.open(data.namespace, data.name, data.data); - break; - } - - case "closeMenu": { - ESX_MENU.close(data.namespace, data.name); - break; - } - - case "controlPressed": { - switch (data.control) { - case "ENTER": { - let focused = ESX_MENU.getFocused(); - - if (typeof focused != "undefined") { - let menu = ESX_MENU.opened[focused.namespace][focused.name]; - let pos = ESX_MENU.pos[focused.namespace][focused.name]; - let elem = menu.elements[pos]; - - if (menu.elements.length > 0) { - ESX_MENU.submit(focused.namespace, focused.name, elem); - } - } + switch (data.action) { + case "openMenu": { + ESX_MENU.open(data.namespace, data.name, data.data); + break; + } - break; - } + case "closeMenu": { + ESX_MENU.close(data.namespace, data.name); + break; + } - case "BACKSPACE": { - let focused = ESX_MENU.getFocused(); + case "controlPressed": { + switch (data.control) { + case "ENTER": { + let focused = ESX_MENU.getFocused(); - if (typeof focused != "undefined") { - ESX_MENU.cancel(focused.namespace, focused.name); - } + if (typeof focused != "undefined") { + let menu = ESX_MENU.opened[focused.namespace][focused.name]; + let pos = ESX_MENU.pos[focused.namespace][focused.name]; + let elem = menu.elements[pos]; - break; - } + if (menu.elements.length > 0) { + ESX_MENU.submit(focused.namespace, focused.name, elem); + } + } - case "TOP": { - let focused = ESX_MENU.getFocused(); + break; + } - if (typeof focused != "undefined") { - let menu = ESX_MENU.opened[focused.namespace][focused.name]; - let pos = ESX_MENU.pos[focused.namespace][focused.name]; + case "BACKSPACE": { + let focused = ESX_MENU.getFocused(); - if (pos > 0) { - ESX_MENU.pos[focused.namespace][focused.name]--; - } else { - ESX_MENU.pos[focused.namespace][focused.name] = menu.elements.length - 1; - } + if (typeof focused != "undefined") { + ESX_MENU.cancel(focused.namespace, focused.name); + } - let elem = menu.elements[ESX_MENU.pos[focused.namespace][focused.name]]; + break; + } - for (let i = 0; i < menu.elements.length; i++) { - if (i === ESX_MENU.pos[focused.namespace][focused.name]) { - menu.elements[i].selected = true; - } else { - menu.elements[i].selected = false; - } - } + case "TOP": { + let focused = ESX_MENU.getFocused(); - ESX_MENU.change(focused.namespace, focused.name, elem); - ESX_MENU.render(); + if (typeof focused != "undefined") { + let menu = ESX_MENU.opened[focused.namespace][focused.name]; + let pos = ESX_MENU.pos[focused.namespace][focused.name]; - $("#menu_" + focused.namespace + "_" + focused.name) - .find(".menu-item.selected")[0] - .scrollIntoView(); - } + if (pos > 0) { + ESX_MENU.pos[focused.namespace][focused.name]--; + } else { + ESX_MENU.pos[focused.namespace][focused.name] = menu.elements.length - 1; + } - break; - } + let elem = menu.elements[ESX_MENU.pos[focused.namespace][focused.name]]; - case "DOWN": { - let focused = ESX_MENU.getFocused(); + for (let i = 0; i < menu.elements.length; i++) { + if (i === ESX_MENU.pos[focused.namespace][focused.name]) { + menu.elements[i].selected = true; + } else { + menu.elements[i].selected = false; + } + } - if (typeof focused != "undefined") { - let menu = ESX_MENU.opened[focused.namespace][focused.name]; - let pos = ESX_MENU.pos[focused.namespace][focused.name]; - let length = menu.elements.length; + ESX_MENU.change(focused.namespace, focused.name, elem); + ESX_MENU.render(); - if (pos < length - 1) { - ESX_MENU.pos[focused.namespace][focused.name]++; - } else { - ESX_MENU.pos[focused.namespace][focused.name] = 0; - } + $("#menu_" + focused.namespace + "_" + focused.name) + .find(".menu-item.selected")[0] + .scrollIntoView(); + } - let elem = menu.elements[ESX_MENU.pos[focused.namespace][focused.name]]; + break; + } - for (let i = 0; i < menu.elements.length; i++) { - if (i === ESX_MENU.pos[focused.namespace][focused.name]) { - menu.elements[i].selected = true; - } else { - menu.elements[i].selected = false; - } - } + case "DOWN": { + let focused = ESX_MENU.getFocused(); - ESX_MENU.change(focused.namespace, focused.name, elem); - ESX_MENU.render(); + if (typeof focused != "undefined") { + let menu = ESX_MENU.opened[focused.namespace][focused.name]; + let pos = ESX_MENU.pos[focused.namespace][focused.name]; + let length = menu.elements.length; - $("#menu_" + focused.namespace + "_" + focused.name) - .find(".menu-item.selected")[0] - .scrollIntoView(); - } + if (pos < length - 1) { + ESX_MENU.pos[focused.namespace][focused.name]++; + } else { + ESX_MENU.pos[focused.namespace][focused.name] = 0; + } - break; - } + let elem = menu.elements[ESX_MENU.pos[focused.namespace][focused.name]]; - case "LEFT": { - let focused = ESX_MENU.getFocused(); + for (let i = 0; i < menu.elements.length; i++) { + if (i === ESX_MENU.pos[focused.namespace][focused.name]) { + menu.elements[i].selected = true; + } else { + menu.elements[i].selected = false; + } + } - if (typeof focused != "undefined") { - let menu = ESX_MENU.opened[focused.namespace][focused.name]; - let pos = ESX_MENU.pos[focused.namespace][focused.name]; - let elem = menu.elements[pos]; + ESX_MENU.change(focused.namespace, focused.name, elem); + ESX_MENU.render(); - switch (elem.type) { - case "default": - break; + $("#menu_" + focused.namespace + "_" + focused.name) + .find(".menu-item.selected")[0] + .scrollIntoView(); + } - case "slider": { - let min = typeof elem.min === "undefined" ? 0 : elem.min; + break; + } - if (elem.value > min) { - elem.value--; - ESX_MENU.change(focused.namespace, focused.name, elem); - } + case "LEFT": { + let focused = ESX_MENU.getFocused(); - ESX_MENU.render(); - break; - } + if (typeof focused != "undefined") { + let menu = ESX_MENU.opened[focused.namespace][focused.name]; + let pos = ESX_MENU.pos[focused.namespace][focused.name]; + let elem = menu.elements[pos]; - default: - break; - } + switch (elem.type) { + case "default": + break; - $("#menu_" + focused.namespace + "_" + focused.name) - .find(".menu-item.selected")[0] - .scrollIntoView(); - } + case "slider": { + let min = typeof elem.min === "undefined" ? 0 : elem.min; - break; + if (elem.value > min) { + elem.value--; + ESX_MENU.change(focused.namespace, focused.name, elem); } - case "RIGHT": { - let focused = ESX_MENU.getFocused(); + ESX_MENU.render(); + break; + } - if (typeof focused != "undefined") { - let menu = ESX_MENU.opened[focused.namespace][focused.name]; - let pos = ESX_MENU.pos[focused.namespace][focused.name]; - let elem = menu.elements[pos]; + default: + break; + } - switch (elem.type) { - case "default": - break; + $("#menu_" + focused.namespace + "_" + focused.name) + .find(".menu-item.selected")[0] + .scrollIntoView(); + } - case "slider": { - if (typeof elem.options != "undefined" && elem.value < elem.options.length - 1) { - elem.value++; - ESX_MENU.change(focused.namespace, focused.name, elem); - } + break; + } - if (typeof elem.max != "undefined" && elem.value < elem.max) { - elem.value++; - ESX_MENU.change(focused.namespace, focused.name, elem); - } + case "RIGHT": { + let focused = ESX_MENU.getFocused(); - ESX_MENU.render(); - break; - } + if (typeof focused != "undefined") { + let menu = ESX_MENU.opened[focused.namespace][focused.name]; + let pos = ESX_MENU.pos[focused.namespace][focused.name]; + let elem = menu.elements[pos]; - default: - break; - } + switch (elem.type) { + case "default": + break; - $("#menu_" + focused.namespace + "_" + focused.name) - .find(".menu-item.selected")[0] - .scrollIntoView(); - } + case "slider": { + if (typeof elem.options != "undefined" && elem.value < elem.options.length - 1) { + elem.value++; + ESX_MENU.change(focused.namespace, focused.name, elem); + } - break; + if (typeof elem.max != "undefined" && elem.value < elem.max) { + elem.value++; + ESX_MENU.change(focused.namespace, focused.name, elem); } - default: - break; + ESX_MENU.render(); + break; + } + + default: + break; } - break; + $("#menu_" + focused.namespace + "_" + focused.name) + .find(".menu-item.selected")[0] + .scrollIntoView(); + } + + break; } + + default: + break; + } + + break; } + } }; window.onload = function (e) { diff --git a/server-data/resources/[esx]/esx_menu_default/html/ui.html b/server-data/resources/[esx]/esx_menu_default/html/ui.html index e7660d818..0c8065a7d 100644 --- a/server-data/resources/[esx]/esx_menu_default/html/ui.html +++ b/server-data/resources/[esx]/esx_menu_default/html/ui.html @@ -1,16 +1,18 @@ -
- - - - - - - + + + + + + + + + + + + + + - - - - \ No newline at end of file diff --git a/server-data/resources/[esx]/esx_multicharacter/client/main.lua b/server-data/resources/[esx]/esx_multicharacter/client/main.lua index 239e63812..0d655fa5d 100644 --- a/server-data/resources/[esx]/esx_multicharacter/client/main.lua +++ b/server-data/resources/[esx]/esx_multicharacter/client/main.lua @@ -11,7 +11,7 @@ if ESX.GetConfig().Multichar then if NetworkIsPlayerActive(PlayerId()) then exports.spawnmanager:setAutoSpawn(false) DoScreenFadeOut(0) - while GetResourceState('esx_context') ~= 'started' do + while GetResourceState("esx_context") ~= "started" do Wait(100) end TriggerEvent("esx_multicharacter:SetupCharacters") @@ -23,8 +23,8 @@ if ESX.GetConfig().Multichar then local canRelog, cam, spawned = true, nil, nil local Characters = {} - RegisterNetEvent('esx_multicharacter:SetupCharacters') - AddEventHandler('esx_multicharacter:SetupCharacters', function() + RegisterNetEvent("esx_multicharacter:SetupCharacters") + AddEventHandler("esx_multicharacter:SetupCharacters", function() ESX.PlayerLoaded = false ESX.PlayerData = {} spawned = false @@ -41,7 +41,7 @@ if ESX.GetConfig().Multichar then StartLoop() ShutdownLoadingScreen() ShutdownLoadingScreenNui() - TriggerEvent('esx:loadingScreenOff') + TriggerEvent("esx:loadingScreenOff") Wait(200) TriggerServerEvent("esx_multicharacter:SetupCharacters") end) @@ -65,7 +65,7 @@ if ESX.GetConfig().Multichar then HideHudComponentThisFrame(21) HideHudAndRadarThisFrame() Wait(0) - local vehicles = GetGamePool('CVehicle') + local vehicles = GetGamePool("CVehicle") for i = 1, #vehicles do SetEntityLocallyInvisible(vehicles[i]) end @@ -105,19 +105,25 @@ if ESX.GetConfig().Multichar then z = SpawnCoords.z, heading = SpawnCoords.w, model = Characters[index].model or mp_m_freemode_01, - skipFade = true + skipFade = true, }, function() canRelog = false if Characters[index] then local skin = Characters[index].skin or Config.Default if not Characters[index].model then - if Characters[index].sex == _U('female') then skin.sex = 1 else skin.sex = 0 end + if Characters[index].sex == _U("female") then + skin.sex = 1 + else + skin.sex = 0 + end end - TriggerEvent('skinchanger:loadSkin', skin) + TriggerEvent("skinchanger:loadSkin", skin) end DoScreenFadeIn(600) end) - repeat Wait(200) until not IsScreenFadedOut() + repeat + Wait(200) + until not IsScreenFadedOut() elseif Characters[index] and Characters[index].skin then if Characters[spawned] and Characters[spawned].model then RequestModel(Characters[index].model) @@ -128,7 +134,7 @@ if ESX.GetConfig().Multichar then SetPlayerModel(PlayerId(), Characters[index].model) SetModelAsNoLongerNeeded(Characters[index].model) end - TriggerEvent('skinchanger:loadSkin', Characters[index].skin) + TriggerEvent("skinchanger:loadSkin", Characters[index].skin) end spawned = index local playerPed = PlayerPedId() @@ -137,21 +143,38 @@ if ESX.GetConfig().Multichar then SetEntityAlpha(playerPed, 255) SendNUIMessage({ action = "openui", - character = Characters[spawned] + character = Characters[spawned], }) end function CharacterDeleteConfirmation(Characters, slots, SelectedCharacter, value) local elements = { - { title = _U('char_delete_confirmation'), icon = "fa-solid fa-users", description = _U('char_delete_confirmation_description'), unselectable = true }, - { title = _U('char_delete'), icon = "fa-solid fa-xmark", description = _U('char_delete_yes_description'), action = 'delete', value = value }, - { title = _U('return'), unselectable = false, icon = "fa-solid fa-arrow-left", description = _U('char_delete_no_description'), action = "return" } + { + title = _U("char_delete_confirmation"), + icon = "fa-solid fa-users", + description = _U("char_delete_confirmation_description"), + unselectable = true, + }, + { + title = _U("char_delete"), + icon = "fa-solid fa-xmark", + description = _U("char_delete_yes_description"), + action = "delete", + value = value, + }, + { + title = _U("return"), + unselectable = false, + icon = "fa-solid fa-arrow-left", + description = _U("char_delete_no_description"), + action = "return", + }, } ESX.OpenContext("left", elements, function(_, Action) if Action.action == "delete" then ESX.CloseContext() - TriggerServerEvent('esx_multicharacter:DeleteCharacter', Action.value) + TriggerServerEvent("esx_multicharacter:DeleteCharacter", Action.value) spawned = false elseif Action.action == "return" then CharacterOptions(Characters, slots, SelectedCharacter) @@ -160,21 +183,55 @@ if ESX.GetConfig().Multichar then end function CharacterOptions(Characters, slots, SelectedCharacter) - local elements = { { title = _U('character', Characters[SelectedCharacter.value].firstname .. " " .. Characters[SelectedCharacter.value].lastname), icon = "fa-regular fa-user", unselectable = true }, - { title = _U('return'), unselectable = false, icon = "fa-solid fa-arrow-left", description = _U('return_description'), action = "return" } } + local elements = { + { + title = _U( + "character", + Characters[SelectedCharacter.value].firstname .. " " .. Characters[SelectedCharacter.value].lastname + ), + icon = "fa-regular fa-user", + unselectable = true, + }, + { + title = _U("return"), + unselectable = false, + icon = "fa-solid fa-arrow-left", + description = _U("return_description"), + action = "return", + }, + } if not Characters[SelectedCharacter.value].disabled then - elements[3] = { title = _U('char_play'), description = _U('char_play_description'), icon = "fa-solid fa-play", action = 'play', value = SelectedCharacter.value } + elements[3] = { + title = _U("char_play"), + description = _U("char_play_description"), + icon = "fa-solid fa-play", + action = "play", + value = SelectedCharacter.value, + } else - elements[3] = { title = _U('char_disabled'), value = SelectedCharacter.value, icon = "fa-solid fa-xmark", description = _U('char_disabled_description'), } + elements[3] = { + title = _U("char_disabled"), + value = SelectedCharacter.value, + icon = "fa-solid fa-xmark", + description = _U("char_disabled_description"), + } + end + if Config.CanDelete then + elements[4] = { + title = _U("char_delete"), + icon = "fa-solid fa-xmark", + description = _U("char_delete_description"), + action = "delete", + value = SelectedCharacter.value, + } end - if Config.CanDelete then elements[4] = { title = _U('char_delete'), icon = "fa-solid fa-xmark", description = _U('char_delete_description'), action = 'delete', value = SelectedCharacter.value } end ESX.OpenContext("left", elements, function(_, Action) if Action.action == "play" then SendNUIMessage({ - action = "closeui" + action = "closeui", }) ESX.CloseContext() - TriggerServerEvent('esx_multicharacter:CharacterChosen', Action.value, false) + TriggerServerEvent("esx_multicharacter:CharacterChosen", Action.value, false) elseif Action.action == "delete" then CharacterDeleteConfirmation(Characters, slots, SelectedCharacter, Action.value) elseif Action.action == "return" then @@ -185,13 +242,28 @@ if ESX.GetConfig().Multichar then function SelectCharacterMenu(Characters, slots) local Character = next(Characters) - local elements = { { title = _U('select_char'), icon = "fa-solid fa-users", description = _U('select_char_description'), unselectable = true } } + local elements = { + { + title = _U("select_char"), + icon = "fa-solid fa-users", + description = _U("select_char_description"), + unselectable = true, + }, + } for k, v in pairs(Characters) do if not v.model and v.skin then - if v.skin.model then v.model = v.skin.model elseif v.skin.sex == 1 then v.model = mp_f_freemode_01 else v.model = mp_m_freemode_01 end + if v.skin.model then + v.model = v.skin.model + elseif v.skin.sex == 1 then + v.model = mp_f_freemode_01 + else + v.model = mp_m_freemode_01 + end end - if not spawned then SetupCharacter(Character) end - local label = v.firstname .. ' ' .. v.lastname + if not spawned then + SetupCharacter(Character) + end + local label = v.firstname .. " " .. v.lastname if Characters[k].disabled then elements[#elements + 1] = { title = label, icon = "fa-regular fa-user", value = v.id } else @@ -199,7 +271,8 @@ if ESX.GetConfig().Multichar then end end if #elements - 1 < slots then - elements[#elements + 1] = { title = _U('create_char'), icon = "fa-solid fa-plus", value = (#elements + 1), new = true } + elements[#elements + 1] = + { title = _U("create_char"), icon = "fa-solid fa-plus", value = (#elements + 1), new = true } end ESX.OpenContext("left", elements, function(_, SelectedCharacter) @@ -213,13 +286,13 @@ if ESX.GetConfig().Multichar then end end local slot = GetSlot() - TriggerServerEvent('esx_multicharacter:CharacterChosen', slot, true) - TriggerEvent('esx_identity:showRegisterIdentity') + TriggerServerEvent("esx_multicharacter:CharacterChosen", slot, true) + TriggerEvent("esx_identity:showRegisterIdentity") local playerPed = PlayerPedId() SetPedAoBlobRendering(playerPed, false) SetEntityAlpha(playerPed, 0) SendNUIMessage({ - action = "closeui" + action = "closeui", }) else CharacterOptions(Characters, slots, SelectedCharacter) @@ -231,8 +304,8 @@ if ESX.GetConfig().Multichar then end, nil, false) end - RegisterNetEvent('esx_multicharacter:SetupUI') - AddEventHandler('esx_multicharacter:SetupUI', function(data, slots) + RegisterNetEvent("esx_multicharacter:SetupUI") + AddEventHandler("esx_multicharacter:SetupUI", function(data, slots) DoScreenFadeOut(0) Characters = data slots = slots @@ -241,7 +314,7 @@ if ESX.GetConfig().Multichar then if not Character then SendNUIMessage({ - action = "closeui" + action = "closeui", }) exports.spawnmanager:spawnPlayer({ x = SpawnCoords.x, @@ -249,7 +322,7 @@ if ESX.GetConfig().Multichar then z = SpawnCoords.z, heading = SpawnCoords.w, model = mp_m_freemode_01, - skipFade = true + skipFade = true, }, function() canRelog = false DoScreenFadeIn(400) @@ -257,16 +330,16 @@ if ESX.GetConfig().Multichar then local playerPed = PlayerPedId() SetPedAoBlobRendering(playerPed, false) SetEntityAlpha(playerPed, 0) - TriggerServerEvent('esx_multicharacter:CharacterChosen', 1, true) - TriggerEvent('esx_identity:showRegisterIdentity') + TriggerServerEvent("esx_multicharacter:CharacterChosen", 1, true) + TriggerEvent("esx_identity:showRegisterIdentity") end) else SelectCharacterMenu(Characters, slots) end end) - RegisterNetEvent('esx:playerLoaded') - AddEventHandler('esx:playerLoaded', function(playerData, isNew, skin) + RegisterNetEvent("esx:playerLoaded") + AddEventHandler("esx:playerLoaded", function(playerData, isNew, skin) local spawn = playerData.coords or Config.Spawn if isNew or not skin or #skin == 1 then local finished = false @@ -280,20 +353,22 @@ if ESX.GetConfig().Multichar then end SetPlayerModel(PlayerId(), model) SetModelAsNoLongerNeeded(model) - TriggerEvent('skinchanger:loadSkin', skin, function() + TriggerEvent("skinchanger:loadSkin", skin, function() local playerPed = PlayerPedId() SetPedAoBlobRendering(playerPed, true) ResetEntityAlpha(playerPed) - TriggerEvent('esx_skin:openSaveableMenu', function() + TriggerEvent("esx_skin:openSaveableMenu", function() finished = true end, function() finished = true end) end) - repeat Wait(200) until finished + repeat + Wait(200) + until finished end - DoScreenFadeOut(750) + DoScreenFadeOut(750) Wait(750) SetCamActive(cam, false) @@ -303,38 +378,42 @@ if ESX.GetConfig().Multichar then FreezeEntityPosition(playerPed, true) SetEntityCoordsNoOffset(playerPed, spawn.x, spawn.y, spawn.z, false, false, false, true) SetEntityHeading(playerPed, spawn.heading) - if not isNew then TriggerEvent('skinchanger:loadSkin', skin or Characters[spawned].skin) end - Wait(500) + if not isNew then + TriggerEvent("skinchanger:loadSkin", skin or Characters[spawned].skin) + end + Wait(500) DoScreenFadeIn(750) Wait(750) - repeat Wait(200) until not IsScreenFadedOut() - TriggerServerEvent('esx:onPlayerSpawn') - TriggerEvent('esx:onPlayerSpawn') - TriggerEvent('playerSpawned') - TriggerEvent('esx:restoreLoadout') + repeat + Wait(200) + until not IsScreenFadedOut() + TriggerServerEvent("esx:onPlayerSpawn") + TriggerEvent("esx:onPlayerSpawn") + TriggerEvent("playerSpawned") + TriggerEvent("esx:restoreLoadout") Characters, hidePlayers = {}, false end) - RegisterNetEvent('esx:onPlayerLogout') - AddEventHandler('esx:onPlayerLogout', function() + RegisterNetEvent("esx:onPlayerLogout") + AddEventHandler("esx:onPlayerLogout", function() DoScreenFadeOut(500) Wait(1000) spawned = false TriggerEvent("esx_multicharacter:SetupCharacters") - TriggerEvent('esx_skin:resetFirstSpawn') + TriggerEvent("esx_skin:resetFirstSpawn") end) if Config.Relog then - RegisterCommand('relog', function() + RegisterCommand("relog", function() if canRelog then canRelog = false - TriggerServerEvent('esx_multicharacter:relog') + TriggerServerEvent("esx_multicharacter:relog") ESX.SetTimeout(10000, function() canRelog = true end) end end) end -end \ No newline at end of file +end diff --git a/server-data/resources/[esx]/esx_multicharacter/config.lua b/server-data/resources/[esx]/esx_multicharacter/config.lua index b60438446..f4002af82 100644 --- a/server-data/resources/[esx]/esx_multicharacter/config.lua +++ b/server-data/resources/[esx]/esx_multicharacter/config.lua @@ -1,5 +1,5 @@ Config = {} -Config.Locale = 'it' +Config.Locale = "it" -- Allows players to delete their characters Config.CanDelete = true @@ -11,7 +11,7 @@ if IsDuplicityVersion() then -------------------- -- Text to prepend to each character (char#:identifier) - keep it short - Config.Prefix = 'char' + Config.Prefix = "char" else -- Sets the location for the character selection scene -- To set the spawn location for new characters, modify the default value in the users SQL table @@ -122,7 +122,7 @@ else beard_1 = 11, beard_2 = 10, beard_3 = 0, - beard_4 = 0 + beard_4 = 0, }, ["f"] = { mom = 28, @@ -219,7 +219,7 @@ else beard_1 = 0, beard_2 = 0, beard_3 = 0, - beard_4 = 0 - } + beard_4 = 0, + }, } end diff --git a/server-data/resources/[esx]/esx_multicharacter/fxmanifest.lua b/server-data/resources/[esx]/esx_multicharacter/fxmanifest.lua index 99e4069c8..cec3f9920 100644 --- a/server-data/resources/[esx]/esx_multicharacter/fxmanifest.lua +++ b/server-data/resources/[esx]/esx_multicharacter/fxmanifest.lua @@ -1,19 +1,19 @@ -fx_version 'cerulean' +fx_version("cerulean") -game 'gta5' -author 'ESX-Framework - Linden - KASH' -description 'Official Multicharacter System For ESX Legacy' -version '1.0.0' -lua54 'yes' +game("gta5") +author("ESX-Framework - Linden - KASH") +description("Official Multicharacter System For ESX Legacy") +version("1.0.0") +lua54("yes") -dependencies { 'es_extended', 'esx_context', 'esx_identity', 'esx_skin' } +dependencies({ "es_extended", "esx_context", "esx_identity", "esx_skin" }) -shared_scripts { '@es_extended/imports.lua', '@es_extended/locale.lua', 'locales/*.lua', 'config.lua' } +shared_scripts({ "@es_extended/imports.lua", "@es_extended/locale.lua", "locales/*.lua", "config.lua" }) -server_scripts { '@oxmysql/lib/MySQL.lua', 'server/*.lua' } +server_scripts({ "@oxmysql/lib/MySQL.lua", "server/*.lua" }) -client_scripts { 'client/*.lua' } +client_scripts({ "client/*.lua" }) -ui_page { 'html/ui.html' } +ui_page({ "html/ui.html" }) -files { 'html/ui.html', 'html/css/main.css', 'html/js/app.js', 'html/locales/*.js' } +files({ "html/ui.html", "html/css/main.css", "html/js/app.js", "html/locales/*.js" }) diff --git a/server-data/resources/[esx]/esx_multicharacter/html/css/main.css b/server-data/resources/[esx]/esx_multicharacter/html/css/main.css index b6d866d54..9e652847e 100644 --- a/server-data/resources/[esx]/esx_multicharacter/html/css/main.css +++ b/server-data/resources/[esx]/esx_multicharacter/html/css/main.css @@ -1,5 +1,6 @@ @import url("https://fonts.googleapis.com/css2?family=Raleway:wght@300;600&display=swap"); @import url("https://fonts.googleapis.com/css2?family=Oswald&display=swap"); + * { margin: 0; padding: 0; @@ -73,4 +74,4 @@ h1 { padding-top: 1.3rem; display: block; font-weight: 0; -} +} \ No newline at end of file diff --git a/server-data/resources/[esx]/esx_multicharacter/html/js/app.js b/server-data/resources/[esx]/esx_multicharacter/html/js/app.js index 00cdb7f9c..0cbdb5c4a 100644 --- a/server-data/resources/[esx]/esx_multicharacter/html/js/app.js +++ b/server-data/resources/[esx]/esx_multicharacter/html/js/app.js @@ -13,34 +13,34 @@ var money = Intl.NumberFormat("en-US", { $("[data-charid=1]") .html( '