Results 1 to 25 of 25

Thread: Combat Script

  1. #1
    Join Date
    Aug 2013
    Posts
    159
    Mentioned
    4 Post(s)
    Quoted
    90 Post(s)

    Default Combat Script

    I need a good way to determine when my character is in combat in the most optimized, fewer lines the better, way possible. I've thought of using player animation, limiting the search range and using color to determine if the opposition is still alive with a repeat, and I'm not sure what would be the best way to execute such a task.

    I could also use some help making the finished product
    and then, if it isn't too much, some more help make a custom object finder. I'm going to attempt it on my own but I'd still like someone to aid me in revising it at the least.

    Edit: The combat part is done I just need some help deciding the finding object method and then someone to revise it after I make it.

  2. #2
    Join Date
    Feb 2007
    Location
    Alberta, Canada
    Posts
    4,615
    Mentioned
    50 Post(s)
    Quoted
    429 Post(s)

    Default

    Quote Originally Posted by Trollcrank View Post
    I need a good way to determine when my character is in combat in the most optimized, fewer lines the better, way possible. I've thought of using player animation, limiting the search range and using color to determine if the opposition is still alive with a repeat, and I'm not sure what would be the best way to execute such a task.

    You could lock the combat bar (health bar whatever) in the top left corner of the screen and then only search for a given colour of the box in the top corner. That would take one line "Result := GetColor(blah)". It's way more efficient and fool-proof than searching all over the screen (or if magic/range, off screen) for the box.

    Scripts: Edgeville Chop & Bank, GE Merchanting Aid
    Tutorials: How to Dominate the Grand Exchange

    Quote Originally Posted by YoHoJo View Post
    I like hentai.

  3. #3
    Join Date
    Aug 2013
    Posts
    159
    Mentioned
    4 Post(s)
    Quoted
    90 Post(s)

    Default

    Quote Originally Posted by 3Garrett3 View Post
    You could lock the combat bar (health bar whatever) in the top left corner of the screen and then only search for a given colour of the box in the top corner. That would take one line "Result := GetColor(blah)". It's way more efficient and fool-proof than searching all over the screen (or if magic/range, off screen) for the box.
    So what method would I use to locate the health bar, findcolortolerence... or a mainscreen edit(I don't know how to do those yet, I've just seen them ).

    Edit: Ya ignore this question. In another post I ask what the numbers in getColor mean and basically how to use it

  4. #4
    Join Date
    Dec 2011
    Location
    East Coast, USA
    Posts
    4,231
    Mentioned
    112 Post(s)
    Quoted
    1869 Post(s)

    Default

    Stolen from my fighting script:


    redCircle is the red targeting reticule that appears around an NPC you're in combat with, let the user set its CTS2 stuff cuz it changes colors a lot

    yellowCircle is the same, but with the yellow reticule

    waitForTarget is a failsafe I implemented for reasons that are now unknown to me

    Simba Code:
    ///////////////////////////////////
    ///////////////////////////////////
    ///////   Combat detection  ///////
    ///////////////////////////////////
    ///////////////////////////////////

    function hasTargeted():boolean;
    var
      tpa:TPointArray;
      i:integer;
    begin
      result := findColorsTolerance(tpa, redCircle.col, redCircle.area, redCircle.tol, redCircle.cts);
      //smartImage.debugTpa(tpa);
    end;

    function hasBeenTargeted():boolean;
    var
      tpa:TPointArray;
    begin
      result := findColorsTolerance(tpa, yellowCircle.col, yellowCircle.area, yellowCircle.tol, yellowCircle.cts);
    end;

    function waitForTarget():boolean;
    var
      t:TTimeMarker
    begin
      result := false;
      minimap.waitPlayerMoving();
      t.start();
      repeat
        wait(randomRange(250, 500));
      until (hasTargeted()) or (t.getTime() > maxWait);
      t.pause();
      if (hasTargeted()) then
       result := true;
      if (result) then
       writeDebug('Target acquired in ' + toStr(t.getTime()) + ' ms');
    end;

    Then, you could even get a TBox of the fight using this:

    Simba Code:
    function getFightLocation():TBox;
    var
      tpa:TPointArray;
    begin
      if not (hasTargeted()) then
       exit;

      if findColorsTolerance(tpa, redCircle.col, mainScreen.getBounds(), redCircle.tol, redCircle.cts) then
       result := getTpaBounds(tpa);

      if not (disableDrawing) then
        smartImage.drawBox(result, false, clYellow); //draw it

      writeDebug('Player is in combat with NPC at ' + toStr(result));
    end;

    E: Just remembered I have a video of it working: https://www.youtube.com/watch?v=ugTypL48hYM
    Ignore how slow and inaccurate it is in that video lol it's only meant to show combat detection
    Last edited by KeepBotting; 11-05-2014 at 11:13 PM.
    GitLab projects | Simba 1.4 | Find me on IRC or Discord | ScapeRune scripts | Come play bot ScapeRune!

    <BenLand100> we're just in the transitional phase where society reclassifies guns as Badâ„¢ before everyone gets laser pistols

  5. #5
    Join Date
    Aug 2013
    Posts
    159
    Mentioned
    4 Post(s)
    Quoted
    90 Post(s)

    Default

    Quote Originally Posted by KeepBotting View Post
    E: Just remembered I have a video of it working: https://www.youtube.com/watch?v=ugTypL48hYM
    Ignore how slow and inaccurate it is in that video lol it's only meant to show combat detection
    Your INSTA-KILLED & BANNED BY A JMOD! was an amazing video, it made me a little sad on the inside though. Also, the red crosshairs seems to be a less accurate and more line consuming process then the Result:= Getcolor..blah

    So what exactly do the numbers mean in Getcolor?
    Simba Code:
    function Fighting: boolean;
    begin
      result := (getColor(61, 43) = 379903);
    end;                 //x, y?    //Color?
    EDIT: So apperanlty there is a ring around enemies that I somehow managed to ignore...Still, the getColors seems like a better option.

  6. #6
    Join Date
    Dec 2011
    Location
    East Coast, USA
    Posts
    4,231
    Mentioned
    112 Post(s)
    Quoted
    1869 Post(s)

    Default

    Quote Originally Posted by Trollcrank View Post
    Your INSTA-KILLED & BANNED BY A JMOD! was an amazing video, it made me a little sad on the inside though. Also, the red crosshairs seems to be a less accurate and more line consuming process then the Result:= Getcolor..blah

    So what exactly do the numbers mean in Getcolor?
    Simba Code:
    function Fighting: boolean;
    begin
      result := (getColor(61, 43) = 379903);
    end;                 //x, y?    //Color?
    EDIT: So apperanlty there is a ring around enemies that I somehow managed to ignore...Still, the getColors seems like a better option.
    Thanks :P

    Yeah you've got the getColor params right. First two are the x,y of the pixel you want, last one is the color.

    personally I haven't the faintest idea what Garrett was talking about with health bars and such. I'm sure his advice was sound but I just don't know enough about EoC combat to understand.
    If you plan on looting you'll still need to scrape the mainscreen anyway, to get the location of the fight
    GitLab projects | Simba 1.4 | Find me on IRC or Discord | ScapeRune scripts | Come play bot ScapeRune!

    <BenLand100> we're just in the transitional phase where society reclassifies guns as Badâ„¢ before everyone gets laser pistols

  7. #7
    Join Date
    Aug 2013
    Posts
    159
    Mentioned
    4 Post(s)
    Quoted
    90 Post(s)

    Default

    Quote Originally Posted by KeepBotting View Post
    Thanks :P

    Yeah you've got the getColor params right.

    If you plan on looting you'll still need to scrape the mainscreen anyway, to get the location of the fight
    No looting, I'm participating in the competition of the 250 line script and there simply won't be enough lines to add all the good stuff like looting. I could have chosen an easier script to make but I wanted one that I would use afterwards, in case I lose, and I feel like I have a better shot with a harder script.

  8. #8
    Join Date
    Dec 2011
    Location
    East Coast, USA
    Posts
    4,231
    Mentioned
    112 Post(s)
    Quoted
    1869 Post(s)

    Default

    Quote Originally Posted by Trollcrank View Post
    No looting, I'm participating in the competition of the 250 line script and there simply won't be enough lines to add all the good stuff like looting. I could have chosen an easier script to make but I wanted one that I would use afterwards, in case I lose, and I feel like I have a better shot with a harder script.
    Ohhh I see.

    In that case, still using the mainscreen method:

    Simba Code:
    function hasTargeted():boolean;
    var
      tpa:TPointArray;
      i:integer;
    begin
      result := findColorsTolerance(tpa, hardcode the other params);
    end;

    should do the trick
    GitLab projects | Simba 1.4 | Find me on IRC or Discord | ScapeRune scripts | Come play bot ScapeRune!

    <BenLand100> we're just in the transitional phase where society reclassifies guns as Badâ„¢ before everyone gets laser pistols

  9. #9
    Join Date
    Aug 2013
    Posts
    159
    Mentioned
    4 Post(s)
    Quoted
    90 Post(s)

    Default

    Quote Originally Posted by KeepBotting View Post
    Ohhh I see.

    In that case, still using the mainscreen method:

    Simba Code:
    function hasTargeted():boolean;
    var
      tpa:TPointArray;
      i:integer;
    begin
      result := findColorsTolerance(tpa, hardcode the other params);
    end;

    should do the trick
    Now that's a good idea. A little late though
    Simba Code:
    function Fighting: boolean; //Determines if fighting.
    begin
      result := (getColor(33, 12) = 1675987);
    end;

    Anyone wanna help me make a custom object finder? I was thinking of locating two different colors and then using the x's and y's to make a box around the object. The more I think about it, would that actually work with multiple objects though? Is the idea actually sound or should I just make a basic sucky generic one that I've seen in a few scripts.

  10. #10
    Join Date
    Aug 2014
    Location
    Australia
    Posts
    932
    Mentioned
    53 Post(s)
    Quoted
    495 Post(s)

    Default

    Quote Originally Posted by KeepBotting View Post
    Thanks :P

    Yeah you've got the getColor params right. First two are the x,y of the pixel you want, last one is the color.

    personally I haven't the faintest idea what Garrett was talking about with health bars and such. I'm sure his advice was sound but I just don't know enough about EoC combat to understand.
    If you plan on looting you'll still need to scrape the mainscreen anyway, to get the location of the fight
    When you enter combat in RS3 a health bar appears above the target that you can move around if the UI is unlocked. It's similar to the regular green and red health bar in 07.

    So OP, just use the SRL function to detect fighting if there is one, then if not you can use that target info thing that Garrett is talking about.



    New to scripting? Procedures & Functions for Beginners
    Do you use your computer at night? Just get f.lux

  11. #11
    Join Date
    Aug 2013
    Posts
    159
    Mentioned
    4 Post(s)
    Quoted
    90 Post(s)

    Default

    Quote Originally Posted by Incurable View Post
    So OP, just use the SRL function to detect fighting if there is one, then if not you can use that target info thing that Garrett is talking about.
    I am unaware of any in built SRL function.

    Anyone wanna help me make a custom object finder? I was thinking of locating two different colors and then using the x's and y's to make a box around the object. The more I think about it, would that actually work with multiple objects though? Is the idea actually sound or should I just make a basic generic one that I've seen in a few scripts.

  12. #12
    Join Date
    Aug 2013
    Posts
    159
    Mentioned
    4 Post(s)
    Quoted
    90 Post(s)

    Default

    Is there anyway to have a custom bound setting in the find object? Any suggestions to add to mine?

    Simba Code:
    function ObjectFinder(bounds: string; col, tol: integer; hue, sat: extended; incSpeed, filter: boolean; mouseTxt: Array of string): boolean;
    var  //Custom object locater.
      x, y: integer;
      TPA: TPointArray;
      ATPA: T2DPointArray;
    begin
      case bounds of
        'ms': mainscreen.getbounds();
        'tb': tabBackpack.getbounds();
        'mm': minimap.getBounds();
        'cb': chatbox.getBounds();
      end;

      findColorsSpiralTolerance(x, y, TPA, col, bounds, tol, colorSetting(2, hue, sat));

      if incSpeed then
        mouseSpeed := 27 + random(15);
      if filter then
        filterTPAsBetween(ATPA, 0, 50);
      if isMouseOverText(mouseTxt) then
        fastClick(MOUSE_LEFT);
    end;

  13. #13
    Join Date
    Dec 2011
    Location
    United States
    Posts
    960
    Mentioned
    21 Post(s)
    Quoted
    504 Post(s)

    Default

    Quote Originally Posted by Trollcrank View Post
    I am unaware of any in built SRL function.

    Anyone wanna help me make a custom object finder? I was thinking of locating two different colors and then using the x's and y's to make a box around the object. The more I think about it, would that actually work with multiple objects though? Is the idea actually sound or should I just make a basic generic one that I've seen in a few scripts.
    You can do that easily using TPAs. You just combine the two TPAs and then use the standard functions.
    Code:
    SetColorSpeed2Modifiers(0.05, 0.06);
    FindColorsSpiralTolerance(mscx, mscy, TPA, 6255480, msx1, msy1, msx2, msy2, 9);
    
    SetColorSpeed2Modifiers(0.06, 0.64);
    FindColorsSpiralTolerance(mscx, mscy, TPA2, 4152166, msx1, msy1, msx2, msy2, 19);
    
    TPA := CombineTPA(TPA,TPA2);
    ATPA := ClusterTPA(TPA, 25);

  14. #14
    Join Date
    Jun 2007
    Location
    The land of the long white cloud.
    Posts
    3,702
    Mentioned
    261 Post(s)
    Quoted
    2006 Post(s)

    Default

    For the combat detection, I use a DTM of the weakness symbol (varies depending on NPC though - you might be better with the gold lock);

    Simba Code:
    function isInCombat() : boolean;
    var
      x, y : integer;
    begin
      result := findDTM(weaknessDTM, x, y, intToBox(mainScreen.x1, mainscreen.y1, minimap.x2, actionBar.y2));
    end;

    Your object finder doesn't do what you think it does. You are still passing a string (bounds) into the findColorsSpiralTolerance function. You'd be better off passing in a TBox as a function parameter and using that directly.

    function ObjectFinder(bounds: TBox; col, tol ...

    findColorsSpiralTolerance(x, y, TPA, col, bounds,

  15. #15
    Join Date
    Aug 2013
    Posts
    159
    Mentioned
    4 Post(s)
    Quoted
    90 Post(s)

    Default

    Quote Originally Posted by The Mayor View Post
    For the combat detection, I use a DTM of the weakness symbol (varies depending on NPC though - you might be better with the gold lock);

    Simba Code:
    function isInCombat() : boolean;
    var
      x, y : integer;
    begin
      result := findDTM(weaknessDTM, x, y, intToBox(mainScreen.x1, mainscreen.y1, minimap.x2, actionBar.y2));
    end;

    Your object finder doesn't do what you think it does. You are still passing a string (bounds) into the findColorsSpiralTolerance function. You'd be better off passing in a TBox as a function parameter and using that directly.

    function ObjectFinder(bounds: TBox; col, tol ...

    findColorsSpiralTolerance(x, y, TPA, col, bounds,
    FINALLY! Your darn isInCombat freaking makes sense! I had no idea how a DTM could even be used and it confused me because I thought you meant the on person equipped bow but I had used it before and it worked with other styles. That just confused me more and then I posted this thread

    Yeah, I knew it didn't work but I wanted to show that I actually wrote something. I'll try that tbox idea, I've thought of that for fincolorsSpiral in the past but for some reason I was considering this as separate. I'll update it sometime tomorrow with my idea of how to do it. Here's what I'm going to try:
    function ObjectFinder(SearchRange...:integer;
    var
    bounds: tbox
    begin


    case SearchRange of
    1: bounds = [Mainscreen cords];
    2: bounds = [Backpack cords];
    3,4: ect.
    end;

    findColorsSpiralTolerance(x, y, TPA, col, bounds,...

  16. #16
    Join Date
    Dec 2011
    Location
    Hyrule
    Posts
    8,662
    Mentioned
    179 Post(s)
    Quoted
    1870 Post(s)

    Default

    Simba Code:
    var
      fightDTM, endFightDTM, kills, XP, startingXP, compassMax: integer;
      XPH, KPH: extended;
      timeout, timeout2, compass, notification: TTimeMarker;

    procedure loadDTM;
    begin
      fightDTM:= DTMFromString('mlwAAAHicY2dgYMhjZGBoBuJNQBwKxBZAbALEu4H4EFB+OxDvB+LDQHwciPcA8XogllBQZRAQk2YQV9YAs0WkFRn4RCTBfHyAEQ+GAgCMMAqs');;
      endFightDTM := DTMFromString('mggAAAHicY2NgYAhmZGCYAsRiQNwGxPpArAHEN4Fy14D4BhA/BuJnQPwUiAXEpBnElTUYRKQVGUwFhRhshIUZZLm4GHABRhwYAgA81wkA');
    end;

    procedure freeData;
    begin
      freeDTM(fightDTM);
      freeDTM(endFightDTM);
    end;

    function inFight: boolean;
    var
      x, y: integer;
    begin
      if not isLoggedIn then
        exit;

      result := (findDTM(fightDTM, x, y, mainscreen.getBounds)) and (not findDTM(endFightDTM, x, y, mainscreen.getBounds));
    end;

  17. #17
    Join Date
    Aug 2013
    Posts
    159
    Mentioned
    4 Post(s)
    Quoted
    90 Post(s)

    Default

    Quote Originally Posted by Ashaman88 View Post
    Simba Code:
    procedure freeData;
    begin
      freeDTM(fightDTM);
      freeDTM(endFightDTM);
    end;
    I saw you looking at the thread but I wasn't sure why you didn't reply. Even Justin looked at the thread O.o

    What are the dtms of, what object?

  18. #18
    Join Date
    Dec 2011
    Location
    Hyrule
    Posts
    8,662
    Mentioned
    179 Post(s)
    Quoted
    1870 Post(s)

    Default

    Quote Originally Posted by Trollcrank View Post
    I saw you looking at the thread but I wasn't sure why you didn't reply. Even Justin looked at the thread O.o

    What are the dtms of, what object?
    hmm I can't remember... but i know it's the popup over the monsters head. Works regardless of what weakness they have or w/e. Granted your mouse can't be hovering over another monster while this is going on or it will think you are always in fight. I had originally based them off of @bonsai; 's script many many many months ago

  19. #19
    Join Date
    Feb 2007
    Location
    Alberta, Canada
    Posts
    4,615
    Mentioned
    50 Post(s)
    Quoted
    429 Post(s)

    Default

    Quote Originally Posted by Ashaman88 View Post
    hmm I can't remember... but i know it's the popup over the monsters head. Works regardless of what weakness they have or w/e. Granted your mouse can't be hovering over another monster while this is going on or it will think you are always in fight. I had originally based them off of bonsai's script many many many months ago
    Part that I bolded can be solved (I think) by having the user lock the combat box in the top left corner, which I've seen done in public scripts. It's much less unreasonable than some script setups, and it makes the script more reliable (probably). I doesn't even require any rewriting of the function itself, except if you wanted to change the searchbox from mainscreen to just the top corner area.

    Scripts: Edgeville Chop & Bank, GE Merchanting Aid
    Tutorials: How to Dominate the Grand Exchange

    Quote Originally Posted by YoHoJo View Post
    I like hentai.

  20. #20
    Join Date
    Dec 2011
    Location
    Hyrule
    Posts
    8,662
    Mentioned
    179 Post(s)
    Quoted
    1870 Post(s)

    Default

    Quote Originally Posted by 3Garrett3 View Post
    Part that I bolded can be solved (I think) by having the user lock the combat box in the top left corner, which I've seen done in public scripts. It's much less unreasonable than some script setups, and it makes the script more reliable (probably). I doesn't even require any rewriting of the function itself, except if you wanted to change the searchbox from mainscreen to just the top corner area.
    Hmm I didn't even know about that haha! I just always have the mouse go off and stay off client after attacking (private script so i don't care if it seems bot-like hehe)

  21. #21
    Join Date
    Aug 2013
    Posts
    159
    Mentioned
    4 Post(s)
    Quoted
    90 Post(s)

    Default

    Quote Originally Posted by 3Garrett3 View Post
    It's much less unreasonable than some script setups
    Quote Originally Posted by Ashaman88 View Post
    Hmm I didn't even know about that haha! I just always have the mouse go off and stay off client after attacking (private script so i don't care if it seems bot-like hehe)
    Either one of you want to help me improve my script before submitting it for the competition?(Not against the rules btw.) I'll send a copy to you in pm if you want to help.
    I can't think of anything to move the mouse if the mouse over text is wrong. The place the script is based has a lot of similar colors and npcs with the exact same colors, so this occurs at points. It is only resolved when another npc moves close enough to be targeted instead cuz I use:
    Simba Code:
    ATPA.sortFromMidPoint(mainscreen.playerPoint);

    For some reason it gives this error and kills the script sometimes:
    Error: Access violation at line 441
    Execution failed.

    SRL code it's mentioning. I'm guessing it's a tbox problem with my object finder.

    function TPointArray.getBounds() : TBox;
    begin
    result := getTPABounds(self); //line 441
    end;

  22. #22
    Join Date
    Jun 2007
    Location
    The land of the long white cloud.
    Posts
    3,702
    Mentioned
    261 Post(s)
    Quoted
    2006 Post(s)

    Default

    Quote Originally Posted by Trollcrank View Post
    Either one of you want to help me improve my script before submitting it for the competition?(Not against the rules btw.) I'll send a copy to you in pm if you want to help.
    I can't think of anything to move the mouse if the mouse over text is wrong. The place the script is based has a lot of similar colors and npcs with the exact same colors, so this occurs at points. It is only resolved when another npc moves close enough to be targeted instead cuz I use:
    Simba Code:
    ATPA.sortFromMidPoint(mainscreen.playerPoint);

    For some reason it gives this error and kills the script sometimes:
    Error: Access violation at line 441
    Execution failed.

    SRL code it's mentioning. I'm guessing it's a tbox problem with my object finder.

    function TPointArray.getBounds() : TBox;
    begin
    result := getTPABounds(self); //line 441
    end;
    Why not just loop through the ATPA until you hit a TPA with matching overText? for i := 0 to high(ATPA) do ...

  23. #23
    Join Date
    Aug 2013
    Posts
    159
    Mentioned
    4 Post(s)
    Quoted
    90 Post(s)

    Default

    Quote Originally Posted by The Mayor View Post
    Why not just loop through the ATPA until you hit a TPA with matching overText? for i := 0 to high(ATPA) do ...
    So that's what that does... I knew you could repeat like that, with an integer, but I didn't know what high(ATPA) did.

    [s]Would that fix the crashing problem? Or should I just test it?[s]

    Edit: It works fine now, anyone wanna review my script with some advice/comments/ideas? You can't be registered or a SRL junior

  24. #24
    Join Date
    Feb 2007
    Location
    Alberta, Canada
    Posts
    4,615
    Mentioned
    50 Post(s)
    Quoted
    429 Post(s)

    Default

    Quote Originally Posted by Trollcrank View Post
    So that's what that does... I knew you could repeat like that, with an integer, but I didn't know what high(ATPA) did.

    Would that fix the crashing problem? Or should I just test it?
    Do you have a check for the TPA length in your function? It sounds like it's trying to access an index ([0, 1 etc]) that doesn't exist. If your TPA returns 0 points, then your ATPA will have no points, and you can't do anything with it.

    Scripts: Edgeville Chop & Bank, GE Merchanting Aid
    Tutorials: How to Dominate the Grand Exchange

    Quote Originally Posted by YoHoJo View Post
    I like hentai.

  25. #25
    Join Date
    Aug 2013
    Posts
    159
    Mentioned
    4 Post(s)
    Quoted
    90 Post(s)

    Default

    Quote Originally Posted by 3Garrett3 View Post
    Do you have a check for the TPA length in your function? It sounds like it's trying to access an index ([0, 1 etc]) that doesn't exist. If your TPA returns 0 points, then your ATPA will have no points, and you can't do anything with it.
    No, I did not. The idea from TheMayor worked though and it's not much of a problem now. Would you be willing to take a look at my script?

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
  •