SRL Archive - OSR Help

Need some help with a combat script and scripting in general


sportsguy217

2013-02-09 00:17:37

I could really use some help with a combat script. I'm making it for a private server, all I want it to do is repeatedly attack one weak little monster that I can keep killing without prayer or food or anything. I've been using rjj95's "how to script for a private server!" thread, and Griff's "script down your first rs tree" thread to help me along the way. This is the furthest I've come, and I'm still getting errors.
program Combat;
var
Attack: Integer;
procedure Combat;
begin
if FindBitmapToleranceIn(Attack, 21, 384, 533, 53, 35) then
begin
mmouse (x,y,1,1);
ClickMouse(x,y, mouse_left)
end;

begin
Attack := BitmapFromString(187, 17, 'meJztmUFywyAMRTkI+y56hqy6a' +
'pZZ9Ga9S0/Qa6XJeEJAX18SNmniGTxa2CCEzH8WZHI4nj4+v6ZNC9' +
'rheMpv79OmBW0CM63LBDDfP7+LPXRSd4p0Phd7+hLFzU44ndPF6pu' +
'hU/sxDZ+lq3ZgzjUwi44pJSEo6rsRqjKRvfIXh30xU9KmiizX7X7o' +
'1H5M5oO51e3CuQBTRFwC1kigvq7itsWByd5nu0nZB4U1FQmK2z/1e' +
'mCuXSQ3ZAaBwcdXAGbg8mL5GgWPC0xc3P6pNwETT1UAI6wGBmuOun' +
'Ox/UstWWxrE5pW/N+VxXuhOzsINTSWyKleJSca0tX0dgKD54fcftp' +
'ql94YgwHrRh2zXQoHmNtOltQKIzYs1qKygc5iEzTWX0oJlQed60dd' +
'+pREi2S1HdhMQQKuAMY+PwifPn9yji0DRZ4YMwgMPga3JKM6MU+VF' +
'qkaKEuB6UKLIBSZItLeCwx14+cfayxcLjBuqmOBwQoTAYb91OIr7y' +
'vbeJplyqKLl6yuNKLAGNuBQREBiRlWngQ/gv4fGHds7jnD0K72wEC' +
'BaT8xFpxWDBuqgcBoeYpebFHbDWByu+/cL7K1rQYmVzVBiM4OvepY' +
'PNiU+zgw1Vs7Sgm0gsCwgcZ0KsMqM5Yo2ievHzY0/yAwzNmuWiowR' +
'Qj7MdhitGNw/LJYowGVEUROrdIVeBEjZ/bilJnw8I738lbMDisCqr' +
'TkPf+XZFehRwwckHOPpk83Ndt9AVP2CDy4dkXYl3AvZfsCJtcHhrW' +
'iT1q22B9QkAGG');
combat
end.


Now if anyone could help me fine tune this that'd be great. I know it's absolutely terrible. I have no programming knowledge and have been reading several other threads like "THE Beginner's Tutorial" but I figure I might as well use the forum that I signed up for to get some other advice. Thanks!

Chris!

2013-02-09 00:24:52

This is with your code (not sure if it will work) but it compiles:

program Combat;
{$i SRL/srl.simba} //Must have

var
Attack: Integer;

