SRL Archive - Scripting Help

For..To..Do Loops


EyYo96

2014-09-05 05:02:07

Hello, I'm trying to create a script for a rsps which drinks brews by low hp. After 3 sips it should drink 1 restore sip.

for i := 0 to 3 do dosn't work because it would repeat 3 times regardless of if hp are low or not.

Thanks in advance ;)

bonsai

2014-09-05 05:22:35

I'm not sure I really understand your requirement, but you would use mod to do something 'every n times'


var sips: integer;
begin

sips := 0;
while (true) do
begin
inc(sips)
if (sips mod 4) then
writeln('Im on my fourth sip again');
end;

Mr. Roboto

2014-09-05 05:42:00

I agree with bonsai, your post is unclear to me too. Sounds like you also want to check the amount of HP left on the character. You can do that like this:


// Check if HP is less than 80
if(actionbar.getHPPercent() < 80)
then begin
// Do your stuff here.
end;

EyYo96

2014-09-05 05:45:05

Thanks for you reply. When I try to use if (sips mod 4) then this error comes up:"Type mismatch". What is mod? or were can I find someting bout it?

slacky

2014-09-05 05:47:50

From: EyYo96
Thanks for you reply. When I try to use if (sips mod 4) then this error comes up:"Type mismatch". What is mod? or were can I find someting bout it?


var sips: integer;
begin
sips := 0;
while True do
begin
inc(sips)

if sips mod 4 = 0 then
WriteLn('Sip: ',sips);
end;
end.

however you seem to want to check if hp is low first:

var i:Integer;
begin
if(actionbar.getHPPercent() < 30) then //if hp is less then 40%
begin
for i:=1 to 3 do
begin
//call proc to drink 1 brew (will be called 3 times) here
end;
//call proc to drink 1 restore sip here
end;
end;

EyYo96

2014-09-05 05:53:51

Hi thanks for your help. Ok I'll try to explain it again. The script should check HP, if hp are under 80, like your example, it should drink a sip of saradomin brew. When he has drunk 3 sips [combat stats r low so he must drink 1 sip of restore so stats go up to 99 again], it should drink one sip of restoration pot and start at beginning. [3 brew sips then 1 restore sip]

Mr. Roboto

2014-09-05 05:54:19

From: EyYo96
Thanks for you reply. When I try to use if (sips mod 4) then this error comes up:"Type mismatch". What is mod? or were can I find someting bout it?


General info on mod. In short it finds the remainder after dividing two numbers.

Ninja edit:

From: EyYo96
Hi thanks for your help. Ok I'll try to explain it again. The script should check HP, if hp are under 80, like your example, it should drink a sip of saradomin brew. When he has drunk 3 sips [combat stats r low so he must drink 1 sip of restore so stats go up to 99 again], it should drink one sip of restoration pot and start at beginning. [3 brew sips then 1 restore sip]


Then what you want is to keep track of how many sips of saradomin brew you have taken. Once that counter is >= 3 you can take your restore potion and wait until your health is below 80% again.




// Check if HP is less than 80
if(actionbar.getHPPercent() < 80)
then begin
drinkSaraPot();
saraPotCounter := saraPotCounter + 1;
end;

// Check how many times you drank sara.
if(saraPotCounter >= 3)
then begin
drinkRestorePot();
saraPotCounter := 0;
end

Make sure saraPotCounter is a global variable. Or depending on how much sara heals and makes you lose in stats you might want to go with slacky's version instead.

EyYo96

2014-09-05 06:14:28

Haha you got it. That's exactly what I wanted :) Thanks everyone

EyYo96

2014-09-05 06:35:57

hm, if i am trying to use if(actionbar.getHPPercent() < 80) it says "Unknown identifier 'actionbar'". Using osr include and pascal. How can I fix it?

riwu

2014-09-05 06:43:18

From: EyYo96
hm, if i am trying to use if(actionbar.getHPPercent() < 80) it says "Unknown identifier 'actionbar'". Using osr include and pascal. How can I fix it?

There's no action bar in OSR. That function is for rs3.
In OSR include the function is just HPPercent();

EyYo96

2014-09-05 06:55:58

Ok ty, tried to replace if(actionbar.getHPPercent() < 80) with if(HPPercent() < 80), "Invalid number of parameters". What am I doing wrong?

riwu

2014-09-05 07:40:30

From: EyYo96
Ok ty, tried to replace if(actionbar.getHPPercent() < 80) with if(HPPercent() < 80), "Invalid number of parameters". What am I doing wrong?

because HPPercent() has a parameter…?

function HPPercent(SwapGTabBack: Boolean): Integer;

Try HPPercent(true);

EyYo96

2014-09-05 11:29:14

I've tried:

if (HPPercent() < 80)
and
if (HPPercent(true) < 80)
and
if (HPPercent(100) < 80)


dosn't work. could someone help me? ;)

Incurable

2014-09-05 12:13:36

Can you post at least part of your script in
 tags? It would really help to be able to see what it is that you've got in order to suggest changes.

EyYo96

2014-09-06 13:25:16

Dosn't work.


// Check if HP is less than 80
if(HPPercent() < 80)
then begin
drinkSaraPot();
end;