SRL Archive - SRL Archives

FindFire(var FX, FY:Integer):Boolean;


Special Ed

2007-06-04 18:46:26

Well… after a lot of FindFire functions failing, working, sometimes working, finding other things, and not working in the least bit I think I've found a very solid FindFire function. Me and Sky Scripter have been kind of "battling" to see who can make the best Findfire function. Because mine works for me and his works for him, but they both don't work good for each other, so we ended up remaking them over.. and over.. so I think I've finally got it.

It doesn't work at all angles because I was just testing it at square angles. N,S,E,W. But to make it work at all angles I think I'd just have to use FindDTMRotated oh well… Also remember to tell me how it worked, or any ideas you have on improving it.

Here it is!
*Also I think I am the first person to use "Array of Boolean" Lol :) .*

function FindFire(var FX, FY:Integer):Boolean;
var ZX, ZY, Fx1, Fx2, Fy1, Fy2, i:Integer;
var Slope:Extended;
var FireDTM:Array[0..3] of Integer;
var FireResult:Array[0..3] of Boolean;
var Coords:Array[0..3] of TPoint;
var Fire:TPoint;
begin
FireDTM[0]:= DTMFromString('78DA6374606460D8C98002ACF41818B880345' +
'086E13F10309A01599B70AB0101460F206B337E350032480838');
FireDTM[1]:= DTMFromString('78DA6334636460D8C48002ACF41818B880342' +
'394CFE801646D26A0C613C85A855B0D08030006B50437');
FireDTM[2]:= DTMFromString('78DA6334636460D8C48002ACF41818B880342' +
'394CFE801646D26A0C602C85A8D5F0D00047D0426');
FireDTM[3]:= DTMFromString('78DA63B467646058CC8002ACF41818B880345' +
'086E13F10309A0359AB71AB0101464F206B157E350026810813');
Fx1:= MSX1;
Fy1:= MSY1;
Fx2:= MSX2;
Fy2:= MSY2;
for i:= 0 to 3 do
begin
if(FindDTM(FireDTM[i], Fx, Fy, Fx1, Fy1, Fx2, Fy2))then
begin
Coords[i].x:= Fx;
Coords[i].y:= Fy;
ZX:= Fx;
ZY:= Fy;
Fx1:= (Fx - 30);
Fy1:= (Fy - 30);
Fx2:= (Fx + 30);
Fy2:= (Fy + 30);
FireResult[i]:= True;
Writeln('Fire[' + inttostr(i) + '] = True');
end else
begin
if(i = 0)then
begin
Coords[0].x:= 0;
Coords[0].y:= 0;
end else
begin
Coords[i].x:= Coords[(i - 1)].x;
Coords[i].y:= Coords[(i - 1)].y;
FireResult[i]:= False;
Writeln('Fire[' + inttostr(i) + '] = False');
end;
end;
end;
if(FireResult[0] or FireResult[1] or FireResult[2] or FireResult[3])then Result:= True else
Result:= False;
Fire:= MdPtOfArray(Slope,Coords);
Writeln('Fire[0].x:= ' + inttostr(Coords[0].x));
Writeln('Fire[0].y:= ' + inttostr(Coords[0].y));
Writeln('Fire[1].x:= ' + inttostr(Coords[1].x));
Writeln('Fire[1].y:= ' + inttostr(Coords[1].y));
Writeln('Fire[2].x:= ' + inttostr(Coords[2].x));
Writeln('Fire[2].y:= ' + inttostr(Coords[2].y));
Writeln('Fire[3].x:= ' + inttostr(Coords[3].x));
Writeln('Fire[3].y:= ' + inttostr(Coords[3].y));
FX:= Fire.x;
FY:= Fire.y;
FreeDTM(FireDTM[0]);
FreeDTM(FireDTM[1]);
FreeDTM(FireDTM[2]);
FreeDTM(FireDTM[3]);
end;

If all of the DTM's turn up False please let me know, I don't think I set the tolerance high enough…

EDIT: Apparently it does work at all angles, a few people that have tested it have gotten it to work at all angles and it does seems to work for me too XD. What a bonus!

Bobarkinator

2007-06-04 19:15:08

Was this half for MSI?

Special Ed

2007-06-04 19:32:58

Yes it's for MSI I just need some testers, before I commit.

SKy Scripter

2007-06-04 19:54:09

i still think mine works better…

mine works for all bright settings.. not just very bright…
and your has miss clicked several times before…. mine is dead on the fire…
Also mine works all Angles…..

actually try them Special Ed.. dont just say your is better i have spent.. alot of time on yours and mine, trying to finds bugs… and i will ammit i have found one bug in mine… Very RARLY.. it will not find the fire.. but it has never click anything else but the flame of the fire…

