Log in

View Full Version : Item Picking Up..



Brandon
01-19-2012, 02:54 AM
How can I make this function better? It highlights all the items on the floor using paint.. but for whatever reason it won't click exactly where the paint is.. instead it hovers NEAR it and always at the same item instead of iterating through all ground items:


Procedure PickUpItems(ItemList: TStringArray);
var
Items, TPA: TPointArray;
Item: TPoint;
ItemArray: Array of ItemPickup;
I, CTS: Integer;
begin
LProc:= 'PickUpItems';
SetLength(ItemArray, Length(ItemCheckList) + 1);
For I:= 0 To High(ItemCheckList) do
Case lowercase(ItemCheckList[I]) of
'noted':
begin
ItemArray[I].Color := 8767731; //Noted Items.
ItemArray[I].Speed := [0.64, 1.34];
ItemArray[I].Tolerance := 10;
end;
'bones', 'bone':
begin
ItemArray[I].Color := 13423589; //Bones Items.
ItemArray[I].Speed := [0.39, 2.16];
ItemArray[I].Tolerance := 11;
end;
'bluecharm', 'blue charm', 'bluecharms':
begin
ItemArray[I].Color := 10725730; //BlueCharm Items.
ItemArray[I].Speed := [0.11, 0.44];
ItemArray[I].Tolerance := 22;
end;
'coins', 'gold', 'gp':
begin
ItemArray[I].Color := 4641005; //Coins Items.
ItemArray[I].Speed := [0.29, 3.33];
ItemArray[I].Tolerance := 5;
end;
end;

Items:= GetMMDotsOnMS('item');
if (Length(Items) > 0) then
begin
Item:= MMToMS(Items[0]);

if ((Item.X <> 0) AND (Item.Y <> 0) AND (InvFull = False)) then
begin
For I:= 0 To High(ItemArray) - 1 do
begin
CTS:= GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(ItemArray[I].Speed[0], ItemArray[I].Speed[1]);
FindColorsTolerance(TPA, ItemArray[I].Color, MSX1, MSY1, MSX2, MSY2, ItemArray[I].Tolerance);
DebugTPA(TPA, '');
ColorToleranceSpeed(CTS);
SetColorSpeed2Modifiers(0.02, 0.02);
end;

if (Length(TPA) < 1) then
exit;

Item.x:= MSCX; Item.y:= MSCY;
SortTPAFrom(TPA, Item);
For I:= 0 To High(TPA) do
begin
//MiddleTPAEx(TPA, Item.X, Item.Y);

//MMouse(Item.X, Item.Y, 0, 0);
MMouse(TPA[I].x, TPA[I].y, 0, 0);
wait(200);
if (isUptextMultiCustom(ItemList) or IsUptextMultiCustom(['ake', 'nteract', 'ttack'])) then
begin
ClickMouse2(False);
WaitOptionMulti(ItemList, 300);
wait(200);
while isMoving do
wait(1);
end;
end;
end;
end;
end;

Press Play
01-19-2012, 01:37 PM
Instead of using: MiddleTPAEx(TPA, Item.X, Item.Y);, maybe try:
Item := MiddleBox(GetTPABounds(TPA));I think it's something like that. Instead of getting the middle of the TPA, it finds the TPA's boundaries and goes for the centre of that box.

tls
01-19-2012, 05:53 PM
I use this for my random point in an array:

function RPDist(TPA: TPointArray; MaxDist: Integer): TPoint;
var
MP, P: TPoint;
begin
if not LoggedIn then Exit;
P := Point(-1, -1);
MP := MiddleTPA(TPA);
while (DistanceTo(MP, P) > MaxDist) do
P := TPA[Random(Length(TPA) - 1)];
Result := P;
end;


It finds a point in the array that is within distance MaxDist from the center. I use it to click the rope in the stronghold of player safety because it is so small.

kitchenrange
01-28-2012, 04:12 PM
It looks like you use Item just to make sure you are returning MS points at first and then again to make sure you sort the TPA from the middle of the MS before attempting to click them.

I'm not sure if you have those lines commented out just to draw attention to them or not but if not, definitely either take those comments out or find the middle point of the TPA before calling MMouse.

I'm trying to make sure I'm understanding your logic right, if you can answer those questions I may be able to help further.