SRL Archive - Research & Development Lounge

New InFight function (using TPA)


marpis

2009-01-08 15:46:30

Now the InFight function doesnt work correctly. I am not sure if this one works 100% of time but id like you to test it.
Thanks to Tniffoc who gave me the idea. :)

I quickly tested it and it seems to detect fights. But so does SRL's InFight sometimes :S
function InFight2 : boolean;
var cTPA : TPointArray;
tpalen : integer;
begin
FindColorsSpiralTolerance(MSCX, MSCY, cTPA, 255, 230, 115, 330, 190, 0);
tpalen := GetArraylength(cTPA);
if (tpalen < 15) then
begin
FindColorsSpiralTolerance(MSCX, MSCY, cTPA, 65280, 230, 115, 330, 190, 0);
tpalen := GetArraylength(cTPA);
if (tpalen < 15) then
begin
Result := false;
end else
begin
Result := true;
writeln('Fight detected!');
end;
end else
begin
Result := true;
writeln('Fight detected!');
end;
end;

EDIT: CONFIRMED better than SRL's. Maybe fix this (i know there's something that needs to be fixed) and add to SRL? :)

EvilChicken!

2009-01-08 15:54:04

A neat way to shorten functions (and procedures) is to do "Result := Condition" instead of "if Condition then Result := True".

function InCloseCombat: Boolean;
var
G, R: TPointArray;
begin
FindColorsTolerance(G, 65280, 233, 134, 282, 172, 0);
FindColorsTolerance(R, 255, 233, 134, 282, 172, 0);
Result := High(CombineTPA(G, R)) > 10;
end;

marpis

2009-01-08 16:11:47

Phewt. Thats kinda my function in 5 lines :D everytime i think i've created something very useful it somehow turns to FAIL

edit: btw, is that srl function? or yours? if yours, can i use it?

EvilChicken!

2009-01-08 16:44:45

Naw, don't think like that.. Your function was good, it's actually rare to see jr. members show knowledge about TPAs, so you should actually be proud of yourself. ;)

The function is taken from an old private autofighter that I never got to finish, I think I might try to finish it sometime soon. As for the function, feel free to use it.

marpis

2009-01-08 17:27:43

i'm applying to members in a few weeks, when i finish my uber script (chop&burn, currently like 85% rdy)

Narcle

2009-01-08 19:10:37

From: EvilChicken!
A neat way to shorten functions (and procedures) is to do "Result := Condition" instead of "if Condition then Result := True".

function InCloseCombat: Boolean;
var
G, R: TPointArray;
begin
FindColorsTolerance(G, 65280, 233, 134, 282, 172, 0);
FindColorsTolerance(R, 255, 233, 134, 282, 172, 0);
Result := High(CombineTPA(G, R)) > 10;
end;


/looks
/looks again

Looks almost exactly like my infight, cept one line shorter
/updates script real quick