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 ➜ Lua ➜ Scripting noob (Need help creating a script)

Scripting noob (Need help creating a script)

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


Posted by Klaak   (5 posts)  Bio
Date Fri 08 Nov 2013 04:16 PM (UTC)

Amended on Fri 08 Nov 2013 04:21 PM (UTC) by Klaak

Message
I have a character I'm playing who is certifiably insane, and I want to create a script that will choose at random from a list of commands that I select, and send that command to the mud at random time intervals between 30 seconds and 90 seconds apart.

So for instance, let's say that this character will randomly do one of the following:

giggle

whimper

cry

emote pulls frantically at her hair!

emote begins to waltz with an unseen partner.

yell 'I hate you! Go away! I'll KILL YOU!!!'
***(This one is always followed by:)***
emote begins swinging wildly at the air, as if fighting something, then suddenly stops.

Once the character does one of those things, the next time she does one could be anywhere from 30 seconds to 90 seconds after the first instance, and what she does will once again be chosen at random from the list. Then the next insane behavior will again happen at random somewhere from 30 seconds to 90 seconds after the last occurance.

Can someone please help me accomplish this? I know next to nothing about scripting.
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #1 on Fri 08 Nov 2013 10:02 PM (UTC)
Message
Check this page out:

Template:post=7855 Please see the forum thread: http://gammon.com.au/forum/?id=7855.


That sends a "social" randomly. You could modify it to not collect all possible socials, but just have a list of the things you want to say.

This simpler version might do it for you:


<aliases>
  <alias
   match="crazy woman"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>
require "wait"

wait.make (function ()  --- coroutine below here


speech = {

  "giggle",
  "whimper",
  "cry",
  "emote pulls frantically at her hair!",
  "emote begins to waltz with an unseen partner.",
  "yell 'I hate you! Go away! I'll KILL YOU!!!'",

 -- more here

  }  -- end of speech table

 
  while not GetVariable ("stop_madness") do
    wait.time (30 + math.random (60))   -- 30 to 90 seconds
    Send (speech [ math.random (1, #speech) ])
  end -- while

  DeleteVariable ("stop_madness")

  Note ("Crazy talk stopped.")
 

end)  -- end of coroutine

</send>
  </alias>

  <alias
   match="stop crazy talk"
   enabled="y"
   variable="stop_madness"
   send_to="9"
   sequence="100"
  >
  <send>stop</send>
  </alias>


</aliases>


Template:pasting For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.


That makes an alias with a list of things to say (see "speech" table above).

Start it by typing:


crazy woman


It picks one from the list every 30 to 90 seconds. It loops doing that, so to stop it type:


stop crazy talk

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Klaak   (5 posts)  Bio
Date Reply #2 on Sat 09 Nov 2013 02:49 AM (UTC)
Message
Thanks Nick! Works great. I added another 80 socials out of the 200+ on the mud, and changed the alias to match on "insane" instead of "crazy woman" and "sane" instead of "stop crazy talk". Those are much quicker to type so I can shut them off when I enter combat.

The only problem with it all, is that the note about "Crazy Talk Stopped" outputs when I use the alias to START the crazy talk, instead of when I STOP it. I tried just moving the note to the second alias, but now the note doesn't show up at all. How do I make that note appear when I turn it off, instead of when I turn it on?
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #3 on Sat 09 Nov 2013 04:19 AM (UTC)
Message
If that variable ("stop_madness") already existed that might happen. Try again, it should be OK the second time.

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