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 ➜ General ➜ New to MUSHclient

New to MUSHclient

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


Pages: 1 2  3  4  5  

Posted by Gid   (18 posts)  Bio
Date Sat 12 Nov 2005 11:55 PM (UTC)
Message
Okay, here I go.

I am very new to MUSHclient. I am learning like mad but I still need some help.

Here's the problem. I play the Iron Realms game "Achaea". The game is based ona balance system so that you cannot complete actions unless you have the specific "balance" that is related to the action. For instance, I eat an herb to cure a sickness. If I have another sickness, I have to wait a good 2 seconds be for I get my herb "balance" back so that I can eat another herb to cure the second sickness. I then receive the message "You may eat another herb". What I want to do is related to these sicknesses. When ever I get a sickness, it gives sends me the line "You are now sick with B" or "You are now sick with C" What I want to be able to do is to make it so that when I receive a messages saying that I am sick, I want it to remember that and be able to cure the sickness by eating the herb when I get my herb "balance" back.


More problems with this: There will be multiple sicknesses given to me while I don't have herb balance, so the system will have to be able to remember all of them and be able to eat a specific herb for each of them each time I receive herb balance back. Also, if I am able to, I want to be able to cure these sicknesses in a certain order, so when I get both the messages "You are now sick with B" and "You are now sick with C" while I don't have herb balance, I can eat the cure for C when I get herb balance back the first time, then eat the cure for B when I get my herb balance back the second time.


I know my question is complicated and I just hope you are able to figure out what I am trying to say.

Thanks
Top

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #1 on Sun 13 Nov 2005 01:06 AM (UTC)
Message
Somehow I thought that question sounded familiar. :)

Try searching the forum, here is one post at least about their herbs:

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

- Nick Gammon

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

Posted by Gid   (18 posts)  Bio
Date Reply #2 on Sun 13 Nov 2005 01:51 AM (UTC)

Amended on Sun 13 Nov 2005 02:11 AM (UTC) by Gid

Message
Thanks, that was helpful, just a few questions.

I don't understand what this is doing:

Sub herbhealing (a, b, c)
Dim value, spell, anorexia, scytherus
anorexia = world.getvariable ("affliction_anorexia")
scytherus = world.getvariable ("affliction_scytherus")

Also, is this actually part of the script? If so, what exactly is it doing?

For Each v In world.GetVariableList
value = world.GetVariable (v)
If Left (v, 11) = "affliction_" Then
spell = Mid (v, 12)
If value = "on" Then
Select Case spell
Case "stupidity" world.sendpush "eat goldenseal"
Case "slickness" world.sendpush "eat bloodroot"
Case "paralysis" world.sendpush "eat bloodroot
etc.



Also: It seems as if every time I get herb balance back I acutally eat the herbs for all of the afflictions I have. Is there any way I can make it so I will only eat 1 herb (I want to be able to specify which afffliction to heal in an order that I somehow put into the script.)

Top

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #3 on Sun 13 Nov 2005 03:40 AM (UTC)
Message
You would put the script into your script file. The word "herbhealing" is the name of the script function in this case and would go into the "script" part of the trigger.

See:

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

That discusses how you interface scripts with triggers and suchlike.

For your 2nd question, this part of the script is important:


Select Case spell 
  Case "stupidity" world.sendpush "eat goldenseal"
  Case "slickness" world.sendpush "eat bloodroot"
  Case "paralysis" world.sendpush "eat bloodroot

etc.


The "select case" statement selects one from the list, depending on what the spell is. So, if the spell was "stupidity" it would send "eat goldenseal" (and nothing else).





- Nick Gammon

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

Posted by Gid   (18 posts)  Bio
Date Reply #4 on Sun 13 Nov 2005 05:23 AM (UTC)
Message
Okay, so I understand how to put all the different afflictions in variables and how to trigger them when I regain herb balance. That still leaves my question on how I can make it so that when I regain herb balance and two afflicts are set on the "on" position, I only eat the herb to cure one of them, and I wait till the next time I get herb balance back to eat the next one.
Top

Posted by Rakon   USA  (123 posts)  Bio
Date Reply #5 on Sun 13 Nov 2005 06:05 AM (UTC)

Amended on Sun 13 Nov 2005 06:05 PM (UTC) by Rakon

Message
Hmm I think the best way for this to work would be
something like the following, I dont really know the syntax in lua, but you should get the idea.

if anor == "off":
 if asleep == "off":
  if plantbal == "yes":
   if *AFFLICTION HERE* == "on":
    world.Send("outr this")
    world.Send("eat plant")
