Charged Magnet auto equip

halfvoid

Member
in this post on the kol wiki. it is mentioned that for the charged magnet effect of encountering rock monsters every 30 adventures the charged magnet only needs to be equipped on the 30th adventure.

I was wondering if anyone had made a script to perform such a task and would be willing to share it.
 

kain

Member
Doesn't seem like it'd be that hard, set a property called turns, set it equal to whatever your turncount is, run a between battle script to compare your current turncount to the stored turncount, if they're 29, equip the magnet and reset the counter ...

I don't care to use one, but maybe tomorrow I'll bang something out
 

halfvoid

Member
yeah. i've been farming for floaties in hopes to get a rock lobster sometime in the near future, and it would seem more worth it if i could use a better +item drop off hand in the turns between the rock battles.
 

Catch-22

Active member
Doesn't seem like it'd be that hard, set a property called turns, set it equal to whatever your turncount is, run a between battle script to compare your current turncount to the stored turncount, if they're 29, equip the magnet and reset the counter ...

I don't care to use one, but maybe tomorrow I'll bang something out

Mmm there might be a better way, but the only way I can think of at the moment is using 2 scripts, a between battle script to count the turns up to 29/equip items and a combat script to reset the counter to zero. I'm guessing you'd probably use map_to_file() and file_to_map() to store the count between sessions/scripts. So you'd map a 0 to the file when you have encountered the monster in your combat script and in the between battle script you would file_to_map() and increment the count, equip items accordingly, and then map_to_file() again so it can be read after the next battle.

It's kinda dirty coz you're storing variables in a text file, but I might just be over-complicating things, there's a lot of stuff in ashref that I don't know about.
 
Last edited:

Veracity

Developer
Staff member
Use settings, via set_property() and get_property(), rather than messing with map files.
I don't see any reason why a single between battle script couldn't handle all the counting, equipping, unequipping, etc.
 

Catch-22

Active member
Use settings, via set_property() and get_property(), rather than messing with map files.
I don't see any reason why a single between battle script couldn't handle all the counting, equipping, unequipping, etc.

I did notice those functions in ashref but unfortunately they're undocumented in the wiki, would they retain values between sessions, or are the properties destroyed when KoLmafia is closed?

How can you tell the last monster fought in between battles?
 

Veracity

Developer
Staff member
Properties retain their values across sessions.
Good point about detecting monsters; it's not literally "every 30 turns". I don't think we have a "last monster fought" function.
 

Bale

Minion
Properties are saved in your character's preference file in the /settings directory. They will persist between sessions, but they are not shared between characters.

Edit: Ninja'ed by veracity. I was really slow. ;)
 

Catch-22

Active member
Good point about detecting monsters; it's not literally "every 30 turns". I don't think we have a "last monster fought" function.

I couldn't find one. However, I don't think it would be hard to implement, it just involves looking back on the CLI output "Encounter: Knob Goblin Elite Guardsman" etc.

I would actually rather a method with which our scripts can handle the output from CLI, which could be used for more than just figuring out the last encountered monster. With RegularExpression support we'd be able to determine all sorts of things just by interpreting CLI output :)

Properties are saved in your character's preference file in the /settings directory. They will persist between sessions, but they are not shared between characters.

Mmm still, I don't like working with variables stored on disk. It's really something you have to put up with, sure you can work with locally defined variables, the downside being they are destroyed when the script is stopped. I think ideally, I would rather have a way to end a script nicely, whether it has been the stop button or by quitting KoLmafia. Imagine if a script were able to run through a "cleanup sequence", where the local variables can get converted to stored properties and stuff like that. If it takes too long to stop on it's own, then sure, go ahead and terminate the script.
 
Last edited:

jasonharper

Developer
I would actually rather a method with which our scripts can handle the output from CLI, which could be used for more than just figuring out the last encountered monster.
Indeed; such a feature could also be used to write scripts that do unrestricted Mall searches, and to write scripts that break unexpectedly due to a chat notification ending up in the middle of the text they're trying to parse.

Perhaps more importantly: if such a feature existed, then the current format of all commands' output would be carved in stone forever. No additional details could ever be provided, and no messages ever reworded to make them clearer, for fear that it would break some script. Is that really what you want?

As for determining the last monster, the lack of a function seems an easily fixable oversight, but here's a workaround for now: require that the monster of interest have its own section in your CCS, starting with a "note" command with some distinctive text - "note floaty" for example. Then, get_ccs_action(0) == "note floaty" will be true only if that was the most recently encountered monster.
 

Bale

Minion
here's a workaround for now: require that the monster of interest have its own section in your CCS, starting with a "note" command with some distinctive text - "note floaty" for example. Then, get_ccs_action(0) == "note floaty" will be true only if that was the most recently encountered monster.
Ooo! Elegant. I like it.
 

zarqon

Well-known member
You can't access the CLI output from within a script.

The best way would be to write a little custom combat script for it that sets a counter. Like this:

Code:
void main(int initround, monster foe, string url) {
   if (foe == $monster[rock snake] || foe == $monster[rock homunculus] || 
       foe == $monster[rock fish] || foe = $monster[clod hopper])
      cli_execute("counters add 31 rockmonster");
}

You can use this by specifying it in your CCS:

[ default ]
consult isitarockmonsterorwhat.ash
consult SmartStasis.ash
attack


By the way, it's 31 because once you finish the combat it will be 30. Then, in your betweenBattleScript, include something like this:

