How to detour SetTeam

Things I tried:
[lua]ply_ = FindMetaTable(“Player”);
local SetTeamOld = self:SetTeam();

function ply_:SetTeam(args)
if args == 1 then
ply:SetNWInt(“Class”, 1);
RunConsoleCommand(“say”, self:Nick()…" has joined the Combine.");
elseif args == 0 then
ply:SetNWInt(“Class”, 5);
RunConsoleCommand(“say”, self:Nick()…" has joined the Resistance.");
end
return self:SetTeamOld(args);
end[/lua]

[lua]ply_ = FindMetaTable(“Player”);
function ply_:SetTeamOld(args)
return self:SetTeam(args);
end

function ply_:SetTeam(args)
self:SetTeamOld(args);
if args == 1 then
ply:SetNWInt(“Class”, 1);
RunConsoleCommand(“say”, self:Nick()…" has joined the Combine.");
elseif args == 0 then
ply:SetNWInt(“Class”, 5);
RunConsoleCommand(“say”, self:Nick()…" has joined the Resistance.");
end
end[/lua]

and many more.
I know how to detour basic functions, but how do I detour a method?



local PLAYER = debug.getregistry().Player
local old_SetTeam = PLAYER.SetTeam

function PLAYER:SetTeam(team)
    -- your code here
    old_SetTeam(self, team)
end


GM/OnPlayerChangedTeam ?

Already tried it a long time ago, doesn’t work.

First off, how is your gamemode changing teams? Show the code for that.

Is it using the default base gamemode team handling? if it is then the hook Kogitsune linked should work fine unless you’re doing hacks.