How to disable team join

Hello, working on a cp test addon that disables gov jobs until a test is passed. I’ve got pretty much everything done besides the actual team disable which I can’t figure out… I looked through some team hooks on the wiki and played around with them couldn’t really get what I wanted. I’m wondering what the proper way is to add a check before a player joins a team.

GM:PlayerCanJoinTeam

Return false if they can’t. (DO NOT return true if they can)

[editline]4th April 2017[/editline]

ninja’d

So would I have that in a hook.Add()? The only way I have used hooks is in a hook.Add… I was thinking of putting this function in a steamauth so that I can set the team join to false, and then when the player completes and passes the test I would set it to true… But I don’t understand how I would do that using hook.Add()?

The function can be used in hook.Add. Almost all GM functions can.

Right, but wouldn’t this be a time where I wouldn’t want to use a hook.Add()? I would be using it in a steam auth hook already.

You would want to use hook.Add; what is your Steam Auth hook for?

[lua]hook.Add(“PlayerCanJoinTeam”, “Some descriptive identifier”, function(ply, team)
if team == THE_RELEVANT_TEAM_ID
and not DO_YOUR_TEST(ply)
then
return false
end
end[/lua]


local function sendData(ply, steamID, uniqueID)
    for k, v in pairs(questions) do
        net.Start("sendQuestions")
            net.WriteString(v)
        net.Send(ply)
    end
end

It’s for sending the client the server test question lines.

It’s a player auth not a steam auth my bad.

[editline]4th April 2017[/editline]

Okay, I understand what you guys mean now. I’ve hooked into it on the server but it seems like it’s not firing, I put a print in and it won’t print when I change jobs. I am using darkRP btw

[editline]4th April 2017[/editline]

Thanks for the help! DarkRP must override it with this, playerCanChangeTeam hook. I was able to get it working using the darkRP hook.