PDA

View Full Version : My second script... My millionth error



Maver
10-25-2006, 01:10 PM
Ok, I'm wondering if anyone could help me clean up this script a little, and advise me on the really crappy areas of this script. I really do feel it helps me when someone tells me what areas I could improve on. Also, I get a runtime error.

Heres the code

program deadlycowkiller;

{.include SRL\SRL.Scar}
{.include SRL\SRL\Skill\Fighting.Scar}

var
Cow : array[0..2] of Integer;
Kills, TakeCount: Integer;
bury, meatCooked, time: Integer;
const
iPlay = 10; //# of minutes until switch player
StartPlayer = 0; //Player to Play first.
cows2kill = 3; //the ammount of cows you want to kill before exiting loop
Col1 = 15922164; // First monster color
Col2 = 2160891; // Second monster color
Col3 = 858759; // Third monster color
Col4 = 993083; // Fourth monster color
procedure suPlayers;
begin
HowManyPlayers:= 4;
NumberOfPlayers(HowManyPlayers);

Players[0].Name :='';
Players[0].Pass :='';
Players[0].Nick :='one';
Players[0].Integer1 := 2; //1 - 4 fightmode.
Players[0].Active := True;

Players[1].Name :='';
Players[1].Pass :='';
Players[1].Nick :='one';
Players[1].Integer1 := 2; //1 - 4 fightmode.
Players[1].Active := True;

Players[2].Name :='';
Players[2].Pass :='';
Players[2].Nick :='t a';
Players[2].Integer1 := 2; //1 - 4 fightmode.
Players[2].Active := True;

Players[3].Name :='';
Players[3].Pass :='';
Players[3].Nick :='one';
Players[3].Integer1 := 1; //1 - 4 fightmode.
Players[3].Active := True;

end;


procedure myAntiBan;
begin
RotateEvery(4 + random(3));
LeaveScreenEvery(5 + random(5));
RandomRClickEvery(15 + random(5));
end;

procedure FindRandoms;
begin
FindNormalRandoms;
FindLamp(LampSkill);
end;


procedure attcow;
begin
if (LoggedIn) then
begin
if isfight = true then
begin
myAntiBan;
wait(5000+random(2500));
end;
FightNPC(Col1, Col2, Col3, Col4, 15922164, 15922164, 10, 12);
kills:= kills + 1
end;
end;


begin
SetupSRL;
repeat
if(not(LoggedIn))then
findrandoms;
attcow;
FindNormalRandoms


until(kills = cows2kill);
end.

It isn't the nicest code, nor have I done alot of the things I want to do in it (mostly make it pick up the bones, bury them and pick up the meat and cook it. Those things will come up later. Also, I'll most likely break up the code into more procedures later, but for now....

Anyway, my error is this
[Runtime Error] : Out Of Range in line 65 in script C:\Program Files\SCAR 2.03\includes\SRL\SRL\Skill\Fighting.Scar
That happens after I kill one cow.

If anyone could help me fix up that error, explain to me what parts of the script are badly coded, and which ones aren't so bad, that'd be great.

Also, i'm unsure if I've scripted it right so that it loggs in...

Thanks,

Maver

Boreas
10-25-2006, 02:10 PM
The kills+1 should only happen after you know the fight is over. Put this in

writeln(inttostr(kills));

after the kills + 1 to see how it's working.

Check out the template or another example for the logging in.

Work on a function that knows when the fight is over, so you don't attack the same cow multiple times.

Also work on a procedure that trys to find cow on MS and if it can't to click on a yellow dot on minimap and try again.

Take things a little at a time and you'll get better and better.