Script problem

Digital Ninja
Posts: 26
Joined: Mon Jun 07, 2010 1:43 am

Script problem

Post by Digital Ninja »

Hi everyone, i don't know what i'm doing wrong here but... i've finally gone through the forum to find out how to do speedwalking. i found a good post which shows how to do forward and reverse and even set up a speedwalk table to store all of your dirs. i'm having a problem with BUTTONS though:

here is the idea:
I want some buttons for some of my popular AREAS to go to, making use of the speedwalk and speedwalktable functions. here is what i have:

Speedwalk function:
Code: [show] | [select all] lua
function speedwalk(walkstring)
   for count, direction in string.gmatch(walkstring, "([0-9]*)([neswdu])") do     
      count = (count == "" and 1 or count)
      for i=1, count do send(direction) end
   end
end
Speedwalk Table function:
Code: [show] | [select all] lua
speedwalktable =   {
	marshlands = "2s13en4en",
	abyss = "2s9es2es10en8e9n",
	alien_king = "2s13en11e2n2e2d2e2ded2s3ws",
	aliens = "2s13en11e2n2e2d2e2ded",
	allemonde = "6w2s",
	ancient_city = "4se4s6e24s6esw"
         }
Button:
Code: [show] | [select all] lua
speedwalk(speedwalktable(marshlands))
i also tried using brackets
Code: [show] | [select all] lua
speedwalk(speedwalktable[marshlands])
Nothing happens when i press the button though

Question 2:
how can you access you're stats? for example:
I want a trigger that will quaff a healing potion if my hps come too low...

I really am new to this, so i don't know how to do that. In zMud though it was super simple.
Could someone help me with that?

It's a DikuMud...
The only info I can offer that might help is that the screen shows the particular stats like this:
< 966hp 1095mana 208mv >

Really would be awesome;
thanks
J

Denarii
Posts: 111
Joined: Thu Dec 03, 2009 10:54 pm

Re: Script problem

Post by Denarii »

speedwalk(speedwalktable["marshlands"])

Digital Ninja
Posts: 26
Joined: Mon Jun 07, 2010 1:43 am

Re: Script problem

Post by Digital Ninja »

Thanks! That was the problem...

I have a new question if you don't mind: i didn't think about this originally but it caused me a problem earlier today.
Let's use the "marshlands example"
Button: Marshlands
Body:
speedwalk(speedwalktable["marshlands"])

OKAY that works:
HOWEVER, I have some directions that require casting a spell first to get to a location, before making the walk cycle. so this works:

Button: Marshlands
Body:
send("cast 'spell_that_takes_you_close_to_marshlands' ")
speedwalk(speedwalktable["marshlands"])


HOWEVER, here is the problem... Today, I got the message:
You lost your concentration!

And then it executed the run cycle...
This is very bad, because I actually didn't MAKE it to the DROP LOCATION, before making the run, because of the spell failure. How can I make it so that it keeps trying to recast the spell until it works?

I have in my head an idea of using an if statement, but not really sure how to check things yet in mudlet.
I'd have to save even after that part is solved... I'd need to add in ONE MORE if, that calls off the walk cycle, if I don't have enough to even cast the spell... so say it trys to cast the spell, don't have enough spellpower left and so, i don't want it to run either.

or actually probably a while loop?
while (you lost your concentration!)
send("cast 'word_to_place' ")

if (you don't have enough to cast this spell)
send("rest")

else
speedwalk(speedwalktable["marshlands"])


so i have the idea in my head, but absolutely no idea how to set that up within this. not sure how i get access to the messages on the screen.

Digital Ninja
Posts: 26
Joined: Mon Jun 07, 2010 1:43 am

Re: Script problem

Post by Digital Ninja »

Also: It's a bit hidden in my first post but:

Question 2:
how can you access you're stats? for example:
I want a trigger that will quaff a healing potion if my hps come too low...

I really am new to this, so i don't know how to do that. In zMud though it was super simple.
Could someone help me with that?

It's a DikuMud...
The only info I can offer that might help is that the screen shows the particular stats like this:
< 966hp 1095mana 208mv >

Really would be awesome;
thanks
J

Denarii
Posts: 111
Joined: Thu Dec 03, 2009 10:54 pm

Re: Script problem

Post by Denarii »

Have the button only cast the spell, then make a trigger for a successful cast that will start the speedwalk.

For question 2, make a trigger with this pattern:

Code: Select all

^< (\d+)hp (\d+)mana (\d+)mv >
that executes this:
Code: [show] | [select all] lua
if tonumber(matches[2]) < 200 then send"quaff potion" end

Digital Ninja
Posts: 26
Joined: Mon Jun 07, 2010 1:43 am

Re: Script problem

Post by Digital Ninja »

Hi Denarii,
Thank you so much for taking the time to help answer my questions.

I do have one problem for the answer for the button to cast the spell and set a trigger to speedwalk...

Sometimes I will cast that spell without needing to go to marshlands for example. Sometimes I will just need to cast that spell and go nowhere. Sometimes I might need to cast the spell and go to another speedwalk.

So i'm not sure how to use a trigger to allow those options. That's why I thought it all needed to be done within the button somehow. Not sure though? Thanks for your help again!

Thanks,
Jonathan

User avatar
demonnic
Posts: 886
Joined: Sat Dec 05, 2009 3:19 pm

Re: Script problem

Post by demonnic »

you have the button set a variable. For instance, to get to the marshlands, you have the button do this:
Code: [show] | [select all] lua
send("cast <whateverspellyouuse")
walkingTo = "marshlands"
tempTimer(1,function() walkingTo = nil end)
And then in the trigger for the spell's successful effect
Code: [show] | [select all] lua
if walkingTo ~= nil then 
  speedwalk(speedwalktable[walkingto])
  walkingTo = nil
end
This way, if you cast the spell with the button, it will then do the speedwalk path. If you don't, then walkingTo will be nil. The tempTimer() function call is to reset walkingTo to nil again in case it fails. You can then just click it again (in case you don't want it continuing to cast the spell and chewing through all of your mana). It will also not tell it to go there twice if it does succeed.

Digital Ninja
Posts: 26
Joined: Mon Jun 07, 2010 1:43 am

Re: Script problem

Post by Digital Ninja »

Denaril:

Thanks! It KIND of works. Just noticed something though.

When i'm not in battle it only shows:
< 966hp 1095mana 208mv >

but when i'm in battle it can show:
< 799hp 167mana 201mv Buf:fine Vic:bleeding >
or
< 799hp 167mana 201mv Buf:fine >

so I just tried this:
Code: [show] | [select all] lua
^< (\d+)hp (\d+)mana (\d+)mv (.*)>
It seemed to work! BUT! More complexity grew out of this...
It always quaffs two potions... Reason why is this... I store my potions in a sack.

So in the script i have: get potion from sack; quaff potion.
But when the trigger executes: It gets the potion from sack: That causes the screen to refresh and post the message: You got a Healing Potion from Sack.

Because the screen refreshed: it shows my health under X hps again, so it registers to get another potion BEFORE quaffing the first one!

So, any ideas how to handle this one?
Thought was that i could have two triggers, one that checks my health and makes me get a potion from the sack and another trigger that activates when the message you got a potion of healing from sack happened and then i thought, oh that's not good because if i just want to get a potion out of the sack without drinking it then that won't work out good.... have some ideas how to deal with this one? Thank you a lot

Demonnic:
Great thanks! I'll give it a go!
J

User avatar
demonnic
Posts: 886
Joined: Sat Dec 05, 2009 3:19 pm

Re: Script problem

Post by demonnic »

The easiest way to handle this, assuming you don't need to wait a certain amount of time before you can drink a second potion, would be to have it set a variable when it decides to drink a potion.
Code: [show] | [select all] lua
if health < somenumber and not quaffing then
  quaffing = true
  send("get potion from pack")
  send("quaff potion")
