Script Request for Mass-Use of Toilet Paper

Watts

New member
So I'm looking for a script that will allow one to hit multiple people at once with a chat effect Item, such as toilet paper. I've browsed the wiki and I can't seem to find anything of the sort, and I've been tinkering with adding a script to the buff function since that too targets the whole channel.

Does anyone have a solution to this, or already know of a script that does this? I'm hoping to have a working version by March 22'nd so I can distribute all 45K rolls across the kingdom.
 

jasonharper

Developer
If you had a file with a list of target players, one per line, then adding "throw toilet paper at " to the start of each line would produce your desired script. Any decent text editor ought to be able to do that easily... The problem is going to be entirely in the generation of that list, not in the actual throwing.
 

StDoodle

Minion
As JH mentioned, the hardest part is coming up with target names. As far as I can come up with, the only ways to automate this would be:

1) Use random() to come up with player id numbers. Upside: easy Downside: likely to hit a lot of inactive accounts
2) Use some form of page scraping, either from chat or some other page with a list of names you'd like to target. Upside: better "utilization" of your tp Downside: Really tough to make a one-size-fits all script to handle this (it would depend greatly on where you wanted to grab player info from).

If you could be more specific about where you'd like to grab names from, I'd happily modify my script that is currently set to simply throw a massive amount of TP at a specified individual.
 

Watts

New member
I can't think of any way to do it other than just /who a channel and do it JH's way. Might I ask for that script you have, StDoodle, just so I can see if I can come up with any way to alter it to fit what I'm after?
 

StDoodle

Minion
Actually, I have something that may be better & is almost done. What I've got is a script that you can paste a chat log into, and it will extract the name of every unique player who participated in said chat. That gets saved to a map, which we could then iterate through or build upon with other chat logs, and throw tp & everyone found. Will post shortly.

EDIT:

Attached are two scripts. Here's my instructions:

parse_names.ash

When you call this script, it will prompt you for a string to parse. What you want to do is open up a chat log (saved under the KoLmafia "chats" directory, if you have chat logging enabled) in a text-editor that allows you to view the source (not in a browser). Copy the whole thing, and paste it into the prompt you get when running parse_names.ash. Note that you'll have to know your operating system's keyboard command for "paste," as you won't have a right-click (or similar) menu in KoLmafia. I'm not entirely sure what the limits are for the length of a string that can be input this way, nor the limits on your copy - paste storage, so it may be necessary to do it in parts for really large chat logs.

The script will loop through this massive string of chat log data, extracting the name of each player it finds as a poster (players mentioned in someone's chat text are ignored). Then, if the player isn't you (you don't want to throw stuff at yourself, I'm guessing) and the player has not yet been added to your list, it will do so. When it's done parsing all of the text, it will save any previous data as well as the list parsed during this function call to a file in your KoLmafia "data" directory called "SavedNames.txt," and end by telling you how many names are currently in said file.

Note that you can call this function as many times as you'd like, pasting new chat log data every time, and it will simply build up your list (it doesn't start from scratch). If for any reason you wish to start a new list, you'll need to move or delete the "SavedNames.txt" file. Also, just in case, you may want to back up said file once in a while if you plan on parsing a ton of chat logs.

throw_at_people.ash

This is the file that does the actual item-throwing. It will prompt you for two things; first, the quantity of items to throw. Then it will prompt you for the item to throw. If this item doesn't match the hard-coded list of curse items, the script will abort & tell you so. If the quantity you specify is greater than the quantity of said item that you have on-hand (it ignores your closet, hangk's, and DC in case you'd like to save some elsewhere), it will abort and tell you so.

Once that all checks out, it will loop through your saved list of names as many times as needed until you've used the specified number of items.

Enjoy!

Edit 2:

Oops, removed the inclusion of mod announcements in the list, which broke everything; all better now (?).
 

Attachments

  • parse_names.ash
    588 bytes · Views: 76
  • throw_at_people.ash
    1.2 KB · Views: 90
Last edited:

Watts

