Results 1 to 8 of 8

Thread: Using a Tbox

  1. #1
    Join Date
    Dec 2011
    Posts
    57
    Mentioned
    0 Post(s)
    Quoted
    4 Post(s)

    Default Using a Tbox

    Hi guys,

    Have been really active in asking questions lately and am sorry about that, feeling like a pest :P

    However I will ask a question about Tboxes

    So with T boxes, can I instantly create a tbox after a click, so after I've used findobject can I get it to create a tbox around the findobject? So I can then search for a colour within the Tbox?


    My use of this, is my script finds a certain bush, it then clicks it and an item appears next to the bush, I need a tbox around the bush so I can search within the Tbox only for the item because the item is the same colour as another part of the screen, if you have any other recommendations for this please say

  2. #2
    Join Date
    Jan 2012
    Posts
    2,568
    Mentioned
    35 Post(s)
    Quoted
    356 Post(s)

    Default

    Yeah something like:
    GetMousePos(x,y);
    box:= IntToBox(x-5, y-5, x+5, y+5);
    will create a size-10 box around the mouse position.

  3. #3
    Join Date
    Mar 2013
    Location
    Freedomville.
    Posts
    155
    Mentioned
    2 Post(s)
    Quoted
    107 Post(s)

    Default

    It's best you write your own object finder.

    Here's an example:
    Simba Code:
    if FindColorsTolerance(BoundsTPA, colour, mainScreen.getBounds(), tolerance, colorSetting(2, hue, sat)) then
    begin
      Bounds2D := BoundsTPA.split(100,100);     //I prefer to use cluster, but use whatever you need it for.
      Bounds2D.sortBySize;                      //or any other sorting method here, depending on what you are finding.

      if FindColorsTolerance(InnerTPA, colour2, Bounds2D[0].getBounds(), tolerance2, colorSetting(2, hue2, sat2)) then
      begin                                                      //uses the bounds of the first found object to find colours within it.
        Inner2D := InnerTPA.cluster(20);
        Inner2D.sortBySize;

        for i:=low(Inner2D) to high(Inner2D) do
          begin
            smartImage.clearArea(mainScreen.getBounds);
            smartImage.debugATPA(Inner2D);
            smartImage.debugTPA(Inner2D[i]);
            MouseBox(Inner2D[i].getBounds, MOUSE_RIGHT, MOUSE_HUMAN);       //from this line, it goes through each valid ATPA and performs an action
            if (chooseOption.select(['some option here'], 500)) then
            begin
              //actions to perform.
            end;
          end;
      end;
    end;

    Riwu's example would be a simpler method, but less dynamic I suppose.

  4. #4
    Join Date
    Dec 2011
    Posts
    57
    Mentioned
    0 Post(s)
    Quoted
    4 Post(s)

    Default

    Quote Originally Posted by sdf View Post
    It's best you write your own object finder.

    Here's an example:
    Simba Code:
    if FindColorsTolerance(BoundsTPA, colour, mainScreen.getBounds(), tolerance, colorSetting(2, hue, sat)) then
    begin
      Bounds2D := BoundsTPA.split(100,100);     //I prefer to use cluster, but use whatever you need it for.
      Bounds2D.sortBySize;                      //or any other sorting method here, depending on what you are finding.

      if FindColorsTolerance(InnerTPA, colour2, Bounds2D[0].getBounds(), tolerance2, colorSetting(2, hue2, sat2)) then
      begin                                                      //uses the bounds of the first found object to find colours within it.
        Inner2D := InnerTPA.cluster(20);
        Inner2D.sortBySize;

        for i:=low(Inner2D) to high(Inner2D) do
          begin
            smartImage.clearArea(mainScreen.getBounds);
            smartImage.debugATPA(Inner2D);
            smartImage.debugTPA(Inner2D[i]);
            MouseBox(Inner2D[i].getBounds, MOUSE_RIGHT, MOUSE_HUMAN);       //from this line, it goes through each valid ATPA and performs an action
            if (chooseOption.select(['some option here'], 500)) then
            begin
              //actions to perform.
            end;
          end;
      end;
    end;

    Riwu's example would be a simpler method, but less dynamic I suppose.


    This sounds like the right idea, just need to get my head around it, I'll show you what I have so far.

    Simba Code:
    procedure findNeverBerryBush();
    var
      findObject, x, y, i: integer;
    begin
      if not isLoggedIn() then
        exit;

      repeat
        mainscreen.findObject(x, y, 1657928, 2, colorSetting(2, 1.29, 6.63), mainscreen.playerPoint, 40, 40, 30, ['arget', 'ush'], MOUSE_LEFT);
        wait(randomRange(1000, 2000));
        inc(i);

      until;
    end;

    This is really simple what I've used, just wondering how I'd implement that variable and be able to start using it?

    also will I in the future be able to implement pixelshift? cheers

  5. #5
    Join Date
    Dec 2011
    Posts
    2,147
    Mentioned
    221 Post(s)
    Quoted
    1068 Post(s)

    Default

    How dare you ask questions and try to learn how to script, unlike 75% of the people who browse these forums. Reporting for spam. ;D

    In my charms sprite script, I have a global variable called "bushLocation" which updates after the sprite lure is activated and the sprites come out of the bush.

    The problem with a limited search is that the sprites move so fast that it's hard to come up with any sort of universal search boundary. So instead, I sort the ATPA of recognized charm sprites in order of proximity to the bush.

    Simba Code:
    ATPA.sortFromMidPoint(bushLocation);

    Hope it's going well for you!

  6. #6
    Join Date
    Mar 2013
    Location
    Freedomville.
    Posts
    155
    Mentioned
    2 Post(s)
    Quoted
    107 Post(s)

    Default

    Basically, instead of using findObject you'll have to use something like I wrote above since findObject doesn't output a TPA for us to grab bounds to find the second colour. Your entire findObject line will be replaced in your procedure.

    I don't use/never tried using findObject, but I take it you've got it left clicking once on a bush (but you can't seem to differentiate between shaking and non-shaking bushes? [assuming you're making a sprite charm hunter]). Pixelshift is definitely possible, but I would imagine it would be slow in finding shaking bushes since you would be checking over one search area at a time for x-amount of time in a field of 10+ bushes (unless of course you are using this to confirm shaking bushes after the secondary colour search).

    A function (albeit messy) you would use would be like this (haven't tested):
    Simba Code:
    function findActiveBush(colour1, colour2, tolerance1, tolerance2: Integer; hue1, sat1, hue2, sat2: Extended): Boolean;
    var
      BoundsTPA, InnerTPA: TPointArray;
      Bounds2D, Inner2D: T2DPointArray;
      i: Integer;
    begin
      if FindColorsTolerance(BoundsTPA, colour1, mainScreen.getBounds(), tolerance1, colorSetting(2, hue1, sat1)) then
      begin
        Bounds2D := BoundsTPA.split(100,100);     //I prefer to use cluster, but use whatever you need it for.
        Bounds2D.sortBySize;                      //or any other sorting method here, depending on what you are finding.

        if FindColorsTolerance(InnerTPA, colour2, Bounds2D[0].getBounds(), tolerance2, colorSetting(2, hue2, sat2)) then
        begin                                                      //uses the bounds of the first found object to find colours within it.
          Inner2D := InnerTPA.cluster(20);
          Inner2D.sortBySize;

          for i:=low(Inner2D) to high(Inner2D) do
            begin
              smartImage.clearArea(mainScreen.getBounds);
              smartImage.debugATPA(Inner2D);
              smartImage.debugTPA(Inner2D[i]);
              MouseBox(Inner2D[i].getBounds, MOUSE_RIGHT, MOUSE_HUMAN);       //from this line, it goes through each valid ATPA and performs an action
              if (chooseOption.select(['some option here'], 500)) then
              begin
                result := true;
                //actions to perform.
              end;
            end;
        end;
      end;
    end;

    If you get exceptions with drawing, edit out the smartImage lines or enable smart drawing in your script.
    Last edited by sdf; 03-04-2014 at 06:38 AM. Reason: Forgot to declare i as integer.

  7. #7
    Join Date
    Dec 2011
    Posts
    57
    Mentioned
    0 Post(s)
    Quoted
    4 Post(s)

    Default

    Thanks heaps clarity, you've been a lifesaver, that pest message was directed towards you probably 60% as I felt I'd kept asking silly questions :P




    Quote Originally Posted by sdf View Post
    Basically, instead of using findObject you'll have to use something like I wrote above since findObject doesn't output a TPA for us to grab bounds to find the second colour. Your entire findObject line will be replaced in your procedure.

    I don't use/never tried using findObject, but I take it you've got it left clicking once on a bush (but you can't seem to differentiate between shaking and non-shaking bushes? [assuming you're making a sprite charm hunter]). Pixelshift is definitely possible, but I would imagine it would be slow in finding shaking bushes since you would be checking over one search area at a time for x-amount of time in a field of 10+ bushes (unless of course you are using this to confirm shaking bushes after the secondary colour search).

    A function (albeit messy) you would use would be like this (haven't tested):
    Simba Code:
    function findActiveBush(colour1, colour2, tolerance1, tolerance2: Integer; hue1, sat1, hue2, sat2: Extended): Boolean;
    var
      BoundsTPA, InnerTPA: TPointArray;
      Bounds2D, Inner2D: T2DPointArray;
    begin
      if FindColorsTolerance(BoundsTPA, colour1, mainScreen.getBounds(), tolerance1, colorSetting(2, hue1, sat1)) then
      begin
        Bounds2D := BoundsTPA.split(100,100);     //I prefer to use cluster, but use whatever you need it for.
        Bounds2D.sortBySize;                      //or any other sorting method here, depending on what you are finding.

        if FindColorsTolerance(InnerTPA, colour2, Bounds2D[0].getBounds(), tolerance2, colorSetting(2, hue2, sat2)) then
        begin                                                      //uses the bounds of the first found object to find colours within it.
          Inner2D := InnerTPA.cluster(20);
          Inner2D.sortBySize;

          for i:=low(Inner2D) to high(Inner2D) do
            begin
              smartImage.clearArea(mainScreen.getBounds);
              smartImage.debugATPA(Inner2D);
              smartImage.debugTPA(Inner2D[i]);
              MouseBox(Inner2D[i].getBounds, MOUSE_RIGHT, MOUSE_HUMAN);       //from this line, it goes through each valid ATPA and performs an action
              if (chooseOption.select(['some option here'], 500)) then
              begin
                result := true;
                //actions to perform.
              end;
            end;
        end;
      end;
    end;

    If you get exceptions with drawing, edit out the smartImage lines or enable smart drawing in your script.

    Hey thanks for that, I do get one exceptio

    Simba Code:
    for i:= low(Inner2D) to high(Inner2D) do


    I just thought I'd put it in and see if it came back with any exceptions and that's the only exception :P

  8. #8
    Join Date
    Mar 2013
    Location
    Freedomville.
    Posts
    155
    Mentioned
    2 Post(s)
    Quoted
    107 Post(s)

    Default

    see above edited post.
    Last edited by sdf; 03-04-2014 at 06:39 AM. Reason: .

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
  •