Writing to file?

Pazleysox

Member
> call scripts\getplayers.ash

Player "cowmanbob" not found!
Error: Player cowmanbob not found in search!
Player "pazsox" not found!
Error: Player pazsox not found in search!
Player "bale" not found!
Error: Player bale not found in search!
Player "skf" not found!
Error: Player skf not found in search!
Anchon the level 10 Pastamancer

searchplayerbot.txt
1 cowmanbob
2 pazsox
3 anchon
4 bale
5 skf
 
> call scripts\getplayers.ash

Player "cowmanbob" not found!
Error: Player cowmanbob not found in search!
Player "pazsox" not found!
Error: Player pazsox not found in search!
Player "bale" not found!
Error: Player bale not found in search!
Player "skf" not found!
Error: Player skf not found in search!
Anchon the level 10 Pastamancer

searchplayerbot.txt
1 cowmanbob
2 pazsox
3 anchon
4 bale
5 skf

Oh ffs, yes apparently the search adds some text for people with pvp enabled for some damn reason so the regex doesn't work in those cases. Here, fixed.

Code:
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> ( \\(PvP\\))?(<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: " (PvP)" 4: Clan HTML, 5: Clan ID, 6: Clan Name, 7: Player ID again, 8: Player Level, 9: 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(9);
		ret[i].level = m.group(8).to_int();
		ret[i].clanname = m.group(6);
		ret[i].clanid = m.group(5);
	}
	
	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:"") + "!" );
	}
}
 

Pazleysox

Member
Oh ffs, yes apparently the search adds some text for people with pvp enabled for some damn reason so the regex doesn't work in those cases. Here, fixed.

PHP:
//getplayers.ash
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> ( \\(PvP\\))?(<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: " (PvP)" 4: Clan HTML, 5: Clan ID, 6: Clan Name, 7: Player ID again, 8: Player Level, 9: 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(9);
		ret[i].level = m.group(8).to_int();
		ret[i].clanname = m.group(6);
		ret[i].clanid = m.group(5);
	}
	
	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:"") + "!" );
	}
}
I have the above as the script being imported.
PHP:
import "getplayers.ash"; // At top of script

// rest of your script goes here
string [int] my_list
file_to_map( "searchplayerbot.txt" , my_list);
playerdata player;
string temp = "";
foreach i,playername in my_list {
	player = GetPlayer( playername );
	if( player.name != "" ) {
		if( temp != "" ) temp += ", ";
		temp += player.name + " the level " + player.level + " " + player.cclass;
	} else {
		print( "Error: Player " + playername + " not found in search!", "red" );
	}
}
print(temp);
kmail("pazsox", temp, 0, map);
I have this in my main script. I have no problem calling this, but when it runs, I get a blank message now. I've even tried pulling the second script, and running it by itself, but I keep getting nothing back. My "Searchplayerbot.txt" file hasn't changed from the last time I posted on it. I'm not sure whats changed. I haven't modified any of this code, I've even gone so far as to copy and paste the code from here over top of my code to make sure it's right. It worked a few days ago, but when I went to try it today, it didn't work.
 

Pazleysox

Member
Neither one appears to have a proper main and the arguments for a chatbot script...

The getplayers.ash script doesn't need a main argument, because it's being imported.

The other script was taken out of my chatbot script for this post. I *DO* have a copy of this script that looks like this:
PHP:
import "zlib.ash"
import "getplayers.ash"; // At top of script
void main() {
int [item] map;
map[$item[adder]] = 0; 

// rest of your script goes here
string [int] my_list;
file_to_map( "searchplayerbot.txt" , my_list);
playerdata player;
string temp = "";
foreach i,playername in my_list {
	player = GetPlayer( playername );
	if( player.name != "" ) {
		if( temp != "" ) temp += ", ";
		temp += player.name + " the level " + player.level + " " + player.cclass;
	} else {
		print( "Error: Player " + playername + " not found in search!", "red" );
	}
}
print(temp);
//kmail("pazsox", temp, 0, map);
}

the getplayers.ash script is the one posted above.
 

Theraze

Active member
Your void main isn't valid for a chatbot script. You're taking in no arguments, rather than the proper three...
 

Pazleysox

Member
I'm aware of that. This script does nothing, regardless of if it's a stand alone, or if it's in my chatbot script.

My chatbot script is working just fine. The ability to call this portion of script through my chatbot works just fine. This portion of script itself however does not work. Weather it is in my chatbot script, or as a stand alone script. It worked when it was first written, now for some reason it fails to work.
 
Last edited:

heeheehee

Developer
Staff member
Your void main isn't valid for a chatbot script. You're taking in no arguments, rather than the proper three...

Well, it is valid, but not useful, since it simply runs once for each incoming message without knowing anything about the message...
 

Theraze

Active member
Does the searchplayerbot.txt file actually exist in your data folder? Does it actually pull strings out?
 

Pazleysox

Member
Does the searchplayerbot.txt file actually exist in your data folder? Does it actually pull strings out?

Yes, the file actually exists. I haven't changed a thing since 2 weeks ago when it worked. Does it pull strings? I have no idea.
 
Top