Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ MUSHclient ➜ Lua ➜ Trigger Help Please

Trigger Help Please

It is now over 60 days since the last post. This thread is closed.     Refresh page


Pages: 1 2  

Posted by Eammon Wright   (17 posts)  Bio
Date Wed 23 Sep 2020 06:20 PM (UTC)

Amended on Thu 24 Sep 2020 03:58 AM (UTC) by Nick Gammon

Message
Ok so I have tried this trigger out of combat and it works fine but only partially works in combat. I'm sure it's something simple but i'd like some help if possible.
the trigger out of combat is


     HP [ */* ]     SP [ */* ]     EP [ */* ]


and the if statements it runs are::


if %1 < 500 then Send "say heal"
if %3 < 300 then Send "say Mana"
if %5 < 200 then Send "vitalize"
end -- if
end -- if
end -- if


so if I type hp out of combat, I have the number very high so they will all execute, but they do all execute.

Now in combat the only difference is the trigger placement but here it is.


HP [ */* ]     SP [ */* ]     EP [ */* ]


Just no spacing prior to hp. each round of combat that hp bar come across the screen. the if statements to check those scores and perform what i want are:


if %1 < 100 then Send "heal me"
if %3 < 100 then Send "eat food"
if %5 < 30 then Send "vitalize"
end -- if
end -- if


only the heal me part will fire off. How should I rewrite this to work?

[EDIT] Used code tags for the trigger.
Top

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #1 on Thu 24 Sep 2020 04:01 AM (UTC)
Message
In both cases your 2nd and 3rd tests are dependent on the first. Is that what you want? Indenting your code it looks like this:


if %1 < 100 then 
  Send "heal me"
  if %3 < 100 then 
    Send "eat food"
    if %5 < 30 then 
      Send "vitalize"
    end -- if
  end -- if
end -- if


In other words, it won't send "eat food" unless your HP is below 100 as well as your SP being lower than 100.

Assuming they are all independent you probably want:


if %1 < 100 then 
  Send "heal me"
end -- if

if %3 < 100 then 
  Send "eat food"
end -- if

if %5 < 30 then 
  Send "vitalize"
end -- if

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Eammon Wright   (17 posts)  Bio
Date Reply #2 on Thu 24 Sep 2020 01:13 PM (UTC)

Amended on Thu 24 Sep 2020 06:32 PM (UTC) by Eammon Wright

Message
That worked great Thank you so much. I think I need to open a new thread for this but i'm also trying to figure out how to make a script for a beach im hunting on. basically if I see the monster I check my health energy and mana and if they are over a certain amount my character will start the fight. is that something a pure beginner like me could shoot for or would that be too complicated sir?

This will trigger when I see a sand lizard, to check my stats before i fight him. well thats the goal.

DoAfter (1, "hp")
if %1 > 200 then
if %3 > 100 then
if %5 < 75 then
Send "attack creature"
end -- if
end -- if
end -- if

This just doesnt work in any sense. Where can I improve on this sir?

I get this error
[string "Trigger: "]:2: unexpected symbol near '>'
Top

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #3 on Thu 24 Sep 2020 09:01 PM (UTC)
Message
Can you show the whole thing, by following this guide:

Template:copying For advice on how to copy aliases, timers or triggers from within MUSHclient, and paste them into a forum message, please see Copying XML.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Eammon Wright   (17 posts)  Bio
Date Reply #4 on Fri 25 Sep 2020 11:59 AM (UTC)
Message
<triggers>
<trigger
enabled="y"
group="Cleric"
match=" sea lobster"
send_to="12"
sequence="100"
>
<send>DoAfter (1, "hp")
if %1 &gt; 200 then
if %3 &gt; 100 then
if %5 &gt; 75 then
Send "attack creature"
end -- if
end -- if
end -- if</send>
</trigger>
</triggers>


So basically I want to make it where when I see a creature it runs the hp command to show all my stats. if my stats in those if statements are all above those levels, then he would attack, if not, he would do nothing.
Top

Posted by Fiendish   USA  (2,533 posts)  Bio   Global Moderator
Date Reply #5 on Fri 25 Sep 2020 12:28 PM (UTC)

Amended on Fri 25 Sep 2020 12:33 PM (UTC) by Fiendish

Message
What you've done will never work (of course).

You've just told MUSHclient: "Send the 'hp' command 1 second from now. Immediately (before the hp command is sent) look at a local variable that doesn't exist."

MUSHclient then does the following in order: Says "that variable doesn't exist", waits 1 second, then sends the hp command.


You need to...

Trigger when seeing the monste and request stats. Then you have to wait for the stats to show up and continue only after they arrive.

Probably the best way to do this is using the wait.lua module's wait.match function to wait for the stats to arrive before continuing.

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Eammon Wright   (17 posts)  Bio
Date Reply #6 on Fri 25 Sep 2020 12:47 PM (UTC)
Message
Ok I see what your saying. Im sorry guys im really new to programming.
<triggers>
<trigger
enabled="y"
group="Cleric"
match=" HP [ */* ] SP [ */* ] EP [ */* ]"
send_to="12"
sequence="100"
>
<send>if %1 &gt; 280 then
Send "DoAfter (1,"attack lobster")"
end -- if</send>
</trigger>
</triggers>

So now when I see the lobster I have a trigger to run the hp command. if my HP is above 280 it should, after 1 second, attack. but this just throws an error. I have tried a single quote before and after the DoAfter statement but that just literally prints DoAfter (1,"attack lobster") on the screen. Also couldnt figure our how to check for more than just the HP being a certain level before the attack.
Top

