DarkRP - Limiting jobs based on other jobs

Hi, I want to know how I can limit how many people can be in a class depending on the size of other classes. Prime Example: Secret Service based on Mayor.

function TeamMax()
     if team.NumPlayers( TEAM_MAYOR ) == 0 then
          Set the SS team max to 0.
     if team.NumPlayers( TEAM_MAYOR ) == 1 then
          Set the SS team max to 2.
hook.Add( Not sure what hook to use. )

That is how I would imagine it would go. I could, very likely, be wrong in my approach. If someone knows what to do or has done something like this, please teach me! Thanks!

There’s a custom check in the job setup.
Check out MuteTM’s post: