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
➜ Lua
➜ Helping a friend
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Shou
USA (30 posts) Bio
|
Date
| Fri 31 Dec 2010 11:19 PM (UTC) |
Message
| Ok, like the subject says, I made some triggers and aliases for a friend to help him with some targeting and attacking issues. Thing is, I script in VBscript, so it would help a lot if someone could help convert these (three or four) items to Lua.
(kinda long..)
<triggers>
<trigger
group="automaul"
lines_to_match="2"
keep_evaluating="y"
match="You spring forwards and maul *\'s *\.\n* parries the attack with a deft maneuver\.\Z"
multi_line="y"
regexp="y"
send_to="12"
sequence="10"
>
<send>if "%2" = "left leg" then
world.setvariable "limb", "right leg"
end if
if "%2" = "right leg" then
world.setvariable "limb", "head"
end if
if "%2" = "head" then
world.setvariable "limb", "left leg"
end if
if "%2" = "right arm" then
world.setvariable "limb", "left leg"
end if
if "%2" = "torso" then
world.setvariable "limb", "left leg"
end if
if "%2" = "left arm" then
world.setvariable "limb", "left leg"
end if</send>
</trigger>
</triggers>
<triggers>
<trigger
expand_variables="y"
group="automaul"
match="You have recovered balance."
sequence="10"
>
<send>target @limb
maul @target</send>
</trigger>
</triggers>
<aliases>
<alias
match="automaul on"
enabled="y"
send_to="12"
sequence="10"
>
<send>world.enablegroup "automaul", 1
world.note "Will automatically maul on balance"</send>
</alias>
</aliases>
<aliases>
<alias
match="automaul off"
enabled="y"
send_to="12"
sequence="10"
>
<send>world.enablegroup "automaul", 0
world.note "Will not automatically maul on balance"</send>
</alias>
</aliases>
Please and Thank You in advance. |
My computer once beat me at chess, but it was no match for me at kickboxing. | Top |
|
Posted by
| Nick Gammon
Australia (23,165 posts) Bio
Forum Administrator |
Date
| Reply #1 on Sat 01 Jan 2011 01:08 AM (UTC) Amended on Sat 01 Jan 2011 01:09 AM (UTC) by Nick Gammon
|
Message
|
- You need to get the function name capitalization right. This post describes how to do it with a simple find-and-replace:
http://www.gammon.com.au/forum/?id=6211
For example "world.setvariable" should be "world.SetVariable".
- You can omit "world." anyway, from both VBscript and Lua, to save typing.
For example "world.setvariable" could be "SetVariable".
- The IF statement looks a bit different.
VBscript
if "%2" = "left leg" then
world.setvariable "limb", "right leg"
end if
Lua
if "%2" == "left leg" then
SetVariable ("limb", "right leg")
end -- if
It is "end" rather than "end if" but I usually do a find-and-replace to change "end if" to "end -- if" (the "--" starts a comment).
Also note that tests for "equals" are "==" rather than "=".
- Function arguments should be in brackets as illustrated above. That is:
Instead of:
world.setvariable "limb", "right leg"
Use:
SetVariable ("limb", "right leg")
You should be able to do a quick fixup in a few minutes based on the above. By the way, this looks wrong:
if "%2" = "head" then
world.setvariable "limb", "left leg"
end if
Do you mean:
if "%2" = "head" then
world.setvariable "limb", "head"
end if
Or why not just replace the whole lot of if-tests with:
SetVariable ("limb", "%2")
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Shou
USA (30 posts) Bio
|
Date
| Reply #2 on Sat 01 Jan 2011 07:44 PM (UTC) Amended on Sat 01 Jan 2011 08:41 PM (UTC) by Shou
|
Message
| Ok, thanks a lot for the help! What I did for the 'if' statement was supposed to be like that, but since I discussed it in the game, I wouldn't expect you to know why.
______________________________
hmm, actually I need a bit of help on one of those triggers.
I have this as the original lines:
You spring forwards and maul Shou's left leg.
Shou parries the attack with a deft maneuver.
So I made it into a multi-line trigger and did this:
<triggers>
<trigger
group="automaul"
lines_to_match="2"
keep_evaluating="y"
match="You spring forwards and maul *\'s *\.\n* parries the attack with a deft maneuver\.\Z"
multi_line="y"
regexp="y"
send_to="12"
sequence="10"
>
<send>if "%2" == "left leg" then
SetVariable ("limb", "right leg")
end
if "%2" == "right leg" then
SetVariable ("limb", "head")
end
if "%2" == "head" then
SetVariable ("limb", "left leg")
end
if "%2" == "right arm" then
SetVariable ("limb", "left leg")
end
if "%2" == "torso" then
SetVariable ("limb", "left leg")
end
if "%2" == "left arm" then
SetVariable ("limb", "left leg")
end</send>
</trigger>
</triggers>
It always switches to the left leg, even when %2 is the right leg(which is supposed to switch to head) did I do something wrong or is it something with the variables? |
My computer once beat me at chess, but it was no match for me at kickboxing. | Top |
|
Posted by
| Nick Gammon
Australia (23,165 posts) Bio
Forum Administrator |
Date
| Reply #3 on Sat 01 Jan 2011 09:28 PM (UTC) |
Message
| Now that you have a regular expression that isn't quite the right syntax for matching wildcards.
 |
