[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  New to scripting, need help learning

New to scripting, need help learning

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


Posted by Traz   (31 posts)  [Biography] bio
Date Sat 23 Dec 2017 04:57 PM (UTC)
Message
I have a basic understanding of the basics after reading several topics and documents on this website, but I'm having trouble putting the pieces together to make something work for me.
One of the first things I'm trying to accomplish is to have a trigger set up to use an item when my energy is at or below a certain number.

The prompt is:
[Pl:562,854][Ki:258,737][7% EXP][Fatigue: 55%][HT][FM]
Which I whittled down to:
[Pl:*][Ki:*,*]*

I need to make it so when %2 is less than or equal to 50, I send three commands to use an item and put it back.

I know it's holiday season and I'm in no rush for assistance, but if anyone would be willing to talk me through a couple things over VOIP, that would be immensely helpful to me. I have Discord, TS3, Steam, and, in a pinch, Skype. If asking for help this way is against the rules then please feel free to delete or alter this post.

Thanks in advance and I hope everyone has a great holiday!
[Go to top] top

Posted by Fiendish   USA  (2,514 posts)  [Biography] bio   Global Moderator
Date Reply #1 on Sat 23 Dec 2017 09:14 PM (UTC)

Amended on Sat 23 Dec 2017 09:16 PM (UTC) by Fiendish

Message
Hiya.

Try

<triggers>
  <trigger
   enabled="y"
   match="[Pl:*][Ki:*,*]*"
   send_to="12"
   sequence="100"
  >
  <send>if %2 &lt;= 50 then
  Send("command_one")
  Send("command_two")
  Send("command_three")
end</send>
  </trigger>
</triggers>


But replace "command_one",etc with what you want to send.

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

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Nick Gammon   Australia  (22,982 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Sat 23 Dec 2017 09:33 PM (UTC)

Amended on Sat 23 Dec 2017 10:20 PM (UTC) by Nick Gammon

Message
I was going to suggest that. :)

The simple approach is to test for %2 being less than 50 in a script:


if %2 <= 50 then
  Send ("Command1")
  Send ("Command2")
  Send ("Command3")
end --- if





The problem is, if you get a few prompts while sending Command1, Command2 etc. then the trigger will fire again, and you may end up doing the action 3 or 4 times, possibly consuming something you don't have a lot of.

A simple fix is to check how much time has elapsed since you last did it, eg.


if %2 <= 50 then

  if lastTriggerTime == nil or os.time () - lastTriggerTime >= 30 then
    Send ("Command1")
    Send ("Command2")
    Send ("Command3")
    lastTriggerTime = os.time ()
  end -- if 30 seconds are up
end --- if


This now won't do the actions more than once every 30 seconds. You can obviously change the 30 to something else.

Put together ready for pasting into the client is:


<triggers>
  <trigger
   enabled="y"
   match="[Pl:*][Ki:*,*]*"
   send_to="12"
   sequence="100"
  >
  <send>
if %2 &lt;= 50 then

  if lastTriggerTime == nil or os.time () - lastTriggerTime &gt;= 30 then
    Send ("Command1")
    Send ("Command2")
    Send ("Command3")
    lastTriggerTime = os.time ()
  end -- if 30 seconds are up
end --- if

</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
[Go to top] top

Posted by Traz   (31 posts)  [Biography] bio
Date Reply #3 on Tue 26 Dec 2017 03:47 PM (UTC)
Message
Thanks for the help, this has helped me better understand how things work and I got a few of my own basic scripts working because of this. I'm still having some issues but this has been of great help, thank you both very much!
[Go to top] 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.


12,070 views.

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

Go to topic:           Search the forum


[Go to top] 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.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]