Hey guys, i am kinda new to Oxide plugins.
So all i want to do is to write a methode that removes every user from a single permission.
Here is what i came up with:
If i just use this methode, i get this as output:Code:void Loaded() { ClearPermission("kits.revolver"); if (permission.UserHasPermission("76561198037281736", "kits.revolver")) // this is for debugging { Puts("failed"); } else { Puts("Success!"); } }void ClearPermission(string perm) { foreach (var item in permission.GetPermissionUsers(perm)) { permission.RevokeUserPermission(item, perm); Puts("Removed permission: {0} from player {1}", perm, item); // just for debuging } }
but i still have the permission, so it does not remove me the permission, am i missing something or so?Code:[DMRights] DMRights loading... [DMRights] Removed permission: kits.revolver from player 76561198037281736(Maik8) [DMRights] failed
Solved Remove users from permission
Discussion in 'Rust Development' started by Maik8, Jun 30, 2017.
-
An example for how to remove all users from a group. When you get all the users it does not just return a user id, it will return: 76561198167856311 (Unnamed) for example. Thats why in my example I used regex to get the user name from the string. And I get the first 17 characters as a steam ID is always 17 chars long.
Code:void WipeGroup(string name) { string[] players = permission.GetUsersInGroup(name); for (var i = 0; i < players.Count(); i++) { string raw, id, user; raw = players[i]; id = raw.Substring(0, 17); user = Regex.Replace(raw, "[^a-zA-Z -]", string.Empty); permission.RemoveUserGroup(id, name); if (!permission.UserHasGroup(id, name)) PrintWarning(""+user+" has been removed from group "+name+""); else PrintWarning("" + user + " was not removed from group " + name + ""); } }
-
Wulf Community Admin
Code:if (!permission.UserHasGroup(id, name)) PrintWarning(user + " has been removed from group " + name);
Could even use string interpolation if you'd like:
Code:if (!permission.UserHasGroup(id, name)) PrintWarning($"{user} has been removed from group {name}");
-
Funny thing is I tried that. But forgot I have to use {variable name} instead of {0}, {1} lol.
-
Wulf Community Admin
-
Thanks for the help guys, i solved it now as follow, since i don't use groups for the permissions that are used in this case (permissions for kits buyable throught a shop, with money you earn by killing ppl):
Code:void ClearPermission(string perm) { foreach (string item in permission.GetPermissionUsers(perm)) { permission.RevokeUserPermission(item.Substring(0, item.LastIndexOf('(')), perm); Puts("Removed permission: {0} from player {1}", perm, item); } }
now i just remove the (Unnamed) part (in this case) and it works.