Help with a script

Pazleysox

Member
PHP:
void main()
{
string [string] save_data;
string log = visit_url("lchat.php");

string player_list;
foreach player in who_clan() {
	chat_clan("/whois " +player);
	if(log.contains_text("This player is currently away from KoL"));
	{print("This player is away");}
	if(log.contains_text("This player is currently online"));
	{print("This player is online");}
   if(length(player_list) > 0)
      player_list += ", ";
   player_list += player;
}

here's my output:
Code:
PazSox (#352918), the Level 9 Seal Clubber (In Ronin)
This player is currently online in channel clan.

Listening to Events, Incoming from: saying: PazSox (#352918), the Level 9 Seal Clubber (In Ronin)This player is currently online in channel clan.
This player is away
This player is online

I get this for each player currently online, regardless of away or not.

Anyone have any suggestions?
 

lostcalpolydude

Developer
Staff member
You aren't doing anything with that /whois, you're repeatedly checking the results from lchat.php. Which probably has a bunch of javascript with all the text you're checking for.
 

Theraze

Active member
Well, what do you get when you look at the text from lchat? Once you have that, you can use split_string to break the text into segments, and then you can use a proper regexp matcher to see which users are away.
 

heeheehee

Developer
Staff member
You recognize why that's not working, right? You're ending your if statements with the semicolons. You then have each print statement in a separate block that executes unconditionally.

On top of that, you're not reloading lchat.php between iterations of the loop, which isn't even what you want in the first place -- lchat uses submitnewchat.php to send that request (and retrieve the corresponding response). And, to top it off, to prevent people from writing spammy chatbots, that URL (along with newchatmessages.php) are banned for use in scripts.

You have a chatbotScript set, per the line "Listening to Events, Incoming from: saying: ...". If you're going to do parsing of this sort, it'll have to be in there.
 

Pazleysox

Member
You recognize why that's not working, right? You're ending your if statements with the semicolons. You then have each print statement in a separate block that executes unconditionally.

You have a chatbotScript set, per the line "Listening to Events, Incoming from: saying: ...". If you're going to do parsing of this sort, it'll have to be in there.

I see. I'll play around with it.

Once I figure it out, I'll have to figure out how to remove said "away" player from the list of online players, so I can PM the list of "active" players.
 

Bale

Minion
Once I figure it out, I'll have to figure out how to remove said "away" player from the list of online players, so I can PM the list of "active" players.

I'd recommend putting them in a map with values of true and false. (True is active and false is inactive.) The comma separated list is awkward for internal purposes, so just make an output function which you send a map and have it turn that into a comma separated list to print.
 

Pazleysox

Member
I'd recommend putting them in a map with values of true and false. (True is active and false is inactive.) The comma separated list is awkward for internal purposes, so just make an output function which you send a map and have it turn that into a comma separated list to print.

I've been thinking along those lines. I have codes that do parts of what I need. I just need to look at them, and try to figure out to get the pieces I need.
 

Pazleysox

Member
How can I script checking the description of an item?

I'm trying to figure out how to check "your cowboy boots" for the enchantment of +5 Adventures per day, from the Ticksilver Spurs
 

Pazleysox

Member
Something along the lines of "numeric_modifier($item[cowboy boots],"adventures")" should do what you want.

http://wiki.kolmafia.us/index.php?title=Numeric_modifier

I was just figuring that out, lol. I'm looking at the forum about moon phases, and grimacite equipment. :)

http://kolmafia.us/showthread.php?1860-question-about-moon-functions&p=11452&viewfull=1#post11452

EDIT:
knowing THIS yesterday would have saved me a lot of time.
PHP:
float init = numeric_modifier( "adventures" );
print(init + " bonus adventures");
lol, I went through, and coded each piece of rollover gear, and turns it would gain to figure out bonus roll over turns. I knew there had to be an easier way!
 
Last edited:

Pazleysox

Member
Is there an easy way to figure out what buffs a player currently has?

I don't want to code checking for each single buff available.

The script I'm working on tells you if you have free MP restorers available, and I want it to use them up.
 

Pazleysox

Member
I'm trying to burn extra MP at the end of my day. I found this code in the forums (somewhere):

PHP:
int [effect] currentEffects = my_effects();
	foreach buff in currentEffects
		{
		skill currentEffect = to_skill(buff);
			{
			cli_execute("cast " + to_string(buff));
			}
		}
I think it was zarqon who wrote it, but I don't remember.

This works really well to maintain all the buffs I currently have, with a few issues...
I'm trying to use up all my free MP restorers (resting, oscus's soda, eternal battery, etc)

I've got the code written to look for, and use available free MP restorers, but the above code doesn't like intrinsic effects, and stops when it reaches one.

How can I get it to stop looking at the intrinsic buffs?
 

ckb

Minion
Staff member
I always like this fancy code:
PHP:
cli_execute("burn extra mp");

There are a bunch of preferences on mana burning that control how this works. I don't remember right now, and my connection is slow, but prefref is your friend.
 

xKiv

Active member
Or if you want to burn down to exact amount of mp (antiundisirregardless of what your mana burn setting is):
Code:
burn -1234

Also works for zero (note the minus):
Code:
burn -0
 

Pazleysox

Member
Or if you want to burn down to exact amount of mp (antiundisirregardless of what your mana burn setting is):
Code:
burn -1234

Also works for zero (note the minus):
Code:
burn -0

Interesting. So, what's a good amount of MP to leave a player? At the moment, I have the script set to burn 50%, regardless of how much they have.
 

Theraze

Active member
If you're doing this for free restores, then the amount that will be restored. If you're doing this for other purposes, then detect how much their mp restoration is set to and make sure you leave them more than that. Because otherwise you can end up in an evil loop that sucks up all their meat.
 

zarqon

Well-known member
Here's the code in my logout script to maximize using all your free sources of MP by burning the MP on casting your skills. Hopefully it will give you some good ideas, or inspire you to steal the code outright. Either or both would gratify me. :)

It probably has some issues which I've never happened to discover, and some of the code (which mostly predates proxy records for skills) could be streamlined by using those instead of the data from classskills.txt. Feel free to suggest any improvements!

PHP:
// skill types
// 0 - passive          not castable
// 1 - summon           castable, oft limited, 1st pref
// 2 - restore          not used here
// 3 - char-only buff   castable, 2nd pref
// 4 - buff             castable, 3rd pref
// 5 - combat           not castable

int max_castable(skill sk) {      // returns how many times you can possibly cast a given skill (NOT based on current MP)
   switch (sk) {
      case $skill[Advanced Cocktailcrafting]: return 3 + 2*to_int(have_skill($skill[superhuman cocktailcrafting])) - to_int(get_property("cocktailSummons"));
      case $skill[Pastamastery]: return 3 + 2*to_int(have_skill($skill[transcendental noodlecraft])) - to_int(get_property("noodleSummons"));
      case $skill[Advanced Saucecrafting]: return 3 + 2*to_int(have_skill($skill[the way of sauce])) - to_int(get_property("reagentSummons"));
      case $skill[Rainbow Gravitation]: return 3 - to_int(get_property("prismaticSummons"));
      case $skill[Summon Hilarious Objects]: return to_int(get_property("grimoire1Summons") == "0");
      case $skill[Summon Tasteful Items]: return to_int(get_property("grimoire2Summons") == "0");
      case $skill[Summon Alice Army Cards]: return to_int(get_property("grimoire3Summons") == "0");
      case $skill[Summon Snowcones]:
      case $skill[Summon Stickers]:
      case $skill[Summon Sugar Sheets]: return 3 - to_int(get_property("tomeSummons"));
      case $skill[Summon Crimbo Candy]: return to_int(get_property("_candySummons") == "0");
  // candyHeartSummons??
   }
   if (mp_cost(sk) == 0) return 0;
   return floor(my_maxmp() / mp_cost(sk));
}

// build list of castable skills
record tskill {
   skill nome;
   int type;
   int irr; int ele; int vent;
};
tskill[int] skills;
file_to_map("classskills.txt",skills);
print("Your castable skills:","blue");
foreach i,s in skills {
   if (!have_skill(s.nome) || (s.nome.combat || s.type < 1 || s.type == 2) ||        // only types 1,3,4 that you have
       max_castable(s.nome) == 0 || $ints[45,90,1025,3101,3102,3103,3104,3105,3106,] contains i ||  // casting limits, skip flavours, deep dark visions, rage gland
       (s.type > 2 && to_effect(s.nome) != $effect[none] && have_effect(to_effect(s.nome)) > 2000)) {  // skip buffs you have too much of
      remove skills[i]; continue;
   }
   print(i+": "+s.nome + " ("+mp_cost(s.nome)+" MP) -- "+to_effect(s.nome));
}

int rest_mp() {             // calculate resting MP
   int[item] campgear = get_campground();
   if (numeric_modifier("Base Resting MP") < 40 && item_amount($item[Frobozz Real-Estate Company Instant House (TM)]) > 0 && use(1,$item[Frobozz Real-Estate Company Instant House (TM)])) {}
   if (numeric_modifier("Base Resting MP") < 10 && retrieve_item(1,$item[Newbiesport™ tent]) && use(1,$item[Newbiesport™ tent])) {}
   if (!have_bartender()) print("You could get a bartender for an additional 15 MP/rest.","olive");
   if (!(campgear contains $item[beanbag chair])) print("You could get a beanbag chair for an additional 30 MP/rest.","olive");
   if (!(campgear contains $item[feng shui for big dumb idiots])) print("You could get some good Feng Shui for an additional 7 MP/rest.","olive");
   return numeric_modifier("Base Resting MP") * (100+numeric_modifier("Resting MP Percent"))/100.0 + numeric_modifier("Bonus Resting MP");
}
int restmp = rest_mp();
print("Resting MP: "+restmp,"blue");

int next_restore(boolean doit) {     // returns MP gained from next available free restore method, 0 if no methods available
   if (item_amount($item[platinum yendorian express card]) > 0 && !get_property("expressCardUsed").to_boolean()) {
      if (doit) use(1,$item[platinum yendorian express card]);
      return my_maxmp();
   }
   if (item_amount($item[license to chill]) > 0 && !get_property("_licenseToChillUsed").to_boolean()) {
      if (doit) use(1,$item[license to chill]);
      return my_maxmp();
   }
   if (my_level() > 11 && get_property("sidequestNunsCompleted") == "fratboy" && to_int(get_property("nunsVisits")) < 3) {
      if (doit) cli_execute("nuns mp");
      return min(1000,my_maxmp());
   }
   if (item_amount($item[clan vip lounge key]) > 0 && !get_property("_aprilShower").to_boolean() && which_shower() == "hot") {
      if (doit) cli_execute("shower hot");
      return min(1000,my_maxmp());
   }
   if ((have_skill($skill[disco nap]) ||
        have_skill($skill[adventurer of leisure]) ||
        have_skill($skill[executive narcolepsy]) ||
        have_skill($skill[food coma]) ||
        have_skill($skill[dog tired]) ||
        get_property("chateauAvailable").to_boolean() ||
        have_familiar($familiar[unconscious collective])) && contains_text(visit_url("campground.php"),"_free.gif")) {  // free rest remains
      if (doit) cli_execute("rest");
      return min(restmp,my_maxmp());
   }
   return 0;
}

boolean burn_to(int target) {     // only returns true if burning occurred!
   target = minmax(target,0,max(0,my_maxmp() - restmp));
   if (my_mp() <= target) return false;
   print("Burning down to "+target+" MP...");
   int init = my_mp();
   if (my_class() == $class[accordion thief]) record_songs();
   cli_execute("burn extra -"+target);
   if (my_mp() <= target) return true;
   int mpflag;
   repeat {
      mpflag = my_mp();
      foreach i,s in skills {
         if (i > 6000 && i < 6028 && (have_effect(to_effect(s.nome)) == 0 ||    // skip AT buffs you don't have or have too much of
            have_effect(to_effect(s.nome)) > 2000)) continue;
         if (!s.nome.song && max_castable(s.nome) > 0 && my_mp() >= mp_cost(s.nome))
            use_skill(count(skills) == 1 ? min(max_castable(s.nome),ceil((my_mp() - target)/mp_cost(s.nome))) : 1, s.nome);
         if (my_mp() <= target) return true;
      }
   } until (mpflag == my_mp());
   return (my_mp() != init);
}

boolean burn_everything() {
   if (my_path() == "Zombie Slayer") return true;
   if ((count(skills) > 0 || have_item($item[the trickster trikitixa]) > 0) && next_restore(false) > 0) {
      maximize("-1000 mana cost, 2 mp, 1 hp",false);
//      maximize("adv, switch disembodied hand, -tie",true);
      burn_to(min(numeric_modifier("_spec","Buffed MP Maximum"),my_maxmp()) - next_restore(false));
      while (next_restore(true) > 0 && burn_to(my_maxmp() - next_restore(false))) {}
   }
   print("No more free MP restores left.");
   maximize("adv, switch disembodied hand, -tie",false);
   if (count(skills) == 0) return true;
   return burn_to(900000);
}
 
Top