countless combinations

Posted by ErockMahan on Mon 26 Jan 2009 05:02 PM — 8 posts, 28,988 views.

#0
I have seen someone else do it, but they don't use MUSHCLIENT, so I'm not sure if this is even possible.

A person will be sent something: "ra rp pff group" where "ra", "rp", and "pff" all refer to a particular spell. I can manually follow that, but they are doing it with a trigger.

If it were always that pattern of "ra rp pff" in that order, I could handle it no problem. The real trick is that there are other spells that can be included in that formula, and then the order isn't static either. I know that I could sit down and hammer out a hundred possibilities by hand, but if there is an easier way to do it, I'd like to know.

If not, I'll live and let die. :)
Australia Forum Administrator #1
You haven't said what it would be used for, but the trigger is easy enough with a regular expression:


<triggers>
  <trigger
   enabled="y"
   match="^(((ra|rp|pff) )+)group$"
   regexp="y"
   send_to="2"
   sequence="100"
  >
  <send>Got: %1</send>
  </trigger>
</triggers>


What this is doing is looking for "ra" or "rp" or "pff" (that is what the "|" means), followed by a space, and then the "+" means "one or more of whatever preceded me".

The final space is then followed by the word "group" (if group was part of it, just move inside the ra|rp|pff part).

Wildcard 1 is then the matching words (ie. in this case "ra rp pff" if that was the order they were entered.

With a bit of scripting you can then break wildcard 1 into the individual words. For example:


<triggers>
  <trigger
   enabled="y"
   match="^(((ra|rp|pff) )+)group$"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>

for w in string.gmatch ("%1", "%%a+") do
  Send ("cast " .. w)
end -- for

</send>
  </trigger>
</triggers>


To test this, I used Game -> Test Trigger to simulate this coming in:


ra rp pff group


And I got in response:


cast ra
cast rp
cast pff



This trigger will match regardless of the order, and you can add more words to the list inside the inner brackets, eg.


match="^(((ra|rp|pff|rb|pfa|rc|rgb) )+)group$"
Amended on Mon 26 Jan 2009 07:31 PM by Nick Gammon
USA #2
And if you didn't feel like listing all the options in the trigger, you could have a dictionary of available words, and in the step Nick wrote that breaks up the trigger into individual words, you would make sure that each word makes sense to you.
#3
It seems to me that you're using Lua for that function. I want to do it in Jscript (or somehow switch the language to Lua for this one trigger).

If it isn't Lua, then for some reason I cannot get your for loop to work. But thanks for the suggestion! Using your model, I did some reasearch on how to split a variable and worked this out:

Dim Splitting
Dim Splitted

Splitted = "%1"
Splitting = Split(Splitted, " ")

Dim i
For i = 0 to Ubound(Splitting)
world.note Splitting(i)
Next

---------------------------------------

What I did works great, but now I want (aren't I just so hard to please?) to have it to split based on a comma, not just a space. I thought that changing: (Splitted, " ") to (Splitted, ",") would do it, but it doesn't work. Any ideas?
Amended on Thu 29 Jan 2009 12:08 AM by ErockMahan
#4
I suppose that it is quite impossible then?
Netherlands #5
Try replacing all commas by a space prior to doing your split. :)
Australia Forum Administrator #6
Quote:

Dim i
For i = 0 to Ubound(Splitting)
world.note Splitting(i)
Next


That looks like VBscript to me, not Jscript. It is not impossible to split at commas, however as I am rusty on Jscript I didn't reply. Try Googling for "jscript split".
#7
Thank you very much for your help! Here is the solution. This checks for 'ra','rp','pff','pfl','fa','npp', and 'rempo' and will execute each as it occurrs, assuming that when no target is provided, the group is the target:




Dim sep

sep = "%1"
pieces = Split(sep, " ")

if pieces(ubound(pieces))="ra" or pieces(ubound(pieces))="rp" or pieces(ubound(pieces))="pff" or pieces(ubound(pieces))="pfl" or pieces(ubound(pieces))="fa" or pieces(ubound(pieces))="rempo" or pieces(ubound(pieces))="npp" then

Dim i

For i = 0 to Ubound(pieces)
world.execute "delay " & (pieces(i)) & " group"

Next

else
if pieces(0)="ra" or pieces(0)="rp" or pieces(0)="pff" or pieces(0)="pfl" or pieces(0)="fa" or pieces(0)="rempo" or pieces(0)="npp" then


Dim g

For g = 0 to Ubound(pieces)-1
world.execute "delay " & (pieces(g)) & " " & pieces(ubound(pieces))

Next

world.note "spell for " & pieces(ubound(pieces))
end if
end if