obtaining playerID from player name?

uffda

New member
Is there any easy way to do this yet? I found Zarqon had written a little script about a year ago that would do it to some degree:

Code:
int to_id(string player) {
   string page = visit_url("searchplayer.php?searching=Yep.&searchstring="+url_encode(player)+"&searchlevel=&searchranking=&hardcoreonly=0");
   if (contains_text(page,"No players found.")) {
      print("Sorry "+my_name()+", but '"+player+"' is in a different kingdom!","red");
      return 0;
   }
   page = substring(page,index_of(page,"showplayer.php?who=")+18);
   return to_int(substring(page,0,index_of(page,"\"")));
}

But this doesn't work all the time. For example if I give it uffda it returns the playerID of someone named bigpuffdaddy007 (which contains uffda, and is the first search result)
 

lostcalpolydude

Developer
Staff member
Something that uses the /whois chat command would be the most reliable, because it will only take exact matches. As for actually writing it, I don't have a clue how to do that.
 

Alhifar

Member
That's really the current best way to do it. /whois can't be used, because mafia doesn't allow any chat scripting.
 

chef noodleman

New member
regex solution

I just recently found I needed to do this for my own purposes. Despite the fact that this thread is a few years old, I figured I'd reply. Here's what I came up with, using regex to improve upon zarqon's idea a little bit. I haven't tested it a bunch, but it worked to give me your ID, uffda. :)

Code:
string getPlayerId( string playerName ) {
	string playerID = "-2";
	string page = visit_url("searchplayer.php?searching=Yep.&searchstring="+playerName+"&searchlevel=&searchranking=&hardcoreonly=0");
	page = to_lower_case(page);
	
	if (contains_text(page,"no players found.")) {
    	print("Sorry "+my_name()+", but '"+playerName+"' is in a different kingdom!","red");
    	return "-1";
	}
	
	matcher match_name = create_matcher('"showplayer.php\\?who=(\\d+)">'+to_lower_case(playerName), page);
	if( match_name.find() ) {
   		playerID = match_name.group(1);
   	}
	
	return playerID;
}
 

Catch-22

Active member
Well, I have no need for this, but I can't resist a challenge...

Example Usage:
Code:
> whois.ash uffda

#843339

> whois.ash uffda2

#1947904

> whois.ash uffda3

Unknown Player

Use only for good.

Edit: Removed attachment, as it exploits a bug in KoLmafia, use the new ASH function in r10922, get_player_id(), instead :)
 
Last edited:
Top