SRL Archive - SRL Archives

GameTab.scar TakeOff();


NCDS

2010-02-10 17:40:27

To me boolean function should always be included when they can be. It just provides more options for failsafes.


Previous procedure:

{*******************************************************************************
procedure TakeOff(I: Integer);
By: RsN
Description: UnEquips Item specified in i.
*******************************************************************************}

procedure TakeOff(I: Integer);
var
TP: TPoint;
begin
TP := EquipmentCoords(I);
if (WearingItem(I)) then
begin
Mouse(TP.x, TP.y, 5, 5, True);
Wait(200 + Random(350));
end;
end;

My version:

{*******************************************************************************
function TakeOff(I: Integer): Boolean;
By: RsN
Description: UnEquips Item specified in i. Returns True if successful.
*******************************************************************************}

function TakeOff(I: Integer): Boolean;
var
TP: TPoint; x, y, ii: Integer;
begin
if not WearingItem(i) then Exit;
TP := EquipmentCoords(I);
for ii := 0 to 4 do
begin
Mouse(TP.x, TP.y, 5, 5, True);
Wait(75 + Random(50));
Result := WaitColorGone(srl_outline_black, Point(tp.x - 8, tp.y - 8), Point(tp.x + 8, tp.y + 8), 0, 3000);
if Result then Exit;
end;
end;

Anyone else find this to be a good idea?

i luffs yeww

2010-02-10 18:11:18

procedure TakeOff(I: Integer): Boolean;

wat

mormonman

2010-02-10 18:24:45

I like it.

NCDS

2010-02-10 18:25:46

From: i luffs yeww
procedure TakeOff(I: Integer): Boolean;

wat


:duh:

Fixed ;)
Thanks for pointing that out

i luffs yeww

2010-02-10 18:46:56

From: NCDS
:duh:

Fixed ;)
Thanks for pointing that out


:p No problem. Glad to give minuscule help towards someone who seems to have a bunch of fixes as far as I've noticed. ^^

YoHoJo

2010-02-10 20:44:16

Yes, but make the wait smaller, and repeat X times and have an If FindColor(BlackOutline) then break.

That way you can have a smaller wait overall :] get it? :/
(SPEED!)

Sir R. M8gic1an

2010-02-10 21:01:20

WaitColorGone ;)

GJ, you've been putting a lot of work in lately.

~RM

NCDS

2010-02-10 21:07:39

Something like this you mean?:

function TakeOff(I: Integer): Boolean;
var
TP: TPoint; x, y, ii: Integer;
begin
if not WearingItem(i) then Exit;
TP := EquipmentCoords(I);
for ii := 0 to 4 do
begin
Mouse(TP.x, TP.y, 5, 5, True);
Wait(75 + Random(50));
Result := (not (FindColor(X, Y, srl_outline_black, TP.x - 8, TP.y - 8, TP.x + 8, TP.y + 8)));
if Result then Exit;
end;
end;
or this?

function TakeOff(I: Integer): Boolean;
var
TP: TPoint; x, y: Integer;
begin
if not WearingItem(i) then Exit;
TP := EquipmentCoords(I);
Mouse(TP.x, TP.y, 5, 5, True);
Result := (not (FindColor(X, Y, srl_outline_black, TP.x - 8, TP.y - 8, TP.x + 8, TP.y + 8)));
t := GetSystemTime + 5000;
repeat
if Result then Exit;
Wait(50 + Random(50));
until(GetSystemTime > t);
srl_Warn('TakeOff', 'Failed to remove item'+IntToStr(i)+'.', warn_Warning);
end;

Is that what you meant or did I misunderstand you?

Edit: and thank you RM :)

YoHoJo

2010-02-10 21:20:49

Both work, WaitColorGone does too. :]

NCDS

2010-02-10 21:52:51

From: YoHoJo
Both work, WaitColorGone does too. :]


Hmm..I've never worked with WaitColorGone before, though it sounds pretty self explanatory :P

I'll look into it and post the fastest/most efficient version I come up with.

Sir R. M8gic1an

2010-02-11 02:53:56

Timing.scar


{*******************************************************************************
function WaitColorGone(Color, x, y, Tol, MaxTime: integer): Boolean;
By: TRiLeZ
Description: Waits until a colour is gone at (x, y) with tolerance and a timeout.
Results true if the colour disappeared at (x, y) within the time cap.
*******************************************************************************}
function WaitColorGone(Color, x, y, Tol, MaxTime: integer): Boolean;
var
Time: Integer;
begin
Result := False;
if Tol = 0 then Tol := 1;
Time := GetSystemTime + MaxTime;
while (Time > GetSystemTime) do
begin
if (not SimilarColors(GetColor(X, Y), Color, Tol)) then
begin
Result := True;
Exit;
end;
Wait(10);
end;
end;

~RM

NCDS

2010-02-11 02:59:34

From: Rasta Magician
Timing.scar


{*******************************************************************************
function WaitColorGone(Color, x, y, Tol, MaxTime: integer): Boolean;
By: TRiLeZ
Description: Waits until a colour is gone at (x, y) with tolerance and a timeout.
Results true if the colour disappeared at (x, y) within the time cap.
*******************************************************************************}
function WaitColorGone(Color, x, y, Tol, MaxTime: integer): Boolean;
var
Time: Integer;
begin
Result := False;
if Tol = 0 then Tol := 1;
Time := GetSystemTime + MaxTime;
while (Time > GetSystemTime) do
begin
if (not SimilarColors(GetColor(X, Y), Color, Tol)) then
begin
Result := True;
Exit;
end;
Wait(10);
end;
end;

~RM

Thanks, and fixed.