SRL Archive - Outdated Tutorials

[#36] DidClick(Red:Boolean; Time:Integer): boolean


Sir R. M8gic1an

2009-07-19 16:59:07


// * Function DidClick(Red: Boolean; Time: integer); // * by Rasta Magician
// * Function DidRedClick: boolean; // * by Rasta Magician
// * Function DidYellowClick: boolean; // * by Rasta Magician

These were added so that you can check for the 'X' after you click something. If the X is red it means you are doing an action, if yellow you clicked somewhere to walk.

This is particularly useful when either you are moving and click or when the object is moving, as monsters do.

This can also be used "just to be sure".

Lots o' Love
SRL Dev Team

Narcle

2009-07-19 17:08:29

I've used the red/yellow click check in a couple of my scripts… question is will it recognize it fast enough after a mouse click is done?… I recall myself doing a check within 50ms or so.

Sir R. M8gic1an

2009-07-19 17:08:39


{*******************************************************************************
Function DidClick(Red: Boolean; Time: integer);
By: Rasta Magician
Description: Checks for the X after a click, Times Out after Time.
*******************************************************************************}
Function DidClick(Red: Boolean; Time: integer): boolean;
var
TimeOut, x, y, Trash: integer;
begin
GetMousePos(x, y);
TimeOut := GetSystemTime + Time;
while (GetSystemTime < TimeOut) do
begin
if FindColor(Trash, Trash, 255, x - 15, y - 15, x + 15, y + 15) then
begin
if Red then
Result := true
else
Result := false;
exit;
end;

if FindColor(Trash, Trash, 65535, x - 15, y - 15, x + 15, y + 15) then
begin
if Red then
Result := false
else
Result := True;
exit;
end;
wait(5);
end;
end;

{*******************************************************************************
Function DidRedClick: boolean;
By: Rasta Magician
Description: Checks for the Red X after a Click, Times out after 500 ms
*******************************************************************************}
Function DidRedClick: boolean;
begin
Result := DidClick(true, 1000);
end;

{*******************************************************************************
Function DidYellowClick: boolean;
By: Rasta Magician
Description: Checks for the Yellow X after a Click, Times out after 500 ms
*******************************************************************************}
Function DidYellowClick: boolean;
begin
Result := DidClick(false, 1000);
end;

Lots o' Love
SRL Dev Team

Sir R. M8gic1an

2009-07-19 17:10:05

From: Narcle
I've used the red/yellow click check in a couple of my scripts… question is will it recognize it fast enough after a mouse click is done?… I recall myself doing a check within 50ms or so.


if you use DidRedClick or DidYellowClick it will, i've tested them. if you call DidClick i guess it's really up to you if it does. I just simply call DidRedClick immediately after Mouse, as if has a 1 sec timeout.

~RM

Richard

2009-07-19 17:32:45

Function DidClick(Red: Boolean; Time: integer): boolean;
var
TimeOut, x, y, Trash, Colour: integer;
begin
GetMousePos(x, y);
Case Red of
True : Colour := 255;
False: Colour := 65535;
end;
TimeOut := GetSystemTime + Time;
while (GetSystemTime < TimeOut) do
begin
Result := FindColor(Trash, Trash, Colour, x - 15, y - 15, x + 15, y + 15);
wait(5);
If Result then Exit;
end;
end;

Would that be the same thing?

marpis

2009-07-19 17:32:53

Shortened:

Function DidClick(Red: Boolean; Time: integer): boolean;
var
TimeOut, x, y, Trash: integer;
FR, FY: boolean;
begin
GetMousePos(x, y);
TimeOut := GetSystemTime + Time;
while (GetSystemTime < TimeOut) do
begin
FR := FindColor(Trash, Trash, 255, x - 15, y - 15, x + 15, y + 15);
if not FR then
FY := FindColor(Trash, Trash, 65535, x - 15, y - 15, x + 15, y + 15);
result := (FR and Red) or (FY and (not Red));
if FR or FY then exit;
wait(5);
end;
end;

Richard, your function exits only if it finds the right colour, mine and rastas exit when either of the colors is found. Once yellow click is found, red click cannot be found and vice versa.

Sir R. M8gic1an

2009-07-19 17:38:06

From: Richard
Function DidClick(Red: Boolean; Time: integer): boolean;
var
TimeOut, x, y, Trash, Colour: integer;
begin
GetMousePos(x, y);
Case Red of
True : Colour := 255;
False: Colour := 65535;
end;
TimeOut := GetSystemTime + Time;
while (GetSystemTime < TimeOut) do
begin
Result := FindColor(Trash, Trash, Colour, x - 15, y - 15, x + 15, y + 15);
wait(5);
If Result then Exit;
end;
end;

Would that be the same thing?


No, the two color checks is because if it finds red and you are looking for yellow it times out because it will know that if there is red there won't be yellow.

Marpis: yours is unreadable..

~RM

Da 0wner

2009-07-19 17:54:41

His is readable O_o..

 result := (FR and Red) or (FY and (not Red));
Result is true if it found red and red is true, or it is true if it finds yellow and red is not true..

marpis

2009-07-19 21:29:50

From: Rasta Magician
No, the two color checks is because if it finds red and you are looking for yellow it times out because it will know that if there is red there won't be yellow.

Marpis: yours is unreadable..

~RM


u vin cuz u be teh devmod :(