Posted by Fiendish   USA  (2,533 posts)  Bio   Global Moderator
Date Reply #7 on Fri 25 Sep 2020 01:15 PM (UTC)

Amended on Fri 25 Sep 2020 01:29 PM (UTC) by Fiendish

Message
First, if you're nesting quotation marks, they can't be the same type. The Lua parser doesn't know that when you say "A"B"C" you really mean for the interal ones to be literal if you don't escape them.

Second, you don't Send DoAfter. You either Send _or_ you DoAfter. Not both.

Also, doing your trigger that way will send "attack lobster" literally every time you check your stats if your HP is high enough, which is not what you want. I recommend looking into my suggestion of using wait.match inside of the sea lobster trigger instead of a new second trigger. Otherwise you'll have to separately manage when to activate and deactivate this stats trigger.

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Eammon Wright   (17 posts)  Bio
Date Reply #8 on Fri 25 Sep 2020 01:28 PM (UTC)

Amended on Fri 25 Sep 2020 01:46 PM (UTC) by Eammon Wright

Message
I definitely see what your saying, the way i'm doing it is not very functional. However, I am unable to understand just yet how to make the wait.match work with it. Like I said this is my first time trying to write scripts. My end goal is to automate this guy so he walks a certain path and fights and waits along the way. I figured this would be a good way to learn a programming language.

Also Thank you guys for being so friendly and actually offering support and advice. It's refreshing.

Just to show what I had tried prior to this though.

<triggers>
<trigger
group="Cleric"
match=" HP [ */* ] SP [ */* ] EP [ */* ]"
send_to="12"
sequence="100"
>
<send>if %1 &gt; 280 and %3 &gt; 280 and %5 &gt; 100 then
DoAfter (1,"attack lobster")
else
DoAfter (60,"look")
end -- if</send>
</trigger>
</triggers>

So when I checked hp it would attack lobster, if one wasnt present it would just wait and look again, so I added a trigger for the 3 types of monsters on the beach, lobster, crab, and gull. so if I attacked lobster and there was not one there it would trigger attack crab, then gull...problem was it was some infinite loop that just kept cycling through them. I think that would work if I could figure out how to make it only fire off once each.
Top

Posted by Fiendish   USA  (2,533 posts)  Bio   Global Moderator
Date Reply #9 on Fri 25 Sep 2020 02:21 PM (UTC)

Amended on Fri 25 Sep 2020 08:46 PM (UTC) by Fiendish

Message
Quote:
if one wasnt present it would

That's not what that does. Nowhere does it evaluate presence.

Another thing you can do which might be simpler to understand is to have your HP/SP/EP trigger just store the values to variables and then check those variables for whatever was stored in them last whenever your monster triggers fire. Of course it will depend on you constantly updating those values in between.

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Eammon Wright   (17 posts)  Bio
Date Reply #10 on Fri 25 Sep 2020 02:54 PM (UTC)
Message
Yea. I'm going to dig around online and try and find an easy to follow example that I can tweak. I'm sure I can figure it out at that point. Thanks for all the advice, i'll be back if I can not figure it out though for sure :)
Top

Posted by Fiendish   USA  (2,533 posts)  Bio   Global Moderator
Date Reply #11 on Fri 25 Sep 2020 08:58 PM (UTC)

Amended on Fri 25 Sep 2020 09:07 PM (UTC) by Fiendish

Message
But anyway, using wait.match isn't hard per se (though it does require you to manually invoke a coroutine wrapper, which I hate). It's just apparently not documented anywhere.

You want your sea lobster trigger to do something like...


require "wait"
wait.make (function ()
   Send("hp")
   local line, wildcards = wait.match(" HP [ */* ] SP [ */* ] EP [ */* ]")
   -- here you check your hp/sp/ep using wildcards[1], wildcards[2], etc instead of %1 %2 etc.
end)


https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #12 on Sat 26 Sep 2020 03:34 AM (UTC)
Message
It's documented here: http://www.gammon.com.au/modules

Scroll down to the "wait.lua" section.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #13 on Sat 26 Sep 2020 03:39 AM (UTC)
Message
Quote:


<triggers>
  <trigger
   enabled="y"
   group="Cleric"
   match="   sea lobster"
   send_to="12"
   sequence="100"
  >
  <send>
DoAfter (1, "hp")
if %1 &gt; 200 then
  if %3 &gt; 100 then
    if %5 &gt; 75 then
      Send "attack creature"
    end -- if
  end -- if
end -- if
  </send>
  </trigger>
</triggers>



As Fiendish was explaining, the use of %1 here is meaningless because what you are matching on (the "match" part) doesn't have any wildcards, hence %1, %3 and %5 will just be empty strings.

A more logical approach would be to capture your prompt, and "remember" your current hp, mana etc. in variables. Then when you see the sea lobster you decide whether to attack it or not depending on the saved variables.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Eammon Wright   (17 posts)  Bio
Date Reply #14 on Mon 28 Sep 2020 12:21 PM (UTC)
Message
<triggers>
<trigger
enabled="y"
group="Cleric"
match=" sea lobster"
send_to="12"
sequence="100"
>
<send>require "wait"
wait.make (function ()
Send("hp")
local line, wildcards = wait.match(" HP [ */* ] SP [ */* ] EP [ */* ]")
end)

if wildcard[1] &gt; 280 and wildcard[3] &gt; 280 and wildcard [5] &gt; 100

Send "attack lobster"
end -- if</send>
</trigger>
</triggers>


Ok so, This is how I understood what you guys are saying. Still not working but am I getting closer?
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


64,429 views.

This is page 1, subject is 2 pages long: 1 2  [Next page]

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.