Unexpected map entry

Grotfang

Developer
So, I am using this code to generate a list of clan members by id (code later adds more info, but that works fine). I am expecting a map to be generated (called player_id) which has the first id on the detailed roster page (obtained from the showplayer.php?who= part of the frame source code) as the entry for 0 in my map. After producing the map, it uses map_to_file to place a text file (called backup.txt) into my data folder. However, when I run the code, the file at the end has nothing at 0, and is filled with the correct ids from 1. Is there any way to make it start from 0?

Sorry if this is unclear. I have tried to be as thorough as possible as to what I am expecting and what is actually happening, but I realise my wording isn't ideal.

Code:
record clan_info
{
	string backup_id;
};

string excise( string source , string start , string end )
{

	if( !source.contains_text( start ) ) return "";

	string result = substring( source , index_of( source , start ) + length( start ) );

	if( !result.contains_text( end ) ) return "";

	return substring( result , 0 , index_of( result , end ) );

}

clan_info [int] parse_ids()
{
	clan_info [int] parsed_id;
	string call_clan_page = visit_url( "clan_detailedroster.php" );
	call_clan_page = substring( call_clan_page , index_of( call_clan_page , "nounder" ) );
	string [int] km = split_string( call_clan_page , "nounder");
	int p = 0;
	for i from 0 upto count( km ) - 1
	{
		if( contains_text( km[i] , "" ) ) 
		{
			parsed_id [p].backup_id = excise( km[i] , "href=\"showplayer.php?who=" , "\">" );
			p = p + 1;
		}
	}
	return parsed_id;
}

void main()
{
	clan_info [int] player_id = parse_ids();
        map_to_file( player_id , "backup.txt" );
}

EDIT:

Looking back through the code, I had a thought. Would I be right in thinking that:

Code:
string [int] km = split_string( call_clan_page , "nounder");

Produces a map whose first line is everything before the first appearance of "nounder", then each subsequent line being the lines after each appearance of the term? If so, is there any way to avoid this, or otherwise remove that line from the map?
 
Last edited:

Catch-22

Active member
Looking back through the code, I had a thought. Would I be right in thinking that:

Code:
string [int] km = split_string( call_clan_page , "nounder");

Produces a map whose first line is everything before the first appearance of "nounder", then each subsequent line being the lines after each appearance of the term? If so, is there any way to avoid this, or otherwise remove that line from the map?

You are correct in thinking that. Try starting your counter at 1, to avoid the zeroth element (yep, it's a word, haha) of km.
Code:
for i from 1 upto count( km ) - 1

Although if you did that, you should also make sure that count(km) > 1 because it could cause an error otherwise.
 

Grotfang

Developer
You are correct in thinking that. Try starting your counter at 1, to avoid the zeroth element (yep, it's a word, haha) of km.
Code:
for i from 1 upto count( km ) - 1

Although if you did that, you should also make sure that count(km) > 1 because it could cause an error otherwise.

Cheers. That makes sense.

By the way, does anyone have a use for this script, as I can post the full version if anyone wants it. It produces a map that contains user id, user name, clan rank, clan title and clan karma, for administration purposes. It's very similar to what mredge has produced here with the addition of getting their titles (although that does generate a few server hits) and without taking their ascension history/stats/class.

I use it to get a backup of players' titles and ranks, as ranks change depending on who needs what permissions when we do hamster and slimeling runs, and it's also useful to have at least one record of titles, as the game doesn't record what they were changed from.
 

mredge73

Member
It is always good to be able to backup your clan information. If you built something that can grab more info than what mine can, then sure we would like to see it. I have yet to build a title parcer, that could be useful because I have a bot that auto-ranks clannies based on Karma but discards their current title since I don't have a record of their current title.
 

Grotfang

Developer
It is always good to be able to backup your clan information. If you built something that can grab more info than what mine can, then sure we would like to see it. I have yet to build a title parcer, that could be useful because I have a bot that auto-ranks clannies based on Karma but discards their current title since I don't have a record of their current title.

Sorry about that! Completely forgot this post...

The title parser is pretty simple - I had a look at your clan info thing and basically we produced the same script, but you did it far more elegantly :)

Titles... (using your script instead of mine as we've essentially been trying to do the same thing...). I think if you add this before your final map_to_file (see here) then this should work.

Code:
foreach x in CurrentRoster
{
   string player_title = visit_url( "showplayer.php?who=" + CurrentRoster [x].ID );
		if( contains_text( player_title , "Title: " ) )
		{
			CurrentRoster [x].Title = excise( player_title , "Title: <b>" , "</b>" );
		}
		else
		{
			CurrentRoster [x].Title = "";
		}
}

You will need to add string Title; to your CurrentRoster record. Note, I do not support players who have left the clan, so if they are in another clan - through whitelist, or because they have been booted, or whatever - then their new clan title will show up here. This can be avoided, I think by adding:

Code:
if( contains_text( player_title , "Title: " ) && contains_text( player_title , clan_name ) )

while having a variable of string clan_name with your clan's name at the top of the page.
 

mredge73

Member
Thanks
I may be able to use that for one of my functions.

I run the clan roster program every hour so I don't want to include this due to the high amount of server hits but I can use it to grab the title of someone before changing their rank. Thanks for that.

Such a easy little function:
Code:
string GetTitle(int id)
{
    string page = visit_url( "showplayer.php?who=" + id );
    if( contains_text( page , "Title: " ) )
        return excise( page , "Title: <b>" , "</b>" );
    return "";
}
 
Last edited:
Top