SRL Archive - Reflection Help

Clicking a NPC


Frt

2009-02-08 05:59:11

Hi guys.

I'm currently working on a reflection cowkiller, but I really can't figure out to click the cow every time. I tried the ClickNPC function in the D-Include but that seems to be missing almost all the time.

This is my current Cow Finder procedure:
procedure CowFinder;
var
i: integer;
a: array of TNPC;
tp: TPoint;
begin
a := GetNPCsByID(81);
for i := 0 to High(a) do
begin
if (not (a[i].InFight)) then
begin
WalkToTile(a[i].Tile, 2, 2);
R_FFlag(0);
if (FindObjCustom(x, y, ['Cow', 'ow', 'Co'], [4018778, 9870498], 4)) then
begin
MMouse(x, y, 4, 4);
if (IsUpText('ttack')) then
begin
GetMousePos(x, y);
Mouse(x, y, 0, 0, true);
Wait(2500 + Random(500));
if (AreWeInteracting(b)) then
begin
repeat
AntiBan;
Wait(500 + Random(500));
until(not(AreWeInteracting(b)));
Players[CurrentPlayer].Integers[1] := Players[CurrentPlayer].Integers[1] + 1;
CKills := CKills + 1;
Report(False);
end;
Break;
end;
end;
end;
end;
end;

Quite simple but I couldn't figure out a better way to do it. :)

Can you guys please give me a hint on how to click the cow everytime instead of just sometimes?

Torrent of Flame

2009-02-08 06:29:22

If it is reflection, why are you using FindObjCustom? There are reflection NPC finders.

Frt

2009-02-08 06:32:42

Hm, which?
Sorry, kind of new to reflection, that's why i wanted to try and make a reflection script.

Torrent of Flame

2009-02-08 06:52:23

function KillCows: boolean;
var
CowNPC: array of TNPC;
P: TPoint;
z, i: integer;
begin
z := 0
if not LoggedIn then Exit;
repeat
z := l + 1;
Wait(500+random(500));
CowNPC := SortNPCs(GetNPCs);
begin
for i:= 0 to High(CowNPC) do
begin
if (CowNPC[i].NPCType= 81) then
begin
if (CowNPC[i].Name = 'Cow') then
begin
if not TileOnMS(CowNPC[i].Tile, 0) then
WalkToTile(CowNPC[i].Tile, 0, 0);
end;
end;
if TileOnMS(CowNPC[i].Tile, 0) then
begin
P := TileToMS(CowNPC[i].Tile, 0);
MMouse(P.x, P.y, 5, 5);
Wait(200+random(300));
if IsUpText('ttack') then
begin
case Random(2) of
0: begin
Mouse(P.x, P.y, 5, 5, false);
Wait(500+random(400));
ChooseOption('ttack');
Wait(700+random(700));
Result := True;
end;
1: begin
Mouse(P.x, P.y, 5, 5, true);
Wait(700+random(700));
Result := True;
end;
end;
end;
end;
end;
end;
until (Result = True) or (z >= 10);
if z >= 10 then
begin
Writeln('Cant find cows');
TerminateScript;
end;
end;

This should work ^.^

Frt

2009-02-08 07:18:56

From: Torrent of Flame


This should work ^.^


TY :D

Just added in my AntiBan function and I'll try to have the script running for an hour or so now just to see the difference from before ^^
Thank you yet again :b

turbobk

2009-02-08 08:35:06

Wow that code is so long and Inefficient.
You could just use my function if you want? :)

It's much shorter..


Function FindNPCBk(Var P: TPoint; TheName: String): Boolean;
Var
Name: Array Of TNPC;
i: Integer;
Begin
Name := SortNPCs(GetNPCsByName(TheName));
For i := 0 To High(Name) Do
If Name[i].MS.X <> 0 Then
Begin
P := Point(Name[i].MS.X, Name[i].MS.Y);
Result := True;
Exit;
End;
End;


If FindNPCBk(P, 'Cow') Then
Begin
MMouse(P.x, P.y, 4, 4);
Wait(75 + Random(75));
If IsUpTextMultiCustom(['ttack', 'Cow']) Then
Begin
//DoStuff;
End;
End;

lordsaturn

2009-02-08 12:15:31

@Torrent
Why use heights of 0? You should use CowNPC.Height/2.

@turbobk
Why use IsUpText? Use OptionExists('Attack Cow').

Frt

2009-02-08 12:30:54

Here is my final code:

