file-circle-plusCreating Extensions

Learn about extensions and how to create them with Pixel Administration.

circle-question What are Extensions?

Extensions is a feature that allows you to integrate custom features for Pixel Administration that haven't been implemented. You can use this for a variety of reasons like integrating new commands, running commands, creating pages, creating modals, and so on. There's almost an unlimited potential that comes with extensions, but that can also leave room for bad ones to come in too.

gear Who can use Extensions?

Right now all admins have access to extensions, but in the near future we'll allow certain ranks access to the extensions just in case some of them are more powerful and should be restricted. However the running commands part of extensions will still detect if that rank has access to commands if you set that up properly. So I don't think that should be an issue.

file-shield How is Extension Security handled?

The security for extensions is important. That's why we've created a system for detecting the bad ones to notify any admins of its existence since it's automatically off and disabled by default. But how do we detect the bad ones? Well it goes through a series of checks. You can find those checks in the ExtensionService (if you're able to get access to the MainModule). I'm just not providing it here because I'd have to update this documentation every time I update those checks, which might cause me to lose track of them. Anyways, the checks are bypassed if an extension is verified. But that's determined by the hash of an extension which can only be modified from a clone of Pixel Administration's MainModule Loader, and shouldn't be able to be bypassed on Pixel Administration's official loader.

file-circle-plus How can I make an Extension?

circle-exclamation

You can create an extension by using the Extensions folder that comes with Pixel Administration. If it doesn't exist, just create it. Extensions are always module scripts, so lets create a module called "Extension" (this module can be named anything).

Open up your newly created extension and replace the contents with this.

local Extension = {}

Extension.Name = script.Name -- The extension's ModuleScript name.
Extension.Version = "1.0.0" -- The extension's version.
Extension.Author = "Your Name" -- Who made this extension.
Extension.Description = "What this extension does." -- The extension's description.

local api = nil -- Variable for the ExtensionService API (will be set in :Init).

return Extension

Pretty simple, right? Now lets make this actually do something. We're going to add an Init function to the Extension to the ExtensionService knows what to do with it once it prepares the extensions.

But why are we using api:Log() rather than print()? Well we're doing that because of user preference. Not everyone wants to see the logs of an extension, so it needs to be detected and used by the API to be disabled. Otherwise there's prints that you cannot remove.

You should see the initialized print in the console! Also there's a ton of APIs I'd like to show you that we can use for extensions. Lets take a look at them below before we continue so you understand how they work! Not every argument or function will be covered in this tutorial.


chevron-rightLog(message: string, isWarning: boolean)hashtag

Allows you to log a message to the console. ExtensionService's equivalent of print() and allows for permission toggling.

message: The message to print in a string.

isWarning: The equivalent of warn(). Defaults to false if unset.


chevron-rightGetDataStore(name: string)hashtag

Allows you to get a datastore for the extension.

name: The datastore's name of that extension to get.

chevron-rightSetDataStore(name: string, key: string, value)hashtag

Allows you to set a datastore's key and value for the extension.

name: The datastore's name of that extension to get.

key: The datastore's key that should be adjusted.

value: The new value for that key.

chevron-rightGetSetting(key: string, default: string)hashtag

Allows you to get a setting for the extension.

key: The Extension's setting key to get.

default: The fallback if something fails.

chevron-rightSetSetting(key: string, value)hashtag

Allows you to set a setting for the extension.

key: The Extension's setting key to get.

value: The new value for that key.


chevron-rightRegisterCommand(commandData)hashtag

Allows you to create a command for that extension. See Custom Commands to learn how to make a custom command.

commandData: The command's data and information.

chevron-rightRunCommand(commandName: string, arguments, executor: Player)hashtag

Allows you to run a command by name and by passing through arguments and the executor.

commandData: The command's data and information.

arguments: A table of arguments.

executor: Who ran the command.


chevron-rightNotify(targetPlayer: Player, title: string, message: string, duration: number)hashtag

Allows you to display a notification to a certain player.

targetPlayer: The player to notify.

title: The title of the notification.

message: The main message of the notification.

duration: How long the notification will stay visible.

chevron-rightNotifyAll(title: string, message: string, duration: number)hashtag

Allows you to display a notification to all players.

title: The title of the notification.

message: The main message of the notification.

duration: How long the notification will stay visible.


chevron-rightIsWhitelisted(player: Player)hashtag

Checks if a player can use Pixel Administration or not.

player: The player to check the whitelist status for.


chevron-rightCreateRemoteEvent(name: string)hashtag

Creates a remote event for the extension.

name: The event's name.

chevron-rightCreateRemoteFunction(name: string)hashtag

Creates a remote function for the extension.

name: The function's name.


chevron-rightRemovePage(pageName: string)hashtag

Creates a page in Pixel Administration for the function.

pageName: The page's name to remove.

chevron-rightCreatePage(config)hashtag

Creates a page in Pixel Administration for the function.

config: The page's data.

Example:

Provided due to complexity of the config argument.

chevron-rightCreateModal(config)hashtag

Creates a page in Pixel Administration for the function.

config: The modal's data.

Example:

Provided due to complexity of the config argument.

Phew! That took a while. Now you should understand how everything works, and how to build onto your extension. Feel free to come back here if you need to learn more! Now lets finish this off. All extensions support OnEnable/OnDisable events to detect when the user has disabled the extension. This is where you'd set everything up, or disable everything here. But most of the time the ExtensionService API should handle the shutdown of most things in the disable function that you used the API for like making pages. Those pages should hide when the extension or permission for Pages is disabled. So you wont have to worry about that. Everything else you should add some disable logic

Also you may be wondering if you should use Init or OnEnable. Both of those work fine, so you can use either one and you shouldn't see any errors. Anyways that's the end of this tutorial! I'm really exited to see what you'll build with this.

Last updated