Trunk Scripting
Branch
lp:~armagetronad-ct/armagetronad/armagetronad-ct
Contents |
Enums
AccessLevel - enumeration used to check authentication level
tAccessLevel_Owner = 0, tAccessLevel_Admin = 1, tAccessLevel_Moderator = 2, tAccessLevel_Armatrator = 5, tAccessLevel_Referee = 6, tAccessLevel_TeamLeader = 7, tAccessLevel_TeamMember = 8, tAccessLevel_Local = 12, tAccessLevel_Remote = 15, tAccessLevel_DefaultAuthenticated = 15, tAccessLevel_FallenFromGrace = 16, tAccessLevel_Shunned = 17, tAccessLevel_Authenticated = 19, tAccessLevel_Program = 20, tAccessLevel_Invalid = 255
Types
Color -
r g b a
Coord -
x y
Classes
armagetronad.LadderLogWriter - Ladderlog stuff
- get_writer(string llog) - Read ladderlog
- llog - The ladderlog message you wish to recieve
- is_enabled() - is_enabled()
- set_all(bool on) - All ladderlog messages on or off
- on - All ladderlog messages On or off
- set_callback(function func) - Callback function
- func - the function you declare
Output -
Output(string identifier) add_literal(string) add_locale(string) add_space() Output set_template_parameter_string(int num, string parameter) Output set_template_parameter_float(int num, float parameter) clear() append(Output o) bool is_empty()
ConfItem -
AccessLevel required_level() load_all(string s); load_line() static ConfItem find(string name) set(string s) get(string s)
AccessLevelSetter -
tAccessLevelSetter(ConfItem item, AccessLevel level)
ConfItemScript -
ConfItemScript(string title, function proc);
LadderLogWriter -
eLadderLogWriter(string ID, bool enabledByDefault) static LadderLogWriter find(string ID) bool is_enabled() //!< check this if you're going to make expensive calculations for ladderlog output enabled(bool b) //!< set or unset enabled flag static set_all(bool enabled) //!< enable or disable all writers set_callback(proc) //!< bind a procedure from scripting language to this ladder log writer.
PlayerConf -
string name() string team_name() int id() PlayerConf player_config(int p) bool is_in_game(int p)
AccessLevelHolder -
AccessLevel get_access_level() set_access_level(AccessLevel level)
Player -
bool is_chatting()
bool is_spectating()
bool stealth_mode()
bool is_team_change_allowed(bool informPlayer=false) //!< is this player allowed to change teams?
set_team_change_allowed(bool allowed) //!< set if this player should always be allowed to change teams
Team next_team() //!< return the team I will be next round
Team current_team() //!< return the team I am in
int team_position() //!< return my position in the team
Team find_default_team() //!< find a good default team for us
join_default_team() //!< register me in a good default team
join_team(Team team) //!< register me in the given team (callable on the server)
join_team_wish(Team team) //!< express the wish to be part of the given team (always callable)
team_name(string) //!< set teamname to be used for my own team
update_team() //!< update team membership
create_new_team() //!< create a new team and join it (on the server)
create_new_team_wish() //!< express the wish to create a new team and join it
static bool is_enemy(Player a, Player b) //!< determines whether two players are opponents and can score points against each other
remove_from_game() //!< suspend the player from playing, forcing him to spectate
suspend(int rounds = 5)
authenticate(string authName, AccessLevel accessLevel = tAccessLevel_Authenticated,
Player admin = 0, bool messages = true) //!< make the authentification valid
deauthenticate(Player admin = 0, bool messages = true) //!< make the authentification invalid
bool is_authenticated() //!< is the authentification valid?
bool is_active()
bool is_silenced()
set_silenced(bool silenced)
bool is_suspended()
bool is_human()
add_score_output(int points, Output reasonwin, Output reasonlose)
int score()
int total_score()
static string ranking(int MAX=12, bool cut = true) //!< returns a ranking list
static real ranking_graph(real y, int MAX) //!< prints a ranking list
static reset_score() //!< resets the ranking list
static remove_chatbots() //!< removes chatbots and idling players from the game
static complete_rebuild() //!< same as above, but rebuilds every ePlayerNetID.
static clear_all() //!< deletes all ePlayerNetIDs.
static spectate_all(bool spectate=true) //!< puts all players into spectator mode.
chat(string s)
set_color(real r, real g, real b)
set_trail_color(real r, real g, real b)
bool is_logged_in()
be_logged_in()
be_not_logged_in()
AccessLevel get_last_access_level()
Cycle cycle()
static Player find_player(string name) //!< finds a player by name using lax name matching.
static int players_count()
static Player players_get(int i)
static string filter_name(string in) //!< filters a name (removes unprintables, color codes and spaces)
bool is_allowed_to_rename() //!< tells if the user can rename or not, takes care about everything
allow_rename(bool allow) //!< Allows a player to rename (or not)
string name() //!< Gets this player's name without colors.
string user_name() //!< Gets this player's full name. Use for writing to files or comparing with admin input.
string log_name() //!< Gets this player's name, cleared for system logs (with escaped special characters). Use for writing to files.
string filtered_authenticated_name() //!< Gets the filtered, ecaped authentication name
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.
Team -
static int num_teams() static Team team(int i) 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) bool is_locked() //!< returns the lock status bool is_locked_for(Player p) //!< returns if a team is locked to join by a certain player (due to ACCESS_LEVEL_PLAY) invite(Player player) //!< invite the player to join uninvite(Player player) //!< revoke an invitation bool is_invited(Player player) //!< check if a player is invited static bool is_enemy_player(Team team, Player player) //!< determines whether the player is an enemy of the team static bool is_enemy_team(Team team1, Team team2) //!< determines whether two teams are enemies static string ranking(int MAX = 6, bool cut = true) //!< return ranking information static real ranking_graph(real y, int MAX = 6) //!< print ranking information add_player(Player player) //!< register a player remove_player(Player player) //!< deregister a player bool player_may_join(Player player) //!< see if the given player may join this team bool is_new_team_allowed() //!< is it allowed to create a new team? static swap_players(Player player1, Player player2) //!< swaps the team positions of the two players (same team or not) shuffle(int startID, int stopID) //!< shuffles the player at team postion startID to stopID bool balance_this_team() bool is_human() int team_id() int score() add_score(int s) reset_score() set_score(int s) add_score_output(int points, Output reasonwin, Output reasonlose) int num_players() Player player(int i) vector_Player players() int num_human_players() //!< number of human players int num_ai_players() //!< number of AI players int alive_players() //!< how many of the current players are currently alive? Player oldest_player() // the oldest player Player oldest_human_player() // the oldest human player Player oldest_ai_player // the oldest AI player Player youngest_player() // the youngest player Player youngest_human_player() // the youngest human player Player youngest_ai_player() // the youngest AI player bool is_alive() // is any of the players currently alive? unsigned short red() unsigned short green() unsigned short blue() string name()
SpawnPoint -
SpawnPoint(Coord loc, Coord dir) Coord position() Coord direction() spawn(Coord loc, Coord dir) real danger() clear()
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()
Cycle -
int winding_number() bool vulnerable() static bool respawn_cycle(Coord pos, Coord dir, Player p, bool warn=true) real max_walls_length() real this_walls_length() request_sync_owner() request_sync_all RequestSyncAll bool do_turn(int dir) drop_wall( bool buildNew=true ) inherited from gCycleMovement: Coord spawn_direction() move_safely(Coord dest, real startTime, real endTime) real get_distance() real get_rubber() unsigned short get_turns() unsigned short get_braking() real get_braking_reservoir() Coord get_last_turn_pos() real get_last_turn_time() real get_acceleration() set_rubber(real rubber) set_braking_reservoir(real brakingReservoir) inherited from eGameObject: real last_time() Coord position() Coord direction() Coord last_direction real death_time() real speed() kill() bool alive() //! tells whether the object is alive real lag() //!< expected average network latency real lag_threshold() //!< tolerated network latency variation
Sample Scripts
You'll first have to load armagetronad module which also required to set path accordingly.
print("Start scripting initialization.")
import sys
sys.path.append('/home/me/tron/server/bin/')
import armagetronad
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:
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")
You can also look for the corresponding setting item so you can use it as much as you want:
console_message_conf=armagetronad.ConfItem.find("CONSOLE_MESSAGE")
console_message_conf.set("Welcome from scripting ...\n")
You might want to react on game event. You can do it binding a procedure to a ladder log message.
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)
You might be able to define new command from scripting.
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(test, armagetronad.tAccessLevel_Moderator)