Code:
if (get_counters("rockmonster",0,0) != "") equip($item[charged magnet]);
   else equip($item[whatever offhand item you normally use])

That should keep you rolling in rock monsters. I think.
 
Last edited:

Bale

Minion
I think zarqon wins this round. Though there's still the small problem of mafia unequipping the charged magnet as soon as the betweenBattleScript ends.
 

zarqon

Well-known member
What's the prize what's the prize what's the prize?? Is it a bat?

Note: if you were planning to go swimming or vacationing you would want to do different get_counters() range checks: 0,1 for the sea or 0,2 for the beach.
 

Bale

Minion
I'll give you a two winged bat if you can tell me how you keep mafia from unequipping the charged magnet after your betweenBattleScript is run.
 

zarqon

Well-known member
Eeeehhhh?? Why would it do that? Mafia doesn't unequip the wooden stakes, equipped by BBBE. I'll look into it.
 

zarqon

Well-known member
I've noticed mafia re-equipping previous gear when a call to adventure() is finished, but not between battles. Maybe that's what you were thinking of.

I just tested the solution I posted above. The counter causes an abort. So, handling of gear switching should be done in the counterScript, not the betweenBattleScript.
 

Spiny

Member
I've been manually adventuring tonight while xp hunting. I figured I'd start trying to be more efficient about hunting rock monsters by equipping the charged magnet and item drop gear rather than have 3 clod hoppers go by without a single drop because I wasn't bothering to anticipate their appearance and didn't have item drop stuff on.

The data in the wiki in regards to the charged magnet had me confused as to WHEN to equip the magnet. In prior attempts I had been equipping it after encountering the rock monster and wondering why it was far more than 30 adventures before seeing one again. There was a kol forum post from the other day that I saw today that shed some light for me.

Terion - Re: Reduced Clod Hopper sand drops:
What might be confusing you (and is confusing me, as I'm not sure which way you're thinking from your post) is that the counter is set depending on whether or not you've a charged magnet equipped when you fight a rock monster, not on the turns after that. So, if you fight a hopper with something else in your offhand, and then equip a charged magnet, it's still going to take 50-some turns for the next one to show.

With this in mind, I started using the counters add command in the CLI.

Here are my turn counters with rock monsters tonight and turns between:

5230
5284
5335
5363
5410
5442

5230-5284=54 turns no magnet
5285-5335=50 turns, equipped magnet on this encounter
5336-5363=27 turns, I did not have magnet on as I set my counter tracker to 29
5364-5410=46 turns, set counter to 40 to prep magnet in time
5411-5442=31 turns, set counter to 24 to equip magnet for the possible 25-35 range, magnet equipped, only had 12 turns left

Anyhow, based on my experiences, I don't know that you can have a finite 30 turns between rock creatures unless I'm still misunderstanding something. At best set the counter to 24 to equip charged for the 25th-35th turn and when the rock creature is found, set new counter and switch off-hands/gear till 24 turns have passed again.

-Spiny
 

Catch-22

Active member
Indeed; such a feature could also be used to write scripts that do unrestricted Mall searches, and to write scripts that break unexpectedly due to a chat notification ending up in the middle of the text they're trying to parse.

Perhaps more importantly: if such a feature existed, then the current format of all commands' output would be carved in stone forever. No additional details could ever be provided, and no messages ever reworded to make them clearer, for fear that it would break some script. Is that really what you want?

Hey I appreciate your response, but there's no need to be so snarky about it. A well written script doesn't need to break. Perhaps all the problems you're trying to point out with my suggestion are really just problems with the current framework for scripting.

Yes I do realize that something like this could cause a lot of scripts to break (if used carelessly or in a bad situation), but half if not over half of the scripts up on these boards are already broken anyway. A broken script deserves to stay broken if nobody cares enough to fix it.

As for the unrestricted mall searches or other "unscrupulous behavior", well really a wrapper for KoL in command line mode could already be used for the same purposes. A lot of the scripters here are already trying to make a conscious effort to limit server hits, so I think there are a lot of legitimate uses for such a functionality.

It just sounded to me like your mind was made up before you even finished thinking about it. That's the way it came across.

Anyhow, based on my experiences, I don't know that you can have a finite 30 turns between rock creatures unless I'm still misunderstanding something. At best set the counter to 24 to equip charged for the 25th-35th turn and when the rock creature is found, set new counter and switch off-hands/gear till 24 turns have passed again.

If I were writing a script, this is what I would be doing. Jick actually stated that it was 25-35 adventures.

I just tested the solution I posted above. The counter causes an abort. So, handling of gear switching should be done in the counterScript, not the betweenBattleScript.
So how do you plan on equipping items in a CCS?

I think what Bale may have been getting at, or at least a potential problem that I can see with what you have there, is that your conditionals are too vague. Equip the magnet when counter reaches 0, otherwise equip another item. So for counter of 30 down to 1, you're going to try to equip another item.

Here are just a few thoughts:

Firstly I would be starting the counter at 25, not 30.

Secondly, the counter should be reset, not added to. Let's say you started the counter at 30, now imagine you encountered the rock monster on adventure 25. You're going to add another 30 on to the remainder of 5, now your counter won't fire for another 35 adventures and this could have a cumulative effect.

Thirdly, it's easier to explain in pseudocode:

If counter = 0 Then
Equip magnet
End If

If counter = 25 Then
Equip other item
End If

See there's no else, so you're avoiding the attempt to equip the other item if the counter hasn't reached 0.
 
Last edited:
Top