Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for spectating for servers with buckets #820

Merged
merged 3 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions client/admin_client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ add_aces, add_principals = {}, {}
MessageShortcuts = {}
FrozenPlayers = {}
MutedPlayers = {}
MyBucket = 0

local cachedInfo = {
ped = PlayerPedId(),
Expand Down Expand Up @@ -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))
Expand All @@ -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
Expand All @@ -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)
Expand Down
34 changes: 26 additions & 8 deletions client/gui_c.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
35 changes: 33 additions & 2 deletions server/admin_server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sneaky, lol.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not intended to be haha, thought that was the norm after the last release included one my request as well 😅

pData.contributor = true
end
end
Expand Down Expand Up @@ -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
Expand Down
Loading