Well there is a function that Janilabo wrote called Explode box, (yes there is a function in SRL that does the same thing called 'grid' but this is much more simple to use IMO):
Simba Code:
function ExplodeBox(bx: TBox; rows, columns: integer): TBoxArray;
var
r, c, w, h, ew, eh, ow, oh, i, x, y: integer;
begin
if ((rows > 0) and (columns > 0) and (bx.X1 <= bx.X2) and (bx.Y1 <= bx.Y2)) then
begin
w := ((bx.X2 - bx.X1) + 1);
h := ((bx.Y2 - bx.Y1) + 1);
if (rows < 1) then
rows := 1
else
if (rows > h) then
rows := h;
if (columns < 1) then
columns := 1
else
if (columns > w) then
columns := w;
w := (w div columns);
h := (h div rows);
ew := (((bx.X2 - bx.X1) + 1) - (w * columns));
eh := (((bx.Y2 - bx.Y1) + 1) - (h * rows));
SetLength(Result, (rows * columns));
y := bx.Y1;
for r := 0 to (rows - 1) do
begin
x := bx.X1;
if ((eh > 0) and (r < eh)) then
oh := 1
else
oh := 0;
for c := 0 to (columns - 1) do
begin
if ((ew > 0) and (c < ew)) then
ow := 1
else
ow := 0;
i := ((r * columns) + c);
Result[i].X1 := x;
Result[i].X2 := (x + (w - 1) + ow);
Result[i].Y1 := y;
Result[i].Y2 := (y + (h - 1) + oh);
x := (Result[i].X2 + 1);
end;
y := (Result[i].Y2 + 1);
end;
end else
SetLength(Result, 0);
end;
How you use it is, You get the coords of the inventory, for example:
Make sure they are EXACT. Next, declare a variable called "inventory", inventory will be a TboxArray:
Now we will use the function like so:
Simba Code:
Inventory := ExplodeBox(IntToBox(X1, Y1, X2, Y2), 7, 4);
for x1, y1, x2, and y2 put the coords of the inventory, and I put 7 because there are 7 rows, and I put 4 because there are 4 collums. The function will then automatically explode "Inventory" into little boxes, like so:
Now that you have that set, think about this: what color does any item in your inventory have? Black. Every item has a black outline, the black is shown in red here:
Now find the black color, in my case it is 65536 (and is probably the same for you), and we are going to want to do a for to do loop to search each one of the boxes for that color:
Simba Code:
function rsps_slotFull(slot:Integer):Boolean;
var
x, y:Integer;
begin
if FindColor(x, y, 65536, Inventory[slot].x1, Inventory[slot].y1, Inventory[slot].x2, Inventory[slot].y) then
result := true;
end;
This function just check if a given slot is full, slow if you want to check if slot 0 (the first inventory slot) is full you would do
Now to get the inventory count we are going to do a for to do loop and call that above function, each time it returns true and result will increase by 1 like so:
Simba Code:
function rsps_Invcount:Integer;
var
i:Integer;
begin
for i := 0 to high(Inventory) do
begin
if rsps_slotFull(i) then
result := result + 1;
end;
end;
now the function to check if the inventory full is simple:
Simba Code:
function rsps_invFull:Boolean;
begin
result := (rsps_invcount = 28);
end;
Here is a test script, you may have to change the inventory coords:
Simba Code:
{$I SRL/SRL.Simba}
{$i SRL/srl/misc/debug.simba}
var
Inventory:TBoxArray;
function ExplodeBox(bx: TBox; rows, columns: integer): TBoxArray;
var
r, c, w, h, ew, eh, ow, oh, i, x, y: integer;
begin
if ((rows > 0) and (columns > 0) and (bx.X1 <= bx.X2) and (bx.Y1 <= bx.Y2)) then
begin
w := ((bx.X2 - bx.X1) + 1);
h := ((bx.Y2 - bx.Y1) + 1);
if (rows < 1) then
rows := 1
else
if (rows > h) then
rows := h;
if (columns < 1) then
columns := 1
else
if (columns > w) then
columns := w;
w := (w div columns);
h := (h div rows);
ew := (((bx.X2 - bx.X1) + 1) - (w * columns));
eh := (((bx.Y2 - bx.Y1) + 1) - (h * rows));
SetLength(Result, (rows * columns));
y := bx.Y1;
for r := 0 to (rows - 1) do
begin
x := bx.X1;
if ((eh > 0) and (r < eh)) then
oh := 1
else
oh := 0;
for c := 0 to (columns - 1) do
begin
if ((ew > 0) and (c < ew)) then
ow := 1
else
ow := 0;
i := ((r * columns) + c);
Result[i].X1 := x;
Result[i].X2 := (x + (w - 1) + ow);
Result[i].Y1 := y;
Result[i].Y2 := (y + (h - 1) + oh);
x := (Result[i].X2 + 1);
end;
y := (Result[i].Y2 + 1);
end;
end else
SetLength(Result, 0);
end;
procedure rsps_setInventory;
begin
Inventory := ExplodeBox(IntToBox(564, 213, 716, 460), 7, 4);
end;
function rsps_slotFull(slot:Integer):Boolean;
var
x, y:Integer;
begin
if FindColor(x, y, 65536, Inventory[slot].x1, Inventory[slot].y1, Inventory[slot].x2, Inventory[slot].y2) then
result := true;
end;
function rsps_Invcount:Integer;
var
i:Integer;
begin
for i := 0 to high(Inventory) do
begin
if rsps_slotFull(i) then
result := result + 1;
end;
end;
function rsps_invFull:Boolean;
begin
result := (rsps_invcount = 28);
end;
begin
rsps_setInventory;
ActivateClient;
wait(1000);
Writeln('Inventory count: ' + ToStr(rsps_Invcount));
if (rsps_invFull) then
Writeln('Inventory Full!');
end.