|Revision as of 15:35, 3 March 2009
Gcamp (Talk | contribs)
← Previous diff
|Revision as of 15:36, 3 March 2009
Gcamp (Talk | contribs)
Next diff →
|Line 9:||Line 9:|
|See [[Scripting|Scorched3D scripting home]] for an introduction to scripting on Scorched3D.||See [[Scripting|Scorched3D scripting home]] for an introduction to scripting on Scorched3D.|
|-||Note: Currently the framework is in place but the library functions available mean that server side scripting has limited functionality.||+||''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.''|
|==Server Side Hooks==||==Server Side Hooks==|
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.
See Scorched3D scripting home for an introduction to scripting on Scorched3D.
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.
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 server hooks 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 hooks are configured via XML files in this directory (these files must have the .xml file extension).
Here is an example hook file:
<hooks> <hook> <filename>testscript.lua</filename> <hook> <hookname>server_channeltext</hookname> <entrypoint>server_channeltextmethod</entrypoint> </hook> <hook> <hookname>server_newgame</hookname> <entrypoint>server_newgamemethod</entrypoint> </hook> </hook> </hooks>
This file registers two hooks, both with the same script file:
A hook file can register any number of hooks.
See server_side_hooks for the hooks currently available.
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.
Here is an example script file:
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.
Unlike weapon scripts it is fine to use global variables in server scripts for any purpose.
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.
Currently there is no debugger for scripts.
There are several console commands you can use to manage the hooks (see Useful_Console_Commands for information on how to access the console).