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.
Entire forum
➜ MUSHclient
➜ Lua
➜ Random commands
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Gpan
(4 posts) Bio
|
Date
| Fri 10 May 2019 03:09 AM (UTC) Amended on Fri 10 May 2019 03:11 AM (UTC) by Gpan
|
Message
| Dear all,
i wanna random to excute commands, Zmud, we can use the #case %random {fill skin} {drink skin} {drop skin}, How can i do it by Lua? which function can help me? | Top |
|
Posted by
| Fiendish
USA (2,533 posts) Bio
Global Moderator |
Date
| Reply #1 on Fri 10 May 2019 04:47 AM (UTC) Amended on Fri 10 May 2019 04:53 AM (UTC) by Fiendish
|
Message
| |
Posted by
| Gpan
(4 posts) Bio
|
Date
| Reply #2 on Fri 10 May 2019 05:13 AM (UTC) |
Message
| thank you for your help, now i know how to execute the random commands,
if i wanna execute the specific commands.
EG. in Zmud, we can use #case @action {fill skin} {drink skin} {drop skin}, the commands depends on the parameter @action, how can i do it by Lua? still use Math.XXX?
please do not use Function "if elseif" that makes the scripts too large. Do we have any other simple short ideas? | Top |
|
Posted by
| Fiendish
USA (2,533 posts) Bio
Global Moderator |
Date
| Reply #3 on Fri 10 May 2019 11:29 AM (UTC) Amended on Fri 10 May 2019 11:39 AM (UTC) by Fiendish
|
Message
| The answer is actually the same, just without generating a random number.
commands = {"fill skin", "drink skin", "drop skin"}
action = 1
commands[action]
This will always result in "fill skin"
The logic is that I have built a list of commands to choose from on the first line, and then I select which one of those commands to use. In my first answer it was selected randomly.
A combination of both answers for clarity is:
commands = {"fill skin", "drink skin", "drop skin"}
action = math.random(#commands)
commands[action]
|
https://github.com/fiendish/aardwolfclientpackage | Top |
|
Posted by
| Nick Gammon
Australia (23,120 posts) Bio
Forum Administrator |
Date
| Reply #4 on Fri 10 May 2019 08:20 PM (UTC) |
Message
|
Gpan said:
thank you for your help, now i know how to execute the random commands
You can use the Send or Execute functions to send the random command to the MUD. "Send" literally sends the command, "Execute" treats it as if you had typed it (so if "fill" was an alias, for example, then that alias is processed).
eg.
commands = {"fill skin", "drink skin", "drop skin"}
Send ( commands[math.random(#commands)] )
Put together as an alias:
<aliases>
<alias
match="test"
enabled="y"
send_to="12"
sequence="100"
>
<send>
commands = {"fill skin", "drink skin", "drop skin"}
Send (commands[math.random(#commands)])
</send>
</alias>
</aliases>
|
For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.
|
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | 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.
15,427 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top