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 Fiendish   USA  (2,533 posts)  Bio   Global Moderator
Date Reply #15 on Mon 28 Sep 2020 01:39 PM (UTC)
Message
In Lua, every "if" needs a "then".

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

Posted by Eammon Wright   (17 posts)  Bio
Date Reply #16 on Mon 28 Sep 2020 02:30 PM (UTC)
Message
[string "Trigger: "]:7: attempt to index global 'wildcard' (a nil value)
stack traceback:
[string "Trigger: "]:7: in main chunk

Ok so this is the error im getting now. and this is what my code looks like.

<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 then

Send "attack lobster"

else
DoAfter (180,"look")
end -- if</send>
</trigger>
</triggers>

Ok so the point was to see the lobsterm have it run hp, if my stats are all over a ceertain level I attack else i wait 180 then look which will start the process all over again.
Top

Posted by Fiendish   USA  (2,533 posts)  Bio   Global Moderator
Date Reply #17 on Mon 28 Sep 2020 06:05 PM (UTC)

Amended on Mon 28 Sep 2020 06:10 PM (UTC) by Fiendish

Message
First you declared "wildcards" with an s, and then tried to access "wildcard" without an s. They must be the same.

Also I think you will need to move your lines around. Put your if/else stuff before the "end)" line that closes out the "wait.make(function()" line. Otherwise I'm pretty sure the waiting won't work.


Quote:
Ok so the point was to see the lobsterm have it run hp, if my stats are all over a ceertain level I attack else i wait 180 then look which will start the process all over again.

Isn't 180 a long time?

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

Posted by Eammon Wright   (17 posts)  Bio
Date Reply #18 on Mon 28 Sep 2020 07:19 PM (UTC)

Amended on Tue 29 Sep 2020 07:06 AM (UTC) by Nick Gammon

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 [ */* ]")
   if wildcards[1] &gt; 280 and wildcards[3] &gt; 280 and wildcards [5] &gt; 100 then

Send "attack lobster"

else
   DoAfter (60,"look")
end -- if
end)</send>
  </trigger>
</triggers>


Ok, See what your saying aboutthe placement and syntax. I get no errors now, however, it doesnt attack either. I see the lobster, it check hp then does nothing. Any thoughts?

EDIT: thought it might have been a spacing issue with the HP out put so I added the proper output spacing and it through this error.


hp
>      HP [ 288/288 ]     SP [ 289/289 ]     EP [ 114/114 ]
Error raised in trigger function (in wait module)
stack traceback:
        [string "Trigger: "]: in function <[string "Trigger: "]:2>
>


[EDIT] Added code blocks.
Top

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #19 on Tue 29 Sep 2020 07:08 AM (UTC)
Message
Inside the "wait" block you shouldn't use DoAfter. You should use wait.time. So, instead of:


   DoAfter (60,"look")


do:


  wait.time (60)
  Send ("look")

- Nick Gammon

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

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #20 on Tue 29 Sep 2020 07:10 AM (UTC)
Message
Template:codetag To make your code more readable please use [code] tags as described here.

- Nick Gammon

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

Posted by Eammon Wright   (17 posts)  Bio
Date Reply #21 on Tue 29 Sep 2020 12:07 PM (UTC)

Amended on Tue 29 Sep 2020 12:20 PM (UTC) by Eammon Wright

Message

require "wait"
wait.make (function ()
   Send("hp")
   local line, wildcards = wait.match(">      HP [ */* ]     SP [ */* ]     EP [ */* ]")
   if wildcards[1] > 280 and wildcards[3] > 280 and wildcards [5] > 100 then

Send "attack lobster"

else
    wait.time (60)
    Send ("look")
end -- if
end)


There we go. Ok. So fixed the wait.time look, and that all works fine. However, it is not firing the attack command even though the wildcard parameters have been met. Any thoughts?

Error:
...son\Desktop\Misc\Passport Backup\MUSHclient\lua\wait.lua:67: [string "Trigger: "]:5: attempt to compare number with string
stack traceback:
[C]: in function 'error'
...son\Desktop\Misc\Passport Backup\MUSHclient\lua\wait.lua:67: in function <...son\Desktop\Misc\Passport Backup\MUSHclient\lua\wait.lua:59>

Error raised in trigger function (in wait module)
stack traceback:
[string "Trigger: "]: in function <[string "Trigger: "]:2>

Now if you notice that the hp trigger has a > and a large space before the stats are parsed, that's the exact output when hp is ran. It seems that the '>' is throwing the error, it's trying to use that as an operator instead of the text output. Also, i'm assuming that they d this to prevent triggers and scripts, but sometimes that '>' is there, and sometimes it's not. Is there a way around that also with this script? Any thoughts on that one as well?
Top

