SRL Archive - Research & Development Lounge

Alternative Item Finding!


Wreck

2012-07-08 14:59:44

So I was bored and was thinking of an alternative to DTM/Bitmap for inventory item finding and this is what I came up with tell me what you think! :p

program Example;
{$i SRL/srl.Simba}

type
Item = record
Col, Tol: Integer;
Uptext: TStringArray;
Name: String;
end;

var
InvSlots: Array [1..28] of Integer;
Items: Array of Item;
x, y: Integer;

const
FOOD_SHARK = 0;

procedure Debug(s: String);
begin
WriteLn('DEBUG: ' + s);
end;

procedure Setup;
begin;
ClearDebug;
Debug('Setting Up Script');

SetLength(Items, 1);
with Items[0] do //Shark
begin
Col := 5794692;
Tol := 3;
Uptext := ['hark', 'at Shar'];
Name := 'Shark';
end;

Debug('Setup Complete');
end;

procedure InvRandomSlots;
var
i, ii: Integer;
begin
For i := 1 To 28 Do
begin
repeat
ii := RandomRange(1, 29);
until (not InIntArray(InvSlots, ii));
InvSlots[i] := ii;
end;
//For i := 1 To 28 Do
// Debug('InvSlots[' + IntToStr(i) + ']: ' + IntToStr(InvSlots[i]));
end;

function InvFindItem(var fx, fy: Integer; Obj: Item): Boolean;
var
i: Integer;
Box: TBox;
P: TPoint;
begin
For i := 1 To 28 Do
begin
Box := InvBox(InvSlots[i]);
if FindColorTolerance(P.x, P.y, Obj.Col, Box.X1, Box.Y1, Box.X2, Box.Y2, Obj.Tol) then
begin
P := MiddleBox(Box);
MMouse(P.x, P.y, 5, 5);
if WaitUpTextMulti(Obj.Uptext, 250 + RandomRange(100, 250)) then
begin
GetMousePos(fx, fy);
Result := True;
Debug(Obj.Name + ' Found - Slot(' + IntToStr(InvSlots[i]) + ') Co-ords(' + IntToStr(fx) + ', ' + IntToStr(fy) + ')');
Break;
end;
end;
end;
end;

begin
SetupSRL;
ActivateClient;
Setup;
InvRandomSlots;
InvFindItem(x, y, Items[FOOD_SHARK]);
end.

Should find food from a different slot every time it is run e.g.

DEBUG: Setting Up Script
DEBUG: Setup Complete
DEBUG: Shark Found - Slot(19) Co-ords(663, 375)
Successfully executed.

Brandon

2012-07-08 15:09:28

No from me.. That just looks for one colour on the item. Imagine trying to find runes with that? It'll flag them all as the same rune.

Wreck

2012-07-08 15:14:51

From: Brandon
No from me.. That just looks for one colour on the item. Imagine trying to find runes with that? It'll flag them all as the same rune.


It can be changed to include multiple colours of course but even so wouldn't you just use a colour/colours that are only found on that rune type?

Brandon

2012-07-08 15:21:19

From: Wreck
It can be changed to include multiple colours of course but even so wouldn't you just use a colour/colours that are only found on that rune type?


Law rune colour is blue. If I have a water staff in the invent, it will flag that as a law rune as well.

What you just suggested is already done. Find a list of colours, find the points where they're located, that's most likely your item. Check out the tutorial section on PointArrays.

Wreck

2012-07-08 15:29:58

From: Brandon
Law rune colour is blue. If I have a water staff in the invent, it will flag that as a law rune as well.

What you just suggested is already done. Find a list of colours, find the points where they're located, that's most likely your item. Check out the tutorial section on PointArrays.


This wasnt meant to be 'the best' way to do this or anything this was just my own attempt at for example you have an invent full of 14 sharks and 14 buckets and it would find the colour in the 14 inventory spots and start checking the inv spots for the uptext in a random order, but thanks for the feedback. :redface: