Overview
Learn about Angelscript and how to mount Angelscript plugins on your server.
Introduction
Hello, my name is Zergeant and I’ve been helping the Sven Coop Team out since June 2015. Today I will help you familiarize yourself with Angelscript plugins and how to autoload them on your server.
Now why would you want to autoload plugins for your server? Well if you desire to have extra functions or features for your server like admin tools or the ability for players to play random game sounds, then the easiest way would be to load an Angelscript plugin that does exactly that. Sven Coop comes bundled with Angelscript plugins ready to be used, a few of these are PlayerManagement.as, EntityManager.as and Teleport.as, all performing and filling their own functions.
So what is Angelscript? Angelscript is a programming language Sven Coop makes use of to give more power to map makers and server owners. With Angelscript a map maker could, for example, create new monsters, new weapons or scripts to perform map events. A server host as you already know by now, can use Angelscript to load admin tools or other features for the server. But a very important note is that there’s a difference between the plugins a server owner loads and the scripts that a map maker loads, which we will be covering in the next section.
Server plugins & Map scripts
While visually identical, Angelscript files meant to be loaded as plugins for the server is loaded differently than how the game loads Angelscript files for maps. Angelscript files can be loaded in two ways, by the ‘default_plugins.txt’ file in your main svencoop directory or by a map’s cfg file. For now we will be looking at default_plugins.txt, which tells the game what plugins should be loaded.
As you can see we already have a few entries as standard and you can also see where I added another plugin to be loaded. Loading a plugin will take a few keyvalues, there are four keyvalues available when loading a plugin.
- “name”
- “script”
- “adminlevel”
- “concommandns”
The “name” keyvalue serves to separate plugins from eachother, this is an obligatory keyvalue.
The path to the script, starting from scripts/plugins directory. Also an obligatory keyvalue.
Defines whether or not this plugin and it’s functions is to be restricted to admins or server owner only. This keyvalue is optional and not necessary to include.
Defines the console command namespace for this plugin, used by the plugin console commands. Optional and can be discluded.
Now you know how to add and load more plugins for your server! Keep in mind that lines starting with “//” will NOT be loaded.
So where do we find all these plugins? In the scripts/plugins directory you will find all Angelscript files that can be loaded as plugins, there is also a directory called scripts/maps which is where the map scripts go. What separates plugins from map scripts is that they use the method PluginInit to get initialized by default_plugins.txt, plugins need to have this method provided or they cannot be loaded. If you need to check if an Angelscript file can be loaded as a plugin, open it up in in a text-editor program, preferrably Notepad++, open the search function (Usually CTRL+F) and search for PluginInit. If you find a result the file is most likely supposed to be a plugin.
Another major note to remember if you create Angelscript plugins is that a plugin cannot define new entities. For example, you cannot load a custom weapon or monster, this can only be done by map scripts.
Commands & Usage
Sven Coop has commands to manage Angelscript files that have been loaded, there’s also specific commands just for plugins.
With the use of these commands we can now manage the plugins currently active on the server. Since we have specified a few plugins to be loaded in our default_plugins.txt we are now ready to venture in game and see if the plugins were successfully loaded.
The plugins have been loaded! We can now make use of the functions they provide. As an example, this guide will go through the use of PlayerManagement, as it’s loaded by default and features very handy admin tools.
This plugin features all the usual admin commands, such as slap, slay and teleport. Unlike typical admin tools, this plugin has you enter the commands in chat, very handy if you don’t want to bring up the menu. And don’t worry, the commands won’t be visible to other players.
- admin_slap [name/steamid] [damage] [times to slap] – Slaps the player for X amount of damage and Y amount of times
- admin_slay [name/steamid] – Kills the player
- admin_kick [name/steamid] [minutes] – Kicks the player. Minutes are optional, otherwise uses the time defined by mp_kickbantime
- admin_ban [name/steamid] [minutes] – Bans the player. Minutes are optional, otherwise uses the time defined by mp_bantime
- admin_teleport [name/steamid] [X] [Y] [Z] – Teleports the player to given map coordinates
- admin_sethealth [name/steamid] [amount] – Gives the player X amount of health
- admin_setarmor [name/steamid] [amount] – Gives the player X amount of armor
Your server is now properly equipped with ease-of-access admin commands. Just dont forget to add all necessary steam ids to your admins.txt file! If you ever need to use another admin.txt file, you can re-direct which file to load using the command “adminsfile”.
Also, if a plugin creates console commands, these will have to be entered with a dot (.) at the start. For example, if I created a plugin that fired a rocket everytime I entered the command “firerocket” in the console, it would have to be entered as “.firerocket”.
Conclusion & Final words
You will now have learnt mostly how Sven Coop’s Angelscript plugin system works, how to load further plugins and which type of Angelscript files can be loaded. Whether you’re a map maker or server owner, Angelscript can easily help you add useful functions. As a proof-of-concept and a bonus for finishing this guide, here’s a video of me going through Black Mesa with the newfound Angelscript possibilities.
Thanks for your time and interest in Sven Coop!
-Zergeant