procedure Attacking;
begin
Attack := BitmapFromString(187, 17, 'meJztmUFywyAMRTkI+y56hqy6a' +
'pZZ9Ga9S0/Qa6XJeEJAX18SNmniGTxa2CCEzH8WZHI4nj4+v6ZNC9' +
'rheMpv79OmBW0CM63LBDDfP7+LPXRSd4p0Phd7+hLFzU44ndPF6pu' +
'hU/sxDZ+lq3ZgzjUwi44pJSEo6rsRqjKRvfIXh30xU9KmiizX7X7o' +
'1H5M5oO51e3CuQBTRFwC1kigvq7itsWByd5nu0nZB4U1FQmK2z/1e' +
'mCuXSQ3ZAaBwcdXAGbg8mL5GgWPC0xc3P6pNwETT1UAI6wGBmuOun' +
'Ox/UstWWxrE5pW/N+VxXuhOzsINTSWyKleJSca0tX0dgKD54fcftp' +
'ql94YgwHrRh2zXQoHmNtOltQKIzYs1qKygc5iEzTWX0oJlQed60dd' +
'+pREi2S1HdhMQQKuAMY+PwifPn9yji0DRZ4YMwgMPga3JKM6MU+VF' +
'qkaKEuB6UKLIBSZItLeCwx14+cfayxcLjBuqmOBwQoTAYb91OIr7y' +
'vbeJplyqKLl6yuNKLAGNuBQREBiRlWngQ/gv4fGHds7jnD0K72wEC' +
'BaT8xFpxWDBuqgcBoeYpebFHbDWByu+/cL7K1rQYmVzVBiM4OvepY' +
'PNiU+zgw1Vs7Sgm0gsCwgcZ0KsMqM5Yo2ievHzY0/yAwzNmuWiowR' +
'Qj7MdhitGNw/LJYowGVEUROrdIVeBEjZ/bilJnw8I738lbMDisCqr' +
'TkPf+XZFehRwwckHOPpk83Ndt9AVP2CDy4dkXYl3AvZfsCJtcHhrW' +
'iT1q22B9QkAGG');
end;

procedure Combat;
var
x, y: Integer;
begin
if FindBitmapToleranceIn(Attack, x, y, 21, 384, 533, 53, 35) then //needed x, y
begin
mmouse (x,y,1,1);
ClickMouse(x,y, mouse_left)
end;
end;

begin //This is the start of your mainloop. This is what makes the script run. :)
SetupSRL; //This sets up SRL
repeat
Combat; //Repeats the procedure: Combat; until false.
until(false);
end. //Do not place anything after this

Do not place anything after end. Also, in your FindBitmapToleranceIn line, you forgot to define the variables: x, y. Also do not forget {$i SRL/srl.simba} at the top of your script. You must also place SetupSRL; in your mainloop.

Good luck.

sportsguy217

2013-02-09 00:34:12

I appreciate the quick reply. Could you explain what you mean by define the variables? I thought I defined them in line 28? Any advice on a better method for finding and attacking npcs besides the "look within the coordinates of the screen" in FindBitMapTolerance.

Chris!

2013-02-09 00:37:55

From: sportsguy217
I appreciate the quick reply. Could you explain what you mean by define the variables? I thought I defined them in line 28? Any advice on a better method for finding and attacking npcs besides the "look within the coordinates of the screen" in FindBitMapTolerance.


Well, variables are what you define under var in a procedure. You can have local or global variables. You had a gloabl variable, 'Attack' which you defined as an Integer. Now that's fine, but you didn't define or include x, y in your procedure. A local variable is a variable that only is available in that procedure.

procedure LocalVars;
var
heresOne: Interger;
andAnother: string;
begin
DoSomething;
end;

The var part. Those are local variables. I'm not the one you should be asking about finding and attacking monsters, I'm hopeless at that stuff. :)

sportsguy217

2013-02-09 00:53:01

lol thanks anyways, this is complicated stuff for a newbie like me. I understand where a variable goes kinda but I don't understand what it does. I appreciate the help

King

2013-02-09 01:44:12

From: sportsguy217
I could really use some help with a combat script. I'm making it for a private server, all I want it to do is repeatedly attack one weak little monster that I can keep killing without prayer or food or anything. I've been using rjj95's "how to script for a private server!" thread, and Griff's "script down your first rs tree" thread to help me along the way. This is the furthest I've come, and I'm still getting errors.
program Combat;
var
Attack: Integer;
procedure Combat;
begin
if FindBitmapToleranceIn(Attack, 21, 384, 533, 53, 35) then
begin
mmouse (x,y,1,1);
ClickMouse(x,y, mouse_left)
end;

begin
Attack := BitmapFromString(187, 17, 'meJztmUFywyAMRTkI+y56hqy6a' +
'pZZ9Ga9S0/Qa6XJeEJAX18SNmniGTxa2CCEzH8WZHI4nj4+v6ZNC9' +
'rheMpv79OmBW0CM63LBDDfP7+LPXRSd4p0Phd7+hLFzU44ndPF6pu' +
'hU/sxDZ+lq3ZgzjUwi44pJSEo6rsRqjKRvfIXh30xU9KmiizX7X7o' +
'1H5M5oO51e3CuQBTRFwC1kigvq7itsWByd5nu0nZB4U1FQmK2z/1e' +
'mCuXSQ3ZAaBwcdXAGbg8mL5GgWPC0xc3P6pNwETT1UAI6wGBmuOun' +
'Ox/UstWWxrE5pW/N+VxXuhOzsINTSWyKleJSca0tX0dgKD54fcftp' +
'ql94YgwHrRh2zXQoHmNtOltQKIzYs1qKygc5iEzTWX0oJlQed60dd' +
'+pREi2S1HdhMQQKuAMY+PwifPn9yji0DRZ4YMwgMPga3JKM6MU+VF' +
'qkaKEuB6UKLIBSZItLeCwx14+cfayxcLjBuqmOBwQoTAYb91OIr7y' +
'vbeJplyqKLl6yuNKLAGNuBQREBiRlWngQ/gv4fGHds7jnD0K72wEC' +
'BaT8xFpxWDBuqgcBoeYpebFHbDWByu+/cL7K1rQYmVzVBiM4OvepY' +
'PNiU+zgw1Vs7Sgm0gsCwgcZ0KsMqM5Yo2ievHzY0/yAwzNmuWiowR' +
'Qj7MdhitGNw/LJYowGVEUROrdIVeBEjZ/bilJnw8I738lbMDisCqr' +
'TkPf+XZFehRwwckHOPpk83Ndt9AVP2CDy4dkXYl3AvZfsCJtcHhrW' +
'iT1q22B9QkAGG');
combat
end.


Now if anyone could help me fine tune this that'd be great. I know it's absolutely terrible. I have no programming knowledge and have been reading several other threads like "THE Beginner's Tutorial" but I figure I might as well use the forum that I signed up for to get some other advice. Thanks!

From: sportsguy217
lol thanks anyways, this is complicated stuff for a newbie like me. I understand where a variable goes kinda but I don't understand what it does. I appreciate the help


I'm on a ipad so bear with me but, you need to define x, y as integers. Because they are storing the coordinates for the bitmap you are looking for. So you can either at the top of the script define x and y under global var like so

var
X, y:Integer;

Or do this below your function/procedure like so

procedure Combat;
Var
X, y:Integer;

This way when you call them in Mmouse(); they will act as numbers in place of coordinates

program Combat;
var
Attack: Integer;
procedure Combat;
var// added as local variables just for this procedure
X, y:integer;
begin
if FindBitmapToleranceIn(Attack, 21, 384, 533, 53, 35) then
begin
mmouse (x,y,1,1);
ClickMouse2(2); //I believe that 1 means right click and 2 means left click. This way the
end. // mouse only moves once. It will already be in position.
else // added an "else" statement for if it fails, these can be much more complex but
Begin // but this one is simple and will end the procedure
Writeln('we did not click on the monster');
Exit;
End;

