Trigger delay in a script with multiple commands

Posted by Cnauir on Thu 16 Jan 2020 12:46 PM — 9 posts, 30,851 views.

#0
Hi, i am completely new to scripts and i wanted to make a script delay before the trigger sends off multiple commands.

Reading the forum i have found out that i can make the trigger "send to script" and someone else posted the script line to make it have a random delay.

DoAfter(math.random(0.5),"daze attacker")

This works like a charm, however i cannot figure out how to add multiple commands to that line.

I want it to send 4-5 commands to the mud on the trigger after the random delay, so something like this?:

DoAfter(math.random(0.5),"daze attacker"/"knockdown attacker"/"kill attacker")

I simply cannot figure out how to make that work :P

Hope you can help me :)
USA Global Moderator #1
First, math.random only accepts integers, so you can't give it 0.5 as input. If you want 0.1-0.5 you need to do 1-5 and then divide by 10.

The thread I found (https://www.gammon.com.au/forum/?id=4351&reply=1) suggests "daze attacker\\nknockdown attacker\\nkill attacker" or "daze attacker\nknockdown attacker\nkill attacker" depending on where you do it.

You can also replace DoAfter with DoAfterSpecial and have _that_ send to Execute (you control where DoAfterSpecial sends to) and then use your configured command stack character if you have that enabled (commonly a semicolon) .

Like


DoAfterSpecial(math.random(5)/10, "daze attacker;knockdown attacker;kill attacker", sendto.execute)


or more generically


local stack_char = GetAlphaOption("command_stack_character")

DoAfterSpecial(math.random(5)/10, "daze attacker"..stack_char.."knockdown attacker"..stack_char.."kill attacker", sendto.execute)


Or you can have it send to script and do


DoAfterSpecial(math.random(5)/10, 'Send("daze attacker");Send("knockdown attacker");Send("kill attacker")', sendto.script)
Amended on Thu 16 Jan 2020 08:55 PM by Fiendish
Australia Forum Administrator #2
The MUD uses newlines to separate commands, so just put newlines between them. Fiendish is right about the math.random function returning integers.


DoAfter (math.random(5)/10, "daze attacker\nknockdown attacker\nkill attacker")


I notice Fiendish actually suggested this, so now you have two such suggestions. :)
Amended on Thu 16 Jan 2020 08:41 PM by Nick Gammon
Australia Forum Administrator #3
If you want more randomness (that is, a random delay between each command) then see this thread:

http://www.gammon.com.au/forum/?id=4956

In particular, the example here:

http://www.gammon.com.au/forum/?id=4956&reply=2#reply2

For example:


<aliases>
  <alias
   match="test"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>
require "wait"
wait.make (function ()

  wait.time (math.random(5)/10)
  Send ("daze attacker")

  wait.time (math.random(5)/10)
  Send ("knockdown attacker")

  wait.time (math.random(5)/10)
  Send ("kill attacker")

end) 
</send>
  </alias>
</aliases>



Template:pasting
For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.
Amended on Thu 16 Jan 2020 08:46 PM by Nick Gammon
#4
Thanks guys!

Got it up and working now :)

I might have some more questions soon :P
#5
Okay i have another question..or two
#6
Weird, it did not send the whole post, just the top line. Will post it again later.
USA Global Moderator #7
Put new unrelated question into another thread please.
Australia Forum Administrator #8
Cnauir said:

Weird, it did not send the whole post, just the top line. Will post it again later.


I agree with Fiendish. However sometimes bad UTF8 characters in a post will cause it to be truncated. Save the post somewhere else (eg. Notepad) before sending, in case you need to examine it and re-post it.