Regular expressions
- Regular expressions (as used in triggers and aliases) are documented on the Regular expression tips forum page.
- Also see how Lua string matching patterns work, as documented on the Lua string.find page.
|
In particular, wildcards need to be in round brackets, and use ".*" instead of "*".
So something like "(.*?)" in a regular expression is the same as "*" not in a regular expression (the final ? makes it non-greedy).
So, without actually testing, it would be something like:
match="^You spring forwards and maul (.*?)'s (.*?)\.\n(.*?) parries the attack with a deft maneuver\.\Z"
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Shou
USA (30 posts) Bio
|
Date
| Reply #4 on Sat 01 Jan 2011 10:37 PM (UTC) |
Message
| Ok awesome. That worked like a charm. Thanks a lot! |
My computer once beat me at chess, but it was no match for me at kickboxing. | Top |
|
Posted by
| Shou
USA (30 posts) Bio
|
Date
| Reply #5 on Fri 07 Jan 2011 09:37 PM (UTC) |
Message
| here ya go This_guy!
<aliases>
<alias
match="rbs"
enabled="y"
expand_variables="y"
send_to="12"
ignore_case="y"
sequence="8"
>
<send>if getvariable "direction" == "nw" then
SetVariable ("direction"), ("se")
Execute ("ridebyshot @target @direction")
end
if getvariable "direction" == "ne" then
SetVariable ("direction"), ("sw")
Execute ("ridebyshot @target @direction")
end
if getvariable "direction" == "se" then
SetVariable ("direction"), ("nw")
Execute ("ridebyshot @target @direction")
end
if getvariable "direction" == "sw" then
SetVariable ("direction"), ("ne")
Execute ("ridebyshot @target @direction")
end
if getvariable "direction" == "n" then
SetVariable ("direction"), ("s")
Execute ("ridebyshot @target @direction")
end
if getvariable "direction" == "w" then
SetVariable ("direction"), ("e")
Execute ("ridebyshot @target @direction")
end
if getvariable "direction" == "e" then
SetVariable ("direction"), ("w")
Execute ("ridebyshot @target @direction")
end
if getvariable "direction" == "s" then
SetVariable ("direction"), ("n")
Execute ("ridebyshot @target @direction")
end
if getvariable "direction" == "d" then
SetVariable ("direction"), ("u")
Execute ("ridebyshot @target @direction")
end
if getvariable "direction" == "u" then
SetVariable ("direction"), ("d")
Execute ("ridebyshot @target @direction")
end
if getvariable "direction" == "in" then
SetVariable ("direction"), ("out")
Execute ("ridebyshot @target @direction")
end
if getvariable "direction" == "out" then
SetVariable ("direction"), ("in")
Execute ("ridebyshot @target @direction")
end</send>
</alias>
</aliases>
enjoy |
My computer once beat me at chess, but it was no match for me at kickboxing. | Top |
|
Posted by
| Nick Gammon
Australia (23,165 posts) Bio
Forum Administrator |
Date
| Reply #6 on Sat 08 Jan 2011 03:05 AM (UTC) Amended on Sat 08 Jan 2011 03:06 AM (UTC) by Nick Gammon
|
Message
| Two comments on the above code:
- In Lua, the functions are case-sensitive, so instead of getvariable you should have GetVariable.
- The replacement of things like @target and @direction are done by the client before the script is executed, so the line:
Execute ("ridebyshot @target @direction")
... would refer to the original value of the direction variable, not the one which was set a line above. This is probably not what you want. Better would be:
Execute (string.format ("ridebyshot %s %s",
GetVariable "target",
GetVariable "direction"))
Also I can't help thinking it would be neater if you used a table, eg.
local rev_dir = {
n = "s",
s = "n",
e = "w",
w = "e",
u = "d",
d = "u",
ne = "sw",
sw = "ne",
nw = "se",
se = "nw",
["in"] = "out",
out = "in",
} -- end of rev_dir
-- find reverse direction
local dir = rev_dir [GetVariable "direction"]
-- if found, swap to opposite
if dir then
SetVariable ("direction", dir)
Execute (string.format ("ridebyshot %s %s",
GetVariable "target",
dir))
end -- if
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Shou
USA (30 posts) Bio
|
Date
| Reply #7 on Sun 09 Jan 2011 06:22 AM (UTC) |
Message
| Oh ok, thanks a lot for fixing it. Don't really script in Lua that much (or at all really). Think your version will actually work |
My computer once beat me at chess, but it was no match for me at kickboxing. | 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.
25,650 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top