Results 1 to 6 of 6

Thread: How can I make this array work better?

  1. #1
    Join Date
    Mar 2013
    Location
    Shaolin
    Posts
    863
    Mentioned
    24 Post(s)
    Quoted
    519 Post(s)

    Default How can I make this array work better?

    So a little back story:
    After entering the SRL Winter Competition and writing a script that would start from a fresh account I had a lot of fun writing the script so I decided to write another script with similar features. What this script does is fishes in Draynor (shrimp and anchovies) and cooks them. What I'm trying to do is get the script to find which slot 1 of each fish is in (this will port over to when it fishes trout and salmon in barbarian village and cooks them as well). What I have right now works but is very repetitive and I'm afraid it is very botty. What it does so far is looks for shrimp by moving from slot to slot for mousetext, then saves the location. After the location is determined for shrimp it will move on to find anchovies in a similar fashion. What I would like it to do is recognize the slots it has looked in already (which would be shrimp) and not have to go through them all over again to find the anchovies. Here is what I have:
    (keep in mind the variables are globally declared for use in the cooking portion)

    Simba Code:
    procedure getRawSlots();
    begin

      if (foundShrimp = False) then
        begin
          for S := 2 to 27 do
            begin
              if tabBackpack.isItemInSlot(S) then
                begin
                  tabBackpack.mouseSlot((S), MOUSE_MOVE);
                  wait(250+random(250));
                    if isMouseOverText(['Raw shrimp'],500) then
                      begin
                        shrimpSlot := S;
                        writeLn('There is raw shrimp in slot: ' + intToStr(S) + ' saving slot number for BurnAndCook');
                        foundShrimp := True;
                        mousecircle(747,540,5, MOUSE_LEFT);
                        break;
                      end;
                end;
            end;
        end;

      if (foundAnchovies = False) then
        begin
            for A := 2 to 27 do
            begin
              if tabBackpack.isItemInSlot(A) then
                begin
                  tabBackpack.mouseSlot((A), MOUSE_MOVE);
                  wait(250+random(250));
                    if isMouseOverText(['Raw anchovies'],500) then
                      begin
                        anchoviesSlot := A;
                        writeLn('There is raw anchovies in slot: ' + intToStr(A) + ' saving slot number for BurnAndCook');
                        foundAnchovies := True;
                        mousecircle(747,540,5, MOUSE_LEFT);
                        break;
                      end;
                end;
            end;
        end;

    end;
    You have permission to steal anything I've ever made...

  2. #2
    Join Date
    Dec 2011
    Posts
    193
    Mentioned
    5 Post(s)
    Quoted
    51 Post(s)

    Default

    Haven't made any RS3 scripts but firstly to make it check for both items with only 1 mouse over iteration

    Simba Code:
    if isMouseOverText(['Raw shrimp'],500) then
    begin
      shrimpSlot := S;
      writeLn('There is raw shrimp in slot: ' + intToStr(S) + ' saving slot number for BurnAndCook');
      foundShrimp := True;
      mousecircle(747,540,5, MOUSE_LEFT);
      break;
    end else
      if isMouseOverText(['Raw anchovies'],500) then
      begin
        shrimpSlot := S;
        writeLn('There is raw anchovies in slot: ' + intToStr(S) + ' saving slot number for BurnAndCook');
        foundShrimp := True;
        mousecircle(747,540,5, MOUSE_LEFT);
        break;
      end;

    Now secondly, again I'm not familiar with RS3 interfaces or even what they look like now, but surely you can create a DTM of each fish and then look for those in the inventory? I'm positive an include function will exist just for this. It'll return each slot a DTM is found. If not, here is one I use for OSRS, but the logic is the same.

    Simba Code:
    if FindDTMs(shrimpDTM, shrimpPoints, MIX1,MIY1,MIX2,MIY2) then //look for our shrimpdtm in the inventory
    begin                                                        //fill shrimpPoints with found dtms point
      for i := 0 to High(shrimpPoints) do                        //loop through each point
        shrimpSlots := shrimpSlots +pntToItem(shrimpPoints[i]);  //add the slot this point correlates to into shrimpSlots  
      ClearSameIntegers(shrimpSlots);   //make sure any matched slots only occur once.
    end;

    OSRS Color Scripts: Borland_Salamanders | Borland_Iron_Ores
    Utilities & Snippets: [Color] OSBuddy Item Looting

  3. #3
    Join Date
    Dec 2013
    Location
    Pitcairn Island
    Posts
    288
    Mentioned
    20 Post(s)
    Quoted
    166 Post(s)

    Default

    Yeah DTM or bitmap would be the best solution as mouse hovering is ban-101. You said you plan to apply this to other fish too, so the best scalable solution would be to use a record for fish types. Maybe something like:

    Simba Code:
    type TFish = record
      name: String;
      bitmap: Integer;
    end;

    var
      Salmon, Trout: TFish;

    function TFish.getSlot(): Integer;
    var
      x, y: Integer;
    begin
      if findBitmapToleranceIn(self.bitmap, x, y, tabBackpack.getBounds(), 15) then
        result := tabBackpack.pointToSlot([x, y]);
    end;

    begin
      //e.g
      Salmon.bitmap := BitmapFromString(6, 6, 'meJzLKK6QN3RTNPV');
      Trout.bitmap := BitmapFromString(6, 6, 'meJzLKK6QN3RTNPV');

      WriteLn('Trout is in slot: ' + toStr(Trout.getSlot()));
    end.

  4. #4
    Join Date
    Mar 2013
    Location
    Shaolin
    Posts
    863
    Mentioned
    24 Post(s)
    Quoted
    519 Post(s)

    Default

    Quote Originally Posted by Borland View Post
    Haven't made any RS3 scripts but firstly to make it check for both items with only 1 mouse over iteration

    Simba Code:
    if isMouseOverText(['Raw shrimp'],500) then
    begin
      shrimpSlot := S;
      writeLn('There is raw shrimp in slot: ' + intToStr(S) + ' saving slot number for BurnAndCook');
      foundShrimp := True;
      mousecircle(747,540,5, MOUSE_LEFT);
      break;
    end else
      if isMouseOverText(['Raw anchovies'],500) then
      begin
        shrimpSlot := S;
        writeLn('There is raw anchovies in slot: ' + intToStr(S) + ' saving slot number for BurnAndCook');
        foundShrimp := True;
        mousecircle(747,540,5, MOUSE_LEFT);
        break;
      end;

    Now secondly, again I'm not familiar with RS3 interfaces or even what they look like now, but surely you can create a DTM of each fish and then look for those in the inventory? I'm positive an include function will exist just for this. It'll return each slot a DTM is found. If not, here is one I use for OSRS, but the logic is the same.

    Simba Code:
    if FindDTMs(shrimpDTM, shrimpPoints, MIX1,MIY1,MIX2,MIY2) then //look for our shrimpdtm in the inventory
    begin                                                        //fill shrimpPoints with found dtms point
      for i := 0 to High(shrimpPoints) do                        //loop through each point
        shrimpSlots := shrimpSlots +pntToItem(shrimpPoints[i]);  //add the slot this point correlates to into shrimpSlots  
      ClearSameIntegers(shrimpSlots);   //make sure any matched slots only occur once.
    end;
    Quote Originally Posted by Laquisha View Post
    Yeah DTM or bitmap would be the best solution as mouse hovering is ban-101. You said you plan to apply this to other fish too, so the best scalable solution would be to use a record for fish types. Maybe something like:

    Simba Code:
    type TFish = record
      name: String;
      bitmap: Integer;
    end;

    var
      Salmon, Trout: TFish;

    function TFish.getSlot(): Integer;
    var
      x, y: Integer;
    begin
      if findBitmapToleranceIn(self.bitmap, x, y, tabBackpack.getBounds(), 15) then
        result := tabBackpack.pointToSlot([x, y]);
    end;

    begin
      //e.g
      Salmon.bitmap := BitmapFromString(6, 6, 'meJzLKK6QN3RTNPV');
      Trout.bitmap := BitmapFromString(6, 6, 'meJzLKK6QN3RTNPV');

      WriteLn('Trout is in slot: ' + toStr(Trout.getSlot()));
    end.
    Im looking at the DTM functions and there doesn't seem to be anything to return the amount of DTMs found in tabbackpack.getbounds(). This might be useful for figuring out the estimated wait times for cooking. Is there a way to get the amount of x,y values returned for findDTMs?
    You have permission to steal anything I've ever made...

  5. #5
    Join Date
    Dec 2011
    Posts
    193
    Mentioned
    5 Post(s)
    Quoted
    51 Post(s)

    Default

    Quote Originally Posted by Wu-Tang Clan View Post
    Im looking at the DTM functions and there doesn't seem to be anything to return the amount of DTMs found in tabbackpack.getbounds(). This might be useful for figuring out the estimated wait times for cooking. Is there a way to get the amount of x,y values returned for findDTMs?
    A quick look at the RS3 include and I saw tabBackpack.countDTM. findItem has the ability to return the boxes where each matching DTM occurs, these boxes will be the bounds of the slot it was in. There's probably a correct way to call that function as part of method.

    If you want to do it yourself the the function I posted above can do it all fairly easily. In that example, shrimpSlots is an array of the slots where the DTM was found. Doing Length(shrimpSlots) will give you the number of shrimps in the inventory. Ex:, numberOfShrimps := Length(shrimpSlots). It's also the most efficient method of finding exact slots and counts of DTMs in the inventory that I've tested. Looping through each slot to find a match was roughly 15 times slower when I tested. As said that's from an OSRS script so some functions names might be slightly different but I know identical ones will exist.

    OSRS Color Scripts: Borland_Salamanders | Borland_Iron_Ores
    Utilities & Snippets: [Color] OSBuddy Item Looting

  6. #6
    Join Date
    Dec 2013
    Location
    Pitcairn Island
    Posts
    288
    Mentioned
    20 Post(s)
    Quoted
    166 Post(s)

    Default

    Quote Originally Posted by Wu-Tang Clan View Post
    Im looking at the DTM functions and there doesn't seem to be anything to return the amount of DTMs found in tabbackpack.getbounds(). This might be useful for figuring out the estimated wait times for cooking. Is there a way to get the amount of x,y values returned for findDTMs?
    As Mr Borland pointed out, those methods exist already: http://docs.villavu.com/srl-6/backpack.html#countdtm


    I have no idea why you want to use that for estimated cooking time though; it seems overly complicated. Couldn't you just use the progressScreen to check when you have finished cooking?

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
  •