Tronner is a python powered event handling and scripting framework for Armagetron Advanced. It reacts to events in the game servers ladder log. Inspired by popular web-frameworks such as Flask, the syntax for creating events looks like this:
#!/usr/bin/env python
from tronner import App
app = App()
@app.event('PLAYER_ENTERED')
def player_entered():
print "Greetings, program."
app.run()
- Read installation notes at the bottom of this readme.
- Place script into your
scripts
directory. - Spawn the script with the
SPAWN_SCRIPT
command.
Variables from ladder log can be passed as keyword arguments to the callback function.
@app.event('DEATH_FRAG <killed> <killer>')
def death_frag(killed, killer):
print "%s killed %s for 1 point." % (killer, killed)
To store the entire rest of the line in one variable you can add ...
to the end of it.
@app.event('CHAT <name> <text...>')
def chat_handler(name, text):
print "%s said: %s" % (name, text)
If you're expecting the variable to be something other than string, you can use a variable-prefix like in the example below.
@app.event('ROUND_SCORE <int:score> <name>')
def round_score(name, score):
total_score += score
The part before the colon can either be int
or float
.
Timed events are triggered a number of seconds after a ladder log event occurs. The following function is called 5 minutes after a round starts.
@app.timed_event('NEW_ROUND', 300)
def sudden_death():
print 'CYCLE_RUBBER 0.1'
print 'CYCLE_BRAKE -100'
If you want the function to be triggered periodically, you can set the last parameter to True
.
@app.timed_event('NEW_ROUND', 30, periodic=True)
def spawn_random_deathzone():
pass
The timer for periodic events is reset after every new occurance of the specified event.
Timed events accept an additional name
argument, which can be useful if you ever need to stop or restart the it.
some_timed_event = app.timed_events.get(name="something")
some_timed_event.stop()
some_timed_event.restart()
The command module contains helper function for easier interaction with the server.
from tronner import command
@app.event('PLAYER_LEFT <name>')
def goodbye(name):
command.say("%s has left the server." % name)
For a full list of available command functions, take a look at the command module in the source files.
The commands are written to standard output by default. Depending on how you run your server, this may not be suitable for you. For example, if you are not using SPAWN_SCRIPT
or piping the output of your script to the server directly, you may need to override the main command function.
from tronner import command
def custom_command(s):
"""Untested example. Appends s to end of input.txt"""
with fopen('input.txt', 'a') as fh:
fh.write(s)
command.command = custom_command
Tronner comes with some helper classes that let you keep track of stuff that happens on the grid.
from tronner import Players
players = Players()
@app.event('PLAYER_ENTERED <name> <gid> <ip>')
def player_entered(name, gid, ip):
players.add(name, gid, ip)
@app.event('PLAYER_LEFT <name>')
def player_left(name):
players.safe_remove(name)
@app.event('PLAYER_RENAMED <old_name> <new_name> <ip> <screen_name>)
def player_renamed(old_name, new_name, ip, screen_name):
player = players.get(old_name)
if player:
player.name = new_name
player.screen_name = screen_name
The player objects have a built in stats
attribute which is an instance of Stats
class. You can use it to store some statistics.
@app.event('DEATH_FRAG <killed> <killer>')
def death_frag(killed, killer):
players.get(killed).stats.deaths += 1
players.get(killer).stats.kills += 1
The attributes in Stats
are automatically initiated to 0
if they do not yet exist.
Probably the most useless thing in this package lets you add some color to your messages.
from tronner.color import YELLOW, RED, BLUE, LIME, colorize, gradient, Color
orange = Color(0xff, 0x66, 0)
colorize("Hello!", BLUE)
gradient("This is some text", LIME, BLUE)
More example applications can be found in the examples
directory. To try them out, can import the app
object in your script and run it.
from tronner.examples import greeter
greeter.app.run()
- SQLite bindings for saving statistics
AUTHORITY_BLURB <blurb> <player> <text>
BASEZONE_CONQUERED <team> <cx> <cy>
BASEZONE_CONQUERER <player>
CHAT <chatter> [/me] <chat string>
COMMAND <command> <player> <text>
DEATH_FRAG <prey> <predator>
DEATH_SUICIDE <player>
DEATH_TEAMKILL <prey> <predator>
ENCODING <charset>
GAME_END <date and time>
GAME_TIME <time>
MATCH_WINNER <team> <players>
NEW_MATCH <date and time>
NEW_ROUND <date and time>
NUM_HUMANS <number of humans>
ONLINE_PLAYER <name> [<ping> [<team>]]
PLAYER_ENTERED <name> <IP> <screen name>
PLAYER_LEFT <name> <IP>
PLAYER_RENAMED <old name> <new name> <ip> <screen name>
POSITIONS <team> <player1 player2 ...>
ROUND_SCORE <score difference> <player> [<team>]
ROUND_SCORE_TEAM <score difference> <team>
ROUND_WINNER <team> <players>
SACRIFICE <hole user> <hole maker> <wall owner>
TEAM_CREATED <team name>
TEAM_DESTROYED <team name>
TEAM_PLAYER_ADDED <team name> <player>
TEAM_PLAYER_REMOVED <team name> <player>
TEAM_RENAMED <old team name> <new team name>
Clone the repository to a directory on your server.
$ git clone [email protected]:palei/tronner.git
Create a symlink to tronner in your data/scripts
directory.
$ ln -s /path/to/tronner/ tronner
Also make sure your version of python is at least 2.6!