SRL Archive - Research & Development Lounge

DetectFood Bitmap


Timer

2008-10-05 19:51:00

I was taking apart my Auto-Fighter today, i just got bored, so, i thought someone might find this function in interest..

function DetectFood(var BitMap: Integer): Boolean;
var
I: Integer;
Item: TBox;
begin
try
FreeBitamp(BitMap);
except
end;//In case its already set before i make one to be used.
for I := 1 to 28 do
begin
MMouseItem(I);
Wait(50 + Random(50));
if (IsUpText('Eat')) then
begin
GetInvItemBounds(I, Item);
BitMap := BitmapFromString(Item.X2 - Item.X1, Item.Y2 - Item.Y1, '');
CopyClientToBitmap(BitMap, Item.X1, Item.Y1, Item.X2, Item.Y2);
Result := True;
Exit;
end;
end;
end;
CREDIT PLEASE!

Use:
[Beginning Of Script]
DetectFood(Global_Food_Bitmap_);//Can be used for If, and Then, for if really found or not.. ;)

[Use In Script]
if (FindBitmapToleranceIn(Global_Food_Bitmap_, x, y, ..., ..., ..., ..., 30)) then
Mouse(x + 10, y + 10, 3, 3, True);//Edge of food, x and y + 10 so its closer to center of food... ;)

bullzeye95

2008-10-05 21:13:54

You need to free "BitMap".

Timer

2008-10-06 07:26:03

Do i still need too?

bullzeye95

2008-10-06 07:31:55

Yes. When you do BitmapFromString, LoadBitmap, etc., the integers that they return are indexes to an array of bitmaps within scar. So when you create that new bitmap, you're adding it to the array without deleting the old one.

Timer

2008-10-06 16:50:52

I'm loosing my touch already.. :p

Yea, forgot to Free Food Bitmap (before i removed..), and never formatted BitMap as a bitmap.. :p All fixed now. :)

Before i completely leave srl, im hoping on creating somthing, somthing big… A bitmap database, that auto updates when a script is ran, including every item in runescape known to man..! xD
PHP & SCAR project ftw. Use for functions of like…
ItemExist('': String): Boolean;
UseItem('': String): Boolean;
WearItem('': String): Boolean;
DropItem('': String): Boolean;

Yet I hope to come back in a year or two.

jakeyboy29

2008-10-06 16:59:29

timer, long time no see, ur still in my siggy. btw r u still not sending me this auto fighter?

Timer

2008-10-06 17:02:09

Lol, nah its a little out of date… :p

bullzeye95

2008-10-06 17:02:21

No, you still need to free BitMap before assigning to it again..

Timer

2008-10-06 17:07:49

what? why would I do that? I generated a bitmap, why then just free it?

EDIT: Ohh!!!!

try
FreeBitamp(BitMap);
except
end;//Incase its already set before i make one.

bullzeye95

2008-10-06 17:10:17

Yep, that's it ;d

Timer

2008-10-06 17:11:00

:), Now, lets see if anyone will use it… xD