You find this a game…? Please.. Test Them Both!!!!

Thanks.

Oh Yeah Heres Mine…


Function FindFire(Var x, y : Integer) : Boolean;
Var
DTM : TDTM;
NewDTM, i : Integer;
Angle : Extended;

begin
ColorToleranceSpeed(2);

DTM.MainPoint.Color := 4505332;
DTM.MainPoint.Tolerance := 20;
DTM.MainPoint.x := 225;
DTM.MainPoint.y := 166;

SetArrayLength(DTM.SubPoints, 3);

DTM.SubPoints[0].Color := 12348;
DTM.SubPoints[0].Tolerance := 20;
DTM.SubPoints[0].x := 223;
DTM.SubPoints[0].y := 174;

DTM.SubPoints[1].Color := 12348;
DTM.SubPoints[1].Tolerance := 20;
DTM.SubPoints[1].x := 234;
DTM.SubPoints[1].y := 162;

DTM.SubPoints[2].Color := 12348;
DTM.SubPoints[2].Tolerance := 20;
DTM.SubPoints[2].x := 217;
DTM.SubPoints[2].y := 160;

NewDTM := AddDTM(DTM);
For i := 1 to 2 do
begin
Result := (FindDTMRotated(NewDTM, x, y, 5, 5, 510, 320, 0.0, 6.28, 0.1, Angle));
If Result Then Break;
Wait(500);
end;
ColorToleranceSpeed(1);
FreeDTM(NewDTM);
end;

bullzeye95

2007-06-04 20:08:13

Whoa SKy, don't get all mad… yours never worked properly for me either. Special's has never misclicked for me. Yours would sometimes find daises, if I'm not mistaken.

Special Ed

2007-06-04 20:08:46

I didn't say it was better I said that I think I've gotten a good formula down, and I could make it work at all angles and all brightness levels I'm just testing it on this one to make sure it works. I've update it to work with all later, I've only seen mine misclick once, and that was because there was only half a fire. I'm not trying to say mines better than yours I was just asking for people to test it for me.

PS - Yes this is a game to me XP.

SKy Scripter

2007-06-04 20:18:07

Whoa SKy, don't get all mad… yours never worked properly for me either. Special's has never misclicked for me. Yours would sometimes find daises, if I'm not mistaken.


Ok, Lol But i dont believe the daisy part….

I didn't say it was better I said that I think I've gotten a good formula down, and I could make it work at all angles and all brightness levels I'm just testing it on this one to make sure it works. I've update it to work with all later, I've only seen mine misclick once, and that was because there was only half a fire. I'm not trying to say mines better than yours I was just asking for people to test it for me.

PS - Yes this is a game to me XP.


Sorry, i took it well that you were saying yours was better… Once Again im sorry.. i just dont feel you spent enough time testing them… but Good Job :)

bullzeye95

2007-06-04 20:22:23

Dunno, it was somebody's that found daises…

Special Ed

2007-06-04 22:22:40

Hey it not like we're against each other or anything Sky, I'm try trying to find the best way possible to do this. I've tried your a few time but for some reason it didn't work for me, probably something on my part but I'd just assume doing it myself. Also I wanted to experiment with arrays and Tpoints so it looked like a good way to do that.

Oh for anyone who wants to test, I got a newer version, works better, doesn't miss… *I don't think* but again let me know if it can't find any of the DTM due to color tolerance, ect. But even if it cant find 1 or 2 it should still work fine.

program New;
{.include SRL/SRL.scar}

function MidPoint(X1, Y1, X2, Y2: Integer): TPoint;
var
MidX, MidY: Integer;
IntStr: String;
begin
MidX:= (X1 + X2) div 2;
IntStr:= IntToStr(MidX);
Delete(IntStr, Pos('-', IntStr), 1);
MidX:= StrToInt(IntStr);
MidY:= (Y1 + Y2) div 2;
IntStr:= IntToStr(MidY);
Delete(IntStr, Pos('-', IntStr), 1);
MidY:= StrToInt(IntStr);
Result.X:= MidX;
Result.Y:= MidY;
end;