begin
Attack := BitmapFromString(187, 17, 'meJztmUFywyAMRTkI+y56hqy6a' +
'pZZ9Ga9S0/Qa6XJeEJAX18SNmniGTxa2CCEzH8WZHI4nj4+v6ZNC9' +
'rheMpv79OmBW0CM63LBDDfP7+LPXRSd4p0Phd7+hLFzU44ndPF6pu' +
'hU/sxDZ+lq3ZgzjUwi44pJSEo6rsRqjKRvfIXh30xU9KmiizX7X7o' +
'1H5M5oO51e3CuQBTRFwC1kigvq7itsWByd5nu0nZB4U1FQmK2z/1e' +
'mCuXSQ3ZAaBwcdXAGbg8mL5GgWPC0xc3P6pNwETT1UAI6wGBmuOun' +
'Ox/UstWWxrE5pW/N+VxXuhOzsINTSWyKleJSca0tX0dgKD54fcftp' +
'ql94YgwHrRh2zXQoHmNtOltQKIzYs1qKygc5iEzTWX0oJlQed60dd' +
'+pREi2S1HdhMQQKuAMY+PwifPn9yji0DRZ4YMwgMPga3JKM6MU+VF' +
'qkaKEuB6UKLIBSZItLeCwx14+cfayxcLjBuqmOBwQoTAYb91OIr7y' +
'vbeJplyqKLl6yuNKLAGNuBQREBiRlWngQ/gv4fGHds7jnD0K72wEC' +
'BaT8xFpxWDBuqgcBoeYpebFHbDWByu+/cL7K1rQYmVzVBiM4OvepY' +
'PNiU+zgw1Vs7Sgm0gsCwgcZ0KsMqM5Yo2ievHzY0/yAwzNmuWiowR' +
'Qj7MdhitGNw/LJYowGVEUROrdIVeBEjZ/bilJnw8I738lbMDisCqr' +
'TkPf+XZFehRwwckHOPpk83Ndt9AVP2CDy4dkXYl3AvZfsCJtcHhrW' +
'iT1q22B9QkAGG');
combat
end.

Sjoe

2013-02-09 01:49:25

Use AutocolorAid for finding the monsters.

if u don't know it, here's a tutorial from Yohojo
http://villavu.com/forum/showthread.php?t=71074

EDIT:
Try to avoid using bitmaps on the mainscreen, they don't work well.
Use color searching functions instead (with ACA for more accuracy)
Use bitmaps for static objects: Inventory and Bank.

King

2013-02-09 01:50:41

From: Sjoekeloe
Use AutocolorAid for finding the monsters.

if u don't know it, here's a tutorial from Yohojo
http://villavu.com/forum/showthread.php?t=71074


This^ YoHoJo' tuts are awesome for learning

sportsguy217

2013-02-09 02:32:01

if FindBitmapToleranceIn(Attack, 21, 384, 533, 53, 35) then begin mmouse (x,y,1,1); ClickMouse2(2);
So essentially.. If the program manages to find the bitmap, then it will move the mouse to the coordinates x and y. (and they're defined as x and y in mmouse because they vary depending where the bitmap is found within the coordinates of the screen that earlier I set in FindBitMapTolerance?) Then once it moves the mouse there it will click it and we're all good.




Thanks guys I'll definitely check YoHoJo's tutorial out. This is great, I honestly expected to be flamed. And with this kind of help I definitely won't shy away from anymore questions I have!

EDIT: Last question, would it be possible to repeat that indefinitely? Repeat… until the program can't find the monster within 30 seconds or so, then WriteLn('we did not click the monster')

sportsguy217

2013-02-09 16:21:19

So I used auto color aid, used it to create an auto color function and put it into my code. It compiles, but I just can't figure out why it won't click anything. It's not even rolling over anything like this, it just sits there. Any help with this?


program New;
{$i srl/srl.simba}
{i SRL/SRL/Misc/Stats.simba}
function MonsterColor: Integer;
var
arP: TPointArray;
arC: TIntegerArray;
tmpCTS, i, arL: Integer;
begin
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.25, 1.36);

if not (FindColorsTolerance(arP, 6591976, MSX1, MSY1, MSX2, MSY2, 14)) then
begin
Writeln('Failed to find the color, no result.');
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
Exit;
end;

arC := GetColors(arP);
ClearSameIntegers(arC);
arL := High(arC);

