SRL Archive - SRL Suggestions

Improved / fixed inventory functions


superuser

2012-06-09 07:03:38

Hi,

I suggest to replace current InvBox and ExistsItem -functions with below I've written. The current ones are over-complicated and doesn't even work. For instance, if you have coal bag in your inventory, current ExistsItem returns false.

function InvBox(s: integer): TBox;
begin
if not InRange(s, 1, 28) then begin
result := IntToBox(-1, -1, -1, -1);

srl_Warn('InvBox', 'Incorrect index: ' + IntToStr(s), warn_AllVersions);

exit;
end;

Dec(s);

with result do begin
x1 := 559 + (s and 3) * 42;
y1 := 210 + (s shr 2) * 36;
x2 := x1 + 40;
y2 := y1 + 34;
end;
end;

function ExistsItem(s: integer): boolean;
var
b: TBox;
begin
GameTab(tab_Inv);

b := InvBox(s);
result := (CountColor(srl_outline_black, b.x1, b.y1, b.x2, b.y2) > 0);
end;

putonajonny

2012-06-09 08:04:51

srl_Warn('InvBox', 'Incorrect index: ' + IntToStr(i), warn_AllVersions);
Shoudln't that be:
srl_Warn('InvBox', 'Incorrect index: ' + IntToStr(s), warn_AllVersions);

Also FindColor should be quicker than CountColor so I think the old ExistsItem Works Better, if I missed something let me know

Your Boxes are slightly different to the current ones (yours are white):
But I think yours are as good if not better, I agree your code is a lot neater

superuser

2012-06-09 08:05:35

From: putonajonny
srl_Warn('InvBox', 'Incorrect index: ' + IntToStr(i), warn_AllVersions);
Shoudln't that be:
srl_Warn('InvBox', 'Incorrect index: ' + IntToStr(s), warn_AllVersions);


Yes, it should!

putonajonny

2012-06-09 08:21:59

From: superuser
Yes, it should!


Also see my edit :)

superuser

2012-06-09 08:25:38

From: putonajonny
Also see my edit :)


Then there must be something wrong with FindColor, since it doesn't work at least with coal bag :) Also, the old InvBox is cropping the actual boundaries, mine does not.

putonajonny

2012-06-09 08:27:45

From: superuser
Then there must be something wrong with FindColor, since it doesn't work at least with coal bag :) Also, the old InvBox is cropping the actual boundaries, mine does not.


Yeah, I think your InvBox is definitely better

superuser

2012-06-11 04:33:51

Gonna be implemented?

putonajonny

2012-06-11 05:34:35

I did some changes, some OCD some actually practical, just for you to consider:
function InvBox(Slot : integer): TBox;
begin

if not InRange(Slot, 1, 28) then
begin
result := IntToBox(-1, -1, -1, -1);
srl_Warn('InvBox', 'Incorrect index: ' + IntToStr(Slot), warn_AllVersions);
exit;
end;

Dec(Slot);

with result do
begin
x1 := 559 + (Slot and 3) * 42;
y1 := 210 + (Slot shr 2) * 36;
x2 := x1 + 40;
y2 := y1 + 34;
end;
end;

function ExistsItem(Slot : integer): boolean;
var
B : TBox;
begin
if(GetCurrentTab <> tab_Inv)then
begin
GameTab(tab_Inv);
Wait(500+Random(500));
end;
B := InvBox(Slot);
result := (CountColor(srl_outline_black, B.x1, B.y1, B.x2, B.y2) > 0);
end;

superuser

2012-06-11 06:36:00

From: putonajonny
I did some changes, some OCD some actually practical, just for you to consider:


function ExistsItem(Slot : integer): boolean;

...

if(GetCurrentTab <> tab_Inv)then
begin
GameTab(tab_Inv);
Wait(500+Random(500));
end;

...
end;


Completely unnecessary. As in gametab.simba:


function GameTab(Tab: Integer): Boolean;
...

Result := (GetCurrentTab = Tab);
if (Result) then exit

Also,

Wait(500+Random(500));

Is unnecessary, as there's dynamic wait in gametab.simba as well:


function GameTab(Tab: Integer): Boolean;
...

Result := (GetCurrentTab = Tab);
Wait(100 + Random(100))

As I said in OP, no need to overcomplicate things. My suggestions are perfect just as they are :)

Master BAW

2012-06-19 10:28:42

From: putonajonny


sorry to interrupt, but how do you make that colored border around something? I need that to make my bot better :D (Is it a function inside the client or simba?:))

and does it have to do something with TBoxes?