function KillCows: boolean;
var
CowNPC: array of TNPC;
P: TPoint;
z, i: integer;
begin
z := 0
if not LoggedIn then Exit;
repeat
z := z + 1;
Wait(500+random(500));
CowNPC := SortNPCs(GetNPCs);
if(GetArrayLength(CowNPC) = 0) then
Attempts := Attempts + 1;
begin
for i:= 0 to High(CowNPC) do
begin
Report(False);
if (CowNPC[i].NPCType= 81) AND (CowNPC[i].Name = 'Cow') AND
not CowNPC[i].InFight then
begin
if not TileOnMS(CowNPC[i].Tile, CowNPC[i].Height/2) then
WalkToTile(CowNPC[i].Tile, 0, 0);
if TileOnMS(CowNPC[i].Tile, CowNPC[i].Height/2) then
begin
P := TileToMS(CowNPC[i].Tile, 0);
MMouse(P.x, P.y, 5, 5);
Wait(200 + Random(300));
if IsUpText('ttack Cow') then
begin
case Random(2) of
0: begin
Mouse(P.x, P.y, 5, 5, false);
Wait(500+random(400));
ChooseOption('ttack');
Wait(700+random(700));
Result := True;
end;
1: begin
Mouse(P.x, P.y, 5, 5, true);
Wait(700 + Random(700));
Result := True;
end;
end;
if (AreWeInteracting(b)) then
begin
repeat
HealthCheck;
AntiBan;
R_FindRandoms;
FindNormalRandoms;
Wait(500 + Random(500));
Report(False);
until(not(AreWeInteracting(b)));
Players[CurrentPlayer].Integers[1] := Players[CurrentPlayer].Integers[1] + 1;
CKills := CKills + 1;
Report(False);
end else
begin
Break;
end;
end;
end;
end;
end;
end;
case Random(6) of
0: AntiBan;
end;
until (Result = True) or (z >= 10);
if z >= 10 then
begin
Writeln('Cant find cows');
Wait(1000);
Exit;
end;
end;

Anything you suggest that could make it better or do you think it's written as it should by now?

Torrent of Flame

2009-02-08 13:55:30

TileOnMS(CowNPC.Tile, CowNPC.Height, 2)

He didnt mean the '/' I dont think?

turbobk, my code had failsafes.

lordsaturn

2009-02-08 14:16:54

From: Torrent of Flame
TileOnMS(CowNPC.Tile, CowNPC.Height, 2)

He didnt mean the '/' I dont think?

turbobk, my code had failsafes.


I did mean the '/'. You are the dividing the NPC's height by 2 so it will return a point exactly in the center of the NPC. TileOnMS/TileToMS only have 2 paramaters.

turbobk

2009-02-08 21:15:11

@ lordsaturn, Yeh or that lol, I was just writting a quick example for him.

@ Torrent of Flame, yes I noticed that yours has failsafes but I wasnt talking about the whole code i was talking about a specific part lol.


CowNPC := SortNPCs(GetNPCs);
if(GetArrayLength(CowNPC) = 0) then
Attempts := Attempts + 1;
begin
for i:= 0 to High(CowNPC) do
begin
Report(False);
if (CowNPC[i].NPCType= 81) AND (CowNPC[i].Name = 'Cow') AND
not CowNPC[i].InFight then


turbobk

2009-02-08 21:33:15

From: Frt
Here is my final code:

function KillCows: boolean;
var
CowNPC: array of TNPC;
P: TPoint;
z, i: integer;
begin
z := 0
if not LoggedIn then Exit;
repeat
z := z + 1;
Wait(500+random(500));
CowNPC := SortNPCs(GetNPCs);
if(GetArrayLength(CowNPC) = 0) then
Attempts := Attempts + 1;
begin
for i:= 0 to High(CowNPC) do
begin
Report(False);
if (CowNPC[i].NPCType= 81) AND (CowNPC[i].Name = 'Cow') AND
not CowNPC[i].InFight then
begin
if not TileOnMS(CowNPC[i].Tile, CowNPC[i].Height/2) then
WalkToTile(CowNPC[i].Tile, 0, 0);
if TileOnMS(CowNPC[i].Tile, CowNPC[i].Height/2) then
begin
P := TileToMS(CowNPC[i].Tile, 0);
MMouse(P.x, P.y, 5, 5);
Wait(200 + Random(300));
if IsUpText('ttack Cow') then
begin
case Random(2) of
0: begin
Mouse(P.x, P.y, 5, 5, false);
Wait(500+random(400));
ChooseOption('ttack');
Wait(700+random(700));
Result := True;
end;
1: begin
Mouse(P.x, P.y, 5, 5, true);
Wait(700 + Random(700));
Result := True;
end;
end;
if (AreWeInteracting(b)) then
begin
repeat
HealthCheck;
AntiBan;
R_FindRandoms;
FindNormalRandoms;
Wait(500 + Random(500));
Report(False);
until(not(AreWeInteracting(b)));
Players[CurrentPlayer].Integers[1] := Players[CurrentPlayer].Integers[1] + 1;
CKills := CKills + 1;
Report(False);
end else
begin
Break;
end;
end;
end;
end;
end;
end;
case Random(6) of
0: AntiBan;
end;
until (Result = True) or (z >= 10);
if z >= 10 then
begin
Writeln('Cant find cows');
Wait(1000);
Exit;
end;
end;

