Newbie Scripting help

Posted by GooGoo on Wed 08 Feb 2012 09:31 PM — 8 posts, 28,345 views.

#0
I am trying to accomplish this script with LUA. Most forum entries I have read seem to over complicate the task.

Is there an easy way to accomplish this:

Alias GO (send to script)

Attack a "monstername"
Wait for "you killed <monstername>
Attack a "monstername"
wait for "you killed <monstername>
..
..
..

Until you receive "no <monstername> to attack"

send to world "go east"

Thanks
USA Global Moderator #1
What forum threads did you read?

It's a simple matter of combining an alias based on this information:
http://www.gammon.com.au/forum/?id=9616

with a trigger based on this information:
http://mushclient.com/forum/?id=7794#22
Australia Forum Administrator #2
You need to use the wait module.

http://www.gammon.com.au/forum/?id=4957

Here is an example:


<aliases>
  <alias
   match="GO *"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>

require "wait"

function cr () 

  monsterName = "%1"

  repeat
    -- attack the mob
    Send ("attack " .. monsterName)

    -- wait until it is dead
    line, wildcards = wait.regexp ("(You killed %1)|(No %1 to attack)")

  until string.find (line, "No %1 to attack")

  Send "go east"

 end -- of function cr

wait.make (cr) -- start coroutine up

</send>
  </alias>
</aliases>


You will need to modify the regular expression to match *exactly* what you see.

Australia Forum Administrator #3
Ninja! Plus what Fiendish said. :)
USA Global Moderator #4
Quote:
You need to use the wait module.

I don't think you do. A trigger on "you killed..." that attacks and a trigger on "no monster..." that moves and attacks will do what was requested.
Australia Forum Administrator #5
Oh, OK. You can manage it with multiple triggers, indeed.

That may well suit you, to break down the problem into smaller parts.

The "wait" module idea shows the flow of decisions in a single place.
#6
Hey,

Thanks for responding and helping out a complete newb, much appreciated. I have reviewed the above links. I don't necessarily even need to target the mob, I can just type in the name. Does this script continue to type kill dog or does it type it once then wait for a response?



<alias
match="GO"
enabled="y"
regexp="y"
send_to="12"
sequence="100"
>
<send>require "wait"
function cr ()
repeat
Send "kill dog"
line, wildcards = wait.regexp ("^(You killed dog)|(No dog here!)$")
until string.find (line, "^No dog here!$")
Send "west"
end -- of function cr
wait.make (cr) -- start coroutine up</send>

I get the following error

Expected statement
Line in error:
until string.find (line, "^No dog here!$")

Thanks.
#7
Sorry, this is it. Same error.

<send>require "wait"
function cr ()
repeat
Send "kill dog"
line, wildcards = wait.regexp ("^No dog here!)$")
until string.find (line, "^No dog here!$")
Send "west"
end -- of function cr
wait.make (cr) -- start coroutine up</send>


I only need to action one string-> No Dog here!. No choice needed.