SRL Archive - Test corner

IsItemSelected


Naum

2009-07-21 19:55:54

Function IsItemSelectedEx(ItemSlot : Integer; UpText : String) : Boolean;
Var TPA : Array of TPoint;
Box : TBox;
Begin
Box := InvBox(ItemSlot);
FindColorsTolerance(TPA, clWhite, Box.x1, Box.y1, Box.x2, Box.y2, 0);
If High(TPA) > -1 Then
MMouse(MiddleTPA(TPA).x, MiddleTPA(TPA).y, 1, 2)
Else Exit;
Result := IsUpText(UpText) And (Pos('->', rs_GetUpText) > 0)
End;


Function IsItemSelectedEx(Name : String) : Boolean;
Var I : Byte;
Begin
For I := 1 to 28 Do
Begin
Result := IsItemSelectedEx(I, Name);
If Result Then Break;
End;
End;

Niels said he used something like this in his scripts. Is this the way to check if an item is selected. Or is there another faster way, shorter even? Will it be useful, and if useful, what will it be useful in?

Or, is this something the script maker should make?

EDIT: This will use InvBox in conjunction with SRL.

HyperSecret

2009-07-21 20:02:32

I think it looks good, good job! Make a series of these functions, one that unselects if it is the wrong selected item, one that selects the item (may already be in SRL), etc… those types of functions all for inventory item clicking.

Naike

2009-07-21 20:30:36

Wouldn't it be smarter to use InvBox instead of X, Y?

Richard

2009-07-21 20:53:21

Function IsItemSelected(ItemSlot : Integer; UpText : String) : Boolean;
Var TPA : Array of TPoint;
Box: TBox;
Begin
Box := InvBox(ItemSlot);
FindColorsTolerance(TPA, clWhite, Box.x1, Box.y1, Box.x2, Box.y2, 0);
If High(TPA) > -1 Then
MMouse(MiddleTPA(TPA).x, MiddleTPA(TPA).y, 1, 2)
Else Exit;
Result := IsUpText(UpText) And (Pos('->', rs_GetUpText) > 0)
End;

Makes more sense to use something like that. Nice idea :)

Naum

2009-07-21 21:02:35

From: N1ke!
Wouldn't it be smarter to use InvBox instead of X, Y?


From: Richard
Function IsItemSelected(ItemSlot : Integer; UpText : String) : Boolean;
Var TPA : Array of TPoint;
Box: TBox;
Begin
Box := InvBox(ItemSlot);
FindColorsTolerance(TPA, clWhite, Box.x1, Box.y1, Box.x2, Box.y2, 0);
If High(TPA) > -1 Then
MMouse(MiddleTPA(TPA).x, MiddleTPA(TPA).y, 1, 2)
Else Exit;
Result := IsUpText(UpText) And (Pos('->', rs_GetUpText) > 0)
End;
Makes more sense to use something like that. Nice idea :)


In made this function with the original intention of finding an object of which the cords of an object had been found before. So to find and Axe or something. I would use SRL's FindAxe procedure to get the x and y. Then use this in the other procedure, so they would inter-depend.

However, saying that, would it be wise to scrap that idea? Then use Richard's version. Or to loop through the InvBoxes, to find with range the x and y is in, then use the InvBox function. The main principle for this was that: the user did not know which InvBox it, the selected item, was in. Furthermore, another Idea popped into my head; that I rename IsItemSelected to IsItemSelectedEx, then make another procedure call IsItemSelected to use the 'Loop through InvBox idea' (Richard :))
Thanks, for commenting.
Rep+ to all!

Edit:

Function IsItemSelectedEx(ItemSlot : Integer; UpText : String) : Boolean;
Var TPA : Array of TPoint;
Box : TBox;
Begin
Box := InvBox(ItemSlot);
FindColorsTolerance(TPA, clWhite, Box.x1, Box.y1, Box.x2, Box.y2, 0);
If High(TPA) > -1 Then
MMouse(MiddleTPA(TPA).x, MiddleTPA(TPA).y, 1, 2)
Else Exit;
Result := IsUpText(UpText) And (Pos('->', rs_GetUpText) > 0)
End;

Function IsItemSelectedEx(Name : String) : Boolean;
Var I : Byte;
Begin
For I := 1 to 28 Do
Begin
Result := IsItemSelectedEx(I, Name);
If Result Then Break;
End;
End;

^That's what my latter idea would look like ^


EDIT2: Missed Hyper's comment, Hyper I would look into that, it could be easily incorporated into IsItemSelectedEx, with an extra parameter.

NCDS

2009-07-21 21:12:16

From: NaumanAkhlaQ
Furthermore, another Idea is that I rename it to IsItemSelectedEx, then make another procedure call IsItemSelected to use the 'Loop through InvBox idea'


I would go with that idea as they both could be useful.

Nice work!
+1

Naum

2009-07-22 11:40:54

From: NCDS
I would go with that idea as they both could be useful.

Nice work!
+1


Updated first post :)

Naum

2009-07-22 20:27:15

Just noticed, due to Boreas's newest addition to SRL, the co-ord idea can still be achieved. Would It be worth it?

{*******************************************************************************
function CoordsToItem(X, Y: Integer): Integer;
By: Boreas
Description: Returns which Inventory slot a ThePoint is in. If point is between
slots (or not in the inventory area at all) it will return 0.
*******************************************************************************}
function CoordsToItem(X, Y: Integer): Integer;
var
tmpBox: TBox;

begin
if not PointInBox(Point(X, Y), IntToBox(MIX1, MIY1, MIX2, MIY2)) then
Exit;
for Result := 1 to 4 do
begin
tmpBox := InvBox(result);
if InRange(X, tmpBox.x1, tmpBox.x2) then
break;
end;
while (not InRange(Y, tmpBox.y1, tmpBox.y2)) do
begin
IncEx(Result, 4);
if (Result > 28) then
Break;
tmpBox := InvBox(Result);
end;
if (not PointInBox(Point(X, Y), tmpBox)) then
Result := 0;
end;