User:VinnyB/Code snippets
From A KoL Wiki
Mafia CLI commands I've found useful (somewhat arbitrary, but with some variations to demonstrate how they can be adjusted):
- Effects
- List all effects that give +ML:
ashq foreach i in $effects[]{float m=numeric_modifier(i ,"Monster Level");if(m>0) print(i+" - "+m);}
- List all effects that give +item%, sorted:
ashq string mod="Item Drop"; effect [int] list; foreach e in $effects[] if (numeric_modifier(e, mod)>0) list[list.count()]=e; sort list by -numeric_modifier(value, mod); foreach e in list print(list[e].default+" ("+list[e]+"): "+numeric_modifier(list[e], mod));
- List all effects that give +ML:
- Items
- List all items that lower your HP:
ash foreach i in $items[]{if(i.numeric_modifier("Maximum hp") < 0){print(i+": "+i.numeric_modifier("maximum hp"));}}
- List all items that give flat +wdmg, sorted:
ashq string mod = "Weapon Damage"; item [int] list; foreach i in $items[] if (i.numeric_modifier(mod)>0) list[list.count()]=i; sort list by -numeric_modifier(value, mod); foreach i in list print(list[i]+": "+numeric_modifier(list[i], mod));
- List all clubs in your inventory:
ashq foreach it in get_inventory() if (it.item_type() == 'club') print(it)
- List all hats with 28 characters in their name (for tea party):
js Item.all().filter((i) => toSlot(i) === Slot.get("hat") && i.toString().replace(/\s+/g, "").length == 28)
- List all hats with power > 170:
ashq item [int] list; foreach i in $items[] if (i.get_power()>170 & i.to_slot()==$slot[hat]) list[list.count()]=i; sort list by -get_power(value); foreach i in list print(list[i]+": "+get_power(list[i]));
- List all martinis (for LTA), also noting whether they qualify for tuxedo shirt bonus:
ashq foreach it in $items[] {if(it.smallimage=="martini.gif") it.print(it.notes.contains_text("MARTINI")? "gray":"red");}
- Acquire 1 of every cheap item into your inventory:
ash foreach i in $items[]{if(i.available_amount() == 0 && i.mall_price() < 5000 && i.mall_price() >= 100 && i.tradeable && !i.gift) cli_execute("acquire "+i);}
- List all items that lower your HP:
- Zones
- List locations by the # of turns spent in them:
ashq location [int] locations; foreach l in $locations[] { locations[locations. count()] = l; } sort locations by value.turns_spent; foreach key, l in locations if (l.turns_spent > 0) print(l + ": " + l.turns_spent)
- Check whether a location allows wanderers:
js Location.get("noob cave").wanderers
- For each location, list all unlocketed monster:
ashq foreach z in $locations[] foreach m in z.get_location_monsters() if (m.copyable && !m.boss && !(get_locket_monsters() contains m)) print(`[{z}] {m}`);
- List locations by the # of turns spent in them:
- Monsters
- List all sleaze-aligned monsters:
ashq foreach m in $monsters[] if (m.defense_element.to_string()=='sleaze') print(m);
- List all monsters with base meat drop > 300:
ash foreach i in $monsters[] if(i.max_meat > 300) print(i);
- List all monsters with base meat drop > 200, sorted:
ash monster [int] list; foreach m in $monsters[] if ( meat_drop(m)>200 ) list[list.count()]=m; sort list by meat_drop(value); foreach m in list print(list[m]+" : "+meat_drop(list[m]));
- List all sleaze-aligned monsters:
- Other
- Getting a top menu command to work:
/goto '?'':function(){ top.chatpane. submitchat ('/yourchatmacro '); throw{};}(); z='
- Alias a weapon-type search:
alias whatis => ash string itemtype=$string[%%] ; foreach it in get_inventory() if (it.item_type() == itemtype) print(it)
- Alias a junk mail clear:
alias junkmail => ashq import zlib; boolean no_penpal(kmessage m) { return ($strings[Lady Spookyraven's Ghost,The Loathing Postal Service,coolestrobot,FairyGodMother,Peace and Love,HermieBot,CheeseFax] contains m.fromname); } process_kmail("no_penpal");
- Alias a "closet everything priced above 50k":
alias pvpcheck => ashq item [int] list; foreach it in $items[] { if (item_amount(it)+closet_amount(it) > 0 && it.tradeable && it.discardable ) { if ( historical_age(it) > 14) { if ( mall_price(it)>50000) list[list.count()] = it; } else if ( historical_price(it) > 50000) list[list.count()] = it; } } sort list by historical_price(value); foreach it in list { print(historical_price(list[it])+" : "+list[it]); put_closet(item_amount(list[it]),list[it]); }
- Getting a top menu command to work:
Moods: sometimes useful for maintaining limited base stats: (Unconditional trigger) ashq if (have_effect($effect [Drenched in Lava])==0) adv1($location[The Bubblin' Caldera],0)