1. Hi guys, I have a strange problem (a minor one).

    I'm trying to check the existence of an oxide permission, if it doesn't exist the plugin (c#) should create it.
    I looked at various C# plugin and I managed to register the permission with no problems.

    The strange thing is, even if I copied the "check if permission exists and, if not, register it" part from another c# plugin (I believe it was GodMode) the code works only in part:

    Code:
    if (!permission.PermissionExists("CanControlLanterns"))  
    {
     permission.RegisterPermission("CanControlLanterns", this);
    }
    I'm executing the code through the Init() hook, but the permission check always returns false. It's not a big deal because returning always false result in always registering the permission (functionally speaking the pluging is good, the permission works as it should).

    I was only wondering why I am not able to have true returned from PermissionExists.

    Am I missing something in the way oxide permissions work?

    Thanks all!
     
  2. Interesting. Just made some tests and can confirm. permission.PermissionExists() always returns false after reload but true after the permission is registered.

    My testcase:
    Code:
    function PLUGIN:Init()
        self:RegisterPermission()
    end
    function PLUGIN:RegisterPermission()
        print(tostring(permission.PermissionExists("testperm")))
        if not permission.PermissionExists("testperm") then
            permission.RegisterPermission("testperm", self.Object)
        end
        print(tostring(permission.PermissionExists("testperm")))
    end
    [​IMG]
    [DOUBLEPOST=1434975051][/DOUBLEPOST]After some more testing I believe permissions are unloaded as soon as the owner plugin gets unloaded.
    If there is no plugin running that registered the permission, PermissionExists() will always be false even if the permission im checking for is used by users or groups.

    Seems like the PermissionExists() function is more like a IsPermissionRegistered() check.
     
    Last edited by a moderator: Jun 22, 2015
  3. Hi Domestos, thank you!
    I see, so, since this is my very first experience with c# developing, what's the best way, according to you, to register my custom permission at init?

    Simply use:

    Code:
    permission.RegisterPermission("CanControlLanterns", this);
    without any particular control?
     
  4. You can simply use the code you posted in your first post. If some other plugin is running using the same permission as your plugin the PermissionExists() function should be true so your plugin doesnt register it again.
     
  5. Perfect! Thank you very much!