SRL Archive - SRL Suggestions

Object.scar and Fighting.scar


mariofan12

2010-07-29 21:16:01

Object.scar-
I've begun to make a simple cow killer/beefy banker, and I noticed that the color finder will spot colors outside the main screen causing my mouse to move all around the border :confused:

Fighting.scar-
the InFight function rarely works. Currently I'm putting that through a for loop to repeat 15 times exiting once it is true. I know that method is terrible, but its a quick fix for now.

I am using the newest version of Simba.

EDIT: bad grammer

Frement

2010-07-29 21:23:07

My fix (if it still works):
function F_InFight: Boolean;
var GTPA, RTPA: TPointArray;
begin
FindColorsTolerance( GTPA, 49499, MSCX - 15, MSCY - 40, MSCX + 15, MSCY, 20 );
FindColorsTolerance( RTPA, 590010, MSCX - 15, MSCY - 40, MSCX + 15, MSCY, 20 );
Result := ( ( GetArrayLength( GTPA ) + GetArrayLength( RTPA ) ) >= 20 );
end;

mariofan12

2010-07-29 21:42:07

Tested your function in a loop of 10 while fighting a cow, all 10 loops came back false :(

Frement

2010-07-29 21:45:19

Oh yeah, maybe the colors need updating.

EDIT: This worked perfectly for me, note that you need to use SetAngle(True); or ClickNorth(True);

program Test;
{$I SRL/SRL.scar}

function F_InFight: Boolean;
var GTPA, RTPA: TPointArray;
begin
FindColorsTolerance( GTPA, 49763, MSCX - 15, MSCY - 40, MSCX + 15, MSCY, 15 );
FindColorsTolerance( RTPA, 590010, MSCX - 15, MSCY - 40, MSCX + 15, MSCY, 15 );
Result := ( ( GetArrayLength( GTPA ) + GetArrayLength( RTPA ) ) >= 20 );
end;

begin
SetupSRL;
repeat
if (F_InFight) then begin
ClearDebug;
Writeln('InFight');
end else begin
ClearDebug;
Writeln('Not InFight');
end;
Wait(200);
until(False);
end.

mariofan12

2010-07-29 22:03:27

Nice! I did ClickNorth(true) and both functions work now lol. Didn't think it would make that big of a difference thanks!

One solution solved, now just need the object finding borders to be fixed.

Frement

2010-07-29 22:05:16

One more thing, I modified it to support hits if they go into the bars way (red hit and blue hit).

function F_InFight: Boolean;
var GTPA, RTPA, BTPA, OTPA: TPointArray;
begin
FindColorsTolerance(GTPA, 49763, MSCX - 15, MSCY - 40, MSCX + 15, MSCY, 20);
FindColorsTolerance(RTPA, 590010, MSCX - 15, MSCY - 40, MSCX + 15, MSCY, 20);
FindColorsTolerance(BTPA, 16097813, MSCX - 15, MSCY - 40, MSCX + 15, MSCY, 20);
FindColorsTolerance(OTPA, 1518036, MSCX - 15, MSCY - 40, MSCX + 15, MSCY, 20);
Result := ((GetArrayLength(GTPA)+GetArrayLength(RTPA)+GetArrayLength(BTPA)+GetArrayLength(OTPA)) >= 35);
end;

EvilChicken!

2010-07-30 12:28:41

const
MS_HEALTH_GREEN = 49763;
MS_HEALTH_RED = 590010;
MS_HIT_GREEN = 16097813;
MS_HIT_RED = 1518036;

function F_InFight: Boolean;
var
TPA1, TPA2: TPointArray;
Colors: TIntegerArray;
I: Byte;
begin
Colors := [MS_HEALTH_GREEN, MS_HEALTH_RED, MS_HIT_GREEN, MS_HIT_RED];
for I := 0 to 4 do
begin
FindColorsTolerance(TPA1, Colors[I], MSCX - 15, MSCY - 40, MSCX + 15, MSCY, 20);
TPA2 := CombineTPA(TPA1, TPA2);
end;

Result := InRange(TPA2, healthbarwidth * healthbarheight - tol, healthbarwidth * healthbarheight - tol);
end;

Quickly did this in notepad, not sure if it's excessive, but it'll probably do.. I do not have Simba here, nor SVN or anything to commit with.
healthbarwidth and healthbarheight ofcourse need to be replaced with the original values, most likely found in one of N3ss3s' functions in Fighting.scar.. unless they've changed since then? *needs confirmation* The "tol", not sure if even needed.. Does the player's health bar vary in width and height?

Other things; are you sure such a big searchbox is needed? (I wouldn't know, I'm just asking..)

Besides, check if I understood all the color values correctly, Frement. I'll test and commit when I get home.
And do remind me to commit this if I forget it, please. :)

