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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Tips and tricks
. . -> [Subject]  wimpy

wimpy

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


Posted by Rockeru66   (5 posts)  [Biography] bio
Date Sat 10 Jan 2004 06:47 AM (UTC)
Message
another question :).
many charact on mud have wimpy mode, but play a charact without wimpy.
how can i make this one to get out the room if let's say HP is lower than 100?
[Go to top] top

Posted by Ian Kirker   (30 posts)  [Biography] bio
Date Reply #1 on Sat 10 Jan 2004 03:50 PM (UTC)

Amended on Sun 11 Jan 2004 09:29 AM (UTC) by Ian Kirker

Message
Assuming your MUD always displays the room exits with the room description, doesn't use MXP to display room exits and doesn't have a "backwards" exit, you'll first want to make a trigger that captures the available exits, parses them and stores them in a variable.

If your mud gives you:

Exits: South, southeast, and southwest.


You need to match "Exits", take the exits, and throw away the "and" and the "." You probably want to get rid of the spaces or the commas as well, to give you a variable that's either a bunch of exits separated by spaces, or by commas.

<triggers>
  <trigger
   enabled="y"
   match="^Exits: (.*)."
   regexp="y"
   send_to="12"
   sequence="100"
   other_text_colour="black"
   other_back_colour="black"
  >
  <send>temp=replace("%1", "and ", "")
temp=replace(temp, ",", "")
world.setvariable "exits", temp</send>
  </trigger>
</triggers>


If your MUD sends exits differently, you'll have to modify either the match line, or the code a leetle bit. It depends. :)

Secondly, you'll either want to make a trigger to detect when you're low on hitpoints and make it send a direction from the list. Or you'll need to add a bit to your existing score script if you've got one.

<triggers>
  <trigger
   enabled="y"
   match="<Hp: (.*?)/"
   regexp="y"
   send_to="12"
   sequence="100"
   other_text_colour="black"
   other_back_colour="black"
  >
  <send>if cint("%1")<=100 then
  world.send split(world.getvariable("exits"), " ")(0)
end if</send>
  </trigger>
</triggers>


This will match a mud that sends a score line like
<Hp: 10/100 Sp: 50/50>
If yours is different, you'll have to alter the "Match" line to take account of that.

One thing to note is that this will always send you in the first direction listed. If you're a purist and want to make it random, you'll have to alter the world.send line.

Hope this helps. :)

-I-
[Go to top] top

Posted by DragonCharmer84   (3 posts)  [Biography] bio
Date Reply #2 on Fri 15 Dec 2006 02:56 AM (UTC)
Message
I've been trying to adapt this trigger to lua, but without success so far. Here's what I've got:

For the regular expression:
^You see exits leading (.*).

It returns the command:
world.setvariable('exits', 'Replace("%1", "and ", "")')

Here's the error message:
Run-time error
World:
Immediate execution
[string "Trigger: "]:1: attempt to call field 'setvariable' (a nil value)
stack traceback:
[string "Trigger: "]:1: in main chunk

Help me please. I've spent several hours trying to troubleshoot what really ought to be simple enough to do already.
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #3 on Fri 15 Dec 2006 03:43 AM (UTC)
Message
See http://www.gammon.com.au/scripts/function.php?name=SetVariable

Note that it's just SetVariable(...).

Also note the capitalization.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Nick Gammon   Australia  (22,990 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Fri 15 Dec 2006 04:02 AM (UTC)
Message
To amplify on that response, VBscript is not case-sensitive, thus you can write "setvariable".

However in Lua you have to get the case right, so you need to write SetVariable.

See the help file, or the online documentation, you must use the exact spelling and capitalization documented there.

If you are using the Trigger editor, you can type a partial word (eg. "setvar") and then hit the Complete button to have it complete the word, with correct capitalization.

Your other problem is you have quoted the call to Replace, which means that it would simply put the words "Replace("%1", "and ", "")" into the variable "exits".

- Nick Gammon

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

Posted by DragonCharmer84   (3 posts)  [Biography] bio
Date Reply #5 on Fri 15 Dec 2006 04:06 AM (UTC)
Message
Yep. That's exactly the problem now. I had hoped that the script would still process the replace command to filter my possible exits for me. I want to be able to create an alias to be able to leave a room quickly. I really don't know what I need to do next to get to my goal.
[Go to top] top

Posted by Nick Gammon   Australia  (22,990 posts)  [Biography] bio   Forum Administrator
Date Reply #6 on Fri 15 Dec 2006 04:22 AM (UTC)
Message
What I was getting at, was you have to remove the quotes, like this:


<triggers>
  <trigger
   enabled="y"
   match="^You see exits leading (.*)\.$"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>
SetVariable ('exits', Replace("%1", "and ", ""))</send>
  </trigger>
</triggers>


If you quote "Replace (...)" it just becomes a string. If you want a function call, you can't quote it.

I also put a backslash before the final period in your regular expression. If you are matching on a period you must put a backslash in front of it, because a period on its own is a wildcard.

- Nick Gammon

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

Posted by Nick Gammon   Australia  (22,990 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Fri 15 Dec 2006 04:30 AM (UTC)

Amended on Fri 15 Dec 2006 04:37 AM (UTC) by Nick Gammon

Message
You could save yourself a bit of trouble by building a table of exits, like this:


<triggers>
  <trigger
   enabled="y"
   match="^You see exits leading (.*)\.$"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>
exits = {}  -- start new table
for e in string.gmatch ("%1", "%%a+") do
  if e ~= "and" then
    table.insert (exits, e)
  end -- not "and"
end -- for
</send>
  </trigger>
</triggers>


What that will do is make an "exits" variable (a Lua variable, not a MUSHclient variable), that contains an entry for each exit. It uses string.gmatch to find words in the matching trigger string, and insert them into a table, excluding the word "and".

Now if you want to flee, you can randomly choose one, like this:


<aliases>
  <alias
   match="flee"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>
if type (exits) == "table" then
  Send (exits [math.random (#exits)] )  -- choose one
end -- we have some exits
</send>
  </alias>
</aliases>



- Nick Gammon

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

Posted by Kemkeris   (1 post)  [Biography] bio
Date Reply #8 on Sat 16 Dec 2006 06:12 PM (UTC)

Amended on Sat 16 Dec 2006 06:13 PM (UTC) by Kemkeris

Message
Thanks for the info Nick!
[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.


22,611 views.

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 HostDash]