mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 00:01:20 +00:00
Dynamic slots (#36)
* Removed slots configuration * feature: dynamic slots * fixes + improvements * edited core functionality * added commands for slots management * added commands english locale Co-authored-by: d3rp-jsx <15928886+derp-jsx@users.noreply.github.com>
This commit is contained in:
+4
-3
@@ -142,9 +142,10 @@ if ESX.GetConfig().Multichar then
|
||||
end
|
||||
|
||||
RegisterNetEvent('esx_multicharacter:SetupUI')
|
||||
AddEventHandler('esx_multicharacter:SetupUI', function(data)
|
||||
AddEventHandler('esx_multicharacter:SetupUI', function(data, slots)
|
||||
DoScreenFadeOut(0)
|
||||
Characters = data
|
||||
local slots = slots
|
||||
local elements = {}
|
||||
local Character = next(Characters)
|
||||
exports.spawnmanager:forceRespawn()
|
||||
@@ -179,7 +180,7 @@ if ESX.GetConfig().Multichar then
|
||||
local label = v.firstname..' '..v.lastname
|
||||
elements[#elements+1] = {label = label, value = v.id}
|
||||
end
|
||||
if #elements < Config.Slots then
|
||||
if #elements < slots then
|
||||
elements[#elements+1] = {label = _('create_char'), value = (#elements+1), new = true}
|
||||
end
|
||||
ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'selectchar', {
|
||||
@@ -228,7 +229,7 @@ if ESX.GetConfig().Multichar then
|
||||
else
|
||||
ESX.UI.Menu.CloseAll()
|
||||
local GetSlot = function()
|
||||
for i=1, Config.Slots do
|
||||
for i=1, slots do
|
||||
if not Characters[i] then
|
||||
return i
|
||||
end
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
Config = {}
|
||||
Config.Locale = 'en'
|
||||
|
||||
Config.Slots = 4
|
||||
Config.Slots = 1
|
||||
Config.Spawn = vector4(-113.7, 565.3, 195.2, 0) -- Sets the location for character selection
|
||||
-- To set the spawn location for new characters, modify the default value in the `users` SQL table
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
CREATE TABLE `multicharacter_slots` (
|
||||
`identifier` VARCHAR(60) NOT NULL DEFAULT '' COLLATE 'utf8mb4_unicode_ci',
|
||||
`slots` INT(11) NOT NULL DEFAULT '1'
|
||||
)
|
||||
COLLATE='utf8mb4_unicode_ci'
|
||||
ENGINE=InnoDB
|
||||
;
|
||||
@@ -8,4 +8,11 @@ Locales['en'] = {
|
||||
['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_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",
|
||||
}
|
||||
|
||||
+46
-2
@@ -12,9 +12,15 @@ elseif ESX.GetConfig().Multichar == true then
|
||||
local SetupCharacters = function(playerId)
|
||||
while Fetch == -1 do Citizen.Wait(500) end
|
||||
local identifier = Config.Prefix..'%:'..ESX.GetIdentifier(playerId)
|
||||
local slots = MySQL.Sync.fetchScalar("SELECT `slots` FROM `multicharacter_slots` WHERE identifier = ?", {
|
||||
ESX.GetIdentifier(playerId)
|
||||
})
|
||||
if not slots then
|
||||
slots = Config.Slots
|
||||
end
|
||||
MySQL.Async.fetchAll(Fetch, {
|
||||
identifier,
|
||||
Config.Slots
|
||||
slots
|
||||
}, function(result)
|
||||
local characters = {}
|
||||
for i=1, #result, 1 do
|
||||
@@ -38,7 +44,7 @@ elseif ESX.GetConfig().Multichar == true then
|
||||
}
|
||||
if result[i].sex == 'm' then characters[id].sex = _('male') else characters[id].sex = _('female') end
|
||||
end
|
||||
TriggerClientEvent('esx_multicharacter:SetupUI', playerId, characters)
|
||||
TriggerClientEvent('esx_multicharacter:SetupUI', playerId, characters, slots)
|
||||
end)
|
||||
end
|
||||
|
||||
@@ -123,6 +129,44 @@ 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)
|
||||
|
||||
Reference in New Issue
Block a user