Frement

2010-07-30 21:20:11

Well yes, but its MS_HIT_BLUE :) not GREEN :P Green is for poison :)

Anyways, looks good actually. I used such a big box because when you hit, the bar moves a bit down and up and stuff. I don't really know if it needs to be _so_ big. I think I made it smaller in some function, I just had to find this from a thread I had posted it to. Anyways, I'll test your function and fix it up :)

EDIT: This seems to work just fine, fixed some compile errors etc.
const
MS_HEALTH_GREEN = 49763;
MS_HEALTH_RED = 590010;
MS_HIT_BLUE = 16097813;
MS_HIT_RED = 1518036;

function F_InFight: Boolean;
var
TPA1, TPA2: TPointArray;
Colors: TIntegerArray;
I: Byte;
begin
Colors := [MS_HEALTH_GREEN, MS_HEALTH_RED, MS_HIT_BLUE, MS_HIT_RED];
for I := 0 to 3 do
begin
FindColorsTolerance(TPA1, Colors[I], MSCX - 15, MSCY - 40, MSCX + 15, MSCY, 30);
TPA2 := CombineTPA(TPA1, TPA2);
end;

Result := InRange(GetArrayLength(TPA2), 35, 380);
end;

Coh3n

2010-07-30 23:35:31

Committed that version of InFight, Frement. :)

Mario, what object finding function are you using? They all use the mainscreen coordinates from what I can see. Also, I wouldn't suggest using them anyway. I recommend using SmartColors, they're much, much better (and easier, IMO). :)

Sir R. M8gic1an

2010-07-31 07:04:48

Good job on the function, EC.
HealthBarWidth and HealthBarHeight could also be constants.
Or just declare them as variables and keep them at the top of the function.

~RM

EvilChicken!

2010-07-31 13:18:54

Guys, thanks for your responses. And for committing it, Coh3n – but I had slightly greater plans in mind for this, considering this function might be more accurate than FindFight in /core/AntiRandoms/AntiRandoms.scar. Any thoughts on that?

Sir R. M8gic1an

2010-07-31 13:21:13

From: EvilChicken!
Guys, thanks for your responses. And for committing it, Coh3n – but I had slightly greater plans in mind for this, considering this function might be more accurate than FindFight in /core/AntiRandoms/AntiRandoms.scar. Any thoughts on that?


Make it all just one function. The one in Antirandoms is in the core, so make that one good. Then for now, just wrap the one in Fighting.scar. That'll avoid code repetition and it'll ensure that both have a good function to use.

~RM

EvilChicken!

2010-07-31 13:38:09

Like this?:

const
MS_HEALTH_GREEN = 49763;
MS_HEALTH_RED = 590010;
MS_HIT_BLUE = 16097813;
MS_HIT_RED = 1518036;

function InFight: Boolean;
var
TPA1, TPA2: TPointArray;
Colors: TIntegerArray;
I: Byte;
begin
Colors := [MS_HEALTH_GREEN, MS_HEALTH_RED, MS_HIT_BLUE, MS_HIT_RED];
for I := 0 to 3 do
begin
FindColorsTolerance(TPA1, Colors[I], MSCX - 15, MSCY - 40, MSCX + 15, MSCY, 30);
TPA2 := CombineTPA(TPA1, TPA2);
end;

Result := InRange(GetArrayLength(TPA2), 35, 380); // SEE "NOTE" REGARDING THIS LINE!
end;

function FindFight: Boolean;
begin
Result := False;
if (not LoggedIn) then exit;

if (InFight) then
begin
if (CheckHpFirst) and (HpPercent = 100) then exit;

Result := True;
AddToSRLLog('******** FOUND FIGHTING RANDOM ********');
WriteLn('******** FOUND FIGHTING RANDOM ********');
TakeScreen('Found Fight');
Inc(RandSolved[rand_Fight]);
end;
end;
^That would all be placed in /AntiRandoms/AntiRandoms.scar. And, this would also requre removal of InFight from /skill/Fighting.scar.

The problem, if existent, is that I don't know how well it's been tested.

And, Cazax's function FindAllHPBars (quite nifty function, actually) uses constant bar widths and heights, 55 and 7. Someone needs to check whether health bars still have those widths and heights, and whether they still are constant. (Which I believe they most likely will be.)

