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
m (Enums)
(Classes)
 
Line 1: Line 1:
Branch
+
==Branch==
 
  lp:~armagetronad-ct/armagetronad/armagetronad-ct
 
  lp:~armagetronad-ct/armagetronad/armagetronad-ct
  
 +
==Overview==
 +
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.
  
==Sample Scripts==
+
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:
 +
* 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...
  
<pre>
+
There's also a few extra features that comes from sty+ct or has been added to provide scripting support:
print("Start scripting initialization.")
+
* 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).
  
import sys, os
+
Eventually, if some servers start using it and this branch becomes somehow useful, we might extend it to other languages as ruby, lua or php, or polish it enough to deserve to be merged in its right place: armagetron mainline.
print os.getcwd()
+
sys.path.append('./src/swig/ext/')
+
import armagetronad
+
  
ci = armagetronad.tConfItemBase.FindConfigItem("CYCLE_SPEED")
+
==Install==
 +
We are working on linux only and there's no support for any other plateform. So here is a raw install procedure for debian/ubuntu users :
  
def round_winner(args):
+
First, get armagetron dependencies:
    print "start round winner ladder log writer callback"
+
Check the following wiki pages, section "Building from sources".
    armagetronad.tConfItemBase.LoadString("CYCLE_SPEED 100")
+
http://wiki.armagetronad.net/index.php?title=Ubuntu_Installation
    print args
+
    print "end round winner ladder log writer callback"
+
  
rw=armagetronad.ladder_log_writer.get_writer("ROUND_WINNER")
+
Add extra dependencies for scripting. For python:
if rw.is_enabled():
+
  sudo apt-get install python-dev swig
    rw.setCallback(round_winner)
+
    print "round_winner enabled!"
+
  
print("End scripting initialization.")
+
Get the branch:
</pre>
+
  bzr co  lp:~armagetronad-ct/armagetronad/armagetronad-ct
<pre>
+
print("Start scripting initialization.")
+
  
import sys, os
+
Build with scripting enabled:
print os.getcwd()
+
  cd armagetronad-ct
sys.path.append('./src/swig/ext/')
+
  ./bootstrap.sh
import armagetronad
+
  ./configure --disable-etc --enable-python --disable-glout --prefix=/your/install/dir/here --enable-armathentication
 +
      --enable-automakedefaults --disable-useradd --disable-initscripts
 +
  make
 +
  make install
  
def player_entered(args):
+
==Running a server==
    p=args[1]
+
The server expects to find scripting related files in a specific place: a subdirectory of armagetron data directory called "scripts".
    print args
+
More precisely, it expects to find a file called initialize.py. File extension vary depending on scripting language. So far, as only python support exists, we'll assume we are working with python as during install part.
  
def round_winner(args):
+
The first step will be to set up out server specific directory tree. Personaly, I like to keep all config, var, and scripts directory in one place for a specific server. So let's start by setting up our directory tree:
    p=args[1]
+
  /home/username/tron/servers/hello_scripting
    print args
+
      ./config
    print("PLAYER_MESSAGE "+p+' "Congratulation from script '+p+' !"')
+
      ./var
    armagetronad.ConfItemBase.LoadString("PLAYER_MESSAGE "+p+' "Congratulation from script '+p+' !"')
+
      ./scripts
    ci = armagetronad.ConfItemBase.FindConfigItem("CYCLE_SPEED")
+
    print "cycle_speed " + ci.WriteVal()
+
    ci.ReadVal("20")
+
  
def script_config(args):
+
I'll assume you have include into the config subdir your config files.
    print ">", args
+
  
t = armagetronad.ConfItemScript("TEST_SCRIPT", script_config)
+
So far, you'll have to copy the armagetronad.py file generated by swig during compilation into the scripts directory. This file is located into the src/swig/ext subdir in you source file directory (the armagetronad-ct directory from install step). Eventually, this file must be copied with other required files into the installation data scripts subdirectory. In this case, this directory should be append in initialize.py below.
 +
Warning, don't forget to update this file each time you reinstall/update your armagetronad-dedicated binary.
  
armagetronad.LadderLogWriter.get_writer("ROUND_WINNER").set_callback(round_winner)
+
You'll have to create the scripts/initialize.py file and include a few lines in it:
armagetronad.LadderLogWriter.get_writer("PLAYER_ENTERED").set_callback(player_entered)
+
  print("Start scripting initialization.")
 +
 
 +
  import sys
 +
  sys.path.append('/home/username/tron/servers/hello_scripting/scripts/')
 +
  import armagetronad
 +
 
 +
  # your code goes here
 +
 
 +
  print("End scripting initialization.")
  
print("End scripting initialization.")
+
Done!
</pre>
+
 
==Enums==
+
Let's run it, taking care of setting the userdata directory
 +
  /path/to/your/binary/armagetron-dedicated --userdatadir="/home/username/tron/servers/hello_scripting/"
 +
 
 +
==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 77: Line 90:
 
     tAccessLevel_Invalid = 255
 
     tAccessLevel_Invalid = 255
  
==Classes==
+
===Types===
 +
{{ClassSetting|Color|}}
 +
  r
 +
  g
 +
  b
 +
  a
 +
 
 +
 
 +
{{ClassSetting|Coord|}}
 +
  x
 +
  y
 +
 
 +
===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 98: Line 123:
 
   append(Output o)
 
   append(Output o)
 
   bool is_empty()
 
   bool is_empty()
 
 
{{ClassSetting|Color|}}
 
  r
 
  g
 
  b
 
  a
 
 
{{ClassSetting|Coord|}}
 
  x
 
  y
 
  
  
 
{{ClassSetting|ConfItem|}}
 
{{ClassSetting|ConfItem|}}
 
   AccessLevel required_level()
 
   AccessLevel required_level()
   load_all(string s);
+
   load_all(string s)
 
   load_line()
 
   load_line()
 
   static ConfItem find(string name)
 
   static ConfItem find(string name)
Line 131: 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 151: Line 166:
  
 
{{ClassSetting|Player|}}
 
{{ClassSetting|Player|}}
  bool is_chatting()
+
{{ClassFunction|is_chatting()| bool - tells if the player is chatting}}
  bool is_spectating()
+
{{ClassFunction|is_spectating()| bool - tells if the player is on the grid or not}}
  bool stealth_mode()
+
{{ClassFunction|stealth_mode()| bool - ???}}
  bool is_team_change_allowed(bool informPlayer=false)   //!< is this player allowed to change teams?
+
{{ClassFunction|is_team_change_allowed(bool informPlayer=false)| bool - is this player allowed to change teams?}}
  set_team_change_allowed(bool allowed)         //!< set if this player should always be allowed to change teams
+
{{FunctionParameter|informPlayer|???}}
 +
{{ClassFunction|set_team_change_allowed(bool allowed)| set if this player should always be allowed to change teams}}
 +
{{FunctionParameter|allowed|}}
 
   Team next_team()              //!< return the team I will be next round
 
   Team next_team()              //!< return the team I will be next round
 
   Team current_team()              //!< return the team I am in
 
   Team current_team()              //!< return the team I am in
Line 209: 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)
 +
 +
 +
{{ClassSetting|ChatCommand|}}
 +
  ChatCommand(string ID, proc, AccessLevel level)
 +
  set_access_level (AccessLevel level)
 +
  static ChatCommand find(string ID)
  
  
Line 214: 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 256: 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 315: Line 318:
 
   real lag()        //!< expected average network latency
 
   real lag()        //!< expected average network latency
 
   real lag_threshold()      //!< tolerated network latency variation
 
   real lag_threshold()      //!< tolerated network latency variation
 +
 +
 +
{{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.
 +
<pre>
 +
print("Start scripting initialization.")
 +
 +
import sys
 +
sys.path.append('/path/to/armagetronad.py/file/')
 +
import armagetronad
 +
</pre>
 +
 +
===Change/get game settings===
 +
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:
 +
<pre>
 +
armagetronad.ConfItem.load_all("CONSOLE_MESSAGE test line\n")
 +
armagetronad.ConfItem.load_line("CONSOLE_MESSAGE test line 4\nCONSOLE_MESSAGE test line 5\nCONSOLE_MESSAGE test line 6")
 +
</pre>
 +
 +
You can also look for the corresponding setting item so you can use it as much as you want:
 +
<pre>
 +
console_message_conf=armagetronad.ConfItem.find("CONSOLE_MESSAGE")
 +
console_message_conf.set("Welcome from scripting ...\n")
 +
</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.
 +
<pre>
 +
def round_winner(args):
 +
    p=args[1]
 +
    print args
 +
    print("PLAYER_MESSAGE "+p+' "Congratulation from script '+p+' !"')
 +
    armagetronad.ConfItem.load_line("PLAYER_MESSAGE "+p+' "Congratulation from script '+p+' !"')
 +
    ci = armagetronad.ConfItem.find("CYCLE_SPEED")
 +
    print "cycle_speed " + ci.get()
 +
    ci.set("20")
 +
 +
def new_round(args):
 +
    ci = armagetronad.ConfItem.find("CONSOLE_MESSAGE")
 +
    ci.set(str(armagetronad.Team.num_teams()))
 +
    for i in range(armagetronad.Team.num_teams()):
 +
        t=armagetronad.Team.team(i)
 +
        ci.set("Team name: "+t.name()
 +
        for i in range(t.num_players()):
 +
            p=t.player(i)
 +
            ci.set("Player name: "+p.name())
 +
 +
armagetronad.LadderLogWriter.find("ROUND_WINNER").set_callback(round_winner)
 +
armagetronad.LadderLogWriter.find("NEW_ROUND").set_callback(new_round)
 +
</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.
 +
Let's build a RESPAWN_PLAYER command:
 +
<pre>
 +
def respawn_player(args):
 +
    # first parse parameters: <player name> <message flag> <x> <y> <dirx> <diry>
 +
    lst = args.split()
 +
    player = armagetronad.Player.find_player(lst[0])
 +
    flag  = int(lst[1])
 +
    pos    = armagetronad.Coord(float(lst[2]), float(lst[3]))
 +
    dirt  = armagetronad.Coord(float(lst[4]), float(lst[5]))
 +
    armagetronad.Cycle.respawn_cycle(pos, dirt, player, flag)
 +
   
 +
respawn_player_conf = armagetronad.ConfItemScript("RESPAWN_PLAYER", respawn_player)
 +
respawn_player_access_level = armagetronad.AccessLevelSetter(respawn_player_conf, armagetronad.tAccessLevel_Moderator)
 +
</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 :
 +
<pre>
 +
def substitute(args):
 +
    lst = args.split()
 +
    print lst
 +
    p_out = armagetronad.Player.find_player(lst[1])
 +
    p_in = armagetronad.Player.find_player(lst[2])
 +
    if (not p_out.is_spectating()) and p_in.is_spectating():
 +
        t = p_out.current_team()
 +
        p_out.join_team(None)
 +
        p_in.join_team(t)
 +
    else:
 +
        print "can't substitute !"
 +
 +
cc = armagetronad.ChatCommand("/substitute",substitute,armagetronad.tAccessLevel_Moderator)
 +
</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