Jump to content
Camosnide

Need help cleaning.

Recommended Posts

I have made a working script that will play a character on a game that fights creatures then heals and repeats over and over.

Its VERY messy as its the first thing i have ever wrote. Could anyone give me some tips on how to clean it up or maybe some shortcuts.

 

Thanks

 

[sCAR]Program FindColorClickColor;

 

 

 

Procedure FindClick;

Var

X,Y,W,H: Integer;

begin

FindWindowTitlePart('Camosnides', false);

ActivateClient;

 

GetClientDimensions(W,H);

If FindColor(X,Y,2500134,18,36,W,H) then

Begin wait(100)

SendKeys ('3');

SendKeys ('3');

SendKeys ('3');

SendKeys ('3');

SendKeys ('3');

SendKeys ('3');

end;

GetClientDimensions(W,H);

If FindColor(X,Y,13233649,18,36,W,H) then

Begin wait(100)

MoveWindMouse(X,Y,18,36);

ClickMouse(X,Y,True);

end;

GetClientDimensions(W,H);

If FindColor(X,Y,2500134,18,36,W,H) then

Begin wait(100)

SendKeys ('3');

 

end;

GetClientDimensions(W,H);

If FindColor(X,Y,13233649,18,36,W,H) then

Begin wait(100)

MoveWindMouse(X,Y,18,36);

ClickMouse(X,Y,True);

end;

GetClientDimensions(W,H);

If FindColor(X,Y,2500134,18,36,W,H) then

Begin wait(100)

SendKeys ('3');

 

end;

GetClientDimensions(W,H);

If FindColor(X,Y,13233649,18,36,W,H) then

Begin wait(100)

MoveWindMouse(X,Y,18,36);

ClickMouse(X,Y,True);

end;

GetClientDimensions(W,H);

If FindColor(X,Y,2500134,18,36,W,H) then

Begin wait(100)

SendKeys ('3');

 

end;

GetClientDimensions(W,H);

If FindColor(X,Y,13233649,18,36,W,H) then

Begin wait(100)

MoveWindMouse(X,Y,18,36);

ClickMouse(X,Y,True);

end;

GetClientDimensions(W,H);

If FindColor(X,Y,2500134,18,36,W,H) then

Begin wait(100)

SendKeys ('3');

 

end;

GetClientDimensions(W,H);

If FindColor(X,Y,13233649,18,36,W,H) then

Begin wait(100)

MoveWindMouse(X,Y,18,36);

ClickMouse(X,Y,True);

end;

GetClientDimensions(W,H);

If FindColor(X,Y,2500134,18,36,W,H) then

Begin wait(100)

SendKeys ('3');

 

end;

GetClientDimensions(W,H);

If FindColor(X,Y,13233649,18,36,W,H) then

Begin wait(100)

MoveWindMouse(X,Y,18,36);

ClickMouse(X,Y,True);

end;

GetClientDimensions(W,H);

If FindColor(X,Y,2500134,18,36,W,H) then

Begin wait(100)

SendKeys ('3');

 

end;

GetClientDimensions(W,H);

If FindColor(X,Y,13233649,18,36,W,H) then

Begin wait(100)

MoveWindMouse(X,Y,18,36);

ClickMouse(X,Y,True);

end;

GetClientDimensions(W,H);

If FindColor(X,Y,2500134,18,36,W,H) then

Begin wait(100)

SendKeys ('3');

 

end;

GetClientDimensions(W,H);

If FindColor(X,Y,13233649,18,36,W,H) then

Begin wait(100)

MoveWindMouse(X,Y,18,36);

ClickMouse(X,Y,True);

end;

GetClientDimensions(W,H);

If FindColor(X,Y,2500134,18,36,W,H) then

Begin wait(100)

SendKeys ('3');

 

end;

GetClientDimensions(W,H);

If FindColor(X,Y,13233649,18,36,W,H) then

Begin wait(100)

MoveWindMouse(X,Y,18,36);

ClickMouse(X,Y,True);

end;

GetClientDimensions(W,H);

If FindColor(X,Y,2500134,18,36,W,H) then

Begin wait(100)

SendKeys ('3');

 

end;

GetClientDimensions(W,H);

If FindColor(X,Y,13233649,18,36,W,H) then

Begin wait(100)

