Author Topic: Respected Rank  (Read 4443 times)

0 Members and 1 Guest are viewing this topic.

Offline TropicalTitties

  • Newbie
  • *
  • Posts: 8
  • Karma: 0
Respected Rank
« on: May 10, 2011, 06:32:02 PM »
How would i make it so that people would have to have a certain rank, such as respected (or above), in order to become a class, such as swat? However, the respected rank would not have admin privileges, just the ability to become swat and other respected rank.

Would I use a function, such as:
Code: [Select]
function GM:PlayerJoinTeam( ply, class, teamid )
if ply:IsUserGroup("User") and teamid == TEAM_SWAT then
return false
else
return true
end
end


Or something else?
I honestly cant figure out what else to try.


EDIT-JamminR Added code block
« Last Edit: May 10, 2011, 07:18:40 PM by JamminR »

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Respected Rank
« Reply #1 on: May 10, 2011, 07:32:12 PM »
Way you have it is the basic idea, but, you need to use lower case when comparing groups. "user" not "User"
A better way to do it, since some groups inherit lower ones, is probably test for the "respected" specifically.
Also, in 99% of Gmod lua, when you wish a hook function to continue, don't return "true", just return.
There are exceptions, but, returning anything will often break the hooks of other mods/scripts using the same hook, even if it is only 'true'
(Yes, I know, the Gmod wiki is full of 'return true'...many hooks break others that way.
Code: [Select]
function GM:PlayerJoinTeam( ply, class, teamid )
if not ply:IsUserGroup("respected") and teamid == TEAM_SWAT then
return false
else
return
end
end
In english, the above statement reads
if player is not in group respected and they want to join Swat team, do nothing, else if they are in group respected and want to join swat, go ahead.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

An Error Has Occurred!

array_keys(): Argument #1 ($array) must be of type array, null given