From 5f5b0138f056d1c21a8418f45befa6a911db9dfe Mon Sep 17 00:00:00 2001 From: Demetrio <15928886+d3rp-jsx@users.noreply.github.com> Date: Fri, 20 Aug 2021 16:56:48 +0200 Subject: [PATCH] feat(chars): enable or disable a specific character of a player (#43) --- client/main.lua | 14 ++++++-- esx_multicharacter.sql | 3 ++ locales/en.lua | 7 ++++ locales/it.lua | 11 ++++-- server/commands.lua | 79 ++++++++++++++++++++++++++++++++++++++++++ server/main.lua | 47 ++----------------------- 6 files changed, 112 insertions(+), 49 deletions(-) create mode 100644 server/commands.lua diff --git a/client/main.lua b/client/main.lua index 15f6b391..e5705d2f 100644 --- a/client/main.lua +++ b/client/main.lua @@ -178,7 +178,11 @@ if ESX.GetConfig().Multichar then end if Spawned == false then SetupCharacter(Character) end local label = v.firstname..' '..v.lastname - elements[#elements+1] = {label = label, value = v.id} + if Characters[k].disabled == 1 then + elements[#elements+1] = {label = label, value = v.id} + else + elements[#elements+1] = {label = label, value = v.id} + end end if #elements < slots then elements[#elements+1] = {label = _('create_char'), value = (#elements+1), new = true} @@ -190,7 +194,11 @@ if ESX.GetConfig().Multichar then }, function(data, menu) local elements = {} if not data.current.new then - elements[1] = {label = _('char_play'), action = 'play', value = data.current.value} + if Characters[data.current.value].disabled == 0 then + elements[1] = {label = _('char_play'), action = 'play', value = data.current.value} + else + elements[1] = {label = _('char_disabled'), value = data.current.value} + end if Config.CanDelete then elements[2] = {label = _('char_delete'), action = 'delete', value = data.current.value} end ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'choosechar', { title = _('select_char'), @@ -203,7 +211,7 @@ if ESX.GetConfig().Multichar then action = "closeui" }) TriggerServerEvent('esx_multicharacter:CharacterChosen', data.current.value, false) - else + elseif data.current.action == 'delete' then local elements2 = {} elements2[1] = {label = _('cancel')} elements2[2] = {label = _('confirm'), value = data.current.value} diff --git a/esx_multicharacter.sql b/esx_multicharacter.sql index 86fb2b36..6aba96ad 100644 --- a/esx_multicharacter.sql +++ b/esx_multicharacter.sql @@ -2,3 +2,6 @@ CREATE TABLE `multicharacter_slots` ( `identifier` VARCHAR(60) NOT NULL, `slots` INT NOT NULL ); + +ALTER TABLE `users` + ADD `disabled` BIT NOT NULL DEFAULT 0; \ No newline at end of file diff --git a/locales/en.lua b/locales/en.lua index e61481b0..b71de307 100644 --- a/locales/en.lua +++ b/locales/en.lua @@ -5,14 +5,21 @@ Locales['en'] = { ['select_char'] = "Select Character", ['create_char'] = "Create new character", ['char_play'] = "Play this character", + ['char_disabled'] = "This character is disabled", ['char_delete'] = "Delete this character", ['cancel'] = "Cancel", ['confirm'] = "Confirm", ['command_setslots'] = "Set multicharacter slots number of a player", ['command_remslots'] = "Remove multicharacter slots number of a player", + ['command_enablechar'] = "Enable a given character of a player", + ['command_disablechar'] = "Disable a given character of a player", + ['command_charslot'] = "Slot number of the character", ['command_identifier'] = "Player identifier", ['command_slots'] = "# of slots", ['slotsadd'] = "You added %s slots to %s", ['slotsedit'] = "You set %s slots to %s", ['slotsrem'] = "You removed slots to %s", + ['charenabled'] = "You enabled character #%s of %s", + ['chardisabled'] = "You disabled character #%s of %s", + ['charnotfound'] = "Character #%s of %s doesn't exist", } diff --git a/locales/it.lua b/locales/it.lua index 6bae31fb..1f2333e5 100644 --- a/locales/it.lua +++ b/locales/it.lua @@ -5,14 +5,21 @@ Locales['it'] = { ['select_char'] = "Seleziona Personaggio", ['create_char'] = "Crea un nuovo personaggio", ['char_play'] = "Gioca questo personaggio", + ['char_disabled'] = "Questo personaggio è disabilitato", ['char_delete'] = "Cancella questo personaggio", ['cancel'] = "Annulla", ['confirm'] = "Conferma", - ['command_setslots'] = "Imposta il numero di slot di personaggi di un player", - ['command_remslots'] = "Rimuovi il numero di slot di personaggi di un player", + ['command_setslots'] = "Imposta il numero di slot di personaggi di un giocatore", + ['command_remslots'] = "Rimuovi il numero di slot di personaggi di un giocatore", + ['command_enablechar'] = "Abilita un personaggio di un giocatore", + ['command_disablechar'] = "Disabilita un personaggio di un giocatore", + ['command_charslot'] = "Numero dello slot del personaggio", ['command_identifier'] = "Identifier del giocatore", ['command_slots'] = "# di slot", ['slotsadd'] = "Hai aggiunto %s slot a %s", ['slotsedit'] = "Hai impostato %s slot a %s", ['slotsrem'] = "Hai rimosso gli slot a %s", + ['charenabled'] = "Hai abilitato il %s° personaggio di %s", + ['chardisabled'] = "Hai disabilitato il %s° personaggio di %s", + ['charnotfound'] = "Il personaggio %s di %s non esiste", } diff --git a/server/commands.lua b/server/commands.lua new file mode 100644 index 00000000..b4fbc2d2 --- /dev/null +++ b/server/commands.lua @@ -0,0 +1,79 @@ +ESX.RegisterCommand('setslots', 'admin', function(xPlayer, args, showError) + local slots = MySQL.Sync.fetchScalar('SELECT `slots` FROM `multicharacter_slots` WHERE identifier = ?', { + args.identifier + }) + + if slots == nil then + MySQL.Async.execute('INSERT INTO `multicharacter_slots` (`identifier`, `slots`) VALUES (?, ?)', { + args.identifier, + args.slots + }) + xPlayer.triggerEvent('esx:showNotification', _U('slotsadd', args.slots, args.identifier)) + else + MySQL.Async.execute('UPDATE `multicharacter_slots` SET `slots` = ? WHERE `identifier` = ?', { + args.slots, + args.identifier + }) + xPlayer.triggerEvent('esx:showNotification', _U('slotsedit', args.slots, args.identifier)) + end +end, true, {help = _U('command_setslots'), validate = true, arguments = { + {name = 'identifier', help = _U('command_identifier'), type = 'string'}, + {name = 'slots', help = _U('command_slots'), type = 'number'} +}}) + +ESX.RegisterCommand('remslots', 'admin', function(xPlayer, args, showError) + local slots = MySQL.Sync.fetchScalar('SELECT `slots` FROM `multicharacter_slots` WHERE identifier = ?', { + args.identifier + }) + + if slots ~= nil then + MySQL.Async.execute('DELETE FROM `multicharacter_slots` WHERE `identifier` = ?', { + args.identifier + }) + xPlayer.triggerEvent('esx:showNotification', _U('slotsrem', args.identifier)) + end +end, true, {help = _U('command_remslots'), validate = true, arguments = { + {name = 'identifier', help = _U('command_identifier'), type = 'string'} +}}) + +ESX.RegisterCommand('enablechar', 'admin', function(xPlayer, args, showError) + + local selectedCharacter = 'char'..args.charslot..':'..args.identifier; + + MySQL.Async.execute('UPDATE `users` SET `disabled` = 0 WHERE identifier = ?', { + selectedCharacter + }, function(result) + if result > 0 then + xPlayer.triggerEvent('esx:showNotification', _U('charenabled', args.charslot, args.identifier)) + else + xPlayer.triggerEvent('esx:showNotification', _U('charnotfound', args.charslot, args.identifier)) + end + end) + +end, true, {help = _U('command_enablechar'), validate = true, arguments = { + {name = 'identifier', help = _U('command_identifier'), type = 'string'}, + {name = 'charslot', help = _U('command_charslot'), type = 'number'} +}}) + +ESX.RegisterCommand('disablechar', 'admin', function(xPlayer, args, showError) + + local selectedCharacter = 'char'..args.charslot..':'..args.identifier; + + MySQL.Async.execute('UPDATE `users` SET `disabled` = 1 WHERE identifier = ?', { + selectedCharacter + }, function(result) + if result > 0 then + xPlayer.triggerEvent('esx:showNotification', _U('chardisabled', args.charslot, args.identifier)) + else + xPlayer.triggerEvent('esx:showNotification', _U('charnotfound', args.charslot, args.identifier)) + end + end) + +end, true, {help = _U('command_disablechar'), validate = true, arguments = { + {name = 'identifier', help = _U('command_identifier'), type = 'string'}, + {name = 'charslot', help = _U('command_charslot'), type = 'number'} +}}) + +RegisterCommand('forcelog', function(source, args, rawCommand) + TriggerEvent('esx:playerLogout', source) +end, true) \ No newline at end of file diff --git a/server/main.lua b/server/main.lua index d8abff13..09617693 100644 --- a/server/main.lua +++ b/server/main.lua @@ -40,7 +40,8 @@ elseif ESX.GetConfig().Multichar == true then firstname = result[i].firstname, lastname = result[i].lastname, dateofbirth = result[i].dateofbirth, - skin = json.decode(result[i].skin) + skin = json.decode(result[i].skin), + disabled = result[i].disabled, } if result[i].sex == 'm' then characters[id].sex = _('male') else characters[id].sex = _('female') end end @@ -83,7 +84,7 @@ elseif ESX.GetConfig().Multichar == true then print(('[^2INFO^7] Attempted to update ^5%s^7 columns to use VARCHAR(60)'):format(varsize)) end if not next(ESX.Jobs) then ESX.Jobs = GetJobs() end - Fetch = MySQL.Sync.store("SELECT `identifier`, `accounts`, `job`, `job_grade`, `firstname`, `lastname`, `dateofbirth`, `sex`, `skin` FROM `users` WHERE identifier LIKE ? LIMIT ?") + Fetch = MySQL.Sync.store("SELECT `identifier`, `accounts`, `job`, `job_grade`, `firstname`, `lastname`, `dateofbirth`, `sex`, `skin`, `disabled` FROM `users` WHERE identifier LIKE ? LIMIT ?") end end) end) @@ -129,48 +130,6 @@ elseif ESX.GetConfig().Multichar == true then TriggerEvent('esx:playerLogout', src) end) - ESX.RegisterCommand('setslots', 'admin', function(xPlayer, args, showError) - local slots = MySQL.Sync.fetchScalar('SELECT `slots` FROM `multicharacter_slots` WHERE identifier = ?', { - args.identifier - }) - - if slots == nil then - MySQL.Async.execute('INSERT INTO `multicharacter_slots` (`identifier`, `slots`) VALUES (?, ?)', { - args.identifier, - args.slots - }) - xPlayer.triggerEvent('esx:showNotification', _U('slotsadd', args.slots, args.identifier)) - else - MySQL.Async.execute('UPDATE `multicharacter_slots` SET `slots` = ? WHERE `identifier` = ?', { - args.slots, - args.identifier - }) - xPlayer.triggerEvent('esx:showNotification', _U('slotsedit', args.slots, args.identifier)) - end - end, true, {help = _U('command_setslots'), validate = true, arguments = { - {name = 'identifier', help = _U('command_identifier'), type = 'string'}, - {name = 'slots', help = _U('command_slots'), type = 'number'} - }}) - - ESX.RegisterCommand('remslots', 'admin', function(xPlayer, args, showError) - local slots = MySQL.Sync.fetchScalar('SELECT `slots` FROM `multicharacter_slots` WHERE identifier = ?', { - args.identifier - }) - - if slots ~= nil then - MySQL.Async.execute('DELETE FROM `multicharacter_slots` WHERE `identifier` = ?', { - args.identifier - }) - xPlayer.triggerEvent('esx:showNotification', _U('slotsrem', args.identifier)) - end - end, true, {help = _U('command_remslots'), validate = true, arguments = { - {name = 'identifier', help = _U('command_identifier'), type = 'string'} - }}) - - RegisterCommand('forcelog', function(source, args, rawCommand) - TriggerEvent('esx:playerLogout', source) - end, true) - else SetTimeout(3000, function() print('[^3WARNING^7] Multicharacter is disabled - please check your ESX configuration') end) end