Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 717

Warning: Invalid argument supplied for foreach() in /var/www/ct/forums/wiki/includes/MagicWord.php on line 718

Warning: preg_replace(): Compilation failed: group name must start with a non-digit at offset 4 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 722

Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 717

Warning: Invalid argument supplied for foreach() in /var/www/ct/forums/wiki/includes/MagicWord.php on line 718

Warning: preg_replace(): Compilation failed: group name must start with a non-digit at offset 4 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 722

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 739

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 739

Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 717

Warning: Invalid argument supplied for foreach() in /var/www/ct/forums/wiki/includes/MagicWord.php on line 718

Warning: preg_replace(): Compilation failed: group name must start with a non-digit at offset 4 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 722

Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 717

Warning: Invalid argument supplied for foreach() in /var/www/ct/forums/wiki/includes/MagicWord.php on line 718

Warning: preg_replace(): Compilation failed: group name must start with a non-digit at offset 4 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 722

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 739

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 739

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 739

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 739

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 739

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 739

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 739

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 739

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 739

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 739

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 739

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 739

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 739

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 739

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 739

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 739

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 739

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 739

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 739

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 739

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 739

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 739

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 739

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 739

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 739

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 739

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 739

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 739

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 739

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 739

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 739

Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 717

Warning: Invalid argument supplied for foreach() in /var/www/ct/forums/wiki/includes/MagicWord.php on line 718

Warning: preg_replace(): Compilation failed: group name must start with a non-digit at offset 4 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 722

Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 717

Warning: Invalid argument supplied for foreach() in /var/www/ct/forums/wiki/includes/MagicWord.php on line 718

Warning: preg_replace(): Compilation failed: group name must start with a non-digit at offset 4 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 722

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 739

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 739

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 739

Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 717

Warning: Invalid argument supplied for foreach() in /var/www/ct/forums/wiki/includes/MagicWord.php on line 718

Warning: preg_replace(): Compilation failed: group name must start with a non-digit at offset 4 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 722

Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 717

Warning: Invalid argument supplied for foreach() in /var/www/ct/forums/wiki/includes/MagicWord.php on line 718

Warning: preg_replace(): Compilation failed: group name must start with a non-digit at offset 4 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 722

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 739

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /var/www/ct/forums/wiki/includes/MagicWord.php on line 739
Crazy Tronners Wiki - Trunk Scripting

Trunk Scripting

From Tronwiki
Jump to: navigation, search
(Setting up a server)
(Classes)
 
Line 5: Line 5:
 
The armagetronad-ct branch comes from an attempt to build armagetronad trunk with scripting enabled. As I faced issues compiling or running it with ruby, and the underlying wrapper, swig, support most of the common scripting language, I started this branch to add an abstraction layer, and eventually, introduce other scripting language support.
 
The armagetronad-ct branch comes from an attempt to build armagetronad trunk with scripting enabled. As I faced issues compiling or running it with ruby, and the underlying wrapper, swig, support most of the common scripting language, I started this branch to add an abstraction layer, and eventually, introduce other scripting language support.
  
At this time, we were switching our script from php to python, and I was unable to compile with ruby, so I've give Python a try ...
+
At this time, we were switching our script from php to python, and I was unable to compile with ruby, so I'd give Python a try ...
 
   
 
   
 
Armagetronad-ct is nothing but an experimental branch, as were armahacktron and sty+ct, based on armagetron trunk, currently being 0.3.x serie. Therefore, there are two major differences with sty+ct:
 
Armagetronad-ct is nothing but an experimental branch, as were armahacktron and sty+ct, based on armagetron trunk, currently being 0.3.x serie. Therefore, there are two major differences with sty+ct:
- sty is not (yet) fully ported to 0.3.x serie and has not been included to this branch. So no flags, no balls, no zombies, no shooting...
+
* sty is not (yet) fully ported to 0.3.x serie and has not been included to this branch. So no flags, no balls, no zombies, no shooting...
- although you can compile (still true?) trunk with zones v1 or v2, this branch has scripting support for zones v2 only...
+
* although you can compile (still true?) trunk with zones v1 or v2, this branch has scripting support for zones v2 only...
  
 +
There's also a few extra features that comes from sty+ct or has been added to provide scripting support:
 +
* DELAY_COMMAND comes from sty+ct.
 +
* INGAME_PARSING, INGAME_PARSING_DTD_VALIDATION and INGAME_PARSING_DTD allow to parse additional data during a round. It's meant to be use for zones. Any other parsing might be confusing and might lead to undefine behavior.
 +
 
