SRL Archive - OSR Help

Question about script non-runescape related


Roflme

2012-04-21 13:25:45

Hope this is the right section…

So I'm still learning the VERY BASICS to scripting. I mean VERY VERY BASIC
I've been trying to improve my scripting knowledge by working with flash games. They seem to be a great way to confirm that I understand how the script works

Currently I've been trying to get a basic script to work for Storm the House 2. If you haven't played the game yet, you simply click the mouse on enemies charging to a house before they reach the house. If they reach the house they will start to damage it until the house reaches 0 health left.

This is what I've got so far:

EDIT: If it helps (I don't think it really makes a difference, expect for some coordinates) I'm playing the game off of addicting games instead of armor games or any other site hosting this one)

program StormTheHouse2;

procedure StartGame;
begin
MoveMouse(89, 201);
ClickMouse(89, 201, 1);
Wait(500)
MoveMouse(431, 290);
ClickMouse(89, 201, 1);
end;

procedure StormHouse;
var
x, y:Integer;
begin
if FindColorSpiralTolerance(x, y, 10066329, 0, 40, 470, 380, 1) or
FindColorSpiralTolerance(x, y, 13421772, 0, 40, 470, 380, 1) Then
begin
MoveMouse(x, y);
ClickMouse(x, y, 1);
Wait(900);
end;
end;





begin
StartGame;
repeat
StormHouse;
until(false);
end.

So my question is, I want it to repeat the moving and clicking mouse until it's shot 7 times (you start with a gun that has only 7 bullets). Then I want it to press the space bar (which will reload the gun). How would I go about doing this?

As far as I'm aware I'd have to add something after the Wait after ClickMouse to tell the script to repeat that part 7 times and then hit the space bar, then wait, then repeat the entire thing all over again. (PLEASE CORRECT ME IF I'M WRONG).

Just need anyone with any knowledge of scripting to tell me how I can have my script repeat a certain section:
 begin
MoveMouse(x, y);
ClickMouse(x, y, 1);
Wait(900);
end;
7 times, and then make it hit the space bar and repeat all of that over again.

Thanks! Sorry if I've confused anyone!


EDIT 2: So I just added this to the script:

procedure Reload;
begin
SendKeys(' ',100);
Wait(3000);
end;

Which ends up doing what I want, somewhat. The only problem is that the entire script will wait those three seconds, then repeat because I have the end of the script like this:
begin
StartGame;
repeat
StormHouse;
Reload;
until(false);
end.
And when I make the end like this:
begin
StartGame;
repeat
StormHouse;
until(false);
repeat
Reload;
until(false);
end.
It doesn't reload.

So now I'm just looking for a better way to rewrite what I added so it ONLY presses the space bar after it's clicked 7 times, rather than typing it in intervals.

NKN

2012-04-21 13:30:07


var
i:Integer;
for i := 0 to 6 do //Starts at 0
begin
MoveMouse(x, y);
ClickMouse(x, y, 1);
Wait(900);
end;
//Space bar code here

Roflme

2012-04-21 13:43:37

From: NKN

var
i:Integer;
for i := 0 to 6 do //Starts at 0
begin
MoveMouse(x, y);
ClickMouse(x, y, 1);
Wait(900);
end;
//Space bar code here


Something like this?
  begin
MoveMouse(x, y);
ClickMouse(x, y, 1);
Wait(1200);
end;
SendKeys(' ',100);
end;

I'll test this after I grab my lunch :p

NKN

2012-04-21 14:01:49

Remember the for loop though.

Roflme

2012-04-21 14:38:25

procedure StormHouse;
var
x, y:Integer;
Click:Integer;
begin
if FindColorSpiralTolerance(x, y, 10066329, 0, 40, 470, 380, 1) or
FindColorSpiralTolerance(x, y, 13421772, 0, 40, 470, 380, 1) Then
for Click:=0 to 6 do
begin
repeat
MoveMouse(x, y);
ClickMouse(x, y, 1);
Wait(1200);
Inc(Click);
until (Click=7)
if (Click = 7) then
begin
SendKeys(' ', 100);
end;
end;
end;

I'm still a little confused. AND I think I messed up. I don't fully understand how to use loops :(

Right now it will click 7 times and then reload, but the problem is that once it moves to coordinates where an enemy was, it will stay at those coordinates and shoot the air until it's shot 7 times. Then it will reload, target another enemy, and shoot 7 times there. I'm about to try to add another repeat and see if that works unless a better solution is known?


EDIT: So it seems when there isn't anything on the screen it will wait. Once another enemy shows up it will target them and leave the reticle in that position for all the clicks. Why does my script stop trying to find the new x,y integer and why will it click 7 times instead of only once?

The full script up to now:

program StormTheHouse2;

procedure StartGame;
begin
MoveMouse(89, 201);
ClickMouse(89, 201, 1);
Wait(500);
MoveMouse(431, 290);
ClickMouse(89, 201, 1);
Wait(500);
end;

procedure StormHouse;
var
x, y:Integer;
Click:Integer;
begin
if FindColorSpiralTolerance(x, y, 10066329, 0, 40, 470, 380, 1) or
FindColorSpiralTolerance(x, y, 13421772, 0, 40, 470, 380, 1) Then
begin
repeat
MoveMouse(x, y);
ClickMouse(x, y, 1);
Wait(1200);
Inc(Click);
writeln('Clicked' + IntToStr(Click) + 'times.');
until(Click = 7);
if (Click = 7) then
begin
SendKeys(' ', 100);
end;
end;
end;


procedure StartNewRound;
var
x, y:Integer;
begin
if FindColorSpiralTolerance(x, y, 1250181, 238, 275, 386, 319, 1) Then
begin
MoveMouse(128, 349);
ClickMouse(128, 349, 1);
end;
end;



begin
StartGame;
repeat
StormHouse;
StartNewRound;
until(false);
end.

NKN

2012-04-21 14:46:16

Don't put the Repeat Until inside the For loop.
The For loop does it for you, but 7 times.

procedure StormHouse;
var
x, y:Integer;
begin
if FindColorSpiralTolerance(x, y, 10066329, 0, 40, 470, 380, 1) or
FindColorSpiralTolerance(x, y, 13421772, 0, 40, 470, 380, 1) Then
for Click:=0 to 6 do
begin
MoveMouse(x, y);
ClickMouse(x, y, 1);
Wait(1200);
end
SendKeys(' ', 100);
end;

Roflme

2012-04-21 15:08:57

AHHHH alright!

procedure StormHouse;
var
x, y:Integer;
Click:Integer;
begin
for Click:=0 to 6 do
if FindColorSpiralTolerance(x, y, 10066329, 0, 40, 470, 380, 1) or
FindColorSpiralTolerance(x, y, 13421772, 0, 40, 470, 380, 1) Then
begin
MoveMouse(x, y);
ClickMouse(x, y, 1);
Wait(1200);
writeln('clicked ' + IntToStr(Click) + 'times.');
end;
SendKeys(' ', 100);
end;

Works but is a little buggy still.

Thank you so much for your help! :D