end
Then in a trigger for having successfully quaffed a potion you do:
quaffing = false


Alternately:
If there's a chance you might not successfully quaff the potion, you could also use a tempTimer in the top bit of pseudocode to automatically set quaffing back to false, so if it hasn't quaffed or failed to quaff for some reason, it'll try again.
Code: [show] | [select all] lua
if health < somenumber and not quaffing then
  quaffing = true
  send("get potion from pack")
  send("quaff potion")
  quaffTimer = tempTimer(1,function() if quaffing then quaffing = false end end)
end
And in fact you may want to combine that with triggers running for the msg you've failed

trigger: you somehow wear your potion instead of quaffing it
Code: [show] | [select all] lua
quaffing = false
killTimer(quaffTimer)
This way, if you fail to quaff, and you somehow fail to get the message saying you failed, it will set quaffing to false so that it can try again. But if you fail and it -tells- you you failed, it will set quaffing to false -and- get rid of the other backup timer, so that it does not inadvertently stuff you up and make you double quaff sometimes but not every time, making it a nightmare to decode. (Not that I've ever done this... oh no... not me... <.<)




Of course, if you work off of something a bit more complicated, such as an IRE MUDs many balances and statistics which must be taken into consideration, the complexity of the problem can seem to quickly get out of hand. But in the end, it's mostly just flipping bits in a state machine, and once you've got it set up and the kinks worked out and you know what all the bits do and when it will totally be worth it.

Digital Ninja
Posts: 26
Joined: Mon Jun 07, 2010 1:43 am

Re: Script problem

Post by Digital Ninja »

Hey Demonnic Once again thank u for the time,
It does not seem to be recognizing that a variable has been set. Do I need to declare it somewhere else initially? It still quaffs 2 potions.

Right now here is what i have:
3 triggers (That's it... am i missing something there?)

Trigger1: Drink Potion:
Code: [show] | [select all] lua
^< (\d+)hp (\d+)mana (\d+)mv 
set to perl regex
Body:
Code: [show] | [select all] lua
if  (tonumber(matches[2]) < 800) and not quaffing then 
	quaffing = true	
	send("get oil 2.leather; quaff oil")
	quaffTimer = tempTimer(1,function() if quaffing then quaffing = false  end end)
end
Trigger2:Quaff Healing Success!
Code: [show] | [select all] lua
You quaff Fish Liver Oil which dissolves.
set to exact match
Body:
quaffing = true

Trigger3: Healing Potions Out!
Code: [show] | [select all] lua
The bag does not contain the oil.
set to exact match
Body:
quaffing = false
killTimer(quaffTimer)

A couple things happened:
ONE here is the first thing that shows the dual potion pull out

< 767hp 553mana 208mv Buf:fine Vic:mauled >
get oil 2.leather; quaff oil
You get Fish Liver Oil from leather bag.

< 767hp 553mana 208mv Buf:fine Vic:mauled >
get oil 2.leather; quaff oil
You quaff Fish Liver Oil which dissolves.
Your wounds cease flowing as you feel better!
That person is not poisoned.

< 884hp 553mana 208mv Buf:fine Vic:mauled >

The Ghoul makes a mystic hand position and utters the words, 'chill touch'
The Ghoul's touch sends shards of frigid ice ripping through A large bunny's body.

< 884hp 553mana 208mv Buf:fine Vic:mauled >
You get Fish Liver Oil from leather bag.

< 884hp 553mana 208mv Buf:fine Vic:mauled >
You quaff Fish Liver Oil which dissolves.
Your wounds cease flowing as you feel better!
That person is not poisoned.

< 1016hp 553mana 208mv Buf:fine Vic:
Secondly, The trigger went on infinitely if there was not a potion in the bag

Hmmmmm! Also, just for future knowledge. is there a way for me to "report" what the quaffing variable is? Just for bug testing, it might be good to learn that part

Post Reply