Dinkleberg's GMod

Full Version: Sittting in Spectator: I have no idea why this is still a rule
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
(10-25-2020, 03:35 PM)RussEfarmer Wrote: [ -> ]
(10-24-2020, 10:26 PM)TheUltraFish Wrote: [ -> ]What would probably be better would be to not have spectator as a  team to join other than staff. Just like how some commands and other things are only accessible by staff.

This script will kick whoever joins spectator out if they are not in the groups table after one second when placed in the lua/autorun folder. The original plan for this was to actually go into the fretta gamemode and disable the spectator button from showing to people other than staff, but B0T convinced me to use something not so.. ad-hoc. He also told me which hook to use :>

Download

Code:
groups = {
    "trusted",
    "dtmod",
    "moderator",
    "adm",
    "admin",
    "superadmin",
    "operator",
    "superdonor"
}

function checkTableValue(table, value)
    for k, v in pairs(table) do
        if v == value then return true end
    end
return false end

hook.Add("PlayerChangedTeam", "RestrictSpectator", function(ply, oldTeam, newTeam)
    if newTeam == TEAM_SPECTATOR then
        if not checkTableValue(groups, ply:GetUserGroup()) then
            timer.Create("SwitchSpectator", 1, 1,
                function()
                    GAMEMODE:PlayerJoinTeam(ply, oldTeam)
                    ply:PrintMessage(HUD_PRINTTALK, "This team is reserved for staff members.")
                end)
        end
    end
end)

so if i am understanding this correctly, it would move the people back to the team they were previously a part of and not kick them from the server?
(10-25-2020, 03:46 PM)TheUltraFish Wrote: [ -> ]so if i am understanding this correctly, it would move the people back to the team they were previously a part of and not kick them from the server?

Yep, they just go back to their original team. If they join spectator from unassigned, they go back to unassigned.
This would be great if it could be implemented.
Pages: 1 2