Advertisement
einsteinK

Reality Breach - Plugin Docs

Jul 5th, 2016
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.92 KB | None | 0 0
  1.  
  2. --[[ Reality Breach - API Documentation ]]--
  3. -- Last updated: 27 oct 2015
  4. -- RB version: Alpha 0.1
  5. -- Mind that not every new RB version brings a new version of this document
  6. -- (Mostly because not every RB version changes anything to the API)
  7. -- (If I fix a bug in the API, I still don't update this, because no reason to)
  8.  
  9. --[[ API Members
  10.     API.Version
  11.         A string indicating the current version.
  12.        
  13.     API:IsRegistered(string name)
  14.         Returns whether or not a pack under that name is registered.
  15.         Useful for making sure your plugins don't run several times.
  16.         It's adviced to check for this, certainly if your plugin
  17.         gets added to the default list, else it'll lead to bugs.
  18.     API:RegisterPack(string name, string creator, string desc)
  19.         Create a new commandpack with the given data.
  20.         Check the section "CommandPack" for using the result.
  21.     API:GetPlayerData(variant player)
  22.         'player' can be: A username, an userId or a Player object.
  23.         You can only load data of in-game players.
  24.         Check the section "PlayerData" for using the result.
  25. --]]
  26.  
  27. --[[ CommandPack
  28.     Note: You better keep a good secure reference to this!
  29.     A CommandPack gets created by API:RegisterPack() and is unique.
  30.     Nobody else can create a pack with the same name, unless this one gets destroyed.
  31.     You can only add commands to RB by adding them to a commandpack.
  32.    
  33.     Pack:RegisterCommand(string name, string permission, function handler,
  34.             string desc, string syntax = "", array aliases = {})
  35.         Adds a new command to RB using this commandpack.
  36.         'name', 'permission' and 'desc' are obvious.
  37.         'handler' gets called when someone uses the command.
  38.         It gets called with: Player player, table arguments
  39.         The 'arguments' holds the player's message, split by whitespace
  40.         An example: ".teleport others me" --> handler(PLAYER,{"others","me"})
  41.         'syntax' is a string containing the arguments for the command.
  42.         Examples: "kick <player> (reason)", "hint ...",
  43.                     "showplayers <group>", "move (player) <player,up,down>"
  44.                     (Actually I'm not sure the last example works... oh well)
  45.         'aliases' is an array (a numeric table) containing aliases for the command.
  46.         A simple example for kill: {"makedead","murder","rip"}
  47.     Pack:UnregisterCommand(string name)
  48.         Remove a command you've registered before
  49.     Pack:RegisterPermission(string name, string desc = "<none>")
  50.         Register a new permission, including adding a description to it, if supplied.
  51.         A commandpack "PackA" can only add permissions that start with:
  52.         - commands.packa. (e.g. commands.packa.banana)
  53.         - pack.packa. (e.g. pack.packa.roomaccess.vip)
  54.         (Mind that permissions are case insensitive)
  55.         Creating the permission "a.b.c" will automaticly create
  56.         the permissions "a.b." and "a" if they're missing.
  57.     Pack:UnregisterPermission(string name)
  58.         Removes a permission (same restrictions as for RegisterPermission)
  59.         Deleting a permission will also delete all its childs.
  60.         (E.g. deleting "a.b" also deletes "a.b.c", "a.b.c.d", "a.b.idk", ...
  61.     Pack:Destroy()
  62.         Destroys this pack, removing all permissions and commands created by it.
  63.         This will remove the permissions "commands.PACK" and "packs.PACK" along
  64.         with all commands that got registered by this pack.
  65. --]]
  66.  
  67. --[[ PlayerData
  68.    
  69. --]]
  70.  
  71. --[[ IN-DEPTH INFORMATION ]]--
  72. --[[ Command names
  73.     In case 2 commandpacks have the same command, for example "kill", the
  74.     command "kill" won't work. You'll have to use "pack.kill".
  75.     For packs A and B that would be "A.kill" and "B.kill".
  76.     The command "murder" would work, though, unless another pack also has that.
  77.     It's best if you use original names, while aliases are abbrevations.
  78.    
  79.     There's a order in which commandnames are "linked" to actual commands.
  80.     Assume we have those 2 packs with the following commands:
  81.     Pack A: "kill" with aliases {"makedead","murder","rip"}
  82.     Pack B: "murder" with aliases {"stopheart"}
  83.             "kill" with aliases {"zerohealth","rip"}
  84.     When the following commands are used, the following happens:
  85.         kill: RB will inform the user it's ambigious, since 2 packs have it as main command
  86.         rip: RB will inform the user it's ambigious, since 2 packs have it as an alias
  87.         murder: "murder" from pack B will be used, even though "kill" has it as alias
  88.         A.kill: "kill" from pack A will be used, since the user used "pack.command"
  89.         makedead: "kill" from pack A will be used, as it's the only command with this alias
  90.     Basicly, when you use a commandname, those are the possible results:
  91.     - There's only one command called that way, which will get used
  92.     - Several commands are called that way, which results in an error (ambigious)
  93.     - There's only one command with it as an alias, that command will get used
  94.     - Several commands have it as an alias, which results in an error (ambigious)
  95.     Of course, a user can bypass this order by using "pack.command", which
  96.     will get the command named "command" directly from the pack "pack"
  97. --]]
  98.  
  99. --[[ LOADING PLUGINS
  100.     There are 2 ways of loading a plugin.
  101.     Those work basicly the same, though:
  102.     - Have a ModuleScript in the Plugins-folder
  103.     - Manually call "local RB = ..." and use that
  104.     Basicly, all ModuleScripts in the Plugins-folder are
  105.     automaticly required right after RB has loaded.
  106.     If they return a function, it'll be called with RB as argument.
  107.     You can just put your MS somewhere else and require the ID.
  108.     You can even use a regular script if you want.
  109.    
  110.     If you are using a Dev Build of RB, make sure the RBLoader is
  111.     in ServerScriptService, unless you want weird dualboot and bugs.
  112. --]]
  113.  
  114. --[[ EXAMPLE PLUGIN ]]--
  115.  
  116.  
  117. -- Ignore this code. Just stops the plugin from running online
  118. -- (This is just a test plugin for in studio, for showing an
  119. -- example to developers who want to create a plugin for RB)
  120. local RS = game:GetService("RunService")
  121. local s,e = pcall(RS.IsStudio,RS)
  122. if s  and not e then return false end
  123. RS = UserSettings().GameSettings
  124. if not RS:InStudioMode() then return false end
  125.  
  126. -- Declare the RB API
  127. local RB = require(293985200)
  128. if RB:IsRegistered("Test") then
  129.     -- We already ran, I guess?
  130.     return false
  131. end
  132.  
  133. -- Create a commandpack
  134. local Pack = RB:RegisterPack("Test","einsteinK","A pack for testing")
  135.  
  136. -- Register a permission for our command
  137. Pack:RegisterPermission("commands.test.banana","Use the banana command")
  138.  
  139. -- Register our command
  140. Pack:RegisterCommand("Banana","commands.test.banana",function(plr,args)
  141.     local num = tonumber(args[1])
  142.     if num and num ~= 1 then
  143.         print(plr,"wants",num,"bananas!")
  144.     else
  145.         print(plr,"wants a banana!")
  146.     end
  147. end,"Announce you want a banana")
  148.  
  149. -- Register our other command
  150. Pack:RegisterCommand("NoBanana","commands.test.banana",function(plr,args)
  151.     -- Doing ".nobanana" would actually remove this and our previous command
  152.     Pack:UnregisterCommand("NoBanana")
  153.     Pack:UnregisterCommand("Banana")
  154.     -- And our permission we created for it too
  155.     Pack:UnregisterPermission("commands.test")
  156.     print("No more bananas!")
  157.     -- Actually let's just destroy the whole pack
  158.     Pack:Destroy()
  159. end)
  160.  
  161. return true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement