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

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Lua Newbie Tutorial
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Lua Newbie Tutorial

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


Posted by Warbit   USA  (47 posts)  [Biography] bio
Date Tue 16 Aug 2011 08:58 PM (UTC)
Message
Hi I am new to scripting with mushclient and Lua. Been using the client for years and have been using just the alias and trigger section of the client.

Now I have decided to get into scripting.


I used and modified the example

Trigger box:
You report */*hp. Change:*. Need:*. Spells:*.

________________________________________________________

Send Box:
if %99 < 100 then
ColourNote ("white", "red", "Warning! - health is low")
end -- if

________________________________________________________



and wanted to add the command inv or inventory

so that when my hp drops below a certain level
it will display my inventory.



I was wondering if some could tell me what to add in the if statement to do than

have tried
if %99 < 100 then
ColourNote ("white", "red", "Warning! - health is low")
send.world inv
end -- if

___________________________________

if %99 < 100 then
ColourNote ("white", "red", "Warning! - health is low")
send inv
end -- if
___________________________________________


if %99 < 100 then
ColourNote ("white", "red", "Warning! - health is low")
inv
end -- if

___________________________________________


but nothing i I have done lets me do it.

Thanks I will be checking back on the sight regularly for the answer.

Then after I get it will be back again with more questions.

Thanks!!!

[Go to top] top

Posted by Fiendish   USA  (1,775 posts)  [Biography] bio   Global Moderator
Date Reply #1 on Tue 16 Aug 2011 09:18 PM (UTC)

Amended on Tue 16 Aug 2011 09:31 PM (UTC) by Fiendish

Message
Warbit said:

I used and modified the example

I'm guessing you mean the example in
http://www.mushclient.com/forum/?id=6030

Quote:

if %99 < 100 then

I think you want this to be
if (%1/%2) < some_number then
where some_number is whatever percentage is your threshold.

Quote:

send.world inv
send inv
inv

Send("inv")
And it is case sensitive.
http://mushclient.com/scripts/doc.php?function=Send

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

Posted by Warbit   USA  (47 posts)  [Biography] bio
Date Reply #2 on Tue 16 Aug 2011 09:29 PM (UTC)
Message
First of all thanks you so very much.
1.Testing it now.

WORKED PERFECTLY !!!
Thanks again !!!

Yeah the example is in the Lua section believe.
instead of %99 it was like %1

it was a colournote tutorial.

Below is my modified version changed %1 to %99 because I didn't want to get that low in heal to see if it worked..lol



Warbit said:

I used and modified the example

Trigger box:
You report */*hp. Change:*. Need:*. Spells:*.

________________________________________________________

Send Box:
if %99 < 100 then
ColourNote ("white", "red", "Warning! - health is low")
end -- if

________________________________________________________




[Go to top] top

Posted by Fiendish   USA  (1,775 posts)  [Biography] bio   Global Moderator
Date Reply #3 on Tue 16 Aug 2011 09:33 PM (UTC)

Amended on Tue 16 Aug 2011 09:35 PM (UTC) by Fiendish

Message
I think you didn't understand that part of the example.

%1 means the first * captured in your trigger pattern. %2 is the second * captured. And so on.

So to get a percentage of your health, assuming that your game sends current_health/max_health in the report, you should do %1/%2 and then compare that against some percentage number. If you want to do stuff when your health drops below 40%, you should do

if %1/%2 < 40 then


The example you looked at was just checking current health and seeing if it's less than 100hp.

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

Posted by Warbit   USA  (47 posts)  [Biography] bio
Date Reply #4 on Tue 16 Aug 2011 09:35 PM (UTC)
Message
Here is the link to where is taught me to use the ColourNote

MUSHclient : Tips and tricks : Introduction to MUSHclient scripting


the link is
http://www.gammon.com.au/forum/?id=6030



Hey thanks again!!!
[Go to top] top

Posted by Warbit   USA  (47 posts)  [Biography] bio
Date Reply #5 on Tue 16 Aug 2011 09:38 PM (UTC)
Message
Wow ok :)

Now I got it !

That helps alot !!

Cool thanks fiendish
[Go to top] top

Posted by Warbit   USA  (47 posts)  [Biography] bio
Date Reply #6 on Tue 16 Aug 2011 10:04 PM (UTC)

Amended on Tue 16 Aug 2011 10:10 PM (UTC) by Warbit

Message
Fiendish said:

I think you didn't understand that part of the example.

%1 means the first * captured in your trigger pattern. %2 is the second * captured. And so on.

So to get a percentage of your health, assuming that your game sends current_health/max_health in the report, you should do %1/%2 and then compare that against some percentage number. If you want to do stuff when your health drops below 40%, you should do

if %1/%2 < 40 then


The example you looked at was just checking current health and seeing if it's less than 100hp.


First of thanks
You are definitely teaching me.

Did the code there is a slight error in yours.

it should be


if %1/%2 < .40 then


The only reason i mention it is because it created a loop.
this fix will create the same loop too at 40% hp.

But as I work out the bottom stuff.
I think, it will fix the loop issue.
just going to take alot of figuring out on my part..hope your with me for the ride Fiendish.



I modified my prompt to be

<498/498hp 91/91ma 252/252mv>


Because autoreport spams everyone you info.
But I will need to modify the code in the if statement.


I want if to use various heal potions.
check and see it current hp is equal to max hp.

if not continue to use heal potions until current hp and max hp are equal

if out of heal potions
I then want to begin casting, cure light until
current hp is equal to max hp

if no mana and no heal potions , I want it to do nothing other than send me a color note say you have no potions and no mana in which to heal with.
And even tough the Colournote is still part of the loop, it will not be irritating and looks cool under my prompt...lol





[Go to top] top

Posted by Fiendish   USA  (1,775 posts)  [Biography] bio   Global Moderator
Date Reply #7 on Wed 17 Aug 2011 05:49 AM (UTC)
Message
Quote:
if %1/%2 < .40 then

Oops, you're right. I forgot to multiply by 100. Good catch.

You will of course get an infinite loop now if you trigger on your prompt and you always get the prompt as a result of doing the trigger script and nothing in the trigger affects your health. The loop will go away once you start adding in that healing logic.

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

Posted by Nick Gammon   Australia  (21,677 posts)  [Biography] bio   Forum Administrator
Date Reply #8 on Wed 17 Aug 2011 06:21 AM (UTC)
Message
In fact, you probably don't want to use all your potions (or all your mana) by healing every 10th of a second.

You want to test for something like:

If <my health is low> and <more than 10 seconds have elapsed since the last heal> then
<heal myself>
end if

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Warbit   USA  (47 posts)  [Biography] bio
Date Reply #9 on Wed 17 Aug 2011 03:16 PM (UTC)

Amended on Wed 17 Aug 2011 03:51 PM (UTC) by Warbit

Message
True true

LOL

I am very tolerant of spam
especially my own spam :)

But that trigger I made without taking the time to figure out
how not to blast myself every-time the prompt showed killed me.

LOL.

It got deleted. as both you all said. Make it a bit more complex.



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


6,563 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 FutureQuest]