From 30bee9343fa61674d175563af69ef5d7552da052 Mon Sep 17 00:00:00 2001 From: Mycroft Date: Thu, 2 Mar 2023 08:34:35 -0800 Subject: [PATCH] refactor: make Config.Multichar an automatic value Credit to Fantik for the idea --- [core]/es_extended/config.lua | 2 +- [core]/esx_multicharacter/server/main.lua | 47 ++++++++++------------- 2 files changed, 21 insertions(+), 28 deletions(-) diff --git a/[core]/es_extended/config.lua b/[core]/es_extended/config.lua index 1c6da954..ceca3601 100644 --- a/[core]/es_extended/config.lua +++ b/[core]/es_extended/config.lua @@ -29,7 +29,7 @@ Config.EnableDefaultInventory = true -- Display the default Inventory ( F2 ) Config.EnableWantedLevel = false -- Use Normal GTA wanted Level? Config.EnablePVP = true -- Allow Player to player combat -Config.Multichar = true -- Enable support for esx_multicharacter +Config.Multichar = GetResourceState("esx_multicharacter") ~= "missing" Config.Identity = true -- Select a characters identity data before they have loaded in (this happens by default with multichar) Config.DistanceGive = 4.0 -- Max distance when giving items, weapons etc. diff --git a/[core]/esx_multicharacter/server/main.lua b/[core]/esx_multicharacter/server/main.lua index 564c7085..12864d99 100644 --- a/[core]/esx_multicharacter/server/main.lua +++ b/[core]/esx_multicharacter/server/main.lua @@ -1,29 +1,26 @@ -if not ESX then - error('\n^1Unable to start Multicharacter - you must be using ESX Legacy^0') -elseif ESX.GetConfig().Multichar then - local databaseConnected = false - local databaseFound = false - local oneSyncState = GetConvar('onesync', 'off') +local databaseConnected = false +local databaseFound = false +local oneSyncState = GetConvar('onesync', 'off') - local DATABASE do - local connectionString = GetConvar('mysql_connection_string', ''); - if connectionString == '' then - error(connectionString..'\n^1Unable to start Multicharacter - unable to determine database from mysql_connection_string^0', 0) - elseif connectionString:find('mysql://') then - connectionString = connectionString:sub(9, -1) - DATABASE = connectionString:sub(connectionString:find('/')+1, -1):gsub('[%?]+[%w%p]*$', '') - databaseFound = true - else - connectionString = {string.strsplit(';', connectionString)} - for i = 1, #connectionString do - local v = connectionString[i] - if v:match('database') then - DATABASE = v:sub(10, #v) - end +local DATABASE do + local connectionString = GetConvar('mysql_connection_string', ''); + if connectionString == '' then + error(connectionString..'\n^1Unable to start Multicharacter - unable to determine database from mysql_connection_string^0', 0) + elseif connectionString:find('mysql://') then + connectionString = connectionString:sub(9, -1) + DATABASE = connectionString:sub(connectionString:find('/')+1, -1):gsub('[%?]+[%w%p]*$', '') + databaseFound = true + else + connectionString = {string.strsplit(';', connectionString)} + for i = 1, #connectionString do + local v = connectionString[i] + if v:match('database') then + DATABASE = v:sub(10, #v) end - databaseFound = true end + databaseFound = true end +end local DB_TABLES = {users = 'identifier'} local FETCH = nil @@ -239,8 +236,4 @@ elseif ESX.GetConfig().Multichar then RegisterNetEvent('esx_multicharacter:relog', function() local source = source TriggerEvent('esx:playerLogout', source) - end) - - else - assert(nil, '^3WARNING: Multicharacter is disabled - please check your ESX configuration^0') - end + end) \ No newline at end of file