Cleric Scripts Question

Post Reply
Lalitaty
Posts: 2
Joined: Tue May 22, 2012 9:51 am

Cleric Scripts Question

Post by Lalitaty »

Hey guys,

New to the forum, been using Mudlet for a few months now, and must confess to love it. I play a different MUD than seems to be represented here (TFE), so I've had trouble checking through previous posts to find stuff totally relevant to what I'm trying to do. If such a post exists, please be so kind as to direct me to it and forgive my inability to find it.

I'm barely above a novice level script writer, but I've been able to get everything going the way I want it to go thus far, but I've hit a bit of a snag. Any advice on the best route to go would be appreciated. I'm playing as a cleric class, and a big part of that is constantly checking the group and picking out members with low Hp, on my mud that's done using the "group" command that gives a readout similar to:

Image

I set up a tick timer to give me the list frequently and I'd like to set up a script to run through the list at each check, find the members whose MaxHit - CurrentHit is >= HealPoint and then set up a function to "cast " healSpell memberName , if the condition is met. It's actually getting the variables filled (CurrentHit, maxHit, and memberName) that I am stuck at. I can't get a trigger that will pull them out correctly. I've also wondered if it would be better to work it into a list and keep it updated through there. Any thoughts would be appreciated.

User avatar
Oneymus
Posts: 321
Joined: Thu Sep 17, 2009 5:24 am

Re: Cleric Scripts Question

Post by Oneymus »

If you're already able to handle multiline triggers (and there are plenty of threads on those if you're not), then it seems like a simple matter of coming up with a good Regex pattern.

Not that this pattern is amazing, but it does match according to regexpal.com/.
^\[[\s\d\w]+]\s(\w+)\s+(\d+)/(\d+)\s+(\d+)/(\d+)\s+(\d+)/(\d+)\s+\d+$
And, yes, I would suggest that you store all of that data in a table, so you can perform any additional steps that may come up. It's not strictly necessary. For instance, you'll want to parse the data AFTER you've triggered on each line, so you have a complete picture of your group's status.
Code: [show] | [select all] lua
-- We want to store all of this data until we're ready to use it, so we need to maintain a group table.
-- We make this table in the first step of the trigger (usually some kind of opening line).
group_status = {}

-- Then, every line until the last, we add our group member data to it...
-- In this particular case, our matches look like this...
-- name = matches[2]
-- hp = matches[3]/matches[4]
-- energy = matches[5]/matches[6]
-- moves = matches[7]/matches[8]
group_status[matches[2]] = {
  hp = {
    current = matches[3],
    max = matches[4]
  },
  nrg = {
    current = matches[5],
    max = matches[6]
  },
  mv = {
    current = matches[7],
    max = matches[8]
  }
}
Once you have the data, you would just need to perform your math on it:
Code: [show] | [select all] lua
-- With our table in place, we can figure out how who needs healing. We would do this one the closing trigger
-- of our multiline trigger.
for name, data in pairs( group_status ) do
  local diff = data.hp.max - data.hp.current
  if diff >= HealPoint then
    send( "cast <heal> " .. name )
  end
end
That's a very basic example of what you're after. Of course, you can do the math each line if you'd like and avoid the table entirely. But storing the data before processing it allows you to do things like, say, prioritize healing in case your mana is low, or you have a cooldown of some sort between casts. Disclaimer: written in forum box.

Lalitaty
Posts: 2
Joined: Tue May 22, 2012 9:51 am

Re: Cleric Scripts Question

Post by Lalitaty »

Thanks for the quick and very detailed reply! It was both what I was looking for and quite a bit extra, and I appreciate it. The prompt is working fine, I just have it running with simple math right now, but I intend to try and work it in the table and script once I'm ready to give myself a headache making everything work right haha. Thanks again!

Post Reply