Trunk Scripting

From Tronwiki
(Difference between revisions)
Jump to: navigation, search
m (Enums)
Line 76: Line 76:
     tAccessLevel_Program = 20,
     tAccessLevel_Program = 20,
     tAccessLevel_Invalid = 255
     tAccessLevel_Invalid = 255
Line 98: Line 111:
   append(Output o)
   append(Output o)
   bool is_empty()
   bool is_empty()

Revision as of 11:20, 8 January 2010




Sample Scripts

print("Start scripting initialization.")

import sys, os
print os.getcwd()
import armagetronad

ci = armagetronad.tConfItemBase.FindConfigItem("CYCLE_SPEED")

def round_winner(args):
    print "start round winner ladder log writer callback"
    armagetronad.tConfItemBase.LoadString("CYCLE_SPEED 100")
    print args
    print "end round winner ladder log writer callback"

if rw.is_enabled():
    print "round_winner enabled!"

print("End scripting initialization.") 
print("Start scripting initialization.")

import sys, os
print os.getcwd()
import armagetronad

def player_entered(args):
    print args

def round_winner(args):
    print args
    print("PLAYER_MESSAGE "+p+' "Congratulation from script '+p+' !"')
    armagetronad.ConfItemBase.LoadString("PLAYER_MESSAGE "+p+' "Congratulation from script '+p+' !"')
    ci = armagetronad.ConfItemBase.FindConfigItem("CYCLE_SPEED")
    print "cycle_speed " + ci.WriteVal()

def script_config(args):
    print ">", args

t = armagetronad.ConfItemScript("TEST_SCRIPT", script_config)


print("End scripting initialization.")


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


Color -


Coord -



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)
  Output set_template_parameter_string(int num, string parameter)
  Output set_template_parameter_float(int num, float parameter)
  append(Output o)
  bool is_empty()

ConfItem -

  AccessLevel required_level()
  load_all(string s);
  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()
  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)
  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()

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()

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()
  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()
  bool alive()         //! tells whether the object is alive
  real lag()         //!< expected average network latency
  real lag_threshold()      //!< tolerated network latency variation
Personal tools