Trunk Scripting
From Tronwiki
(Difference between revisions)
(→Classes) |
(→Classes) |
||
| Line 86: | Line 86: | ||
{{ClassFunction|set_callback(function func)|Callback function}} | {{ClassFunction|set_callback(function func)|Callback function}} | ||
{{FunctionParameter|func|the function you declare}} | {{FunctionParameter|func|the function you declare}} | ||
| + | |||
{{ClassSetting|Output|}} | {{ClassSetting|Output|}} | ||
| Line 97: | Line 98: | ||
append(Output o) | append(Output o) | ||
bool is_empty() | bool is_empty() | ||
| + | |||
{{ClassSetting|Color|}} | {{ClassSetting|Color|}} | ||
| Line 107: | Line 109: | ||
x | x | ||
y | y | ||
| + | |||
{{ClassSetting|ConfItem|}} | {{ClassSetting|ConfItem|}} | ||
| Line 115: | Line 118: | ||
set(string s) | set(string s) | ||
get(string s) | get(string s) | ||
| + | |||
{{ClassSetting|AccessLevelSetter|}} | {{ClassSetting|AccessLevelSetter|}} | ||
tAccessLevelSetter(ConfItem item, AccessLevel level) | tAccessLevelSetter(ConfItem item, AccessLevel level) | ||
| + | |||
{{ClassSetting|ConfItemScript|}} | {{ClassSetting|ConfItemScript|}} | ||
ConfItemScript(string title, function proc); | ConfItemScript(string title, function proc); | ||
| + | |||
{{ClassSetting|LadderLogWriter|}} | {{ClassSetting|LadderLogWriter|}} | ||
| Line 129: | Line 135: | ||
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. | ||
| + | |||
{{ClassSetting|PlayerConf|}} | {{ClassSetting|PlayerConf|}} | ||
| Line 136: | Line 143: | ||
PlayerConf player_config(int p) | PlayerConf player_config(int p) | ||
bool is_in_game(int p) | bool is_in_game(int p) | ||
| + | |||
{{ClassSetting|AccessLevelHolder|}} | {{ClassSetting|AccessLevelHolder|}} | ||
AccessLevel get_access_level() | AccessLevel get_access_level() | ||
set_access_level(AccessLevel level) | set_access_level(AccessLevel level) | ||
| + | |||
{{ClassSetting|Player|}} | {{ClassSetting|Player|}} | ||
| Line 200: | Line 209: | ||
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. | ||
| + | |||
{{ClassSetting|Team|}} | {{ClassSetting|Team|}} | ||
| Line 246: | Line 256: | ||
unsigned short blue() | unsigned short blue() | ||
string name() | string name() | ||
| + | |||
{{ClassSetting|SpawnPoint|}} | {{ClassSetting|SpawnPoint|}} | ||
| Line 254: | Line 265: | ||
real danger() | real danger() | ||
clear() | clear() | ||
| + | |||
{{ClassSetting|Arena|}} | {{ClassSetting|Arena|}} | ||
| Line 266: | Line 278: | ||
static real size_multiplier() | static real size_multiplier() | ||
remove_all_spawn() | remove_all_spawn() | ||
| + | |||
{{ClassSetting|Cycle|}} | {{ClassSetting|Cycle|}} | ||
Revision as of 11:06, 8 January 2010
Branch
lp:~armagetronad-ct/armagetronad/armagetronad-ct
Sample Scripts
print("Start scripting initialization.")
import sys, os
print os.getcwd()
sys.path.append('./src/swig/ext/')
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"
rw=armagetronad.ladder_log_writer.get_writer("ROUND_WINNER")
if rw.is_enabled():
rw.setCallback(round_winner)
print "round_winner enabled!"
print("End scripting initialization.")
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):
p=args[1]
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()
ci.ReadVal("20")
def script_config(args):
print ">", args
t = armagetronad.ConfItemScript("TEST_SCRIPT", script_config)
armagetronad.LadderLogWriter.get_writer("ROUND_WINNER").set_callback(round_winner)
armagetronad.LadderLogWriter.get_writer("PLAYER_ENTERED").set_callback(player_entered)
print("End scripting initialization.")
Enums
AccessLevel -
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
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()
Color -
r g b a
Coord -
x y
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