Page 5 of 6 FirstFirst ... 3 4 5 6 LastLast
Results 41 to 50 of 51

Thread: Writing to file?

  1. #41
    Senior Member Pazleysox's Avatar
    Join Date
    Feb 2009
    Posts
    260

    Default

    > 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

  2. #42

    Default

    > 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
    Originally Posted by Pazleysox View Post
    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:"") + "!" );
    	}
    }

  3. #43
    Senior Member Pazleysox's Avatar
    Join Date
    Feb 2009
    Posts
    260

    Default

    Thanks! Works perfect!

  4. #44
    Senior Member Pazleysox's Avatar
    Join Date
    Feb 2009
    Posts
    260

    Default

    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 Code:
    //getplayers.ash
    record playerdata {
        
    string name;
        
    string id;
        
    string cclass;
        
    int level;
        
    string clanname;
        
    string clanid;
    };

    playerdata[intGetPlayers(string search) {
        
    playerdata[intret;
        
        
    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[intplayers 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[intplayers 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:"") + "!" );
        }

    Originally Posted by Smelltastic View Post
    I have the above as the script being imported.
    PHP Code:
    import "getplayers.ash"// At top of script

    // rest of your script goes here
    string [intmy_list
    file_to_map
    "searchplayerbot.txt" my_list);
    playerdata player;
    string temp "";
    foreach 
    i,playername in my_list {
        
    player GetPlayerplayername );
        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"temp0map); 
    Originally Posted by Smelltastic View Post
    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.

  5. #45
    Senior Member Theraze's Avatar
    Join Date
    Mar 2010
    Posts
    8,735

    Default

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

  6. #46
    Senior Member Pazleysox's Avatar
    Join Date
    Feb 2009
    Posts
    260

    Default

    Neither one appears to have a proper main and the arguments for a chatbot script...
    Originally Posted by Theraze View Post
    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 Code:
    import "zlib.ash"
    import "getplayers.ash"// At top of script
    void main() {
    int [itemmap;
    map[$item[adder]] = 0

    // rest of your script goes here
    string [intmy_list;
    file_to_map"searchplayerbot.txt" my_list);
    playerdata player;
    string temp "";
    foreach 
    i,playername in my_list {
        
    player GetPlayerplayername );
        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.

  7. #47
    Senior Member Theraze's Avatar
    Join Date
    Mar 2010
    Posts
    8,735

    Default

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

  8. #48
    Senior Member Pazleysox's Avatar
    Join Date
    Feb 2009
    Posts
    260

    Default

    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 by Pazleysox; 04-19-2017 at 07:02 PM. Reason: chatbot's ok

  9. #49
    Developer
    Join Date
    Aug 2009
    Posts
    2,700

    Default

    Your void main isn't valid for a chatbot script. You're taking in no arguments, rather than the proper three...
    Originally Posted by Theraze View Post
    Well, it is valid, but not useful, since it simply runs once for each incoming message without knowing anything about the message...

  10. #50
    Senior Member Theraze's Avatar
    Join Date
    Mar 2010
    Posts
    8,735

    Default

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •