SRL Archive - RuneScape Private-Server Scripts

Help with if on rsps combat script


henryuscola

2015-03-12 08:13:36

Hi all, I've been working on a combat script and been having trouble with quick prayers.
I have a function to tell me if I'm in combat and a procedure to turn on quick prayers only when in combat
And close it after not in combat now it sounds simple but when I'm in combat my script keeps opening and closing prayers ?

Chris

2015-03-12 08:39:13

Could you show us the script?

We can't help you without looking at the code you're executing.

henryuscola

2015-03-12 09:29:24

From: Chris
Could you show us the script?

We can't help you without looking at the code you're executing.


Here is what I have so far;
function prayersOn(): boolean;
const
PRAYERS = 9222802;
begin
result := getColor(910, 118) = PRAYERS;
end;

procedure togglePrayer();
var
praybox: TBox;
begin
if PRAYERS = 0 then exit();

writeLn('Toggling prayers.');
praybox := intToBox(613, 83, 627, 92);
mouseBox(praybox, MOUSE_LEFT);
end;

function inCombat(): boolean;
var
x, y: integer;
box: Tbox;
begin
result := findColorTolerance(x, y, 50824, intToBox(256, 226, 528, 352), 5)
end;

function inFightarea(): boolean;
var
x, y: integer;
const
FF_COLOR = 2116475;
begin
if result := getColor(775, 286) = FF_COLOR then
begin
writeln('we are in fightarea now.............');
end;
end;

///then main loop
begin
repeat
if inFightarea and InCombat() and not prayersOn then togglePrayer until false
end.

3Garrett3

2015-03-12 10:15:47

From: henryuscola
Here is what I have so far;
function prayersOn(): boolean;
const
PRAYERS = 9222802;
begin
result := getColor(910, 118) = PRAYERS;
end;

procedure togglePrayer();
var
praybox: TBox;
begin
if PRAYERS = 0 then exit();

writeLn('Toggling prayers.');
praybox := intToBox(613, 83, 627, 92);
mouseBox(praybox, MOUSE_LEFT);
end;

function inCombat(): boolean;
var
x, y: integer;
box: Tbox;
begin
result := findColorTolerance(x, y, 50824, intToBox(256, 226, 528, 352), 5)
end;

function inFightarea(): boolean;
var
x, y: integer;
const
FF_COLOR = 2116475;
begin
if result := getColor(775, 286) = FF_COLOR then
begin
writeln('we are in fightarea now.............');
end;
end;

///then main loop
begin
repeat
if inFightarea and InCombat() and not prayersOn then togglePrayer until false
end.


I'd suggest trying something like this:

function prayersOn(): boolean;
const
PRAYERS = 9222802;
begin
result := getColor(910, 118) = PRAYERS;
Writeln('prayersOn Result : ' + toStr(Result)); // Debugging so you know if this function is working
end;

procedure togglePrayer();
var
praybox: TBox;
begin
if PRAYERS = 0 then exit();

writeLn('Toggling prayers.');
praybox := intToBox(613, 83, 627, 92);
mouseBox(praybox, MOUSE_LEFT);
end;

function inCombat(): boolean;
var
x, y: integer;
box: Tbox;
begin
result := findColorTolerance(x, y, 50824, intToBox(256, 226, 528, 352), 5)
Writeln('inCombat Result : ' + toStr(Result)); // Debugging so you know if this function is working
end;

function inFightarea(): boolean;
var
x, y: integer;
const
FF_COLOR = 2116475;
begin
if result := getColor(775, 286) = FF_COLOR then
writeln('we are in fightarea now.............');
end;

///then main loop
begin
repeat
if inFightarea and InCombat() and (not prayersOn) then
togglePrayer;
wait(randomRange(1000,2000)); // Insert a wait so that it isn't constantly checking and clicking
until (false);
end.

That should debug if something is broken, and will wait between checks. I assume there is a slight delay between clicking and the button changing color so you were probably not having enough delay and it just kept clicking over and over. Change the wait range if you'd like (it's currently 1-2 seconds).

henryuscola

2015-03-12 10:54:29

From: 3Garrett3
I'd suggest trying something like this:

function prayersOn(): boolean;
const
PRAYERS = 9222802;
begin
result := getColor(910, 118) = PRAYERS;
Writeln('prayersOn Result : ' + toStr(Result)); // Debugging so you know if this function is working
end;

procedure togglePrayer();
var
praybox: TBox;
begin
if PRAYERS = 0 then exit();

writeLn('Toggling prayers.');
praybox := intToBox(613, 83, 627, 92);
mouseBox(praybox, MOUSE_LEFT);
end;

function inCombat(): boolean;
var
x, y: integer;
box: Tbox;
begin
result := findColorTolerance(x, y, 50824, intToBox(256, 226, 528, 352), 5)
Writeln('inCombat Result : ' + toStr(Result)); // Debugging so you know if this function is working
end;

function inFightarea(): boolean;
var
x, y: integer;
const
FF_COLOR = 2116475;
begin
if result := getColor(775, 286) = FF_COLOR then
writeln('we are in fightarea now.............');
end;

///then main loop
begin
repeat
if inFightarea and InCombat() and (not prayersOn) then
togglePrayer;
wait(randomRange(1000,2000)); // Insert a wait so that it isn't constantly checking and clicking
until (false);
end.

That should debug if something is broken, and will wait between checks. I assume there is a slight delay between clicking and the button changing color so you were probably not having enough delay and it just kept clicking over and over. Change the wait range if you'd like (it's currently 1-2 seconds).


Thank you very much sir ! I always get a fix to my compiling errors when I post here. :)