From b4e5ed64808d0d432193c6e39e6919293dc0f983 Mon Sep 17 00:00:00 2001 From: Linden Date: Tue, 11 May 2021 19:38:32 +1000 Subject: [PATCH] Update for ESX Legacy; nuclear disarmament --- client/main.lua | 113 ++++++++++++------------ config.lua | 2 +- esx_kashacters.sql | 39 --------- fxmanifest.lua | 2 + html/ui.html | 2 +- server/main.lua | 211 ++++++++++++++++----------------------------- 6 files changed, 134 insertions(+), 235 deletions(-) delete mode 100644 esx_kashacters.sql diff --git a/client/main.lua b/client/main.lua index b73d8b77..8a5b5bae 100644 --- a/client/main.lua +++ b/client/main.lua @@ -1,44 +1,32 @@ -local ESX = nil local IsChoosing = true -Citizen.CreateThread(function() - while ESX == nil do - TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) - Citizen.Wait(0) - end -end) - -- This Code Was changed to fix error With player spawner as default -- -- Link to the post with the error fix -- -- https://forum.fivem.net/t/release-esx-kashacters-multi-character/251613/316?u=xxfri3ndlyxx -- - -Citizen.CreateThread(function() - while true do - Citizen.Wait(200) - if ESX ~= nil then - if NetworkIsSessionStarted() and not ESX.IsPlayerLoaded() then - TriggerServerEvent("kashactersS:SetupCharacters") - TriggerEvent("kashactersC:SetupCharacters") - return -- break the loop - end - end - end +CreateThread(function() + while true do + Wait(0) + if NetworkIsPlayerActive(PlayerId()) and not ESX.IsPlayerLoaded() then + TriggerServerEvent("kashactersS:SetupCharacters") + TriggerEvent("kashactersC:SetupCharacters") + break + end + end end) -Citizen.CreateThread(function () - while true do - Citizen.Wait(0) - if IsChoosing then - DisplayHud(false) - DisplayRadar(false) - end - end +AddEventHandler("onClientMapStart", function() + exports.spawnmanager:spawnPlayer() + Citizen.Wait(5000) + exports.spawnmanager:setAutoSpawn(false) end) local cam, cam2 = nil, nil RegisterNetEvent('kashactersC:SetupCharacters') AddEventHandler('kashactersC:SetupCharacters', function() + ESX.UI.HUD.SetDisplay(0.0) + DisplayHud(false) + DisplayRadar(false) ShutdownLoadingScreen() Citizen.Wait(100) DoScreenFadeOut(10) @@ -46,7 +34,7 @@ AddEventHandler('kashactersC:SetupCharacters', function() Citizen.Wait(10) end SetTimecycleModifier('hud_def_blur') - FreezeEntityPosition(GetPlayerPed(-1), true) + FreezeEntityPosition(PlayerPedId(), true) cam = CreateCamWithParams("DEFAULT_SCRIPTED_CAMERA", -1355.93,-1487.78,520.75, 300.00,0.00,0.00, 100.00, false, 0) SetCamActive(cam, true) RenderScriptCams(true, false, 1, true, true) @@ -64,45 +52,58 @@ AddEventHandler('kashactersC:SetupUI', function(Characters) end) RegisterNetEvent('kashactersC:SpawnCharacter') -AddEventHandler('kashactersC:SpawnCharacter', function(spawn, isnew) +AddEventHandler('kashactersC:SpawnCharacter', function(spawn, skin) local pos = spawn SetTimecycleModifier('default') - SetEntityCoords(GetPlayerPed(-1), pos.x, pos.y, pos.z) - DoScreenFadeIn(500) - Citizen.Wait(500) + exports.spawnmanager:spawnPlayer({ + x = spawn.x, + y = spawn.y, + z = spawn.z + 0.25, + heading = spawn.heading, + model = `mp_m_freemode_01`, + skipFade = true + }, function() + TriggerServerEvent('esx:onPlayerSpawn') + TriggerEvent('esx:onPlayerSpawn') + TriggerEvent('playerSpawned') -- compatibility with old scripts, will be removed soon. - cam2 = CreateCamWithParams("DEFAULT_SCRIPTED_CAMERA", -1355.93,-1487.78,520.75, 300.00,0.00,0.00, 100.00, false, 0) - PointCamAtCoord(cam2, pos.x,pos.y,pos.z+200) - SetCamActiveWithInterp(cam2, cam, 900, true, true) + DoScreenFadeIn(500) - Citizen.Wait(900) + Citizen.Wait(500) - cam = CreateCamWithParams("DEFAULT_SCRIPTED_CAMERA", pos.x,pos.y,pos.z+200, 300.00,0.00,0.00, 100.00, false, 0) - PointCamAtCoord(cam, pos.x,pos.y,pos.z+2) - SetCamActiveWithInterp(cam, cam2, 3700, true, true) + cam2 = CreateCamWithParams("DEFAULT_SCRIPTED_CAMERA", -1355.93,-1487.78,520.75, 300.00,0.00,0.00, 100.00, false, 0) + PointCamAtCoord(cam2, pos.x,pos.y,pos.z+200) + SetCamActiveWithInterp(cam2, cam, 900, true, true) - Citizen.Wait(3700) + Citizen.Wait(900) - PlaySoundFrontend(-1, "Zoom_Out", "DLC_HEIST_PLANNING_BOARD_SOUNDS", 1) - RenderScriptCams(false, true, 500, true, true) - PlaySoundFrontend(-1, "CAR_BIKE_WHOOSH", "MP_LOBBY_SOUNDS", 1) - FreezeEntityPosition(GetPlayerPed(-1), false) + cam = CreateCamWithParams("DEFAULT_SCRIPTED_CAMERA", pos.x,pos.y,pos.z+200, 300.00,0.00,0.00, 100.00, false, 0) + PointCamAtCoord(cam, pos.x,pos.y,pos.z+2) + SetCamActiveWithInterp(cam, cam2, 3700, true, true) - Citizen.Wait(500) + Citizen.Wait(3700) - SetCamActive(cam, false) - DestroyCam(cam, true) - IsChoosing = false - DisplayHud(true) - DisplayRadar(true) + PlaySoundFrontend(-1, "Zoom_Out", "DLC_HEIST_PLANNING_BOARD_SOUNDS", 1) + RenderScriptCams(false, true, 500, true, true) + PlaySoundFrontend(-1, "CAR_BIKE_WHOOSH", "MP_LOBBY_SOUNDS", 1) + FreezeEntityPosition(PlayerPedId(), false) - TriggerEvent('esx:kashloaded') - TriggerEvent('esx_ambulancejob:multicharacter', source) - if isnew == true then - TriggerEvent('esx_identity:showRegisterIdentity') - end + Citizen.Wait(500) + + SetCamActive(cam, false) + DestroyCam(cam, true) + IsChoosing = false + if skin then + TriggerEvent('skinchanger:loadSkin', skin) + else + -- New character + end + DisplayHud(true) + DisplayRadar(true) + ESX.UI.HUD.SetDisplay(1.0) + end) end) RegisterNetEvent('kashactersC:ReloadCharacters') diff --git a/config.lua b/config.lua index a49893d7..bb79ddf5 100644 --- a/config.lua +++ b/config.lua @@ -1,3 +1,3 @@ Config = {} -Config.databaseName = "Changeme" \ No newline at end of file +Config.databaseName = "es_extended" \ No newline at end of file diff --git a/esx_kashacters.sql b/esx_kashacters.sql deleted file mode 100644 index 19d18ded..00000000 --- a/esx_kashacters.sql +++ /dev/null @@ -1,39 +0,0 @@ --- phpMyAdmin SQL Dump --- version 4.8.0.1 --- https://www.phpmyadmin.net/ --- --- Host: 127.0.0.1 --- Gegenereerd op: 02 feb 2019 om 20:58 --- Serverversie: 10.1.32-MariaDB --- PHP-versie: 7.2.5 - -SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; -SET AUTOCOMMIT = 0; -START TRANSACTION; -SET time_zone = "+00:00"; - - -/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; -/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; -/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; -/*!40101 SET NAMES utf8mb4 */; - --- --- Database: `es_extended` --- - --- -------------------------------------------------------- - --- --- Tabelstructuur voor tabel `user_lastcharacter` --- - -CREATE TABLE `user_lastcharacter` ( - `license` varchar(255) NOT NULL, - `charid` int(11) NOT NULL -) ENGINE=InnoDB DEFAULT CHARSET=latin1; -COMMIT; - -/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; -/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/fxmanifest.lua b/fxmanifest.lua index c7393b21..441e3f09 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -2,6 +2,8 @@ fx_version 'adamant' game 'gta5' +shared_script '@es_extended/imports.lua' + server_scripts { "@mysql-async/lib/MySQL.lua", "config.lua", diff --git a/html/ui.html b/html/ui.html index 8d68656f..f3e75f25 100644 --- a/html/ui.html +++ b/html/ui.html @@ -12,7 +12,7 @@ - +
diff --git a/server/main.lua b/server/main.lua index 2306a1ba..d3fd6324 100644 --- a/server/main.lua +++ b/server/main.lua @@ -1,163 +1,98 @@ ---------------------------------------------------------------------------------------- --- Edit this table to all the database tables and columns --- where identifiers are used (such as users, owned_vehicles, owned_properties etc.) ---------------------------------------------------------------------------------------- - local IdentifierTables = {} function GetTables() - MySQL.ready(function () - MySQL.Async.fetchAll('SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME = @id AND TABLE_SCHEMA = @db', { ['@id'] = "owner", ["@db"] = Config.databaseName}, function(result) - if result then - print(json.encode(result)) - for k, v in pairs(result) do - table.insert( IdentifierTables, {table = v.TABLE_NAME, column = "owner"}) - end - end - end) - MySQL.Async.fetchAll('SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME = @id AND TABLE_SCHEMA = @db', { ['@id'] = "identifier", ["@db"] = Config.databaseName}, function(result) - if result then - print(json.encode(result)) - for k, v in pairs(result) do - table.insert( IdentifierTables, {table = v.TABLE_NAME, column = "identifier"}) - end - end - end) - end) - end + MySQL.ready(function () + MySQL.Async.fetchAll('SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME = @id AND TABLE_SCHEMA = @db', { ['@id'] = "owner", ["@db"] = Config.databaseName}, function(result) + if result then + --print(json.encode(result)) + for k, v in pairs(result) do + table.insert( IdentifierTables, {table = v.TABLE_NAME, column = "owner"}) + end + end + end) + MySQL.Async.fetchAll('SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME = @id AND TABLE_SCHEMA = @db', { ['@id'] = "identifier", ["@db"] = Config.databaseName}, function(result) + if result then + --print(json.encode(result)) + for k, v in pairs(result) do + table.insert( IdentifierTables, {table = v.TABLE_NAME, column = "identifier"}) + end + end + end) + end) +end GetTables() + RegisterServerEvent("kashactersS:SetupCharacters") AddEventHandler('kashactersS:SetupCharacters', function() - local src = source - local LastCharId = GetLastCharacter(src) - - SetIdentifierToChar(GetRockstarID(src), LastCharId) - local Characters = GetPlayerCharacters(src) - TriggerClientEvent('kashactersC:SetupUI', src, Characters) + local src = source + local Characters = GetPlayerCharacters(src) + TriggerClientEvent('kashactersC:SetupUI', src, Characters) end) RegisterServerEvent("kashactersS:CharacterChosen") AddEventHandler('kashactersS:CharacterChosen', function(charid, ischar) - local src = source - local new = true - local spawn = {} - if type(charid) == "number" and string.len(charid) == 1 and type(ischar) == "boolean" then - SetLastCharacter(src, tonumber(charid)) - SetCharToIdentifier(GetRockstarID(src), tonumber(charid)) - - if ischar == true then - new = false - spawn = GetSpawnPos(src) - else - TriggerClientEvent('skinchanger:loadDefaultModel', src, true, cb) - spawn = { x = 195.55, y = -933.36, z = 29.90 } -- DEFAULT SPAWN POSITION - end - - TriggerClientEvent("kashactersC:SpawnCharacter", src, spawn, new) - else - -- Trigger Ban Event here to ban individuals trying to use SQL Injections - end + local src = source + local isNew = true + if ischar then isNew = false end + local spawn = {} + if type(charid) == "number" and string.len(charid) == 1 and type(ischar) == "boolean" then + TriggerEvent('esx:onPlayerJoined', src, charid, isNew) + else + -- Trigger Ban Event here to ban individuals trying to use SQL Injections + end end) RegisterServerEvent("kashactersS:DeleteCharacter") AddEventHandler('kashactersS:DeleteCharacter', function(charid) - local src = source - if type(charid) == "number" and string.len(charid) == 1 then - DeleteCharacter(GetRockstarID(src), charid) - TriggerClientEvent("kashactersC:ReloadCharacters", src) - else - -- Trigger Ban Event here to ban individuals trying to use SQL Injections - end + local src = source + if type(charid) == "number" and string.len(charid) == 1 then + DeleteCharacter(ESX.GetIdentifier(src), charid) + TriggerClientEvent("kashactersC:ReloadCharacters", src) + else + -- Trigger Ban Event here to ban individuals trying to use SQL Injections + end end) function GetPlayerCharacters(source) - local Chars = MySQLAsyncExecute("SELECT * FROM `users` WHERE identifier LIKE '%"..GetIdentifierWithoutLicense(GetRockstarID(source)).."%'") - for i = 1, #Chars, 1 do - charJob = MySQLAsyncExecute("SELECT * FROM `jobs` WHERE `name` = '"..Chars[i].job.."'") - charJobgrade = MySQLAsyncExecute("SELECT * FROM `job_grades` WHERE `grade` = '"..Chars[i].job_grade.."' AND `job_name` = '"..Chars[i].job.."'") - local accounts = json.decode(Chars[i].accounts) - Chars[i].bank = accounts["bank"] - Chars[i].money = accounts["money"] - Chars[i].job = charJob[1].label - if charJob[1].label == "Unemployed" then - Chars[i].job_grade = "" - else - Chars[i].job_grade = charJobgrade[1].label - end - if Chars[i].sex == "m" then - Chars[i].sex = "Male" - else - Chars[i].sex = "Female" - end - end - return Chars -end - -function GetLastCharacter(source) - local LastChar = MySQLAsyncExecute("SELECT `charid` FROM `user_lastcharacter` WHERE `license` = '"..GetRockstarID(source).."'") - - if LastChar[1] ~= nil and LastChar[1].charid ~= nil then - return tonumber(LastChar[1].charid) - else - MySQLAsyncExecute("INSERT INTO `user_lastcharacter` (`license`, `charid`) VALUES('"..GetRockstarID(source).."', 1)") - return 1 - end -end - -function SetLastCharacter(source, charid) - MySQLAsyncExecute("UPDATE `user_lastcharacter` SET `charid` = '"..charid.."' WHERE `license` = '"..GetRockstarID(source).."'") -end - -function SetIdentifierToChar(identifier, charid) - for _, itable in pairs(IdentifierTables) do - MySQLAsyncExecute("UPDATE `"..itable.table.."` SET `"..itable.column.."` = 'Char"..charid..GetIdentifierWithoutLicense(identifier).."' WHERE `"..itable.column.."` = '"..identifier.."'") - end -end - -function SetCharToIdentifier(identifier, charid) - for _, itable in pairs(IdentifierTables) do - MySQLAsyncExecute("UPDATE `"..itable.table.."` SET `"..itable.column.."` = '"..identifier.."' WHERE `"..itable.column.."` = 'Char"..charid..GetIdentifierWithoutLicense(identifier).."'") - end + local Chars = MySQLAsyncExecute("SELECT * FROM `users` WHERE `identifier` LIKE 'char%:"..ESX.GetIdentifier(source).."'") + for i = 1, #Chars, 1 do + charJob = MySQLAsyncExecute("SELECT * FROM `jobs` WHERE `name` = '"..Chars[i].job.."'") + charJobgrade = MySQLAsyncExecute("SELECT * FROM `job_grades` WHERE `grade` = '"..Chars[i].job_grade.."' AND `job_name` = '"..Chars[i].job.."'") + local accounts = json.decode(Chars[i].accounts) + Chars[i].bank = accounts["bank"] + Chars[i].money = accounts["money"] + Chars[i].job = charJob[1].label + if charJob[1].label == "Unemployed" then + Chars[i].job_grade = "" + else + Chars[i].job_grade = charJobgrade[1].label + end + if Chars[i].sex == "m" then + Chars[i].sex = "Male" + else + Chars[i].sex = "Female" + end + end + return Chars end function DeleteCharacter(identifier, charid) - for _, itable in pairs(IdentifierTables) do - MySQLAsyncExecute("DELETE FROM `"..itable.table.."` WHERE `"..itable.column.."` = 'Char"..charid..GetIdentifierWithoutLicense(identifier).."'") - end -end - -function GetSpawnPos(source) - local spawn = MySQLAsyncExecute("SELECT `position` FROM `users` WHERE `identifier` = '"..GetRockstarID(source).."'") - return json.decode(spawn[1].position) -end - -function GetIdentifierWithoutLicense(Identifier) - return string.gsub(Identifier, "license", "") -end - -function GetRockstarID(playerId) - local identifier - - for k,v in ipairs(GetPlayerIdentifiers(playerId)) do - if string.match(v, 'license') then - identifier = v - break - end - end - - return identifier + local identifier = 'char'..charid..':'..identifier + for _, itable in pairs(IdentifierTables) do + MySQLAsyncExecute("DELETE FROM `"..itable.table.."` WHERE `"..itable.column.."` = '"..identifier.."'") + end end function MySQLAsyncExecute(query) - local IsBusy = true - local result = nil - MySQL.Async.fetchAll(query, {}, function(data) - result = data - IsBusy = false - end) - while IsBusy do - Citizen.Wait(0) - end - return result + local IsBusy = true + local result = nil + MySQL.Async.fetchAll(query, {}, function(data) + result = data + IsBusy = false + end) + while IsBusy do + Citizen.Wait(0) + end + return result end