Fixes for relogging while scaled

This commit is contained in:
najeetpie committed 2026-06-29 21:55:25 +00:00
1 parent 886a2cd5c4
commit f2188916e8
3 files changed
+25 -8

No files matched your search

+23 -7
View File
@@ -91,6 +91,15 @@ end
local syncedScales = {} local syncedScales = {}
-- Resolve the ped that belongs to a server id. Returns 0 when that player is
-- not currently in scope. IMPORTANT: never fall through to GetPlayerPed(-1),
-- which returns the LOCAL player's ped and would scale the wrong ped.
local function getPedForServerId(src)
local playerIdx = GetPlayerFromServerId(src)
if playerIdx == -1 then return 0 end
return GetPlayerPed(playerIdx)
end
RegisterNetEvent('nass_pedscaler:syncCurrentScaling', function(players) RegisterNetEvent('nass_pedscaler:syncCurrentScaling', function(players)
for k, v in pairs(players) do for k, v in pairs(players) do
TriggerEvent('nass_pedscaler:syncScale', tonumber(k), v) TriggerEvent('nass_pedscaler:syncScale', tonumber(k), v)
@@ -100,24 +109,31 @@ end)
RegisterNetEvent('nass_pedscaler:syncScale', function(src, scale) RegisterNetEvent('nass_pedscaler:syncScale', function(src, scale)
if syncedScales[tostring(src)] ~= nil then if syncedScales[tostring(src)] ~= nil then
syncedScales[tostring(src)] = nil syncedScales[tostring(src)] = nil
applyScaleToEntity(PlayerPedId(), 1.0) local ped = getPedForServerId(src)
if ped ~= 0 and DoesEntityExist(ped) then
applyScaleToEntity(ped, 1.0)
end
Wait(100) Wait(100)
end end
syncedScales[tostring(src)] = scale syncedScales[tostring(src)] = scale
if scale ~= nil then if scale ~= nil then
local playerId = GetPlayerFromServerId(src) startScale(src, scale)
startScale(src, playerId, scale)
else else
applyScaleToEntity(PlayerPedId(), 1.0) local ped = getPedForServerId(src)
if ped ~= 0 and DoesEntityExist(ped) then
applyScaleToEntity(ped, 1.0)
end
end end
end) end)
function startScale(src, playerId, scale) function startScale(src, scale)
CreateThread(function() CreateThread(function()
while syncedScales[tostring(src)] ~= nil do while syncedScales[tostring(src)] ~= nil do
local ped = GetPlayerPed(playerId) -- Re-resolve every frame: the target player may not be in scope
if DoesEntityExist(ped) then -- yet (e.g. right after joining) and only stream in later.
local ped = getPedForServerId(src)
if ped ~= 0 and DoesEntityExist(ped) then
applyScaleToEntity(ped, scale) applyScaleToEntity(ped, scale)
if Config.scaling.scaleSpeed.enabled then if Config.scaling.scaleSpeed.enabled then
SetPedMoveRateOverride(ped, Config.scaling.scaleSpeed.inverse and (1 / scale) or scale) SetPedMoveRateOverride(ped, Config.scaling.scaleSpeed.inverse and (1 / scale) or scale)
-1
View File
@@ -7,7 +7,6 @@ function onPlayerLoaded(identifier, source)
if playerscale and playerscale ~= 1.0 then if playerscale and playerscale ~= 1.0 then
TriggerClientEvent('nass_pedscaler:syncScale', -1, source, playerscale) TriggerClientEvent('nass_pedscaler:syncScale', -1, source, playerscale)
end end
end end
AddEventHandler('onResourceStart', function(resourceName) AddEventHandler('onResourceStart', function(resourceName)
+2
View File
@@ -20,6 +20,7 @@ RegisterNetEvent('nass_pedscaler:syncScale', function(scale)
scaledPlayers[tostring(src)] = scale scaledPlayers[tostring(src)] = scale
TriggerClientEvent('nass_pedscaler:syncScale', -1, src, scale) TriggerClientEvent('nass_pedscaler:syncScale', -1, src, scale)
SaveResourceFile(GetCurrentResourceName(), "./playerScaling.json", json.encode(playerScaling, {indent = true}))
end) end)
if Config.commands.openMenu.enabled then if Config.commands.openMenu.enabled then
@@ -38,6 +39,7 @@ if Config.commands.resetScale.enabled then
playerScaling[getPlayerIdentifier(id)] = nil playerScaling[getPlayerIdentifier(id)] = nil
scaledPlayers[tostring(id)] = nil scaledPlayers[tostring(id)] = nil
TriggerClientEvent('nass_pedscaler:syncScale', -1, id, nil) TriggerClientEvent('nass_pedscaler:syncScale', -1, id, nil)
SaveResourceFile(GetCurrentResourceName(), "./playerScaling.json", json.encode(playerScaling, {indent = true}))
end end
end, false) end, false)
end end