• ply:IsUserGroup problem.
    9 replies, posted
I'm having a problem with the IsUserGroup code. [code] function PropRestrict(ply) if ply:IsUserGroup("superadmin") and ply:GetCount("props") == 50 then return false end if ply:IsUserGroup("admin") and ply:GetCount("props") == 40 then return false end if not ply:IsUserGroup("superadmin") or ply:IsUserGroup("admin") and ply:GetCount("props") == 20 then return false end end hook.Add("PlayerSpawnProp", "PropRestrict", PropRestrict) [/code] The superadmin and admin prop restrict both work fine. But when the player is not in the usergroup superadmin or admin. It just doesn't work. The player simply can't spawn any prop. It's the "if not" thing, I know. It basically says the player needs a count of 20 props, before he/she can spawn a prop. Then I tried this. [code] if not ply:IsUserGroup("superadmin") or ply:IsUserGroup("admin") and if ply:GetCount("props") == 20 then return false end [/code] Didn't work either. Then I tried this. [code] if ply:IsUserGroup("superadmin") and ply:GetCount("props") == 50 then return false else if ply:IsUserGroup("admin") and ply:GetCount("props") == 40 then return false else if ply:GetCount("props") == 20 then return false end [/code] That didn't work either. I don't know what to try anymore.. Any help would be appreciated.
if ply:GetCount("props") > 20 then return false end [lua] if ply:IsUserGroup("superadmin") and ply:GetCount("props") > 50 then return false else if ply:IsUserGroup("admin") and ply:GetCount("props") > 40 then return false else if ply:GetCount("props") > 20 then return false end [/lua]
That doesn't work at all. How can I make this piece of script work. [code] if not ply:IsUserGroup("superadmin") or ply:IsUserGroup("admin") and ply:GetCount("props") == 20 then return false end [/code] Since it's the only thing that's not working.
Bah, couldn't get it to work this maintenance. It's just that players who are not in any of the UserGroups can't spawn anything. While superadmin and admin can.
Then do this: [lua] if not ply:IsUserGroup("superadmin") or ply:IsUserGroup("admin") and ply:IsUserGroup("player") and ply:GetCount("props") == 20 then return false end [/lua]
Is this what you want? [lua]local function PropRestrict(ply) if (ply:GetCount("props") >= 50 or ply:GetCount("props") >= 40 and not ply:IsSuperAdmin() or ply:GetCount("props") >= 20 and not ply:IsAdmin()) then return false; end end hook.Add("PlayerSpawnProp", "PropRestrict", PropRestrict)[/lua]
Basically what I want is that certain Usergroups can spawn more props then other usergroups. So I have superadmin, admin and premium in my usergroup file. If I'd only have SuperAdmin and Admin I would've used that piece of code. But I want Premium in the code too. Is ply:IsUserGroup("player") the usergroup that any player falls under that isn't in an usergroup? Because that would make it alot easier. This is what I have now. [code] function PropRestrict(ply) if ply:IsUserGroup("superadmin") and ply:GetCount("props") >= 60 then Notify(ply, 1, 4, "You've hit the Super Admin prop limit!") return false end if ply:IsUserGroup("admin") and ply:GetCount("props") >= 50 then Notify(ply, 1, 4, "You've hit the Admin prop limit!") return false end if ply:IsUserGroup("premium") and ply:GetCount("props") >= 40 then Notify(ply, 1, 4, "You've hit the Premium prop limit!") return false end if not ply:IsUserGroup("superadmin") or ply:IsUserGroup("admin") or ply:IsUserGroup("premium") and ply:GetCount("props") >= 20 then Notify(ply, 1, 4, "You've hit the Guest prop limit!") return false end end Add("PlayerSpawnProp", "PropRestrict", PropRestrict)[/code] Last time I checked, superadmin and admin prop limit both ceased to function. They couldn't spawn any prop, it would just be returned false..
[QUOTE=DDooby;18492184]Basically what I want is that certain Usergroups can spawn more props then other usergroups. So I have superadmin, admin and premium in my usergroup file. If I'd only have SuperAdmin and Admin I would've used that piece of code. But I want Premium in the code too. Is ply:IsUserGroup("player") the usergroup that any player falls under that isn't in an usergroup? Because that would make it alot easier. This is what I have now. [code] function PropRestrict(ply) if ply:IsUserGroup("superadmin") and ply:GetCount("props") >= 60 then Notify(ply, 1, 4, "You've hit the Super Admin prop limit!") return false end if ply:IsUserGroup("admin") and ply:GetCount("props") >= 50 then Notify(ply, 1, 4, "You've hit the Admin prop limit!") return false end if ply:IsUserGroup("premium") and ply:GetCount("props") >= 40 then Notify(ply, 1, 4, "You've hit the Premium prop limit!") return false end if not ply:IsUserGroup("superadmin") or ply:IsUserGroup("admin") or ply:IsUserGroup("premium") and ply:GetCount("props") >= 20 then Notify(ply, 1, 4, "You've hit the Guest prop limit!") return false end end Add("PlayerSpawnProp", "PropRestrict", PropRestrict)[/code] Last time I checked, superadmin and admin prop limit both ceased to function. They couldn't spawn any prop, it would just be returned false..[/QUOTE] the problem with that code is the logic works out like this: if (not ply:IsUserGroup("superadmin")) or ply:IsUserGroup("admin") or (ply:IsUserGroup("premium") and ply:GetCount("props") >= 20) then You wanted if not ( ply:IsUserGroup("superadmin") or ply:IsUserGroup("admin") or ply:IsUserGroup("premium")) and ply:GetCount("props") >= 20 then. However there is a better solution: [lua]hook.Add("PlayerSpawnProp","PropRestrict",function(ply) local count = ply:GetCount("props"); if (ply:IsUserGroup("superadmin")) then if (count >= 60) then Notify(ply, 1, 4, "You've hit the Super Admin prop limit!"); return false; end elseif (ply:IsUserGroup("admin")) then if (count >= 50) then Notify(ply, 1, 4, "You've hit the Admin prop limit!"); return false; end elseif (ply:IsUserGroup("premium")) then if (count >= 40) then Notify(ply, 1, 4, "You've hit the Premium prop limit!"); return false; end elseif (count >= 20) then Notify(ply, 1, 4, "You've hit the prop limit!"); return false; end end)[/lua]
It's working perfectly! I never knew you could use two IF in one IF, if you know what I mean.. :P And I didn't knew about the brackets either. Thanks Lexic!
Sorry, you need to Log In to post a reply to this thread.