MUSH Auto-sipper

Okay, so I run MUSH versus Mudlet. Only reason is because my system's too old, need to upgrade. Anyway, for MUSH, I wrote an auto-sipper(written in Lua). Works fairly well, except for one thing: As soon as health or mana hits X% (X being the percent I set it, in the case 75% health, 65% Mana), it sips without regard to the sip balance. Now, I've no actually coding expereince (got the help of a friend who codes for a living), so I don't know what the issue is within the code, or how to fix it. Any help would be appreciated.

Comments

One thing that jumps out right away is that when you send("sip "..typeof);, you don't then set (or ever check) some control flag that says "Hey, I'm trying to sip, don't just keep spamming the command until I see the sip line when the first goes through". Of course, you need to have a check that then unsets this if the sip fails or just takes too long, though.

Edit: Now that I have more than a minute to type this...I would personally make your sip balance a trinary value, or just an integer, rather than binary, and do something like on balance = 1, off balance = 0, trying to expend balance = 0.5, and then you know the state of what you're doing and attempting to do at any given moment and only have to check one variable for a specific state rather than have your if checks contain more and more conditions that gets progressively harder to digest at once.

The other thing is that I don't know what your triggers look like. For example, do you have both elixirs and tonics accounted for in your sipped trigger, and does that properly set the sip balance variable to false? Really simple, but easy to overlook if the Regex got mangled trying to account for both elixirs and tonics. Should look something like (going off of memory)...

^The (?:elixir|tonic) heals and soothes you.$

^The (?:elixir|tonic) flows down your throat with no effect.$

^Your mind feels stronger and more alert.$

And all of those feed into the same that sets your sip balance off.

Post edited by Kei on March 2014

Bydar, a garish-looking trader says, "I'm not a man, I'm an experience."