-
Notifications
You must be signed in to change notification settings - Fork 4
Plugins
Sven Co-op supports the use of plugins for servers. This allows you to write scripts that run as long as the server is active, allowing you to do almost as much you can do in a map script.
The minimum requirements for a plugin are that it provides a PluginInit function, and properly sets up the author and contact info fields. This is to prevent plugins with no known source from existing.
void PluginInit()
{
g_Module.ScriptInfo.SetAuthor( "Sven Co-op Development Team" );
g_Module.ScriptInfo.SetContactInfo( "www.svencoop.com" );
}
In order to prevent malicious scripts from altering this information, you can only set this information from PluginInit itself. It should be the first thing you do in PluginInit, to avoid any confusion.
Plugins must be placed in the scripts/plugins directory. You can place them in a subdirectory if you want, but be aware that using long paths can cause issues, so avoid using deeply nested paths and long directory names.
It is recommended that you use directories to group scripts together to avoid cluttering the main directory, and to avoid using the same name as other scripts.
The plugin list file is a text file, using the Keyvalues format, that contains a list of all plugins that the server will load.
The list uses the following format:
"plugins"
{
"plugin"
{
"name" "PluginName"
"script" "PluginScriptName"
"adminlevel" "<admin level>"
"concommandns" "pluginns"
}
}
Each plugin has its own plugin block, which contains 2 required keyvalues: name and script. These define the name of the plugin (case insensitive, no duplicates allowed) and the main script file to include.
The adminlevel keyvalue is optional, and defines the minimum admin level required for players to use console commands and hooks that have the admin flag set, such as the ClientSay hook. You must choose one of these possible values:
Name | Who can use commands |
---|---|
ADMIN_NO | All players |
ADMIN_YES | Only admins and the server owner |
ADMIN_OWNER | Only the server owner |
The concommandns keyvalue is also optional, and defines the console command namespace used for plugin console commands (see console command system documentation).
The list file also allows the use of single line commands that start with "//".
Note: if your plugin is located in a subdirectory of the main plugin directory, you must also include that subdirectory in the script path. For instance, if your script is named "myplugin.as" and is located in "scripts/plugins/wip/", you will need to write the script name as wip/myplugin.
There are a few console commands that apply to plugins:
Command name | Purpose | Admin only? |
---|---|---|
as_listplugins | Shows a list of all plugins currently active on this server | No |
as_reloadplugin | Reloads a plugin that is in the list of plugins | Yes |
as_reloadplugins | Reloads all plugins from the plugin list file | Yes |
as_removeplugin | Removes a plugin from the plugin list | Yes |
as_removeplugins | Removes all plugins | Yes |
Most of the API is available for plugins to use, but there are a few things that are exclusive to them:
- CAdminControl: administrative control for actions such as penalizing, killing, kicking, and banning players.
- Plugin and plugin temp directories in the filesystem: Ability to read/write files in these directories is restricted to plugins.
- Hooks:
- CanPlayerUseReservedSlot
- ClientConnected
Consult the documentation for the respective features for more information. For information on which parts of the API are exclusive to other script types, consult their documentation.