Skip to content

v0.97 HowTo: Add a custom permission

Dubjunk edited this page May 1, 2019 · 7 revisions

If you want to add a custom permission, you'll need to do the following:

Add a "permission handler"

A new permission is initialized in your modules postInit function and needs to be called on the server. You can add a new permission with the following Code:

[
    "MyPermissionName",
    {},
    true,
    "MyPermissionGroup",
] call KPLIB_fnc_permission_addPermissionHandler;

The following parameters can be used for the addPermissionHandler:

  • Permission name
    • This declares the name of the permission and is used to "read" the permission
    • When using a stringtable key it needs the following name "STR_KPLIB_PERMISSION_MYPERMISSIONNAME" (MyPermissionName is replaced with your declared permission name)
  • Code which is executed on permission check
    • This optional code can be used for longer permission checks
  • Default permission
    • Declares if a permission is true or false by default
  • Permission group name
    • Optional group name for a clearer permission dialog ("Misc" by default)
    • When using a stringtable key it needs the following name "STR_KPLIB_PERMISSION_MYPERMISSIONGROUP" (MyPermissionGroup is replaced with your declared permission name)

Use the permission

If you've added your permission successfully you can check your permission with the following code:

  • This function passes you the result of the defined permission and the declared code
    • Example 1:
      • Defined code: {}
      • ["MyPermissionName"] call KPLIB_fnc_permission_checkPermission checks now if the permission returns true
    • Example 2:
      • Defined code: {(str player) isEqualTo "KPLIB_eden_commander"}
      • ["MyPermissionName"] call KPLIB_fnc_permission_checkPermission checks now if the permission or the declared code returns true
      • While ["MyPermissionName", true] call KPLIB_fnc_permission_checkPermission checks now if the permission and the declared code returns true
    • Example usage in a function:
      • if (["PermissionName"] call KPLIB_fnc_permission_checkPermission) then {MyCode};
      • If the function returns "true" MyCode will be executed

Hints

  • An admin will bypass every permission