MoveWindMouse(X,Y,18,36);

ClickMouse(X,Y,True);

end;

GetClientDimensions(W,H);

If FindColor(X,Y,2500134,18,36,W,H) then

Begin wait(100)

SendKeys ('3');

 

end;

GetClientDimensions(W,H);

If FindColor(X,Y,13233649,18,36,W,H) then

Begin wait(100)

MoveWindMouse(X,Y,18,36);

ClickMouse(X,Y,True);

end;

GetClientDimensions(W,H);

If FindColor(X,Y,2500134,18,36,W,H) then

Begin wait(100)

SendKeys ('3');

 

end;

GetClientDimensions(W,H);

If FindColor(X,Y,13233649,18,36,W,H) then

Begin wait(100)

MoveWindMouse(X,Y,18,36);

ClickMouse(X,Y,True);

end;

Wait(3000)

GetClientDimensions(W,H);

If FindColor(X,Y,2249071,18,36,W,H) then

Begin wait(1000)

MoveWindMouse(X,Y,18,36);

ClickMouse(X,Y,True);

end;

Wait(3000)

GetClientDimensions(W,H);

 

Begin wait(1000)

SendKeys ('3')

end;

Wait(50)

GetClientDimensions(W,H);

If FindColor(X,Y,550399,18,36,W,H) then // This is self

Begin wait(1000)

MoveWindMouse(X,Y,18,36);

ClickMouse(X,Y,True);

 

end;

GetClientDimensions(W,H);

Wait(3000)

Begin wait(1000)

SendKeys ('3')

end;

Wait(50)

GetClientDimensions(W,H);

If FindColor(X,Y,550399,18,36,W,H) then // This is self

Begin wait(1000)

MoveWindMouse(X,Y,18,36);

ClickMouse(X,Y,True);

 

end;

GetClientDimensions(W,H);

If FindColor(X,Y,6514024,18,36,W,H) then

Begin wait(1000)

MoveWindMouse(459, 732,18,36);

ClickMouse(459, 732,True);

end;

Wait(4000)

 

GetClientDimensions(W,H);

If FindColor(X,Y,2632000,18,36,W,H) then

Begin wait(1000)

MoveWindMouse(X,Y,18,36);

ClickMouse(X,Y,True);

 

end;

end;

 

begin

Repeat

FindClick;

Wait(150);

Until False;

end.[/sCAR]

Link to comment
Share on other sites

Yeah, your standards need a bit of work. Couple questions:

Does the client size ever change? If not you only need to get the dimensions once.

You have a number of begin/end blocks that look like they should have had a if FindColor in front of them???

 

Here's what I come up with. Note that Wanted makes fun of my spacing, but it works for me.

[sCAR]program FindColorClickColor;

 

var

W: Integer; // Client width

H: Integer; // Client height

 

procedure FindClick;

var

X: Integer; // X coord

Y: Integer; // Y coord

I: Integer; // Loop counter

begin

if FindColor(X, Y, 2500134, 18, 36, W, H) then

begin

Wait(100);

for I := 0 to 5 do

SendKeys('3');

end;

 

for I := 0 to 10 do

begin

if FindColor(X, Y, 13233649, 18, 36, W, H) then

begin

Wait(100);

MoveWindMouse(X, Y, 18, 36);

ClickMouse(X, Y, True);

end;

if FindColor(X, Y, 2500134, 18, 36, W, H) then

begin

Wait(100);

SendKeys('3');

end;

end;

 

if FindColor(X, Y, 13233649, 18, 36, W, H) then

begin

Wait(100);

MoveWindMouse(X, Y, 18, 36);

ClickMouse(X, Y, True);

end;

Wait(3000);

 

if FindColor(X, Y, 2249071, 18, 36, W, H) then

begin

Wait(1000);

MoveWindMouse(X, Y, 18, 36);

ClickMouse(X, Y, True);

end;

Wait(3000);

 

for I := 0 to 1 do

begin

// If statement missing here?

begin

Wait(1000);

SendKeys ('3');

end;

Wait(50);

 

if FindColor(X, Y, 550399, 18, 36, W, H) then // This is self

begin

Wait(1000);

MoveWindMouse(X, Y, 18, 36);

ClickMouse(X, Y, True);

end;

Wait(3000);

end;

 