for i := 0 to arL do
begin
Result := arC[i];
// Writeln('AutoColor = ' + IntToStr(arC[i]));
Break;
end;

ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);

if (i = arL + 1) then
//Writeln('AutoColor failed in finding the color.');
end;



Function Attack: Boolean;
Var
x,y: integer;
begin
//FindObjCustom(x, y, ['att', 'ack'], [123456, 345678], 5);
if FindObjCustom(x,y, ['att', 'ack'], [MonsterColor], 5) then
begin
ClickMouse2(2);
end;
end;
begin
SetUpSRL;

//Repeat
Attack;
//until(false);
end.

Sjoe

2013-02-09 16:42:06

Is your uptext right? It says 'att' , but it probably needs to be 'Att'
Use clickmouse2(Mouse_left), clickmouse is not good function!
It could get u banned

Here are some examples for knowing where the script fails and
implying the 30 seconds time-out:


var
NotInFight: Integer; //global variable

Function Attack: Boolean;
Var
x,y: integer;

begin
if FindObjCustom(x,y, ['Att', 'ack'], [MonsterColor], 5) then
begin
Writeln('I found the monster we are searching for') //This tells you if the script found the monster.
ClickMouse2(mouse_right); // Don't use clickmouse!
Result := True; // Since u have a function, it returns a value. True = found monster.
MarkTime(NotInFight) // Check below, everytime we call it again, it resets to 0
end;
end;

begin
SetUpSRL;
Marktime(NotInFight) // Starts the Initial timer
Repeat
Attack;
until(TimeFromMark(NotInFight >= 30000);
// Time in ms, if not in fight reaches 30 seconds, we get out of the loop and continue with mainloop.

TerminateScript; // Terminates scripts (not needed in this occasion, but good to know this function!)
end.

Using Writeln lines after 'if then' statements is used to Debug the script, if it's on the debug then the script found it.
If not, then your script doesn't find it.


Also I noticed u do this


if FindObjCustom(x,y, ['Att', 'ack'], [MonsterColor], 5) then
begin
ClickMouse2(mouse_right);
end;

// this can be shortened to

if FindObjCustom(x,y, ['att', 'ack'], [MonsterColor], 5) then ClickMouse2(mouse_right);
// because u only use on function/ procedure after 'then'
// when u want it to do multiple actions, then we use begin end;

Edit: I like it that you're starting to learn how to script, but u should widen your knowledge.
Learn how to use failsafes, DTM's, Bitmaps, Walking ( SPS, Radial, TPA, ObjDTM )
There are a lot of good tutorials , read em!!

rj

2013-02-09 17:28:08

Also, you cannot use Uptext if this is for a RSPS unless it's a 2006 version and you have the project2006 include

sportsguy217

2013-02-09 22:03:45

Yea I really just wanted to create a script for combat for this private server as quick as possible. I figured I'd make the script using as small of an amount of commands as possible. I'd still like to and I'm still gonna try, but in the process I'll look over more of yohojo's videos.

Sjoe

2013-02-09 22:16:47

From: sportsguy217
Yea I really just wanted to create a script for combat for this private server as quick as possible. I figured I'd make the script using as small of an amount of commands as possible. I'd still like to and I'm still gonna try, but in the process I'll look over more of yohojo's videos.


Don't do that, give yourself time to write a script, test it. Get rid of the bugs, failsafes.
Till you're perfectly happy with it!

sportsguy217

2013-02-10 00:53:53

All I wanted to do was get the script to find and cilck the monster :p then from there I would fine tune it. Repeat until you can't find the color, find and click color when the last color you clicked on disappeared (npc is dead). Then eventually make a script that can walk to the bank and back on a private server. Idk I had it planned in my head, but only being able to get as far as finding the color is pretty discouraging.

Once again I appreciate the help, I'll probably be back on these forums in a week looking for more help on walking or something. Is it even possible to create a bot that walks in a private server using pathcreator?