// getplayers.ash (not a relay script, import it into your own script and call GetPlayer or GetPlayers)
record playerdata {
string name;
string id;
string cclass;
int level;
string clanname;
string clanid;
};
playerdata[int] GetPlayers(string search) {
playerdata[int] ret;
buffer page = visit_url( "searchplayer.php?searching=Yep.&searchstring=" + search.url_encode() );
matcher m = create_matcher( "href=\"showplayer.php\\?who=(\\d+)\">([^<]+)</a></b> (<br>\\(<a target=mainpane href=\"showclan.php\\?whichclan=(\\d+)\">([^<]+)" +
"</a>\\))?</td><td valign=top class=small>(\\d+)</td><td valign=top class=small>(\\d+)</td><td class=small valign=top>([^<]+)</td>", page );
// Groups:
// 1: Player ID, 2: Player Name, 3: Clan HTML, 4: Clan ID, 5: Clan Name, 6: Player ID again, 7: Player Level, 8: Player Class
while( m.find() ) {
int i = ret.count();
ret[i].name = m.group(2);
ret[i].id = m.group(1);
ret[i].cclass = m.group(8);
ret[i].level = m.group(7).to_int();
ret[i].clanname = m.group(5);
ret[i].clanid = m.group(4);
}
return ret;
}
// The only way to get a specific player is to search on their name and check the responses for a match.
playerdata GetPlayer(string pname) {
playerdata[int] players = GetPlayers(pname);
foreach i,p in players {
if( p.name.to_lower_case() == pname.to_lower_case() )
return p;
}
print("Player \"" + pname + "\" not found!", "red");
return new playerdata;
}
void PrintPlayers(string search) {
playerdata[int] players = GetPlayers(search);
foreach i,p in players {
print( "Player found: " + p.name + " the level " + p.level.to_string() + " " + p.cclass + (p.clanname!=""?", in clan " + p.clanname:"") + "!" );
}
}