function FindFire(var FX, FY:Integer):Boolean;
var ZX, ZY, Fx1, Fx2, Fy1, Fy2, i:Integer;
var FireDTM:Array[0..3] of Integer;
var FireResult:Array[0..3] of Boolean;
var Coords:Array[0..3] of TPoint;
var FireMidPoint:Array[0..2] of TPoint;
begin
FireDTM[0]:= DTMFromString('78DA6394606460D8C28002ACF51918B880345' +
'086E13F1030F20159BB70AB01014605206B377E3500134207D1');
FireDTM[1]:= DTMFromString('78DA631463646038CD8002ACF51918B880345' +
'086E13F1030F202594770AB0101460520EB287E35001F3A07F9');
FireDTM[2]:= DTMFromString('78DA63E465646038C28002ACF51918B880345' +
'086E13F10302A00594771AB0101B09A3DF8D500001D1707F4');
FireDTM[3]:= DTMFromString('78DA6354606460D8C38002ACF51918B880345' +
'086E13F103082D41CC1AD060418F980AC5DF8D500001ED907EA');
Fx1:= MSX1;
Fy1:= MSY1;
Fx2:= MSX2;
Fy2:= MSY2;
for i:= 0 to 3 do
begin
if(FindDTM(FireDTM[i], Fx, Fy, Fx1, Fy1, Fx2, Fy2))then
begin
Coords[i].x:= Fx;
Coords[i].y:= Fy;
ZX:= Fx;
ZY:= Fy;
Fx1:= (Fx - 30);
Fy1:= (Fy - 30);
Fx2:= (Fx + 30);
Fy2:= (Fy + 30);
FireResult[i]:= True;
Writeln('Fire[' + inttostr(i) + '] = True');
end else
begin
if(i = 0)then
begin
Coords[0].x:= 0;
Coords[0].y:= 0;
Writeln('Fire[' + inttostr(i) + '] = 0');
end else
begin
Coords[i].x:= Coords[(i - 1)].x;
Coords[i].y:= Coords[(i - 1)].y;
FireResult[i]:= False;
Writeln('Fire[' + inttostr(i) + '] = False');
end;
end;
end;
if(FireResult[0] or FireResult[1] or FireResult[2] or FireResult[3])then Result:= True else
Result:= False;
Writeln('Fire[0].x:= ' + inttostr(Coords[0].x));
Writeln('Fire[0].y:= ' + inttostr(Coords[0].y));
Writeln('Fire[1].x:= ' + inttostr(Coords[1].x));
Writeln('Fire[1].y:= ' + inttostr(Coords[1].y));
Writeln('Fire[2].x:= ' + inttostr(Coords[2].x));
Writeln('Fire[2].y:= ' + inttostr(Coords[2].y));
Writeln('Fire[3].x:= ' + inttostr(Coords[3].x));
Writeln('Fire[3].y:= ' + inttostr(Coords[3].y));
FireMidPoint[0]:= MidPoint(Coords[0].x, Coords[0].y, Coords[1].x, Coords[1].y);
FireMidPoint[1]:= MidPoint(Coords[2].x, Coords[2].y, Coords[3].x, Coords[3].y);
FireMidPoint[2]:= MidPoint(FireMidPoint[0].x, FireMidPoint[0].y, FireMidPoint[1].x, FireMidPoint[1].y);
FX:= FireMidPoint[2].x;
FY:= FireMidPoint[2].y;
FreeDTM(FireDTM[0]);
FreeDTM(FireDTM[1]);
FreeDTM(FireDTM[2]);
FreeDTM(FireDTM[3]);
end;

begin
SetupSRL;
FindFire(x, y);
MMouse(x, y, 0, 0);
end.

@ Sky: Hey I did some more testing with yours and mine, yours works phenomenally well.. good job but one problem I noticed is that it can only find it if the fire is 100% in view, mostly unobstructed. It works good if your not around a lot of people but for this situation it might miss the fire if someone is standing on it or leaning over it "cooking". Thats kind of an answer to your question / statement about me using the 4 DTM's I made them small so that they don't lag and I made them in different spot so that if someone is standing on the fire or cooking it still can be found. Sorry if it sounds like I'm bashing you but it's just me trying to get my point across…

PS: Has anyone tested this YET!!!!

SKy Scripter

2007-06-05 01:34:13

Lol, Thanks Dude i Feel Better i dont care Whos FindFire is on now just as long as it works, lol… Nice Job :)

Sorry Again… Please dont find me as a enemy…

Special Ed

2007-06-05 20:21:04

From: SKy Scripter
Lol, Thanks Dude i Feel Better i dont care Whos FindFire is on now just as long as it works, lol… Nice Job :)

Sorry Again… Please dont find me as a enemy…


Hey man its cool, but I was thinking, maybe we could combine the functions, first it would search for yours then if it couldn't find it it would use mine, or do you think that would just create a lot of lag?

bullzeye95

2007-06-05 20:57:27

I think that would work good. Lag maybe, but safer.

SKy Scripter

2007-06-06 01:00:52

Hey man its cool, but I was thinking, maybe we could combine the functions, first it would search for yours then if it couldn't find it it would use mine, or do you think that would just create a lot of lag?

Yeah… considering mine is a strict FindFire
you would just have to change mine to this for less lagg….


Function FindFire(Var x, y : Integer) : Boolean;
Var
DTM : TDTM;
NewDTM : Integer;
Angle : Extended;