Anything you suggest that could make it better or do you think it's written as it should by now?


If fixed up some of your code for you.
Just take out the comments..


function KillCows: boolean;
var
CowNPC: array of TNPC;
P: TPoint;
z, i: integer;
begin
z := 0
if not LoggedIn then
Exit; // <-----------
repeat
Inc(z); // <-----------
Wait(500 + random(500)); // <----------- Put a space between mathematical symbols
CowNPC := SortNPCs(GetNPCs);
if(GetArrayLength(CowNPC) = 0) then
Inc(Attempts); // <-----------
begin
for i := 0 to High(CowNPC) do // <-----------
begin
Report(False);
if (CowNPC[i].NPCType = 81) and (CowNPC[i].Name = 'Cow') and // <--------- Dont capitilze bold words
not CowNPC[i].InFight then
begin
if not TileOnMS(CowNPC[i].Tile, CowNPC[i].Height / 2) then // <-----------
WalkToTile(CowNPC[i].Tile, 0, 0);
if TileOnMS(CowNPC[i].Tile, CowNPC[i].Height / 2) then // <-----------
begin
P := TileToMS(CowNPC[i].Tile, 2); // <----------- Height of 2
MMouse(P.x, P.y, 5, 5);
Wait(200 + Random(300));
if OptionExists('Attack Cow') then // <----------- Use Reflection
begin
case Random(2) of
0: begin
Mouse(P.x, P.y, 5, 5, false);
Wait(500 + random(400)); // <-----------
R_ChooseOption('Attack Cow'); // <----------- Use Reflection
Wait(700 + random(700)); // <-----------
Result := True;
end;
1: begin
Mouse(P.x, P.y, 5, 5, true);
Wait(700 + Random(700));
Result := True;
end;
end;
if (AreWeInteracting(b)) then // <----------- where have you declared b? Global?
begin
repeat
HealthCheck;
AntiBan;
R_FindRandoms;
FindNormalRandoms;
Wait(500 + Random(500));
Report(False);
until(not(AreWeInteracting(b)));
Inc(Players[CurrentPlayer].Integers[1]); // <----------- Use Inc instead of blah := blah + 1
Inc(CKills); // <-----------
Report(False);
end else Break; // <----------- no need for 'end else begin'.
end;
end;
end;
end;
end;
If (Random(6) = 0) Then // <----------- no need for a case of.
AntiBan;
until (Result = True) or (z >= 10);
if (z >= 10) then // <----------- ( )'s
begin
Writeln('Cant find cows');
Wait(1000 + Random(1000)); // <----------- always use random wait times, even if they are not needed.
Exit;
end;
end;

TurboBk. :)

mormonman

2009-02-08 21:42:34

something := something + 1 is actually faster than inc(something)… but they do the same thing so no need to change them turbobk

turbobk

2009-02-08 21:46:37

From: mormonman
something := something + 1 is actually faster than inc(something)… but they do the same thing so no need to change them turbobk


since when?
I heard Inc had always been faster.. hmm.

lordsaturn

2009-02-08 22:15:01

Inc is faster.

http://www.srl-forums.com/forum/showpost.php?p=464896&postcount=3

mormonman

2009-02-08 22:22:31

Hmm… ok, but I thought I had read it the other way around somewhere, nevermind turbo!

Sandstorm

2009-02-09 20:00:22

Also, I believe Wizzup? (or WT-Fakawi, not 100% sure on which one) said that you should ALWAYS capitalize bold words, on the IRC.

Someone does.

~Sandstorm

Edit: It isn't Mixster xD.

Shuttleu

2009-02-09 20:11:56

From: Sandstorm
Also, I believe Wizzup? (or WT-Fakawi, not 100% sure on which one) said that you should ALWAYS capitalize bold words, on the IRC.

Someone does.

~Sandstorm

Edit: It isn't Mixster xD.


no you should NEVER capatilise bold words
go search your standards

~shut

EDIT: http://www.villavu.com/forum/showthread.php?t=3293?t=3997&highlight=standard
Object Pascal language reserved words and key words shall always be completely lowercase. Never capitalize words that SCAR displays in bold. It's completely unnecessary and looks ugly!

Sandstorm

2009-02-09 22:19:51

I could have sworn that Wizzup or someone that high up said that…. Oh well lol.

~Sandstorm

turbobk

2009-02-10 20:55:55

It is considered ok to capitalize the first letter of a bold word.

Like this:

Procedure CheckSomething;
Begin
If (This = That) Then
Begin
DoThis;
End;
End;

NOT like this:

PROCEDURE CheckSomething;
BEGIN
IF (This = That) THEN
BEGIN
DoThis;
END;
END;

That just looks ugly anyway.

Sandstorm

2009-02-10 21:10:34

@Turbo - That's what I was talking about.

~Sandstorm