Posted by Fiendish   USA  (2,533 posts)  Bio   Global Moderator
Date Reply #22 on Tue 29 Sep 2020 12:29 PM (UTC)

Amended on Tue 29 Sep 2020 12:42 PM (UTC) by Fiendish

Message
Quote:
It seems that the '>' is throwing the error, it's trying to use that as an operator instead of the text output.

No. wait.match wildcard results don't work the same way as %1, %2 pattern replacement does. You have to convert wildcards[1] etc to numbers with tonumber if you want them to be treated as numbers.

You do still have to be careful about the XML parser though. The <triggers><trigger><send></send></trigger></triggers> block gets parsed as XML first before being sent to the Lua engine, which is why you'll often see &gt; and &lt; inside there instead of > and <. But the parser will usually only care about < and not about > for technical reasons.

Quote:
sometimes that '>' is there, and sometimes it's not. Is there a way around that also with this script?

Either switch from wait.match to wait.regex and use a regular expression pattern instead or replace the leading > with another wildcard capture and shift your index numbers up one.

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

Posted by Eammon Wright   (17 posts)  Bio
Date Reply #23 on Tue 29 Sep 2020 01:06 PM (UTC)

Amended on Tue 29 Sep 2020 01:15 PM (UTC) by Fiendish

Message

require "wait"
wait.make (function ()
   Send("hp")
   local line, wildcards = wait.match("*      HP [ */* ]     SP [ */* ]     EP [ */* ]")
   if wildcards[2] > 280 and wildcards[4] > 280 and wildcards [6] > 100 then

        Send "attack lobster"

    else
        wait.time (60)
        Send ("look")
    end -- if
end)


I'm assuming that's what you meant about the '>' problem. But I am unsure how to use tonumber here. I have read through the function file on it here ont he forums. Would you please be able to show me an example maybe?
Top

Posted by Fiendish   USA  (2,533 posts)  Bio   Global Moderator
Date Reply #24 on Tue 29 Sep 2020 01:12 PM (UTC)

Amended on Tue 29 Sep 2020 01:20 PM (UTC) by Fiendish

Message
Quote:
I'm assuming that's what you meant about the '>' problem.

Yup. Keep in mind that doing it this way will also match if the line starts with "ASDasdfasdfSDFSDFSDFSD" or "SomePlayer says ". To avoid that, you'd need to switch to a regular expression pattern and use wait.regex instead. But get this working first before you worry about that.

Quote:
Would you please be able to show me an example maybe?

tonumber(wildcards[2]) > 280

etc

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

Posted by Eammon Wright   (17 posts)  Bio
Date Reply #25 on Tue 29 Sep 2020 01:47 PM (UTC)

Amended on Tue 29 Sep 2020 05:50 PM (UTC) by Eammon Wright

Message

require "wait"
wait.make (function ()
   Send("hp")
   local line, wildcards = wait.match("*      HP [ */* ]     SP [ */* ]     EP [ */* ]")
   if tonumber(wildcards[2]) > 280 and tonumber(wildcards[4]) > 280 and tonumber(wildcards [6]) > 100 then

        Send "attack lobster"

    else
        wait.time (60)
        Send ("look")
    end -- if
end)


Works great. Now when it sees the creature, it checks my stats, if their above those levels it attacks, if not it waits 60 seconds while i regen and looks again.

So what was the next problem you were saying with my code sir?

EDIT: Actually I'm running across a small but annoying problem. There are 3 creatures on the beach I have that script for. Lobster, Crab, and Gull. Sometimes when I see one, it will try and attack a different one instead. Any htoughts on that?
Top

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #26 on Wed 30 Sep 2020 01:03 AM (UTC)
Message
You need to detect which one you see, eg. trigger on "A * is here" and remember (save as a variable) which mob is there.

- Nick Gammon

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

Posted by Eammon Wright   (17 posts)  Bio
Date Reply #27 on Wed 30 Sep 2020 12:24 PM (UTC)
Message
I either trigger on the crab, lobster, or gull, depending on which is on the screen. I was afraid if I set a generic * and made it a variable and attacked the variable that could bite me. If someone were to walk on the screen I would attack them. Other than that though the script seems to work fine. I have to find a way to put it into my array loop once I get it working.
Top

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #28 on Thu 01 Oct 2020 07:06 AM (UTC)
Message
Well, with a regexp you can do:


^A (lobster|crab|gull) is here\.$


That only matches on those 3 words.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
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,430 views.

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

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.