Register forum user name Search FAQ

Gammon Forum

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 ➜ New to Scripting - Random Timer Needed Please

New to Scripting - Random Timer Needed Please

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Mikeof85   (2 posts)  Bio
Date Thu 27 Nov 2014 01:57 AM (UTC)
Message
Hello. I'm COMPLETELY NEW to scripting. I have zero experience. I'm usually good at researching for the answers I need, but I just cannot seem to find anything that works. Could someone please help?

Okay here's an example of what I need:

I cast a spell and the world returns with "You cast hurricane."



What I would like is to have a random timer between that notice and me automatically casting again with "Cast hurricane"



**World** "You successfully cast hurricane."
--Random amount of time elapses between 2 and 20 seconds--
**Me** "Cast Hurricane"



I want it to be a one-shot timer, this way I can switch to another task if I need to.



I'm open to LUA or Jscript, but I'll need helping learning how to do either, and setting mushclient up to execute the script.
Top

Posted by Mikeof85   (2 posts)  Bio
Date Reply #1 on Thu 27 Nov 2014 02:05 AM (UTC)
Message
Here's what I have so far. In all likelihood I could be waaaaay off base. The musclient is saying i have an error on line 2... No clue what to do. Thanks for any help!


function randtimer ( ) {
var randomtimer = (Math.random()*20)+2);
World.DoAfter(randomtimer,"cast hurricane");
}
Top

Posted by Nick Gammon   Australia  (23,166 posts)  Bio   Forum Administrator
Date Reply #2 on Thu 27 Nov 2014 05:10 AM (UTC)
Message
If you are really new to scripting I suggest you use Lua rather than Jscript. Then it is easy:


<triggers>
  <trigger
   custom_colour="2"
   enabled="y"
   match="You cast hurricane."
   send_to="12"
   sequence="100"
  >
  <send>
DoAfter(math.random (2, 20), "cast hurricane")
</send>
  </trigger>
</triggers>


Template:pasting 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

Posted by Fiendish   USA  (2,551 posts)  Bio   Global Moderator
Date Reply #3 on Thu 27 Nov 2014 07:25 PM (UTC)

Amended on Thu 27 Nov 2014 07:26 PM (UTC) by Fiendish

Message
This particular task is just as easy in Javascript as in Lua. You just have mismatched parentheses on your second line. (2 open, 3 close)

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Nick Gammon   Australia  (23,166 posts)  Bio   Forum Administrator
Date Reply #4 on Thu 27 Nov 2014 08:03 PM (UTC)
Message
Quote:

The musclient is saying i have an error on line 2.


It might have been easier to help if the original question included the error message.

- 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.


24,074 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.