[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Simple script
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Simple script

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


Pages: 1 2  3  

Posted by Metsuro   USA  (389 posts)  [Biography] bio
Date Thu 08 Dec 2005 01:25 AM (UTC)
Message
Ok I am tring to get an script to automaticly pick herbs based on a formula from 2 triggers and an alias.

alias would be like

pick (herb)

first trigger would catch on:

you have recovered balance -- and then do "plants"

second trigger will match on

(herb) (number) left.

so I was thinking it might work like

local herb
local pick

function start_pick (name, output, wildcs)
herb = wildcards[1]
Send("plants")
end

function check_pick (name, output, wildcs)
(something to check if the herb was the right one if not have another function to check it maybe?)
if wildcard[2] > 0 then
Send("pick ", herb)
else
Note("Cant pick anymore ", herb)
end
end

something... like that... I guess?

Everything turns around in the end
[Go to top] top

Posted by Nick Gammon   Australia  (21,399 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Thu 08 Dec 2005 02:22 AM (UTC)
Message
Well you are on the right track. Time to start testing your ideas. For some simple things you don't need a separate script file. I'll take your "pick" alias idea and show how it can all be done in the alias:


<aliases>
  <alias
   match="pick *"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>herb = "%1"
Send "plants"</send>
  </alias>
</aliases>



Now if you type "pick mushroom" (for example), it saves the word "mushroom" in the herbs variable, and sends "plants" to the MUD.

You can check the variable by typing into the command window:

/print (herb)

You should see echoed: mushroom

Now try the other things yourself. If you are posting, try using the copy function in the alias list to copy the actual alias as I have done, to avoid typing errors.

By the way, you need attention to detail in your scripts. For example:


function start_pick (name, output, wildcs)
herb = wildcards[1]
Send("plants")
end


The variable name you have used in the function line is "wildcs" but then you are using "wildcards" a line later. They have to be spelt the same.


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Metsuro   USA  (389 posts)  [Biography] bio
Date Reply #2 on Thu 08 Dec 2005 03:02 AM (UTC)

Amended on Thu 08 Dec 2005 03:09 AM (UTC) by Nick Gammon

Message
Ok I got it work, using:


function do_pick (name, output, wildcs)
 if wildcs[2] == herb then
  if wildcs[3] > "10" then
   Send("pick ", herb)
  else
   Note("No more for you to pick.")
   EnableTriggerGroup ("Herbs", false)
  end
 end
end


but now I notice its really spammy checking plants over and over again... so how could I gag it maybe?

Everything turns around in the end
[Go to top] top

Posted by Nick Gammon   Australia  (21,399 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Thu 08 Dec 2005 03:07 AM (UTC)
Message
Can you paste the actual output you receive, and your actual trigger?

I wouldn't do this:


if wildcs[3] > "10" then


You want a numeric compare, right? That is a string compare. Try:


if wildcs[3] > 10 then


No, I wouldn't gag anything, I would fix the problem.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Metsuro   USA  (389 posts)  [Biography] bio
Date Reply #4 on Thu 08 Dec 2005 03:12 AM (UTC)

Amended on Thu 08 Dec 2005 11:40 PM (UTC) by Metsuro

Message
no see I tried that it said I was comparing a number to a string, and thats the only way I could get it to work.

<triggers>
<trigger
enabled="y"
group="Herbs"
match="^(.*) \((.*?)\) (.*?) left\.$"
regexp="y"
script="do_pick"
sequence="100"
>
</trigger>
</triggers>

Everything turns around in the end
[Go to top] top

Posted by Nick Gammon   Australia  (21,399 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Thu 08 Dec 2005 03:56 AM (UTC)
Message
You are right, it should read:


if tonumber (wildcs[3]) > 10 then


You still want a numeric compare.

Try this:


/print ("20" > "5") --> false


But 20 is greater than 5. String compares work like that. It thinks the 5 is greater than the 2.

Now try:


/print (tonumber ("20") > 5) --> true


Why is it spamming? Is the other trigger not in the "Herbs" group?

It is really hard to help you, despite repeated requests you are only giving parts of what you are doing. You haven't posted your trigger that matches on "you have recovered balance".


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Metsuro   USA  (389 posts)  [Biography] bio
Date Reply #6 on Thu 08 Dec 2005 10:28 AM (UTC)

Amended on Thu 08 Dec 2005 11:41 PM (UTC) by Metsuro

Message
all that does is do the command plants it was the only way I could figure to do it.

<triggers>
<trigger
custom_colour="2"
group="Herbs"
match="You have recovered balance on all limbs."
regexp="y"
sequence="99"
>
<send>plants</send>
</trigger>
</triggers>

which makes it spam cause its always checking to see the herbs. well I could have it just check once and store it as a variable, on how many I can pick and just subtract one when I do it... but sometimes when you pick the herb will grow more or someone till come in and pick them too, so I thought it best to do it this way.

the prompt will get spammier depending on the season because of the different herbs. and the trigger I didn't really know how to do so...

--You have recovered balance on all limbs.
plants
1410h, 1500m, 1860e, 10p ex-
The following plants are growing in this room:
A sprig of chervil (chervil) 11 left.
pick chervil
1410h, 1500m, 1860e, 10p ex-
You reach down and carefully harvest a sprig of chervil.
1410h, 1500m, 1860e, 10p e-

You have recovered balance on all limbs.
plants
1410h, 1500m, 1860e, 10p ex-

Across the heavens, the stars and moon challenge night's dark reign, revealing
familiar constellations that tell the tales of myth and legend.
1410h, 1500m, 1860e, 10p ex-
The following plants are growing in this room:
A sprig of chervil (chervil) 10 left.
No more for you to pick.--
to get all this in a course of several seconds trying to speak with others... is rather... hard...

[edit] the prompt was meant to go in this one... donno why I put it in the other...

Everything turns around in the end
[Go to top] top

Posted by Metsuro   USA  (389 posts)  [Biography] bio
Date Reply #7 on Fri 09 Dec 2005 12:02 AM (UTC)
Message
and now that I think of it... I would like to add another trigger and script to check to see if the plant is in hibernation or not hrm...

Everything turns around in the end
[Go to top] top

Posted by Metsuro   USA  (389 posts)  [Biography] bio
Date Reply #8 on Fri 09 Dec 2005 07:21 PM (UTC)
Message
Ok well I am wanting to make a table to go with this... but I'm not sure how I'd set up a script to look for the information I want, and I dont think I would need a linear scan for it either...

Everything turns around in the end
[Go to top] top

Posted by Metsuro   USA  (389 posts)  [Biography] bio
Date Reply #9 on Fri 09 Dec 2005 10:37 PM (UTC)
Message
and yet if tonumber (wildcs[4]) > 10 then still doesn't work either

Everything turns around in the end
[Go to top] top

Posted by Nick Gammon   Australia  (21,399 posts)  [Biography] bio   Forum Administrator
Date Reply #10 on Fri 09 Dec 2005 11:52 PM (UTC)
Message
Please post the whole thing, not just a snippet.

In what way doesn't it work? Error message? If so, what?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Metsuro   USA  (389 posts)  [Biography] bio
Date Reply #11 on Sat 10 Dec 2005 12:48 AM (UTC)
Message
in my idioicy I didn't bother to look around and found out what was causing it not to work, simple error in my typing. So thank you for working with me on that, but I am still needing a way to make a none linear scan of a table i guess?

Everything turns around in the end
[Go to top] top

Posted by Nick Gammon   Australia  (21,399 posts)  [Biography] bio   Forum Administrator
Date Reply #12 on Sat 10 Dec 2005 12:55 AM (UTC)
Message
See my post about using tables:

http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=6036

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Metsuro   USA  (389 posts)  [Biography] bio
Date Reply #13 on Sat 10 Dec 2005 01:52 AM (UTC)
Message
herbs = {
{ name = "Arnica" , month = "Klangiary"},
{ name = "Calamus" , month = "Dioni" },
{ name = "Chervil" , month = "Roarkian" },
{ name = "Colewort" , month = "Kiani" },
{ name = "Coltsfoot" , month = "Juliary" },
{ name = "Faeleaf" , month = "Juliary" },
{ name = "Flax" , month = "Estar" },
{ name = "Galingale" , month = "Shanthin" },
{ name = "Horehound" , month = "Vestia" },
{ name = "Juniper" , month = "Dioni" },
{ name = "Kafe" , month = "Urlachmar"},
{ name = "Kombu" , month = "Dioni" },
{ name = "Marjoram" , month = "Shanthin" },
{ name = "Merbloom" , month = "Estar" },
{ name = "Mistletoe" , month = "Avechary" },
{ name = "Myrtle" , month = "Estar" },
{ name = "Pennyroyal" , month = "Klangiary"},
{ name = "Reishi" , month = "Tzarin" },
{ name = "Rosehips" , month = "Shanthin" },
{ name = "Sage" , month = "Dioni" },
{ name = "Sargassum" , month = "Tzarin" },
{ name = "Sparkleberry" , month = "Dvarsh" },
{ name = "Weed" , month = "Estar" },
{ name = "Wormwood" , month = "Vestia" },
{ name = "Yarrow" , month = "Roarkian" },
}

function do_pick (name, output, wildcs)
-- a for here if thats even possible maybe...
-- check for name?
-- check for month?
-- check month vs curret month?
if wildcs[2] == herb then
if tonumber (wildcs[4]) > 10 then
Send("pick ", herb)
else
Note("No more for you to pick.")
Send("inr all ", herb)
DoAfter(4, EnableTriggerGroup ("Herbs", false))
end
end
end

OK this is what I have so far.. I've put comments in where think things might go... but I'm not even sure where I could put something... and how to do it using what I have...

Everything turns around in the end
[Go to top] top

Posted by Nick Gammon   Australia  (21,399 posts)  [Biography] bio   Forum Administrator
Date Reply #14 on Sat 10 Dec 2005 07:51 PM (UTC)
Message
You are on the right track here. Maybe you can take a look at the other script for balances and understand what it is doing better. What to do next depends a fair bit on the MUD output and what you want to achieve.

If it is trying to eat herbs too often, then I would be keeping a table of the ones I need to eat (as I did in the other script) and then match the list of herbs I actually get to what I need. If none, then no more eating required.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] 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.


17,738 views.

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

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]