From e9a53c6c2170760b06b5018c496b32965ddc84cf Mon Sep 17 00:00:00 2001 From: Gellipapa Date: Sun, 19 May 2024 20:07:16 +0200 Subject: [PATCH] :ambulance: Fix random default spawn coords --- [core]/es_extended/common/modules/math.lua | 6 ++++++ [core]/es_extended/server/main.lua | 2 +- [core]/esx_multicharacter/client/main.lua | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/[core]/es_extended/common/modules/math.lua b/[core]/es_extended/common/modules/math.lua index 9910d17e..868773b6 100644 --- a/[core]/es_extended/common/modules/math.lua +++ b/[core]/es_extended/common/modules/math.lua @@ -23,3 +23,9 @@ function ESX.Math.Trim(value) return nil end end + +function ESX.Math.Random(minRange, maxRange) + math.randomseed(GetGameTimer()) + return math.random(minRange or 1, maxRange or 10) +end + diff --git a/[core]/es_extended/server/main.lua b/[core]/es_extended/server/main.lua index e268ec80..092bd8f2 100644 --- a/[core]/es_extended/server/main.lua +++ b/[core]/es_extended/server/main.lua @@ -239,7 +239,7 @@ function loadESXPlayer(identifier, playerId, isNew) end -- Position - userData.coords = json.decode(result.position) or Config.DefaultSpawns[math.random(#Config.DefaultSpawns)] + userData.coords = json.decode(result.position) or Config.DefaultSpawns[ESX.Math.Random(1,#Config.DefaultSpawns)] -- Skin userData.skin = (result.skin and result.skin ~= "") and json.decode(result.skin) or { sex = userData.sex == "f" and 1 or 0 } diff --git a/[core]/esx_multicharacter/client/main.lua b/[core]/esx_multicharacter/client/main.lua index 556ccfe3..16f9a0ed 100644 --- a/[core]/esx_multicharacter/client/main.lua +++ b/[core]/esx_multicharacter/client/main.lua @@ -1,7 +1,7 @@ local mp_m_freemode_01 = `mp_m_freemode_01` local mp_f_freemode_01 = `mp_f_freemode_01` -local SpawnCoords = Config.Spawn[math.random(#Config.Spawn)] +local SpawnCoords = Config.Spawn[ESX.Math.Random(1,#Config.Spawn)] if ESX.GetConfig().Multichar then CreateThread(function()