Although this branch main target is dedicated server, it might be extended to some client side features. For example, you can define new chat command from scripting on server side. This might be extended to client side soon as it allows to build dynamic instant messages (ex: /hi [<playername>] to salute last entered or specified player(s).
 
Although this branch main target is dedicated server, it might be extended to some client side features. For example, you can define new chat command from scripting on server side. This might be extended to client side soon as it allows to build dynamic instant messages (ex: /hi [<playername>] to salute last entered or specified player(s).
  
Line 67: Line 71:
 
   /path/to/your/binary/armagetron-dedicated --userdatadir="/home/username/tron/servers/hello_scripting/"
 
   /path/to/your/binary/armagetron-dedicated --userdatadir="/home/username/tron/servers/hello_scripting/"
  
==Enums==
+
==Constants, Types and Classes==
 +
===Enums===
 
{{ClassSetting|AccessLevel|enumeration used to check authentication level}}
 
{{ClassSetting|AccessLevel|enumeration used to check authentication level}}
 
     tAccessLevel_Owner = 0,
 
     tAccessLevel_Owner = 0,
Line 85: Line 90:
 
     tAccessLevel_Invalid = 255
 
     tAccessLevel_Invalid = 255
  
==Types==
+
===Types===
 
{{ClassSetting|Color|}}
 
{{ClassSetting|Color|}}
 
   r
 
   r
Line 97: Line 102:
 
   y
 
   y
  
 
+
===Classes===
==Classes==
+
 
{{ClassSetting|armagetronad.LadderLogWriter|Ladderlog stuff}}
 
{{ClassSetting|armagetronad.LadderLogWriter|Ladderlog stuff}}
 
{{ClassFunction|get_writer(string llog)| Read ladderlog}}
 
{{ClassFunction|get_writer(string llog)| Read ladderlog}}
Line 141: Line 145:
 
   eLadderLogWriter(string ID, bool enabledByDefault)
 
   eLadderLogWriter(string ID, bool enabledByDefault)
 
   static LadderLogWriter find(string ID)
 
   static LadderLogWriter find(string ID)
   bool is_enabled()         //!< check this if you're going to make expensive calculations for ladderlog output
+
   bool is_enabled()           //!< check this if you're going to make expensive calculations for ladderlog output
   enabled(bool b)           //!< set or unset enabled flag
+
   enabled(bool b)             //!< set or unset enabled flag
   static set_all(bool enabled)     //!< enable or disable all writers
+
   static set_all(bool enabled) //!< enable or disable all writers
   set_callback(proc)         //!< bind a procedure from scripting language to this ladder log writer.
+
   set_callback(proc)           //!< bind a procedure from scripting language to this ladder log writer.
 +
  unset_callback(proc)        //!< unbind a procedure from scripting language to this ladder log writer.
  
  
Line 221: Line 226:
 
   Player set_name(string name)            //!< Sets this player's name. Sets processed names (colored, username, nameFromCLient) as well.
 
   Player set_name(string name)            //!< Sets this player's name. Sets processed names (colored, username, nameFromCLient) as well.
 
   Player set_user_name(string userName)        //!< Sets this player's name, cleared for system logs. Use for writing to files or comparing with admin input. The other names stay unaffected.
 
   Player set_user_name(string userName)        //!< Sets this player's name, cleared for system logs. Use for writing to files or comparing with admin input. The other names stay unaffected.
 +
  center_message(string)
  
  
Line 232: Line 238:
 
   static int num_teams()
 
   static int num_teams()
 
   static Team team(int i)
 
   static Team team(int i)
 +
  declare_winner(string message)
 
   int rounds_played()      //!< number of rounds played (updated right after spawning, so it includes the current round)
 
   int rounds_played()      //!< number of rounds played (updated right after spawning, so it includes the current round)
 
   set_locked(bool locked)      //!< sets the lock status (whether invitations are required)
 
   set_locked(bool locked)      //!< sets the lock status (whether invitations are required)
Line 274: Line 281:
 
   unsigned short blue()
 
   unsigned short blue()
 
   string name()
 
   string name()
 
 
{{ClassSetting|SpawnPoint|}}
 
  SpawnPoint(Coord loc, Coord dir)
 
  Coord position()
 
  Coord direction()
 
  spawn(Coord loc, Coord dir)
 
  real danger()
 
  clear()
 
 
 
{{ClassSetting|Arena|}}
 
  static Arena get_arena()
 
  int winding_number()
 
  int direction_winding(const eCoord& dir)
 
  Coord get_direction(int winding)
 
  new_spawn_point(Coord loc, Coord dir)
 
  Coord get_random_pos( REAL factor )
 
  SpawnPoint closest_spawn_point(Coord loc)
 
  SpawnPoint least_dangerous_spawn_point()
 
  static real size_multiplier()
 
  remove_all_spawn()
 
  
  
Line 334: Line 319:
 
   real lag_threshold()      //!< tolerated network latency variation
 
   real lag_threshold()      //!< tolerated network latency variation
  
==Sample Scripts==
 
  
 +
{{ClassSetting|SpawnPoint|}}
 +
  SpawnPoint(Coord loc, Coord dir)
 +
  Coord position()
 +
  Coord direction()
 +
  spawn(Coord loc, Coord dir)
 +
  real danger()
 +
  clear()
 +
 +
 +
{{ClassSetting|Arena|}}
 +
  static Arena get_arena()
 +
  int winding_number()
 +
  int direction_winding(const eCoord& dir)
 +
  Coord get_direction(int winding)
 +
  new_spawn_point(Coord loc, Coord dir)
 +
  Coord get_random_pos( REAL factor )
 +
  SpawnPoint closest_spawn_point(Coord loc)
 +
  SpawnPoint least_dangerous_spawn_point()
 +
  static real size_multiplier()
 +
  remove_all_spawn()
 +
 +
==Sample Scripts==
 +
===Initialization===
 
You'll first have to load armagetronad module which also required to set path accordingly.
 
You'll first have to load armagetronad module which also required to set path accordingly.
 
<pre>
 
<pre>
Line 341: Line 348:
  
 
import sys
 
import sys
sys.path.append('/home/me/tron/server/bin/')
+
sys.path.append('/path/to/armagetronad.py/file/')
 
import armagetronad
 
import armagetronad
 
</pre>
 
</pre>
  
 +
===Change/get game settings===
 
You might want to change some settings from scripting. There's 2 ways to achieve that.
 
You might want to change some settings from scripting. There's 2 ways to achieve that.
 
You can send a string as you can do from console:
 
You can send a string as you can do from console:
Line 358: Line 366:
 
</pre>
 
</pre>
  
 +
You might want to get or test any setting value (well, except those bind to a procedure like SPAWN_ZONE:
 +
<pre>
 +
num_ais_conf=armagetronad.ConfigItem.find("NUM_AIS").get()
 +
</pre>
 +
 +
===Game events===
 
You might want to react on game event. You can do it binding a procedure to a ladder log message.
 
You might want to react on game event. You can do it binding a procedure to a ladder log message.
 
<pre>
 
<pre>
Line 382: Line 396:
 
armagetronad.LadderLogWriter.find("NEW_ROUND").set_callback(new_round)
 
armagetronad.LadderLogWriter.find("NEW_ROUND").set_callback(new_round)
 
</pre>
 
</pre>
 +
Any script procedure binded to a ladder log message must take a single argument (here named args). This argument is a list of 0 to n value of any type, depending on the value returned by corresponding ladder log message.
  
 +
Change:
 +
LadderLogWriter now allows multiple bindings, and unbinding too. This is particulary convinient to organize you script code and also to change bindings according to maps. There's no change in the binding logic. Unbinding is straighforward, too.
 +
Please note that bindings are managed as a queue: they are run in the very same order they are bound to an event. There's no way to reorganize bindings other then remove and requeue them.
 +
 +
===Create new Commands\Settings===
 
You might be able to define new command from scripting. The new command will be available from console within the game, from other console commands like DELAY_COMMAND.
 
You might be able to define new command from scripting. The new command will be available from console within the game, from other console commands like DELAY_COMMAND.
 +
Let's build a RESPAWN_PLAYER command:
 
<pre>
 
<pre>
 
def respawn_player(args):
 
def respawn_player(args):
Line 395: Line 416:
 
      
 
      
 
respawn_player_conf = armagetronad.ConfItemScript("RESPAWN_PLAYER", respawn_player)
 
respawn_player_conf = armagetronad.ConfItemScript("RESPAWN_PLAYER", respawn_player)
respawn_player_access_level = armagetronad.AccessLevelSetter(test, armagetronad.tAccessLevel_Moderator)
+
respawn_player_access_level = armagetronad.AccessLevelSetter(respawn_player_conf, armagetronad.tAccessLevel_Moderator)
 
</pre>
 
</pre>
  
 +
Every command defined in scripting must take a single argument (here named args).
 +
Don't forget to set the appropriate access level! Default one is Owner.
 +
 +
===Chat commands===
 
You're now able to define chat commands. Here's an example :
 
You're now able to define chat commands. Here's an example :
 
<pre>
 
<pre>
Line 414: Line 439:
 
cc = armagetronad.ChatCommand("/substitute",substitute,armagetronad.tAccessLevel_Moderator)
 
cc = armagetronad.ChatCommand("/substitute",substitute,armagetronad.tAccessLevel_Moderator)
 
</pre>
 
</pre>
 +
Once again, command chat must take exactly one argument which will be a list of exactly 1 string. Pretty pointless list but it's to handle all bindings the very same way.

Latest revision as of 17:19, 26 August 2010

Personal tools