begin
ColorToleranceSpeed(2);

DTM.MainPoint.Color := 4505332;
DTM.MainPoint.Tolerance := 20;
DTM.MainPoint.x := 225;
DTM.MainPoint.y := 166;

SetArrayLength(DTM.SubPoints, 3);

DTM.SubPoints[0].Color := 12348;
DTM.SubPoints[0].Tolerance := 20;
DTM.SubPoints[0].x := 223;
DTM.SubPoints[0].y := 174;

DTM.SubPoints[1].Color := 12348;
DTM.SubPoints[1].Tolerance := 20;
DTM.SubPoints[1].x := 234;
DTM.SubPoints[1].y := 162;

DTM.SubPoints[2].Color := 12348;
DTM.SubPoints[2].Tolerance := 20;
DTM.SubPoints[2].x := 217;
DTM.SubPoints[2].y := 160;
NewDTM := AddDTM(DTM);
Result := (FindDTMRotated(NewDTM, x, y, 5, 5, 510, 320, 0.0, 6.28, 0.1, Angle));
ColorToleranceSpeed(1);
FreeDTM(NewDTM);
end;

Special Ed

2007-06-06 16:30:15

Hey any idea oh how to make it search from the center of the mainscreen out? Effectively of course…

SKy Scripter

2007-06-06 16:49:27

Hey any idea oh how to make it search from the center of the mainscreen out? Effectively of course…


Somthing Like This :p


program New;
{.include srl/srl.scar}



function ObjPoints(Var P : TPointArray; color, tol: Integer): Boolean;
var
x, y, a, c, i, x1, y1, x2, y2: Integer;
begin
If (Not(FindColorTolerance(x, y, color, 5, 5, 510, 330, tol))) then exit;
Result := True;
SetArrayLength(P, 0);
x1 := 245;
y1 := 165;
x2 := 277;
y2 := 185;
repeat
if (not (Loggedin)) then
Break;
a := a + 1;
if (a = 1) or (a = 3) then
c := c + 1;
for i := 1 to c do
begin
if (a = 1) then
begin
x1 := x1 + 30;
x2 := x2 + 30;
end else
if (a = 2) then
begin
y1 := y1 - 20;
y2 := y2 - 20;
end else
if (a = 3) then
begin
x1 := x1 - 30;
x2 := x2 - 30;
end else
if (a = 4) then
begin
y1 := y1 + 20;
y2 := y2 + 20;
end;
if (x1 = 485) and (x2 = 517) then
x2 := x2 - 2;
if (y1 = 325) and (y2 = 345) then
y2 := y2 - 7;
if (x2 > 515) then
Break;
if (FindColorTolerance(x, y, color, x1, y1, x2, y2, tol)) then
begin
SetArrayLength(P, GetArrayLength(P)+1);
P[GetArrayLength(p)-1].x := x;
P[GetArrayLength(p)-1].y := y;
end;
end;
if (a = 4) then a := 0;
until (x2 > 515);
end;


Function FindFire(Var x, y : Integer) : Boolean;
Var
P : TPointArray;
DTM : TDTM;
NewDTM, i : Integer;
Angle : Extended;

begin
ColorToleranceSpeed(2);
If (Not(ObjPoints(P, 4505332, 20))) then
begin
ColorToleranceSpeed(1);
Exit;
end;

DTM.MainPoint.Color := 4505332;
DTM.MainPoint.Tolerance := 20;
DTM.MainPoint.x := 225;
DTM.MainPoint.y := 166;

SetArrayLength(DTM.SubPoints, 3);

DTM.SubPoints[0].Color := 12348;
DTM.SubPoints[0].Tolerance := 20;
DTM.SubPoints[0].x := 223;
DTM.SubPoints[0].y := 174;

DTM.SubPoints[1].Color := 12348;
DTM.SubPoints[1].Tolerance := 20;
DTM.SubPoints[1].x := 234;
DTM.SubPoints[1].y := 162;

DTM.SubPoints[2].Color := 12348;
DTM.SubPoints[2].Tolerance := 20;
DTM.SubPoints[2].x := 217;
DTM.SubPoints[2].y := 160;
NewDTM := AddDTM(DTM);
For i := 0 To GetArrayLength(P)-1 do
begin
Result := (FindDTMRotated(NewDTM, x, y, P[i].x -30, P[i].y -30, P[i].x +30, P[i].y +30, 0.0, Radians(360), 0.1, Angle));
If (Result) then Break;
end;
ColorToleranceSpeed(1);
FreeDTM(NewDTM);
end;




begin
SetupSRL;
FindRS;
ActivateClient;
Wait(500);
if (FindFire(x, y)) then
MMouse(x, y, 0, 0);
end.