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_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
Crazy Tronners Wiki - Trunk Scripting

Trunk Scripting

From Tronwiki
Jump to: navigation, search
(Sample Scripts)
Line 263: Line 263:
 
==Sample Scripts==
 
==Sample Scripts==
  
 +
You'll first have to load armagetronad module which also required to set path accordingly.
 
<pre>
 
<pre>
 
print("Start scripting initialization.")
 
print("Start scripting initialization.")
  
import sys, os
+
import sys
print os.getcwd()
+
sys.path.append('/home/me/tron/server/bin/')
sys.path.append('./src/swig/ext/')
+
 
import armagetronad
 
import armagetronad
 +
</pre>
  
ci = armagetronad.tConfItemBase.FindConfigItem("CYCLE_SPEED")
+
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>
  
def round_winner(args):
+
You can also look for the corresponding setting item so you can use it as much as you want:
    print "start round winner ladder log writer callback"
+
<pre>
    armagetronad.tConfItemBase.LoadString("CYCLE_SPEED 100")
+
console_message_conf=armagetronad.ConfItem.find("CONSOLE_MESSAGE")
    print args
+
console_message_conf.set("Welcome from scripting ...\n")
    print "end round winner ladder log writer callback"
+
</pre>
  
rw=armagetronad.ladder_log_writer.get_writer("ROUND_WINNER")
+
You might want to react on game event. You can do it binding a procedure to a ladder log message.
if rw.is_enabled():
+
    rw.setCallback(round_winner)
+
    print "round_winner enabled!"
+
 
+
print("End scripting initialization.")
+
</pre>
+
 
<pre>
 
<pre>
print("Start scripting initialization.")
 
 
import sys, os
 
print os.getcwd()
 
sys.path.append('./src/swig/ext/')
 
import armagetronad
 
 
def player_entered(args):
 
    p=args[1]
 
    print args
 
 
 
def round_winner(args):
 
def round_winner(args):
 
     p=args[1]
 
     p=args[1]
 
     print args
 
     print args
 
     print("PLAYER_MESSAGE "+p+' "Congratulation from script '+p+' !"')
 
     print("PLAYER_MESSAGE "+p+' "Congratulation from script '+p+' !"')
     armagetronad.ConfItemBase.LoadString("PLAYER_MESSAGE "+p+' "Congratulation from script '+p+' !"')
+
     armagetronad.ConfItem.load_line("PLAYER_MESSAGE "+p+' "Congratulation from script '+p+' !"')
     ci = armagetronad.ConfItemBase.FindConfigItem("CYCLE_SPEED")
+
     ci = armagetronad.ConfItem.find("CYCLE_SPEED")
     print "cycle_speed " + ci.WriteVal()
+
     print "cycle_speed " + ci.get()
     ci.ReadVal("20")
+
     ci.set("20")
  
def script_config(args):
+
def new_round(args):
     print ">", 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())
  
t = armagetronad.ConfItemScript("TEST_SCRIPT", script_config)
+
armagetronad.LadderLogWriter.find("ROUND_WINNER").set_callback(round_winner)
 +
armagetronad.LadderLogWriter.find("NEW_ROUND").set_callback(new_round)
 +
</pre>
  
armagetronad.LadderLogWriter.get_writer("ROUND_WINNER").set_callback(round_winner)
+
You might be able to define new command from scripting.
armagetronad.LadderLogWriter.get_writer("PLAYER_ENTERED").set_callback(player_entered)
+
<pre>
 
+
def respawn_player(args):
print("End scripting initialization.")
+
    # 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(test, armagetronad.tAccessLevel_Moderator)
 
</pre>
 
</pre>

Revision as of 21:12, 19 January 2010

Personal tools