elif *AFFLICTION* == "on":
    world.Send("outr this")
    world.Send("eat plant")
   elif *AFFLICTION* == "on":
     

And so on adding afflictions with the most priority at the top. IE Aeon, stupidity etc.

**EDIT:Thought I was writing html with the code tags :P --Rakon**

Yes, I am a criminal.
My crime is that of curiosity.
My crime is that of judging people by what they say and think, not what they look like.
My crime is that of outsmarting you, something that you will never forgive me for.
Top

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #6 on Sun 13 Nov 2005 09:22 PM (UTC)

Amended on Sun 13 Nov 2005 09:27 PM (UTC) by Nick Gammon

Message
OK, let's take a look at doing this in Lua, whose table handling makes keeping track of this sort of stuff quite easy.

I haven't played Achaea for a while, and am not familiar with their affliction system, but I gather from the other posts about this that it goes along these lines:


  • You can become afflicted by lots of things, where an affliction is indicated by one or more messages, like:


    An odd sensation descends upon you.
    You feel the urge to slash, cut, and bruise yourself.
    With the heel of your palm, you smack *
    You drive a clenched fist into your gut.
    You use your * foot to stomp on your * as hard as possible.


  • When you are cured of that affliction, either by time or the cure, you get another message, like:


    You no longer enjoy pain.


  • You can eat something to cure the affliction, eg.


    eat lobelia


  • Once eaten something you can't eat again until you see a message, like:


    You may eat another plant.


  • You can't eat while afflicted by the "food" affliction, or "anorexia", and other things.





The first thing we need is a table of what we are currently afflicted by, and a flag to show if we are currently eating a cure. I presume when you start a new game the afflictions are cleared, so the table can be a straight Lua table. If not, you could serialize the table into a variable on world disconnect, as described in other posts, and re-import it when you reconnect.


afflicted_by = {}  -- table of current afflictions
eating = false  -- are we currently eating a cure?


Next, we want a table of the various afflictions and their cures. I would rather have a table keyed by affliction name, but I gather that you would prefer to cure afflictions in a certain order (most urgent to least urgent) so we'll just have a table keyed in numeric order:


cures = {
    { name =  "stupidity"       , cure =  "goldenseal" },
    { name =  "slickness"       , cure =  "bloodroot" },
    { name =  "paralysis"       , cure =  "bloodroot" },
    { name =  "confusion"       , cure =  "ash" },
    { name =  "scytherus"       , cure =  "ginseng" },
    { name =  "epilepsy"        , cure =  "goldenseal" },
    { name =  "masochism"       , cure =  "lobelia" },
    { name =  "dizziness"       , cure =  "goldenseal" },
    { name =  "recklessness"    , cure =  "lobelia" },
    { name =  "heroism"         , cure =  "lobelia" },
    { name =  "justice"         , cure =  "bellwort" },
    { name =  "paranoia"        , cure =  "ash" },
    { name =  "shyness"         , cure =  "lobelia" },
    { name =  "hallucinations"  , cure =  "ash" },
    { name =  "generosity"      , cure =  "bellwort" },
    { name =  "loneliness"      , cure =  "lobelia" },
    { name =  "impatience"      , cure =  "goldenseal" },

-- and so on --

  } -- end of cures




Now we want a "cure me" routine, that can be called as soon as we become afflicted, and also when an affliction wears off, and we can eat another herb. For example, if the "food" affliction wears off, we can start curing other things.


-- find an affliction we have, and try to cure it
function do_cure ()

  -- can't eat more if just ate, or can't eat food

  if eating or 
    afflicted_by.food or 
    afflicted_by.anorexia then
    return
  end -- if can't do it yet

  -- find most urgent one to cure  

  for _, v in ipairs (cures) do
    if afflicted_by [v.name] then
      if v.cure ~= "" then  -- some afflictions might not have cures
        Send ("outb ", v.cure)  -- get out of bag
        Send ("eat ", v.cure)   -- eat it
        ColourNote ("black", "yellow", "Curing " .. v.name .. 
                    " with " .. v.cure)
        eating = true
        return  -- done 
      end -- of having a cure for it
    end -- found one
  end -- for

end -- function do_cure