New member
That's pretty damned nifty. And it works great too! I can think of a way to make the name list a bit easier though, I'm going to tinker with it. I'll update this post once I have it working.

~Edit~

No, now I've gone back to the original scripts and I'm getting a constant "Unable to invoke throw".

What if the name list instead just picks the names from a /who list of a channel? Like you boot up the browser chat, do a /who on a channel, then you get the copy / pasteable blob from chat that you can post in the parse_names.ash file. Seems a bit more organized. That's basically what I'm trying to do (and failing) And it doesn't even seem "Throw roll of toilet paper at" works, it gives the same "Unable to invoke throw" message. Am I forgetting something?
 
Last edited:

StDoodle

Minion
What if the name list instead just picks the names from a /who list of a channel? Like you boot up the browser chat, do a /who on a channel, then you get the copy / pasteable blob from chat that you can post in the parse_names.ash file. Seems a bit more organized.

Probably wouldn't be hard to do with split_string() and perhaps a tad more parsing logic, I can certainly look into it.

this really doesn't belong here but is there a way of using the random() function for an item?

That depends on what you mean, exactly. You can invoke $item[ ] with a number, so it's possible to randomly generate an item, as long as you make sure to generate valid item id's. Or, if you want to work with a limited list, just create a switch statement that took a random input.
 

icon315

Member
I want it to choose a random item, that's at a budget of 3000 meat per item in the mall
 
Last edited:

heeheehee

Developer
Staff member
Sure (re: random items)! For instance, my heart-attack alias is as follows:
heartspam => ashq if( "%%" == "" ) abort( "Usage: heartspam [amount] [user]" ) ; int num=substring("%%" ,0,index_of( "%%" , " ")).to_int() ; string player=substring("%% ",index_of("%%"," ")+1);string page ; for i from num downto 1{ page = visit_url( "curse.php?action=use&pwd&whichitem="+(2304+random(6))+"& targetplayer=" + player );if(contains_text( page , "You don't have that item." ) ){ print( "Attacked " + player + " with " + num + " candy hearts!" );cli_execute("inv refresh"); return 1;}}print("Attacked " + player + " with " + num + " candy hearts!" );cli_execute("inv refresh" );

Modified, of course, from some alias that Alhifar provided somewhere...

But for what you have in mind, you'd probably want switches and cases and stuff. So a full-on script, as opposed to a tiny alias.
 

StDoodle

Minion
It's going to be a bit before I can look at parsing the results of "/who" but in the mean time:
1) Copy the text
2) Paste as special / plain whatever into a decent text editor
3) Delete any cruft (ie "Players in this channel:", "(XX Total)" etc.)
4) Do a find & replace to turn ", " into a line-break
5) Clone the names with a tab between them (ie you want each line to be "name"tab"name")
a) Using a spreadsheet program may help with this
b) Simply copy the list there, and copy into another column
c) Then, export as tab-delimited text
6) Save the file that has each player name twice, with a tab between, as "SavedNames.txt" in your data folder.
Optional:
7) If the format was done correctly, you can still add chat log results onto this file if desired.
8) Sorting your file while in a spreadsheet will help with duplicates if you use the results of more than one "/who" command

Edit:
Randomness!
The following function will generate a random number, see if it converts to a valid item, and if so it will return said item if it is tradeable & under the supplied limit parameter in the mall
(and also not 0, as that's what an item not found in the mall returns). If these tests don't all check out, it will start again till it finds one that does.
Code:
item get_rand_item(int limit) {
    int rnd;
    item rnd_item;
    boolean found_one = false;
    while (! found_one) {
        rnd = 1 + random(5000);
        rnd_item =  to_item(rnd);
        if (rnd_item != $item[none]) {
            if (is_tradeable(rnd_item)) {
                if (mall_price(rnd_item) <= limit && mall_price(rnd_item) != 0) {
                    found_one = true;
                }
            }    
        }
    } // while
    return rnd_item;
}
Note; currently, item numbers go up to 4535; don't worry about higher numbers, they will be discarded; if you keep using this script well into the future, you may want to bump up the random(5000) line.
 
Last edited:
Top