Scorched3D supports a huge amount of functionality "out of the box". However, sometimes you may wish to perform some actions that are specific to your server, and are so specific they will never be in an actual release of Scorched3D. Perhaps you wish to reward players with a certain clan tag, or award more points for different objectives, or even implement a betting system.
Scorched3D allows the server to be enhanced through the use of server side scripts written in the LUA scripting language. These scripts are plugged into the engine and are called when the engine makes certain decisions or performs certain operations.
Note: Currently the framework is in place but the library functions available mean that server side scripting has limited functionality. This will be changed if people show an interest.
The server hooks and scripts need to be placed into a directory called serverhooks in your scorched3d user settings directory. This directory is usualy in :
c:\documents and settings\<user name>\.scorched\serverhooks - for windows
~/.scorched/serverhooks - for unix
The server hooks directory structure is as follows:
.scorched - The scorched3d user settings directory
|
+----> serverhooks - The server hooks directory
|
+---> testscript.lua - A server script file
|
+---> testhook.xml - A server hook file
As previously mentioned Scorched3D can be configured to call a server script (or many scripts) when a specific action occurs. The scripts are hooked into the server by registering them with a hook name. The server has a set of pre-defined hook names that it already knows about. When the server performs certain actions it also executes the scripts registered agains the action's hook name.
The hooks are configured via XML files in the scripts directory (these files must have the .xml file extension).
Script files are the files that contain the actual lua code. There is nothing special about these files except that they must contain the method(s) that were specified in the hooks file.
The scripts are written as LUA files in the scripts directory (these files usualy have the .lua file extension).
function server_channeltextmethod(playerid, channel, text)
print("--server_channeltextmethod---called---");
end
function server_newgamemethod()
print("--server_newgamemethod---called---");
end
This script implements the two methods mentioned in the earlier hook configuration file. The script prints some debugging text to the console whenever these methods are called.
You can use the Scorched3D client (the 3D graphical game) to test your scripts. Since the client also has a server imbedded in it, it will behave the same way as a standalone server.