PDA

View Full Version : Combat Script



Trollcrank
11-05-2014, 10:36 PM
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.

3Garrett3
11-05-2014, 10:53 PM
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.

Trollcrank
11-05-2014, 10:58 PM
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 :p ).

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

KeepBotting
11-05-2014, 11:08 PM
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

///////////////////////////////////
///////////////////////////////////
/////// 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:

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

Trollcrank
11-05-2014, 11:26 PM
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?

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.

KeepBotting
11-05-2014, 11:35 PM
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?

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

Trollcrank
11-05-2014, 11:43 PM
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.

KeepBotting
11-05-2014, 11:52 PM
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:

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

should do the trick

Trollcrank
11-05-2014, 11:59 PM
Ohhh I see.

In that case, still using the mainscreen method:

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

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.

Incurable
11-06-2014, 12:06 AM
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.

Trollcrank
11-06-2014, 01:24 AM
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.

Trollcrank
11-06-2014, 02:26 AM
Is there anyway to have a custom bound setting in the find object? Any suggestions to add to mine?


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;

Wetish
11-06-2014, 02:29 AM
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.


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);

The Mayor
11-06-2014, 02:41 AM
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);


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,

Trollcrank
11-06-2014, 03:20 AM
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);


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 :p

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,...

Ashaman88
11-06-2014, 03:41 AM
var
fightDTM, endFightDTM, kills, XP, startingXP, compassMax: integer;
XPH, KPH: extended;
timeout, timeout2, compass, notification: TTimeMarker;

procedure loadDTM;
begin
fightDTM:= DTMFromString('mlwAAAHicY2dgYMhjZGBoBuJNQBwKxBZAbA LEu4H4EFB+OxDvB+LDQHwciPcA8XogllBQZRAQk2YQV9YAs0Wk FRn4RCTBfHyAEQ+GAgCMMAqs');;
endFightDTM := DTMFromString('mggAAAHicY2NgYAhmZGCYAsRiQNwGxPpArA HEN4Fy14D4BhA/BuJnQPwUiAXEpBnElTUYRKQVGUwFhRhshIUZZLm4GHABRhwYAg A81wkA');
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;

Trollcrank
11-06-2014, 03:09 PM
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?

Ashaman88
11-06-2014, 03:16 PM
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

3Garrett3
11-06-2014, 04:11 PM
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.

Ashaman88
11-06-2014, 04:31 PM
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)

Trollcrank
11-08-2014, 04:54 AM
It's much less unreasonable than some script setups

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: 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;

The Mayor
11-08-2014, 04:57 AM
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: 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 ...

Trollcrank
11-08-2014, 02:50 PM
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

3Garrett3
11-08-2014, 04:14 PM
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.

Trollcrank
11-08-2014, 04:49 PM
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?