And, if they really are constant, maximum accuracy would be achieved by altering the "SEE NOTE REGARDING THIS LINE"-line of the mentioned function into comparing lengths of the result TPA with the constant bar width * height, and also adding a little tolerance to the result, since I believe the numbers inside the red/blue damage indicator aren't counted as part of the result in the function?

Coh3n

2010-07-31 13:38:13

From: EvilChicken!
Guys, thanks for your responses. And for committing it, Coh3n – but I had slightly greater plans in mind for this, considering this function might be more accurate than FindFight in /core/AntiRandoms/AntiRandoms.scar. Any thoughts on that?

Yeah I figured you might. I just committed so there was something that worked until you got the chance to do what you want with it. :)

mariofan12

2010-07-31 14:08:12

From: Coh3n
Committed that version of InFight, Frement. :)

Mario, what object finding function are you using? They all use the mainscreen coordinates from what I can see. Also, I wouldn't suggest using them anyway. I recommend using SmartColors, they're much, much better (and easier, IMO). :)


I was using whatever FightNPC used, which was FindObjCustom. And I thought it used them as well, but my mouse would go outside the border by about 10 pixels because I was searching for a similar color on a cow :p

Maybe make the FightNPC use SmartColors? I may make a modified version of that in my script until otherwise.

Frement

2010-07-31 14:53:18

I also had some ideas for the InFight function, but I haven't investigated yet if my idea will work.

EDIT: The height and width btw:
HP_BAR_WIDTH = 56;
HP_BAR_HEIGHT = 7;
EDIT2: And thats with the border.

EvilChicken!

2010-07-31 15:24:20

From: Frement
I also had some ideas for the InFight function, but I haven't investigated yet if my idea will work.


Post it! :) I'll wait a bit before committing this, for people to test this and come with more input. I'll add a [FEEDBACK] tag to this thread.

From: Frement
EDIT: The height and width btw:
HP_BAR_WIDTH = 56;
HP_BAR_HEIGHT = 7;
EDIT2: And thats with the border.


So it would be 54 * 5 without the borders? (Assuming the borders are 1px wide..) Only the area containing the colors is needed.
By the way, size is static, right?

EDIT: mariofan12, I'm really sorry to be hijacking your thread. >_<
As mentioned, try SmartColors in /misc/ ..
.. or FindObjTPA in Object.scar.

Frement

2010-07-31 15:25:54

From: EvilChicken!
So it would be 54 * 5 without the borders? (Assuming the borders are 1px wide..) Only the area containing the colors is needed.
By the way, size is static, right?


Yes.

EDIT: Btw, the actual formula for calculating the min/max would be.

Min: HP_BAR_WIDTH * HP_BAR_HEIGHT / 7 - TOL;
Max: HP_BAR_WIDTH * HP_BAR_HEIGHT + TOL;

Because the function does return like 38+ values everytime, and sometimes just a bit lower then 300.

EDIT2: I edited the function a bit to give more accurate results, however this was not what was in my mind, I haven't gotten into that yet :)
var
HP_BAR_GREEN, HP_BAR_RED: TIntegerArray;
HP_BAR_MIN, HP_BAR_MAX: Integer;
HP_BAR_DECLARED: Boolean;

const
HP_BAR_TOL = 3;
HP_BAR_WIDTH = 57;
HP_BAR_HEIGHT = 7;

procedure DeclareHPBar;
begin
if not (HP_BAR_DECLARED) then
begin
HP_BAR_GREEN := [49499, 52611, 51081, 52641, 47667];
HP_BAR_RED := [590010, 590002, 131211, 524453, 594402];
HP_BAR_MIN := HP_BAR_WIDTH * HP_BAR_HEIGHT / 10 - HP_BAR_TOL;
HP_BAR_MAX := HP_BAR_WIDTH * HP_BAR_HEIGHT * 3 / 2 + HP_BAR_TOL;
HP_BAR_DECLARED := True;
end;
end;

function F_InFight: Boolean;
var
TPA1, TPA2: TPointArray;
Colors: T2DIntegerArray;
I, C: Integer;
begin
DeclareHPBar;
Colors := [HP_BAR_GREEN, HP_BAR_RED];
for I := 0 to 1 do
begin
for C := 0 to High(Colors[I]) do
begin
FindColorsTolerance(TPA1, Colors[I][C], MSCX - 25, MSCY - 40, MSCX + 25, MSCY - 15, 30);
TPA2 := CombineTPA(TPA1, TPA2);
end;
end;
Result := InRange(GetArrayLength(TPA2), HP_BAR_MIN, HP_BAR_MAX);
end;

EvilChicken!

2010-08-05 19:28:49

I believe we can call this resolved and committed?