if FindColor(X, Y, 6514024, 18, 36, W, H) then

begin

Wait(1000)

MoveWindMouse(459, 732, 18, 36);

ClickMouse(459, 732, True);

end;

Wait(4000);

 

if FindColor(X, Y, 2632000, 18, 36, W, H) then

begin

Wait(1000);

MoveWindMouse(X, Y, 18, 36);

ClickMouse(X, Y, True);

end;

end;

 

begin

if not FindWindowTitlePart('Camosnides', False) then

begin

WriteLn('Client window not found.');

Exit;

end;

ActivateClient;

GetClientDimensions(W, H);

 

repeat

FindClick;

Wait(150);

until False;

end.

[/sCAR]

Link to comment
Share on other sites

Yeah, your standards need a bit of work. Couple questions:

Does the client size ever change? If not you only need to get the dimensions once.

You have a number of begin/end blocks that look like they should have had a if FindColor in front of them???

 

Here's what I come up with. Note that Wanted makes fun of my spacing, but it works for me.

[sCAR]program FindColorClickColor;

 

var

W: Integer; // Client width

H: Integer; // Client height

 

procedure FindClick;

var

X: Integer; // X coord

Y: Integer; // Y coord

I: Integer; // Loop counter

begin

if FindColor(X, Y, 2500134, 18, 36, W, H) then

begin

Wait(100);

for I := 0 to 5 do

SendKeys('3');

end;

 

for I := 0 to 10 do

begin

if FindColor(X, Y, 13233649, 18, 36, W, H) then

begin

Wait(100);

MoveWindMouse(X, Y, 18, 36);

ClickMouse(X, Y, True);

end;

if FindColor(X, Y, 2500134, 18, 36, W, H) then

begin

Wait(100);

SendKeys('3');

end;

end;

 

if FindColor(X, Y, 13233649, 18, 36, W, H) then

begin

Wait(100);

MoveWindMouse(X, Y, 18, 36);

ClickMouse(X, Y, True);

end;

Wait(3000);

 

if FindColor(X, Y, 2249071, 18, 36, W, H) then

begin

Wait(1000);

MoveWindMouse(X, Y, 18, 36);

ClickMouse(X, Y, True);

end;

Wait(3000);

 

for I := 0 to 1 do

begin

// If statement missing here?

begin

Wait(1000);

SendKeys ('3');

end;

Wait(50);

 

if FindColor(X, Y, 550399, 18, 36, W, H) then // This is self

begin

Wait(1000);

MoveWindMouse(X, Y, 18, 36);

ClickMouse(X, Y, True);

end;

Wait(3000);

end;

 

if FindColor(X, Y, 6514024, 18, 36, W, H) then

begin

Wait(1000)

MoveWindMouse(459, 732, 18, 36);

ClickMouse(459, 732, True);

end;

Wait(4000);

 

if FindColor(X, Y, 2632000, 18, 36, W, H) then

begin

Wait(1000);

MoveWindMouse(X, Y, 18, 36);

ClickMouse(X, Y, True);

end;

end;

 

begin

if not FindWindowTitlePart('Camosnides', False) then

begin

WriteLn('Client window not found.');

Exit;

end;

ActivateClient;

GetClientDimensions(W, H);

 

repeat

FindClick;

Wait(150);

until False;

end.

[/sCAR]

Hard to tell what belongs to what when you have If statements on the same spacing with begins, ends, etc IMO, more chunky looking

 

Is this game 3 dimensional? If it is, Color finding might not be totally reliable.

 

Alright so you are trying to search for Colors in the client, if W, and H are not working try W - 1, and H - 1 not totally sure on that I think that is a must or maybe Freddy has already implemented that for the GetClientDimensions function ( doubt that, no reason? ).

 

Tips: Use fail safes for everything, unless it doesn't matter ( game with no ban/no loss from ur guy mis clicking forever )

Try to avoid infinite loops, I find that, if SCAR does something too much for a long time ( keys, mouse clicks ) bad things might happen. Just make sure if you have multiple mouse clicks/key presses that they have wait(200); or so between them. Also never test KeyDown only in a script, I think that screws up your keyboard ( done it before ).

 

 

EDIT: Also I don't advise making new threads on this same script, might get you in trouble

Edited by LordJashin
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...