Lua Newbie Tutorial

Posted by Warbit on Tue 16 Aug 2011 08:58 PM — 10 posts, 38,665 views.

USA #0
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!!!

USA Global Moderator #1
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
Amended on Tue 16 Aug 2011 09:31 PM by Fiendish
USA #2
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

________________________________________________________




USA Global Moderator #3
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.
Amended on Tue 16 Aug 2011 09:35 PM by Fiendish
USA #4
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!!!
USA #5
Wow ok :)

Now I got it !

That helps alot !!

Cool thanks fiendish
USA #6
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





Amended on Tue 16 Aug 2011 10:10 PM by Warbit
USA Global Moderator #7
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.
Australia Forum Administrator #8
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
USA #9
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.