What this does is first test for whether we can cure anything right now (eg. if we have just eaten we can't).

Then it goes through the cures table in sequence, and for each one, checks to see if we are afflicted by that thing. That way the most important things get cured first.

When it finds one, it pulls the herb out of the bag and eats it, and notes we are currently eating.




Next we need a series of triggers to indicate we have an affliction. Since multiple things may indicate the same affliction we call a function with "send to script" to indicate which affliction we now have:



<triggers>
  <trigger
   enabled="y"
   match="You drive a clenched fist into your gut."
   send_to="12"
   sequence="100"
  >
  <send>afflicted "masochism"</send>
  </trigger>
</triggers>


You would make a similar one for each affliction, where the "match" is what you see (it could be a regular expression), and the "send" text calls the "afflicted" function with the name of the affliction.


-- call this from a trigger to show we are afflicted by something

function afflicted (what)
  if afflicted_by [what] then
    ColourNote ("white", "red", "Already afflicted by " .. what)
  else
    afflicted_by [what] = true  -- note the affliction
    ColourNote ("white", "red", "Now afflicted by " .. what)
  end -- if
  do_cure ()  -- try a cure
end -- function afflicted 


This function calls "do_cure" to try to cure something straight away, which may be this affliction, or it may not if we are currently eating a herb.




Next we need to know when the affliction is cured.


<triggers>
  <trigger
   enabled="y"
   match="You no longer enjoy pain."
   send_to="12"
   sequence="100"
  >
  <send>cured "masochism"</send>
  </trigger>
</triggers>


This is similar to the above trigger, except it calls the "cured" function instead.


-- call this from a trigger to show we are cured

function cured (what)
  afflicted_by [what] = nil  -- note not afflicted
  ColourNote ("white", "green", "Now cured of " .. what)
  do_cure ()  -- try a cure for the next affliction if any
end -- function cured 


This also calls do_cure to try to cure something else. For example, if we are no longer afflicted by "food" we can start curing other things.




Next we need to know if we can eat another herb:


<triggers>
  <trigger
   enabled="y"
   match="You may eat another plant."
   script="can_eat"
   sequence="100"
  >
  </trigger>
</triggers>


This calls the can_eat function:


-- call this from a trigger when we have finished eating

function can_eat ()
  eating = false
  do_cure () -- now we can cure something else
end -- function can_eat



This also calls do_cure to try to cure something else if necessary.




The above techniques won't be perfect, for one thing it doesn't check if you actually have the herb in your inventory. You might maintain another table of the herbs you are carrying, which could be updated when you buy them, and when you use them. However it should be enough to give you some ideas.

- Nick Gammon

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

Posted by Gid   (18 posts)  Bio
Date Reply #7 on Mon 14 Nov 2005 02:30 AM (UTC)
Message
That is all great! It might take me a while to go through it all and try to make it work for me but this is good till then.

What I don't understand right now is where I set up the table and what exactly the the table's function is.


Thanks for all your help on this.
Top

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #8 on Mon 14 Nov 2005 03:08 AM (UTC)

Amended on Mon 14 Nov 2005 03:09 AM (UTC) by Nick Gammon

Message
All this stuff goes into your script file:



afflicted_by = {}  -- table of current afflictions
eating = false  -- are we currently eating a cure?

-- cures for afflictions, put in order you want them cured

cures = {
    { name =  "stupidity"       , cure =  "goldenseal" },
    { name =  "slickness"       , cure =  "bloodroot" },
    { name =  "paralysis"       , cure =  "bloodroot" },
    { name =  "confusion"       , cure =  "ash" },
    { name =  "scytherus"       , cure =  "ginseng" },
    { name =  "epilepsy"        , cure =  "goldenseal" },
    { name =  "masochism"       , cure =  "lobelia" },
    { name =  "dizziness"       , cure =  "goldenseal" },
    { name =  "recklessness"    , cure =  "lobelia" },
    { name =  "heroism"         , cure =  "lobelia" },
    { name =  "justice"         , cure =  "bellwort" },
    { name =  "paranoia"        , cure =  "ash" },
    { name =  "shyness"         , cure =  "lobelia" },
    { name =  "hallucinations"  , cure =  "ash" },
    { name =  "generosity"      , cure =  "bellwort" },
    { name =  "loneliness"      , cure =  "lobelia" },
    { name =  "impatience"      , cure =  "goldenseal" },

-- and so on --

  } -- end of cures

-- find an affliction we have, and try to cure it
function do_cure ()

  -- can't eat more if just ate, or can't eat food

  if eating or 
    afflicted_by.food or 
    afflicted_by.anorexia then
    return
  end -- if can't do it yet

  -- find most urgent one to cure  

  for _, v in ipairs (cures) do
    if afflicted_by [v.name] then
      if v.cure ~= "" then  -- some afflictions might not have cures
        Send ("outb ", v.cure)  -- get out of bag
        Send ("eat ", v.cure)   -- eat it
        ColourNote ("black", "yellow", "Curing " .. v.name .. 
                    " with " .. v.cure)
        eating = true
        return  -- done 
      end -- of having a cure for it
    end -- found one
  end -- for

end -- function do_cure

-- call this from a trigger to show we are afflicted by something

function afflicted (what)
  if afflicted_by [what] then
    ColourNote ("white", "red", "Already afflicted by " .. what)
  else
    afflicted_by [what] = true  -- note the affliction
    ColourNote ("white", "red", "Now afflicted by " .. what)
  end -- if
  do_cure ()  -- try a cure
end -- function afflicted 

-- call this from a trigger to show we are cured

function cured (what)
  afflicted_by [what] = nil  -- note not afflicted
  ColourNote ("white", "green", "Now cured of " .. what)
  do_cure ()  -- try a cure for the next affliction if any
end -- function cured 

-- call this from a trigger when we have finished eating

function can_eat ()
  eating = false
  do_cure () -- now we can cure something else
end -- function can_eat




The rest is a few triggers, which you can copy and paste (or write your own based on them).

The purpose of the big table above is to relate afflictions to cures. The purpose of the afflicted_by table is to keep track of each affliction. Each affliction you have will make a single entry in the table. eg.


afflicted_by.food = true

- Nick Gammon

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

Posted by Gid   (18 posts)  Bio
Date Reply #9 on Mon 21 Nov 2005 04:05 AM (UTC)

Amended on Mon 21 Nov 2005 04:07 AM (UTC) by Gid

Message
Wonderful.....Now I don't understand this part.

for _, v in ipairs (cures) do
if afflicted_by [v.name] then
if v.cure ~= "" then -- some afflictions might not have cures

Do I actually write "for _, v in ipairs (cures)????
and will [v.name] acutually put in the name of the affiction that I get? Or do I need to type something in there?





do_cure () -- try a cure

Do I leave the space inside of the parantheses blank?
Top

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #10 on Mon 21 Nov 2005 04:31 AM (UTC)
Message
Read this post, it talks about tables:


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


Quote:

Do I actually write "for _, v in ipairs (cures)????


Well, I would copy and paste it, but yes, that works as written.

"cures" is a table of affliction/cure pairs (actually a table of tables).

We are doing a linear scan of the table (which is why you put the most urgent one at the start).

The for loop extracts key/value pairs. The key is assigned to variable "_" which is usually used in Lua to indicate a temporary variable. The value is put into v.

In this case the value "v" is the inner table. The inner table has two entries for each one, "name" and "cure" (see the table definition).


So, this line:


if afflicted_by [v.name] then


... checks if we are afflicted by this particular affliction (v.name) and if so, we do the cure (v.cure).


- Nick Gammon

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

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #11 on Mon 21 Nov 2005 04:54 AM (UTC)
Message
Quote:

Do I leave the space inside of the parantheses blank?


Yes. do_cure is a function, and to call it you must use parentheses. However as there are no arguments, the contents of the parentheses are empty.

- Nick Gammon

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

Posted by Gid   (18 posts)  Bio
Date Reply #12 on Sat 26 Nov 2005 11:58 PM (UTC)
Message
Another Question.

Is there anyway I can stop the script from working for a line or two? Heres what I would see:


John casts an illusion at you.
An odd sensation descends upon you.
You begin to puke.

I want to be able to ignore the two lines after "John casts an illusion at you."


Your help is greatly appreciated.
Top

Posted by Metsuro   USA  (389 posts)  Bio
Date Reply #13 on Sun 27 Nov 2005 01:37 AM (UTC)
Message
couldn't you have john casts illusion on you trigger it to omit from output new lines till the prompt is reached and disable it?

Everything turns around in the end
Top

Posted by Metsuro   USA  (389 posts)  Bio
Date Reply #14 on Sun 27 Nov 2005 03:46 AM (UTC)
Message
And I would like to use this for another of the Iron Realm games Lusternia. However they have a very weird... healing system. they have some herbs you eat, some your apply (one) and three you smoke. then they have Purgatives and Potions/Salves to cure the aliments, now I would like to use this system to do all of them, but I dont understand it enough to even start, so might you be willing to show me a little?

Everything turns around in the end
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.


159,795 views.

This is page 1, subject is 5 pages long: 1 2  3  4  5  [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.