[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]  how do I ignore scripting?
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

how do I ignore scripting?

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


Posted by Caeser   (22 posts)  [Biography] bio
Date Wed 21 Jun 2006 03:40 AM (UTC)
Message
Lately, I switched over to Aetolia, another IRE MUD, as was wondering.

In the game, there is a skill that allows you to detect illusions, which are primarily used by the stealthy class in order to throw off their combatant's system for healing.
Basically, it gives the line ****Illusion****. It has a 25% chance of coming before the actual illusion, and a 25% of coming after.

Now, what I would like to do is this: When the first ****Illusion**** comes in, I would like to to completely ignore the next lines until I receive the prompt. When I mean ignore, I mean everything. Gags and stops it from doing the script I want those lines to do.

I figure I can do the same thing for the 2nd ****Illusion**** line, but it'd work through a different multi-line trigger.

Any help is appreciated. I have been wracking my brains, and what limited programming I know, for at least a week.
[Go to top] top

Posted by Nick Gammon   Australia  (21,412 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Wed 21 Jun 2006 03:51 AM (UTC)
Message
You could make a trigger to detect the Illusion line and turn off all triggers:


SetOption ('enable_triggers', 0) -- disable all triggers


Of course, the problem is now you can't make a trigger to turn them on again. :P

Or, put all your triggers into a group, and disable the group:


EnableTriggerGroup ('groupname', 0) -- disable the group


The trigger that detects the prompt line would, of course, not be in that group.

- Nick Gammon

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

Posted by Caeser   (22 posts)  [Biography] bio
Date Reply #2 on Wed 21 Jun 2006 04:15 AM (UTC)
Message
I'm sitting in shame right now... I didn't even *THINK* to use that.

The only downside to that though, would be that I couldn't do that for the second ****Illusion**** line.
[Go to top] top

Posted by Nick Gammon   Australia  (21,412 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Thu 22 Jun 2006 08:57 AM (UTC)
Message
I don't see how you can make the 2nd one work - that is a line that occurs after the things you have already seen? You can't retrospectively ignore stuff, unless you batched it up, and processed it later.

- Nick Gammon

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

Posted by Caeser   (22 posts)  [Biography] bio
Date Reply #4 on Thu 22 Jun 2006 10:08 PM (UTC)

Amended on Fri 23 Jun 2006 11:55 PM (UTC) by Caeser

Message
Well, I had an idea just now to write a function that would find the trigger for the last two lines... say I get:

You are stupid.
Your arms are broken.
****Illusion****
prompt

Well, when it gets the second illusion, I could have it do a search to see what the triggers for the lines before it did, scripting wise, and then do the reverse.

I'm going to be taking a Java programming class, so it can wait until after I'm better at programming. I figure that if I can get decent at one language, I'll be able to program in a different.

I'm just wondering, if that type of function even possible?

Thanks for the help though.
[Go to top] top

Posted by Nick Gammon   Australia  (21,412 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Sat 24 Jun 2006 12:24 AM (UTC)
Message
Quote:

I could have it do a search to see what the triggers for the lines before it did, scripting wise, and then do the reverse.


Yes, but how? Say the trigger did "drink green potion", how do you undrink something?

- Nick Gammon

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

Posted by Ked   Russia  (524 posts)  [Biography] bio
Date Reply #6 on Sat 24 Jun 2006 02:16 AM (UTC)
Message
As long as you want to guard a specific class of messages (i.e. affliction ones) it is definitely possible.

You could set up a table of patterns that you want to safeguard against illusions, with patterns as keys and "action names" as values. Action names could be whatever, for example affliction names. Then you make all your affliction triggers record what afflictions they save or remove on/from your character in another (array) table. That table would function like a stack - you push an affliction name when saving an affliction, pop when removing it. It would need to push only when a save was successful, meaning that you didn't have that affliction already at the time of saving it. Otherwise, someone could afflict you, make you save an affliction, and then illusion the same affliction - making you remove it.

Then you use a multiline trigger like "^prompt\n(?:\*Illusion\*\n)?(.*?)\*Illusion\*\n" to call a function that would split the captured wildcard around newlines, loop on the resulting table (in reverse), take each line and match it against every pattern in the first table. As soon as you get a match, take the value associated with the matched pattern, compare it with whatever is in the last position of the stack table, if they compare true, then remove the affliction. Move on to the next line. Something like that should work.
[Go to top] top

Posted by Ked   Russia  (524 posts)  [Biography] bio
Date Reply #7 on Sat 24 Jun 2006 02:39 AM (UTC)
Message
On a second thought, pushing/popping like that would be a bad idea. Then someone could afflict you and illusion you curing that affliction, resulting in trouble.

But any problem can be solved by making its solution more complicated :) Create a third table with "action names" as keys and function as values. These functions would be called whenever one of the "action" patterns matches. For afflictions and their cures you'd need only one such function, as long as you choose the naming scheme wisely. Supposing that you store afflictions in a table "afflicts" and name afflictions "affl_name" and cures "cure_name", such a function could look like:


function (name)
  local t = utils.split(name, "_")
  if t[1] == "affl" then
    afflicts[t[2]] = false
  elseif t[1] == "cure" then
    afflicts[t[2]] = true
  end
end


Then a function for saving/removing afflictions - presuming that the stack table is called "stktab", and you name your affliction/cure triggers the same way as above (for simplicity's sake) - would be:


function (name,...)
  local t = utils.split(name, "_")
  if t[1] == "affl" then
    if not afflicts[t[2]] then
       table.insert(stktab, name)
       afflicts[t[2]] = true
    end
  elseif t[1] == "cure" then
    if afflicts[t[2]] then
      table.insert(stktab, name)
      afflicts[t[2]] = false
    end
  end
end


That would basically push messages for both afflictions and cures, leaving you with the task of preventing the stack from bloating up with values, which task can be fairly easily solved by limitting its length. I think PIL has examples of doing that.

The rest of the mechanics remain the same: the multiline trigger still calls a function that parses the captured lines, only when a match occurs it would pop the value and use the name to call the function saved in the third table.
[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.


5,640 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 FutureQuest]