• Print

Author Topic: Respected Rank  (Read 7578 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

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: Respected Rank
« Reply #2 on: May 10, 2011, 08:29:26 pm »
In this situation he would want to use return true.

If you are calling a function and expecting a boolean value then returning true/false in that function is appropriate. It's generally okay to return true unless you are using it in a hook (like JamminR said).


for example:::


Code: Lua
  1.  
  2. function TestFunction()
  3.     if IsATree( entity ) then
  4.         Print("This is a Tree")
  5.     else
  6.         Print("This is NOT a Tree")
  7.     end
  8. end
  9.  
  10. function IsATree( entity )
  11.     if entity:GetModel() == "models/props/tree.mdl" then
  12.         return true
  13.     else
  14.         return false
  15.     end
  16. end
  17.  
  18.  
It's kind of rough.. some of it's pseudo(ish) code...
« Last Edit: May 10, 2011, 08:36:08 pm by MrPresident »

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 #3 on: May 10, 2011, 09:15:12 pm »
In this situation he would want to use return true.
But, with GM:<function> being a gamemode hook, wouldn't he NOT want to return anything if he wanted all other scripts calling it to continue, including whatever game uses a "Swat" team?

I really am ignorant and out of practice, and to be honest, never have fully understood where to allow it when it comes to Gmod.
I understand YOUR (mrP) code perfectly, and know a boolean is expected.
But I thought that Gmod expects no boolean values unless false though, and breaks stuff if one is received even when true.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline TropicalTitties

  • Newbie
  • *
  • Posts: 8
  • Karma: 0
Re: Respected Rank
« Reply #4 on: May 11, 2011, 05:45:29 am »
Thanks guys, and Jammin i understand your code perfectly and it should work, although it doesnt. Ive tried using both return true and return.

however neither of these seem to work and normal users can still become the SWAT . I used the exact code that jammin used, with and without the true after return.
Code: [Select]
function GM:PlayerJoinTeam( ply, class, teamid )
if not ply:IsUserGroup("respected") and teamid == TEAM_SWAT then
return false
else
return true
end
end
« Last Edit: May 11, 2011, 05:49:53 am by TropicalTitties »

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Respected Rank
« Reply #5 on: May 11, 2011, 01:54:50 pm »
Where is this code being added?
Experiencing God's grace one day at a time.

Offline TropicalTitties

  • Newbie
  • *
  • Posts: 8
  • Karma: 0
Re: Respected Rank
« Reply #6 on: May 11, 2011, 02:14:11 pm »
gamemodes/DarkRP/gamemode/sv_gamemode_functions.lua

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Respected Rank
« Reply #7 on: May 11, 2011, 06:59:55 pm »
gamemodes/DarkRP/gamemode/sv_gamemode_functions.lua

Are you sure that this gamemode doesn't already have a PlayerJoinTeam function?
Experiencing God's grace one day at a time.

Offline Aaron113

  • Hero Member
  • *****
  • Posts: 803
  • Karma: 102
Re: Respected Rank
« Reply #8 on: May 11, 2011, 07:22:28 pm »
Gamemode.PlayerJoinTeam
According to this you have the arguments in the function wrong.

Offline TropicalTitties

  • Newbie
  • *
  • Posts: 8
  • Karma: 0
Re: Respected Rank
« Reply #9 on: May 11, 2011, 07:26:40 pm »
So it would be
Code: [Select]
function GM:PlayerJoinTeam( ply, teamid )
if not ply:IsUserGroup("respected") and teamid == TEAM_SWAT then
return false
else
return true
end
end

  • Print