Gammon Forum
Entire forum
MUSHclient
General
Call last command in a trigger
Call last command in a trigger
|
It is now over 60 days since the last post. This thread is closed.
  Refresh page
Posted by
| Faedara
(106 posts) bio
|
Date
| Thu 18 Nov 2010 08:54 PM (UTC) |
Message
| Is there a viable Lua string for calling the last command sent to the world before a trigger was activated?
I want to create a few different triggers for varying functions in Achaea, including but not limited to unlocking/opening closed doors and entering through them ((Scriptable without this)) and drawing my weapon if I attack while it's sheathed ((Not so easy))
I use the word 'string' because I don't know the proper word if that isn't the word for a function or... bah, I just don't know the terminology yet. I need a personal tutor for this stuff, I'm supposed to be a certified genius and yet I can't figure out scripting =.w.= |
The eternally clueless <3
Currently looking for a mentor/tutor to help me learn everything about Lua from the ground up. I can't understand 28*41 until I learn what causes 2+2. | top |
|
Posted by
| Nick Gammon
Australia (22,988 posts) bio
Forum Administrator |
Date
| Reply #1 on Thu 18 Nov 2010 09:20 PM (UTC) |
Message
| Take a look at this first:
Also, try:
That lets you get recent commands you typed. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|
Posted by
| Faedara
(106 posts) bio
|
Date
| Reply #2 on Thu 18 Nov 2010 10:00 PM (UTC) |
Message
| I want to say I don't quite understand what it means by
"for k, v in pairs (GetCommandList (10)) do
Note (v)
end"
But to be honest I just don't understand how it turned the table into a variable usable in note form.
Not that I need to understand to use it, but I want to do more than just use the code, I want to understand just what makes the function tick. Or at least what k stands for and why v is calculated in pairs. |
The eternally clueless <3
Currently looking for a mentor/tutor to help me learn everything about Lua from the ground up. I can't understand 28*41 until I learn what causes 2+2. | top |
|
Posted by
| Nick Gammon
Australia (22,988 posts) bio
Forum Administrator |
Date
| Reply #3 on Thu 18 Nov 2010 10:13 PM (UTC) Amended on Thu 18 Nov 2010 10:15 PM (UTC) by Nick Gammon
|
Message
| GetCommandList returns a table of recent commands. So for example, if you did this:
emote laughs and sings
/print (GetCommandList (1) [1]) --> emote laughs and sings
So, GetCommandList (1) returns a table consisting of a single item, keyed by the key 1, which is the most recent command you typed.
Then accessing key 1 gives you that command.
In this case:
for k, v in ipairs (GetCommandList (10)) do
print (k, v)
end
You get a table of 10 items, and ipairs accesses them in sequence (eg. command 1, command 2 etc.)
That was really a typo in the help, it should be ipairs not pairs, to get the commands in sequence.
k is the key (ie. 1, 2, 3, 4, 5) and v is the value (eg. "look", "sing", "kill")
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|
Posted by
| Faedara
(106 posts) bio
|
Date
| Reply #4 on Thu 18 Nov 2010 10:21 PM (UTC) |
Message
| OH! So k assigns them a value according to when the reverse order they were sent in, so that the table is organized, while v is the actual command as it was sent?
If I got that at all correct I think I can understand it. Also, for anyone who wants it or wants to improve on it, this is the trigger I used it in:
<triggers>
<trigger
enabled="y"
match="You must be wielding a whip in order to garrote someone."
send_to="12"
sequence="100"
>
<send>for k, v in pairs (GetCommandList (1)) do
Send ("Draw whip strong")
Execute (v)
Send ("Sheathe whip")
end</send>
</trigger>
</triggers>
Right now it's more flashy than practical, but I'm sure I'll find more than a few uses for it given enough time and studying. |
The eternally clueless <3
Currently looking for a mentor/tutor to help me learn everything about Lua from the ground up. I can't understand 28*41 until I learn what causes 2+2. | top |
|
Posted by
| Nick Gammon
Australia (22,988 posts) bio
Forum Administrator |
Date
| Reply #5 on Thu 18 Nov 2010 10:49 PM (UTC) |
Message
|
Faedara said:
for k, v in pairs (GetCommandList (1)) do
Send ("Draw whip strong")
Execute (v)
Send ("Sheathe whip")
end
Yes, good. But you don't really need to loop over one item. Try:
Send ("Draw whip strong")
Execute (GetCommandList (1) [1])
Send ("Sheathe whip")
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|
Posted by
| Faedara
(106 posts) bio
|
Date
| Reply #6 on Thu 18 Nov 2010 10:52 PM (UTC) |
Message
| I love Lua. I really do. I actually make things *more* complicated than they need to be. |
The eternally clueless <3
Currently looking for a mentor/tutor to help me learn everything about Lua from the ground up. I can't understand 28*41 until I learn what causes 2+2. | top |
|
Posted by
| Nick Gammon
Australia (22,988 posts) bio
Forum Administrator |
Date
| Reply #7 on Thu 18 Nov 2010 11:16 PM (UTC) Amended on Thu 18 Nov 2010 11:18 PM (UTC) by Nick Gammon
|
Message
| I've added GetInfo (87) to version 4.71 of MUSHclient. The usage of GetCommandList is potentially flawed, in that this is commands you actually type, not scripted sends or speedwalks. It might not matter in your case, but it might fail in other ones.
Just as one example:
/print "hello world"
/print (GetCommandList (1) [1]) --> print "hello world"
So this is printing the last thing you did, not the last thing you sent to the MUD.
Another way of working around that problem in a plugin is to use OnPluginSent. That records the last thing actually sent to the MUD (after alias expansions, speedwalks, scripts, etc.).
So for example:
function OnPluginSent (sText)
last_command_sent = sText
end -- function
Effectively, GetInfo (87) will record that last thing for you, so you can access it without needing a plugin, or to write a small function like that. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|
Posted by
| Faedara
(106 posts) bio
|
Date
| Reply #8 on Thu 18 Nov 2010 11:34 PM (UTC) Amended on Thu 18 Nov 2010 11:35 PM (UTC) by Faedara
|
Message
| Which is exactly why I used send for the normal functions and Execute for the actual command. I use a group variables for attacking, so my arsenal is very flexible. I use K and L to set the action (which can be anything from an attack to a greeting) and E R T as targets.
When I first made this trigger I was sending KE to the world, hehehe |
The eternally clueless <3
Currently looking for a mentor/tutor to help me learn everything about Lua from the ground up. I can't understand 28*41 until I learn what causes 2+2. | 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,584 views.
It is now over 60 days since the last post. This thread is closed.
  Refresh page
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.