Introduction
Before reading this you should be familiar with tremulous scripting (set, vstr, ...), you MUST know how to use the admin system, and it is better to be the owner of a server, to know useful cvars, admin.dat and so on ...
There is a lot of admin commands built in the server, but we cannot include all the possible commands, moreover most of the commands you'll want to be added are some server specific commands like !train when your have a clanwar or !friendlyfireon etc ...
Perhaps you don't know it but there is a way to do it without changing the source-code of tremulous.
You can do it by adding a section in the admin.dat file (or whatever file contains the admin and ban data). That section looks like that:
[command] command = train exec = exec train.cfg desc = Lock the server for a clan war. levels = 4 5
- The "command" attributes is the name of the command, here to lock the server the admin will have to type !train.
- "exec" will be the tremulous script that will be executed when an admin will use the command, here it executes the tremulous script contained (which could set g_needpass to 1, change the name of the server etc ...)
- "desc" is a short description that will be showed when tiping !help <command> (here !help train will print "Lock the server for a clan war.")
- "levels" is a space separated list of the admin levels that are able to use that command, since the train command locks the server, we only want high-level admins to be able to use it.
But that system with no changes is quite limited, you cannot make commands to be used with arguments like !friendlyfire (with the on or off argument). Our server adds these fuctionalities, in fact making a !friendlyfire command is easy. We will see how to do it.
Using arguments in your scripted commands
To allow you to make (far) better scripted admin commands, we added a way to retrieve arguments given when calling the commands. Let's look at an example: when doing !friendlyfire on the server automatically sets arg_1 to "on" (without quotes), arg_count to 1 and arg_all to "on".
In a more general way, arg_count is the number of arguments (words) given, arg_all contains the all the arguments (keeping spaces as entered by the admin) and arg_n (n a positive integer) contains the n-ieth argument.
But being able to retrieve these arguments is not enough, you'll want to use them. We added a concatenation method, '#foo' will be replaced with the content of the foo cvar, if that cvar doesn't exist, '#foo' is left as-is. For example it is quite simple to make a basic !ff (friendly fire) command by making it execute this script:
set g_friendlyfire '#arg_1'
But it has got some issues, what does happen if and admin type !ff 2 ? ... Go to the "Good scripting methods" to learn how to check that the input is valid. You might be tempted to make a !cp (centerprint) command by using executing that script:
cp '#arg_all'
But if that script is not located in admin.dat it will fail miserably... that is because we added another feautre that imitates functions.
Using "functions" like in other programming langages
We made a way to reuse the code you made using the exec command. In fact exec works exactly like an admin command: exec bar.cfg baz will set arg_1 to "baz", arg_count to 1 and arg_all to "baz". That way you can reuse several time the same script but with arguments.
