Skip to content

Commit

Permalink
Merge pull request #860 from Gravxd/master
Browse files Browse the repository at this point in the history
Code cleanup / efficiency
  • Loading branch information
Blumlaut authored Dec 5, 2024
2 parents a02f7bb + c437744 commit 6cd4c62
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 75 deletions.
59 changes: 26 additions & 33 deletions client/admin_client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -129,36 +129,34 @@ RegisterNetEvent('EasyAdmin:SetPlayerMuted', function(player,state)
end
end)

function freezeMe()
function FreezeMyself(state)

Citizen.CreateThread(function()
if state then
if frozen then return end -- prevents double threads
CreateThread(function()

local disableShootingWhileFrozen = GetConvar("ea_disableShootingWhileFrozen", 'false')

while frozen do

FreezeEntityPosition(cachedInfo.ped, frozen)
if cachedInfo.veh ~= 0 then
FreezeEntityPosition(cachedInfo.veh, frozen)
end
if disableShootingWhileFrozen == 'true' then
while frozen do

FreezeEntityPosition(cachedInfo.ped, frozen)
if cachedInfo.veh ~= 0 then
FreezeEntityPosition(cachedInfo.veh, frozen)
end
DisablePlayerFiring(cachedInfo.player, true)

Wait(0)

end

Wait(0)


end)
else
-- unfreeze
local localPlayerPedId = PlayerPedId()
FreezeEntityPosition(localPlayerPedId, false)
if IsPedInAnyVehicle(localPlayerPedId, true) then
FreezeEntityPosition(GetVehiclePedIsIn(localPlayerPedId, true), false)
end

end)

end

function unFreezeMe()
local localPlayerPedId = PlayerPedId()
FreezeEntityPosition(localPlayerPedId, false)
if IsPedInAnyVehicle(localPlayerPedId, true) then
FreezeEntityPosition(GetVehiclePedIsIn(localPlayerPedId, false), false)
end

end

RegisterNetEvent("EasyAdmin:CopyDiscord", function(discord)
Expand Down Expand Up @@ -200,7 +198,7 @@ RegisterNetEvent("EasyAdmin:requestSpectate", function(playerServerId, playerDat
end
spectatePlayer(localPlayerPed,GetPlayerFromServerId(PlayerId()),GetPlayerName(PlayerId()))
frozen = false
unFreezeMe()
FreezeMyself(false)
return
else
if not oldCoords then
Expand All @@ -209,9 +207,8 @@ RegisterNetEvent("EasyAdmin:requestSpectate", function(playerServerId, playerDat
end
SetEntityCoords(localPlayerPed, tgtCoords.x, tgtCoords.y, tgtCoords.z - 10.0, 0, 0, 0, false)
frozen = true
freezeMe()
FreezeMyself(true)
stopSpectateUpdate = true
local adminPed = localPlayerPed
local playerId = GetPlayerFromServerId(playerServerId)
repeat
Wait(200)
Expand Down Expand Up @@ -369,11 +366,7 @@ end, false)

RegisterNetEvent("EasyAdmin:FreezePlayer", function(toggle)
frozen = toggle
if frozen then
freezeMe()
else
unFreezeMe()
end
FreezeMyself(frozen)
end)


Expand Down Expand Up @@ -417,7 +410,7 @@ function spectatePlayer(targetPed,target,name)
StopDrawPlayerInfo()
TriggerEvent("EasyAdmin:showNotification", GetLocalisedText("stoppedSpectating"))
frozen = false
unFreezeMe()
FreezeMyself(false)
Citizen.Wait(200) -- to prevent staying invisible
SetEntityVisible(playerPed, true, 0)
SetEntityCollision(playerPed, true, true)
Expand Down
2 changes: 1 addition & 1 deletion client/gui_c.lua
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ RegisterCommand('easyadmin', function(source, args)
collectgarbage()
end
end)
end)
end, false)


RegisterCommand('ea', function(source,args)
Expand Down
1 change: 0 additions & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,5 @@ convar_category 'EasyAdmin' {
{ "Channel for Discord bot to log", "$ea_botLogChannel", "CV_STRING", "none" },
{ "Channel for Discord bot to enable live status", "$ea_botStatusChannel", "CV_STRING", "true" },
{ "Enable Allowlist", "$ea_enableAllowlist", "CV_BOOL", "false" },
{ "Disable Shooting Whilst Frozen", "$ea_disableShootingWhileFrozen", "CV_BOOL", "false" },
}
}
58 changes: 18 additions & 40 deletions server/admin_server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -680,52 +680,30 @@ Citizen.CreateThread(function()
if AnonymousAdmins[src] and not anonymousdisabled then
return GetLocalisedText("anonymous")
elseif CachedPlayers[src] and CachedPlayers[src].name then
if CachedPlayers[src].identifiers then
if identifierPref then
-- split identifierPref by comma and find first identifier in CachedPlayers[src].identifiers that starts with the split string
-- this code was written by GitHub Copilot, neat, huh?
for i,v in ipairs(identifierPref:split(",")) do
for i2,v2 in ipairs(CachedPlayers[src].identifiers) do
if string.sub(v2, 1, string.len(v)) == v then
identifier = v2
break
end
end
if identifier ~= "~No Identifier~" then break end
end
end
end
if identifier:find('discord:') then
identifier = string.gsub(identifier, "discord:", "")
identifier = "<@"..identifier..">"

if not identifierenabled then
return CachedPlayers[src].name
end
if identifierenabled then
return (string.format("%s [ %s ]", CachedPlayers[src].name, identifier))
else

if not CachedPlayers[src].discord then
return CachedPlayers[src].name
end

return (string.format("%s [ %s ]", CachedPlayers[src].name, CachedPlayers[src].discord))

elseif (GetPlayerName(src)) then
identifiers = getAllPlayerIdentifiers(src)
if identifierPref then
for i,v in ipairs(identifierPref:split(",")) do
for i2,v2 in ipairs(identifiers) do
if string.sub(v2, 1, string.len(v)) == v then
identifier = v2
break
end
end
if identifier ~= "~No Identifier~" then break end
end
end
if identifier:find('discord:') then
identifier = string.gsub(identifier, "discord:", "")
identifier = "<@"..identifier..">"
local playerName = GetPlayerName(src)
if not identifierenabled then
return playerName
end
if identifierenabled then
return (string.format("%s [ %s ]", GetPlayerName(src), identifier))
else
return GetPlayerName(src)

local playerDiscord = GetPlayerIdentifierByType(src, "discord") and GetPlayerIdentifierByType(src, "discord"):gsub("discord:", "") or false
if not playerDiscord then
return playerName
end

return (string.format("%s [ %s ]", playerName, playerDiscord))

else
return "Unknown - " .. src
end
Expand Down

0 comments on commit 6cd4c62

Please sign in to comment.