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.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Jscript
➜ countless combinations
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| ErockMahan
(81 posts) Bio
|
Date
| Mon 26 Jan 2009 05:02 PM (UTC) |
Message
| 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. :) | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #1 on Mon 26 Jan 2009 07:29 PM (UTC) Amended on Mon 26 Jan 2009 07:31 PM (UTC) by Nick Gammon
|
Message
| 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:
And I got in response:
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$"
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #2 on Mon 26 Jan 2009 07:45 PM (UTC) |
Message
| 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. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| ErockMahan
(81 posts) Bio
|
Date
| Reply #3 on Mon 26 Jan 2009 11:58 PM (UTC) Amended on Thu 29 Jan 2009 12:08 AM (UTC) by ErockMahan
|
Message
| 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? | Top |
|
Posted by
| ErockMahan
(81 posts) Bio
|
Date
| Reply #4 on Mon 09 Feb 2009 11:23 PM (UTC) |
Message
| I suppose that it is quite impossible then? | Top |
|
Posted by
| Worstje
Netherlands (899 posts) Bio
|
Date
| Reply #5 on Mon 09 Feb 2009 11:34 PM (UTC) |
Message
| Try replacing all commas by a space prior to doing your split. :) | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #6 on Tue 10 Feb 2009 12:53 AM (UTC) |
Message
|
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". |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| ErockMahan
(81 posts) Bio
|
Date
| Reply #7 on Tue 10 Feb 2009 05:23 PM (UTC) |
Message
| 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 | 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.
21,099 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top