Results 1 to 4 of 4

Thread: function for inventory

  1. #1
    Join Date
    Dec 2012
    Posts
    24
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default function for inventory

    hello guys! I was wondering if there existed some kind of function that detects if my inventory is full? I need it for my thieving scripts that will bank the stuff if the inventory is full.

    please note this is for a RSPS so i can't use srl and i need to write the function of my own .

  2. #2
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    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:

    Simba Code:
    var
    Inventory: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
    Simba Code:
    rsps_slotFull(0);

    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.

  3. #3
    Join Date
    Sep 2012
    Location
    Netherlands
    Posts
    2,752
    Mentioned
    193 Post(s)
    Quoted
    1468 Post(s)

    Default

    Quote Originally Posted by Officer Barbrady View Post
    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:

    Simba Code:
    var
    Inventory: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
    Simba Code:
    rsps_slotFull(0);

    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.
    rsps addict!

  4. #4
    Join Date
    Dec 2012
    Posts
    24
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    Quote Originally Posted by Officer Barbrady View Post
    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:

    Simba Code:
    var
    Inventory: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
    Simba Code:
    rsps_slotFull(0);

    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.
    Wow thanx alot! you're amazing I heard alot about you!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •