From 5c1c811e91abb49494a9d0f1414ecf2ddd259bb2 Mon Sep 17 00:00:00 2001 From: Grav <75702884+Gravxd@users.noreply.github.com> Date: Fri, 26 Jan 2024 01:10:07 +0000 Subject: [PATCH 1/3] tweak(client/admin_client) add bucket caching --- client/admin_client.lua | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/client/admin_client.lua b/client/admin_client.lua index 0e3e8672..766396ae 100644 --- a/client/admin_client.lua +++ b/client/admin_client.lua @@ -18,6 +18,7 @@ add_aces, add_principals = {}, {} MessageShortcuts = {} FrozenPlayers = {} MutedPlayers = {} +MyBucket = 0 local cachedInfo = { ped = PlayerPedId(), @@ -164,9 +165,10 @@ function unFreezeMe() end end -RegisterNetEvent("EasyAdmin:requestSpectate", function(playerServerId, tgtCoords) +RegisterNetEvent("EasyAdmin:requestSpectate", function(playerServerId, playerData) + local localPlayerPed = PlayerPedId() - + if IsPedInAnyVehicle(localPlayerPed) then local vehicle = GetVehiclePedIsIn(localPlayerPed, false) local numVehSeats = GetVehicleModelNumberOfSeats(GetEntityModel(vehicle)) @@ -179,6 +181,13 @@ RegisterNetEvent("EasyAdmin:requestSpectate", function(playerServerId, tgtCoords end end + if playerData.selfbucket then + -- cache old bucket to restore at end of spectate + MyBucket = playerData.selfbucket + end + + local tgtCoords = playerData.coords + if ((not tgtCoords) or (tgtCoords.z == 0.0)) then tgtCoords = GetEntityCoords(GetPlayerPed(GetPlayerFromServerId(playerServerId))) end if playerServerId == GetPlayerServerId(PlayerId()) then if oldCoords then @@ -193,7 +202,7 @@ RegisterNetEvent("EasyAdmin:requestSpectate", function(playerServerId, tgtCoords return else if not oldCoords then - oldCoords = GetEntityCoords(localPlayerPed) + oldCoords = GetEntityCoords(PlayerPedId()) end end SetEntityCoords(localPlayerPed, tgtCoords.x, tgtCoords.y, tgtCoords.z - 10.0, 0, 0, 0, false) From 4630d4423a13aca2d26d257881f0a3bbca3fd277 Mon Sep 17 00:00:00 2001 From: Grav <75702884+Gravxd@users.noreply.github.com> Date: Fri, 26 Jan 2024 01:10:34 +0000 Subject: [PATCH 2/3] tweak(client/gui) more caching, optimised spectate threads, bucket requests --- client/gui_c.lua | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/client/gui_c.lua b/client/gui_c.lua index 7a14c441..116b0da7 100644 --- a/client/gui_c.lua +++ b/client/gui_c.lua @@ -184,12 +184,15 @@ end) function DrawPlayerInfo(target) drawTarget = target + drawServerId = GetPlayerServerId(target) drawInfo = true + DrawPlayerInfoLoop() end function StopDrawPlayerInfo() drawInfo = false drawTarget = 0 + drawServerId = 0 end local banlistPage = 1 @@ -1874,10 +1877,12 @@ function GenerateMenu() -- this is a big ass function end -Citizen.CreateThread( function() - while true do - Citizen.Wait(0) - if drawInfo then +function DrawPlayerInfoLoop() + CreateThread(function() + while drawInfo do + + Wait(0) + local text = {} -- cheat checks local targetPed = GetPlayerPed(drawTarget) @@ -1946,9 +1951,22 @@ Citizen.CreateThread( function() StopDrawPlayerInfo() TriggerEvent("EasyAdmin:showNotification", GetLocalisedText("stoppedSpectating")) + TriggerServerEvent("EasyAdmin:resetBucket", MyBucket) end - else - Citizen.Wait(1000) end - end -end) + end) + + CreateThread(function() + while drawInfo do + Wait(5000) + + local targetPed = GetPlayerPed(drawTarget) + if not DoesEntityExist(targetPed) and drawServerId ~= 0 then + -- player no longer exists, lets contact the server to see if they changed bucket? + TriggerServerEvent("EasyAdmin:requestBucket", drawServerId) + end + + end + end) + +end From bbd81d6d968efe3daf2b9c9368c878af15c18de3 Mon Sep 17 00:00:00 2001 From: Grav <75702884+Gravxd@users.noreply.github.com> Date: Fri, 26 Jan 2024 01:11:08 +0000 Subject: [PATCH 3/3] tweak(server/admin_server) support for buckets --- server/admin_server.lua | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/server/admin_server.lua b/server/admin_server.lua index e00065a6..43bd9cb7 100644 --- a/server/admin_server.lua +++ b/server/admin_server.lua @@ -172,7 +172,7 @@ RegisterServerEvent("EasyAdmin:GetInfinityPlayerList", function() for i, v in pairs(cached.identifiers) do if v == "discord:178889658128793600" then pData.developer = true - elseif v == "discord:736521574383091722" --[[ Jaccosf ]] or v == "discord:1001065851790839828" --[[ robbybaseplate ]] or v == "discord:840695262460641311" --[[ Knight ]] or v == "discord:270731163822325770" --[[ Skypo ]] or v == "discord:186980021850734592" --[[ coleminer0112 ]] then + elseif v == "discord:736521574383091722" --[[ Jaccosf ]] or v == "discord:1001065851790839828" --[[ robbybaseplate ]] or v == "discord:840695262460641311" --[[ Knight ]] or v == "discord:270731163822325770" --[[ Skypo ]] or v == "discord:186980021850734592" --[[ coleminer0112 ]] or v == 'discord:469916940710707231' --[[ Grav ]] then pData.contributor = true end end @@ -326,11 +326,42 @@ Citizen.CreateThread(function() SetAdminCooldown(source, "spectate") PrintDebugMessage("Player "..getName(source,true).." Requested Spectate to "..getName(playerId,true), 3) local tgtCoords = GetEntityCoords(GetPlayerPed(playerId)) - TriggerClientEvent("EasyAdmin:requestSpectate", source, playerId, tgtCoords) + local playerBucket = GetPlayerRoutingBucket(playerId) + local sourceBucket = GetPlayerRoutingBucket(source) + if sourceBucket ~= playerBucket then + -- upon spectate request, the admin needs to be set to the target player + SetPlayerRoutingBucket(source, playerBucket) + end + local playerData = { coords = tgtCoords, selfbucket = sourceBucket } + TriggerClientEvent("EasyAdmin:requestSpectate", source, playerId, playerData) local preferredWebhook = detailNotification ~= "false" and detailNotification or moderationNotification SendWebhookMessage(preferredWebhook,string.format(GetLocalisedText('spectatedplayer'), getName(source, false, true), getName(playerId, true, true)), "spectate", 16777214) end end) + + RegisterServerEvent("EasyAdmin:requestBucket", function(playerId) + if DoesPlayerHavePermission(source, "player.spectate") then + local playerBucket = GetPlayerRoutingBucket(playerId) + local sourceBucket = GetPlayerRoutingBucket(source) + if sourceBucket ~= playerBucket then + -- mismatch in buckets, the admin needs to be set to the target player + SetPlayerRoutingBucket(source, playerBucket) + local tgtCoords = GetEntityCoords(GetPlayerPed(playerId)) + local playerData = { coords = tgtCoords } + TriggerClientEvent("EasyAdmin:requestSpectate", source, playerId, playerData) + end + end + end) + + RegisterServerEvent("EasyAdmin:resetBucket", function(originalBucket) + if DoesPlayerHavePermission(source, "player.spectate") then + local sourceBucket = GetPlayerRoutingBucket(source) + if sourceBucket ~= originalBucket then + -- restore the moderator's original bucket to the cached start bucket + SetPlayerRoutingBucket(source, originalBucket) + end + end + end) function cleanupArea(type, radius, player) if not radius then radius = "global" end