Gammon Forum
Entire forum
MUSHclient
General
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 page
Posted by
| Traz
(31 posts) 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! | top |
|
Posted by
| Nick Gammon
Australia (22,982 posts) 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 <= 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
</send>
</trigger>
</triggers>
|
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
| Traz
(31 posts) 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! | 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 page
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.