New to scripting, need help learning

Posted by Traz on Sat 23 Dec 2017 04:57 PM — 4 posts, 18,293 views.

#0
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!
USA Global Moderator #1
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.
Amended on Sat 23 Dec 2017 09:16 PM by Fiendish
Australia Forum Administrator #2
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.
Amended on Sat 23 Dec 2017 10:20 PM by Nick Gammon
#3
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!