• ScreenGrab Permissions
    30 replies, posted
ScreenGrab permissions for multiple groups. I contacted a coder friend of mine and they told me to do this: [CODE] if !ply:IsUserGroup("owner") or !ply:IsUserGroup("staffchief") or !ply:IsUserGroup("servermanager") or !ply:IsUserGroup("dev") or !ply:IsUserGroup("admin") or !ply:IsUserGroup("moderator") or !ply:IsUserGroup("donatoradmin") or !ply:IsUserGroup("donatoradmin+") or !ply:IsUserGroup("donatoradmin++") or !ply:IsUserGroup("moderator") or !ply:IsUserGroup("donatormod") or !ply:IsUserGroup("donatormod+") or !ply:IsUserGroup("donatormod++") then return end[/CODE] The if then statement is all one line, but anyways it did not work. Any advice?
[QUOTE=Frubbs;44494492]ScreenGrab permissions for multiple groups. I contacted a coder friend of mine and they told me to do this: [CODE] if !ply:IsUserGroup("owner") or !ply:IsUserGroup("staffchief") or !ply:IsUserGroup("servermanager") or !ply:IsUserGroup("dev") or !ply:IsUserGroup("admin") or !ply:IsUserGroup("moderator") or !ply:IsUserGroup("donatoradmin") or !ply:IsUserGroup("donatoradmin+") or !ply:IsUserGroup("donatoradmin++") or !ply:IsUserGroup("moderator") or !ply:IsUserGroup("donatormod") or !ply:IsUserGroup("donatormod+") or !ply:IsUserGroup("donatormod++") then return end[/CODE] The if then statement is all one line, but anyways it did not work. Any advice?[/QUOTE] remove all exclamation points, replace if with "if !(" replace then with ") then" (no quotes)
[QUOTE=OzymandiasJ;44494515]remove all exclamation points, replace if with "if !(" replace then with ") then"[/QUOTE] What does that even mean? replace then with?
this codes fine
It's really dumb though. Just have a table of groups.
[QUOTE=nettsam;44494542]this codes fine[/QUOTE] Well it doesn't work, the specified user groups cannot execute the !sg command properly. It does nothing!
[QUOTE=Frubbs;44494492]ScreenGrab permissions for multiple groups. I contacted a coder friend of mine and they told me to do this: [CODE] if !ply:IsUserGroup("owner") or !ply:IsUserGroup("staffchief") or !ply:IsUserGroup("servermanager") or !ply:IsUserGroup("dev") or !ply:IsUserGroup("admin") or !ply:IsUserGroup("moderator") or !ply:IsUserGroup("donatoradmin") or !ply:IsUserGroup("donatoradmin+") or !ply:IsUserGroup("donatoradmin++") or !ply:IsUserGroup("moderator") or !ply:IsUserGroup("donatormod") or !ply:IsUserGroup("donatormod+") or !ply:IsUserGroup("donatormod++") then return end[/CODE] The if then statement is all one line, but anyways it did not work. Any advice?[/QUOTE] Replace all the 'or' with 'and'
[QUOTE=Shinycow;44494565]Replace all the 'or' with 'and'[/QUOTE] So you're suggesting him to see if the person trying to type the "!sg" command is member of ALL the listed usergroups? I doubt someone is a donatoradmin and owner at the same time...
[QUOTE=Cyberuben;44494599]So you're suggesting him to see if the person trying to type the "!sg" command is member of ALL the listed usergroups? I doubt someone is a donatoradmin and owner at the same time...[/QUOTE] No. What his code is saying is that if the player is not in the owner usergroup, or if they're not in staffchief, etc then return end. A player can't be in staffchief / owner at the same time, which is WHY I'm telling him to replace the or with and. By replacing those instances, if one of them equates to false (meaning they are in the group) then it won't stop. [lua] if not ply:IsUserGroup("owner") and not ply:IsUserGroup("staffchief") and not ply:IsUserGroup("servermanager") and not ply:IsUserGroup("dev") and not ply:IsUserGroup("admin") and not ply:IsUserGroup("moderator") and not ply:IsUserGroup("donatoradmin") and not ply:IsUserGroup("donatoradmin+") and not ply:IsUserGroup("donatoradmin++") and not ply:IsUserGroup("moderator") and not ply:IsUserGroup("donatormod") and not ply:IsUserGroup("donatormod+") and not ply:IsUserGroup("donatormod++") then return end [/lua] This isn't very nice way of doing things though. A better way would be this: [lua] -- put this outside the function local accessable = { ["owner"] = true, ["staffchief"] = true, ["servermanager"] = true, ["dev"] = true, ["admin"] = true, ["moderator"] = true, ["donatoradmin"] = true, ["donatoradmin+"] = true, ["donatoradmin++"] = true, ["moderator"] = true, ["donatormod"] = true, ["donatormod+"] = true, ["donatormod++"] = true, } -- and in the function use this if not accessable[ ply:GetNWString("UserGroup", "user") ] then return end [/lua]
[QUOTE=Shinycow;44494622]No. What his code is saying is that if the player is not in the owner usergroup, or if they're not in staffchief, etc then return end. A player can't be in staffchief / owner at the same time, which is WHY I'm telling him to replace the or with and. By replacing those instances, if one of them equates to false (meaning they are in the group) then it won't stop. [lua] if not ply:IsUserGroup("owner") and not ply:IsUserGroup("staffchief") and not ply:IsUserGroup("servermanager") and not ply:IsUserGroup("dev") and not ply:IsUserGroup("admin") and not ply:IsUserGroup("moderator") and not ply:IsUserGroup("donatoradmin") and not ply:IsUserGroup("donatoradmin+") and not ply:IsUserGroup("donatoradmin++") and not ply:IsUserGroup("moderator") and not ply:IsUserGroup("donatormod") and not ply:IsUserGroup("donatormod+") and not ply:IsUserGroup("donatormod++") then return end [/lua] This isn't very nice way of doing things though. A better way would be this: [lua] -- put this outside the function local accessable = { ["owner"] = true, ["staffchief"] = true, ["servermanager"] = true, ["dev"] = true, ["admin"] = true, ["moderator"] = true, ["donatoradmin"] = true, ["donatoradmin+"] = true, ["donatoradmin++"] = true, ["moderator"] = true, ["donatormod"] = true, ["donatormod+"] = true, ["donatormod++"] = true, } -- and in the function use this if not accessable[ ply:GetNWString("UserGroup", "user") ] then return end [/lua][/QUOTE] I'm sorry for missing the exclamation marks, you may now put me up for public humilliation for not spotting that one.
I figured you misread, that's why I replaced the exclamation marks with 'not' ha
fuck [lua] if !(ply:IsUserGroup("owner") or ply:IsUserGroup("staffchief") or ply:IsUserGroup("servermanager") or ply:IsUserGroup("dev") or ply:IsUserGroup("admin") or ply:IsUserGroup("moderator") or ply:IsUserGroup("donatoradmin") or ply:IsUserGroup("donatoradmin+") or ply:IsUserGroup("donatoradmin++") or ply:IsUserGroup("moderator") or ply:IsUserGroup("donatormod") or ply:IsUserGroup("donatormod+") or ply:IsUserGroup("donatormod++")) then return end[/lua] if you are not (this or this or this, et al) then simple directions, first post
I replaced them all with "and" and it works fine now.
I see what Shinycow is trying to do. You two are trying to do it in different ways. Shinycow's code was checking if they are not any of the ranks, and if they are not any of the ranks, then exit. Cyberuben, you were expecting code that would check if they [b]are[/b] any of the groups, and if so, do the screengrab. It's something that had me confused for a minute as well, because I couldn't understand Shinycow. The table way is the best way to do it, but instead of using a key with a value of true, I'd just use a value and use table.HasValue(accessable, player:GetNWString("usergroup")), though.
Fixed Code that works [lua]local groupPerms = {"owner", "admin", "staffchief", "servermanager", "moderator", "donatormod" ,"donatormod+", "donatormod++", "donatoradmin", "donatoradmin+", "donatoradmin++"} if !ply:IsUserGroup(groupPerms) then return end[/lua] tbh I didnt even know you can supply a table to the func and it'll read through it all
[QUOTE=zerothefallen;44495103]Fixed Code that works [lua]local groupPerms = {"owner", "admin", "staffchief", "servermanager", "moderator", "donatormod" ,"donatormod+", "donatormod++", "donatoradmin", "donatoradmin+", "donatoradmin++"} if !ply:IsUserGroup(groupPerms) then return end[/lua] tbh I didnt even know you can supply a table to the func and it'll read through it all[/QUOTE] That actually didn't work... I spoke too soon [editline]9th April 2014[/editline] [QUOTE=Shinycow;44494622]No. What his code is saying is that if the player is not in the owner usergroup, or if they're not in staffchief, etc then return end. A player can't be in staffchief / owner at the same time, which is WHY I'm telling him to replace the or with and. By replacing those instances, if one of them equates to false (meaning they are in the group) then it won't stop. [lua] if not ply:IsUserGroup("owner") and not ply:IsUserGroup("staffchief") and not ply:IsUserGroup("servermanager") and not ply:IsUserGroup("dev") and not ply:IsUserGroup("admin") and not ply:IsUserGroup("moderator") and not ply:IsUserGroup("donatoradmin") and not ply:IsUserGroup("donatoradmin+") and not ply:IsUserGroup("donatoradmin++") and not ply:IsUserGroup("moderator") and not ply:IsUserGroup("donatormod") and not ply:IsUserGroup("donatormod+") and not ply:IsUserGroup("donatormod++") then return end [/lua] This isn't very nice way of doing things though. A better way would be this: [lua] -- put this outside the function local accessable = { ["owner"] = true, ["staffchief"] = true, ["servermanager"] = true, ["dev"] = true, ["admin"] = true, ["moderator"] = true, ["donatoradmin"] = true, ["donatoradmin+"] = true, ["donatoradmin++"] = true, ["moderator"] = true, ["donatormod"] = true, ["donatormod+"] = true, ["donatormod++"] = true, } -- and in the function use this if not accessable[ ply:GetNWString("UserGroup", "user") ] then return end [/lua][/QUOTE] Worked great thanks!
[QUOTE=Frubbs;44495170]That actually didn't work... I spoke too soon[/QUOTE] well it seems my intuition was correct then, you cant supply a table. [lua]local groupPerms = {"owner", "admin", "staffchief", "servermanager", "moderator", "donatormod" ,"donatormod+", "donatormod++", "donatoradmin", "donatoradmin+", "donatoradmin++"} if !(table.HasValue(groupPerms, ply:GetNetworkedString("UserGroup"))) then return end[/lua] test this i'd user getusergroup but i forgot if it exists
Nevermind, I'm dumb.
[URL=http://wiki.garrysmod.com/page/Player/GetUserGroup]lies[/URL]
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/benchmarking_tips/benchmarking_hud_stuff.lua.html[/url] Use the direct access code that was given to you; using table.HasValue can be expensive. The only other change I'd make to what was supplied is: [lua]local _groupsTable = { user = true; vip = true; admin = true; superadmin = true; owner = true; // ... etc };[/lua] because [""] isn't needed unless you're using a non-standard string ( such as something that starts with a number, or has a space, etc... )
[QUOTE=zerothefallen;44495193]well it seems my intuition was correct then, you cant supply a table.[/QUOTE] No your intuition was correct, the code was just wrong. You can supply a table for a function. For example you could do [code] local allowedgroups = {"owner", "admin", "superadmin"} if ply:IsUserGroup(allowedgroups) then -- do stuff end [/code] The code he sent you in the pm was partly my code. You can obviously use table.hasvalue but i do this was for the sake of time. From what ive seen you can use it with any function that requires any arguments.
[QUOTE=_Jacob;44497993]No your intuition was correct, the code was just wrong. You can supply a table for a function. For example you could do [code] local allowedgroups = {"owner", "admin", "superadmin"} if ply:IsUserGroup(allowedgroups) then -- do stuff end [/code] The code he sent you in the pm was partly my code. You can obviously use table.hasvalue but i do this was for the sake of time. From what ive seen you can use it with any function that requires any arguments.[/QUOTE] Oh, well i didnt know lua would look through the entire table. Why does table.hasvalue exist then?
[QUOTE=zerothefallen;44498050]Oh, well i didnt know lua would look through the entire table. Why does table.hasvalue exist then?[/QUOTE] Idk, but it only seems to work if you stick the table as the argument like [code] if atk:SteamID(alloweduser) then atk:ChatPrint("BOOM!") end [/code] As where [code] if atk:SteamID() == alloweduser then atk:ChatPrint("BOOM!") end [/code] Doesnt seem to work. edit: My code used for testing: [lua] alloweduser = {"STEAM_0:1:70639523"} if atk:SteamID(alloweduser) then for i=1, 10 do atk:ChatPrint("BOOM!") end end [/lua] Output: [IMG]http://i.gyazo.com/97d647aca7c5996a11962443dc77997b.png[/IMG]
ITT Nookyava has a grudge! This thread is solved now I believe - but to answer _Jacob: if atk:SteamID() == alloweduser then atk:ChatPrint("BOOM!") end Won't work because you're checking if a player's steamid is equal to a table. Which it will never be. As for this code, [lua] alloweduser = {"STEAM_0:1:70639523"} if atk:SteamID(alloweduser) then for i=1, 10 do atk:ChatPrint("BOOM!") end end [/lua] Player.SteamID doesn't take arguments. Meaning you're simply checking for an output, which Player.SteamID returns. So if you do this, [lua] alloweduser = {"STEAM_0:1:70639523"} if atk:SteamID("test") then for i=1, 10 do atk:ChatPrint("BOOM!") end end [/lua] It will still print in your chat, "BOOM!"
Turns out this thread was useful for me too :') I used it in my "customCheck" for DarkRP entities / jobs! Woohoo!
[QUOTE=Shinycow;44501074]stuff[/QUOTE] Thats where you're wrong :) Ive used this method as a way to allow my staff members who have donated to have access to donor stuff. Doing so doesn't allow everyone to use it only the ids i put. Also i know it doesn't take an arg, but hell it works so whatever :v: edit: and about your comment about nooky, I just ignore him. I think of it as him giving me his undivided attention, and that makes it nice. So thanks nooky <3
[QUOTE=_Jacob;44502516]Thats where you're wrong :) Ive used this method as a way to allow my staff members who have donated to have access to donor stuff. Doing so doesn't allow everyone to use it only the ids i put. Also i know it doesn't take an arg, but hell it works so whatever :v: edit: and about your comment about nooky, I just ignore him. I think of it as him giving me his undivided attention, and that makes it nice. So thanks nooky <3[/QUOTE] How exactly? Running this code in my console prints "no." lua_run_cl local tbl = {"STEAM_0:0:29257121"} if LocalPlayer():SteamID() == tbl then print("ya") else print("no") end
-snip-
[QUOTE=Shinycow;44502634]How exactly? Running this code in my console prints "no." lua_run_cl local tbl = {"STEAM_0:0:29257121"} if LocalPlayer():SteamID() == tbl then print("ya") else print("no") end[/QUOTE] for whatever reason it doesnt like that way, try if LocalPlayer():SteamID(tbl) then print("ya") else print("no") end If that doesnt work ill admit defeat, but it works fine for me
B-b-but, I already said Player.SteamID doesn't take arguments. All you're doing is checking if SteamID returns anything - which is does - and if it does - which it does - then print("ya"). Here: [code] ] lua_run_cl local tbl = {"STEAM_0:0:29257121"} if LocalPlayer():SteamID( tbl ) then print("ya") else print("no") end ya ] lua_run_cl local tbl = {"STEAM_0:0:notevennumbers"} if LocalPlayer():SteamID( tbl ) then print("ya") else print("no") end ya [/code]
Sorry, you need to Log In to post a reply to this thread.