SRL Archive - OSR Help

Finding obj help


cadet54

2012-06-24 14:10:03

Hi there I am working on a cow fighter/looter with banking features, currently I have got the going to cows and locating the field of and the from cow field to bank and banking complete.

I am struggling with the fighting part I have looked at most fighting scripts and am struggling to get to grips with them, yeah I know im a noob but gotta stop leeching at some stage lol.

I am using the in built functions to detect when im fighting, not fighting and when a mob is already under attack.

The part where I find and attack the cows is that hard part if the cows were all similar colour I would just use the following but modified.
Function FindGate:Boolean;
Var
a, h: Integer;
TPA : TPointArray;
ATPA : T2DPointArray;
tmpCTS : Integer;
Begin
FindNormalRandoms;
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.13, 0.44);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, 4741737, MSX1, MSY1, MSX2, MSY2, 4);
ATPA := TPAtoATPAEx(TPA, 20, 20);
SortATPASize(ATPA,True);

H := High(ATPA);

for a := 0 to H do
Begin
MiddleTPAEx(atpa[a], X, Y);
MMouse(X, Y, 2, 2);
If (WaitUpTextMulti(['open', 'pen'], 750)) Then
Begin
ClickMouse2(False);
ChooseOption('Open');
writeln('Gate is now open')
Result := True
Exit;
End;
If (WaitUpTextMulti(['close', 'ose', 'lose'], 750)) Then
Begin
writeln('Gate was already open')
Result := True
Exit;
End else
begin
ObjDTM_Walk('73:84:4:1:7:62:101:1:7:49:79:1:7:61:61:3:7:101:66:4:69:79:77:81:76:90:70:88', 0, 100, 80, True);
Wait(500);
FindGate;
Result := True
End;
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
End;
end;

But since theres multiple colours I dont really know were to go I have this but its extremely in accurate.

Function FightCow: Boolean;
var
X, Y: Integer;
begin
if not loggedIn then exit;
repeat
inc(F1);
if InFight then
begin
repeat
FindNormalRandoms;
until (not (OthersInFight) or (not LoggedIn) or (not InFight))
end;
if FindObjEx(X, Y, ['ttack Co'], CowColours, Tolerance, 50, 1, 5, 689, 390) and not(WaitUpText('Walk', random(50))) then
begin
if not (IsFightAt(X, Y) and not InFight) then
begin
GetMousePos(X, Y);
Mouse(X, Y, 2, 2, false);
if WaitOptionMulti(['ttack Co', 'attack Cow', 'attack Co'], 200)then
begin
//Writeln('You got a kill');
end;
WaitOptionMulti(['ttack Co', 'attack Cow', 'attack Co'], 200);
Wait(1000);
end;
while IsMoving do
begin
Wait(250);
end;
Result := True;
exit;
end;
until (F1=5) or (true)
end;

Runaway

2012-06-24 14:15:56

Hi there,

If you're having trouble accounting for multiple colors, you could try modifying this a bit:


function FindFire(Color, Min: TIntegerArray; UseItem: Integer; Strict: Boolean): Boolean;
var
Found, Tol, t, i: Integer;
P: TPoint;
Temp1, Temp2: TPointArray;
TPA, ATPA: T2DPointArray;
begin
Result := False;
for Tol := 10 to 20 do
begin
Found := 0;
for i := 0 to High(Color) do
begin
Writeln('Searching for fire: Tolerance is '+ ToStr(Tol) +'...');
FindColorsTolerance(Temp1, Color[i], MSX1, MSY1, MSX2, MSY2, Tol);
if (Length(Temp1) >= Min[i]) then
begin
SetLength(TPA, Found + 1);
TPA[Found] := Temp1;
Inc(Found);
end;
end;
if Strict then
begin
if (Found >= Length(Color)) then
Temp2 := MergeATPA(TPA)
else
Break;
end else
begin
if (Found >= 1) then
Temp2 := MergeATPA(TPA)
else
Break;
end;
ATPA := TPAToATPAEx(Temp2, 40, 40);
SortATPASize(ATPA, True);
for t := 0 to High(ATPA) do
begin
P := MiddleTPA(ATPA[t]);
if (UseItem <> 0) then
begin
if not ItemActivated(UseItem) then
MouseItem(UseItem, mouse_left);
Wait(200+Random(100));
end;
Mouse(P.x, P.y, 3, 3, mouse_right);
Result := WaitOption('ire', 1000);
if Result then
begin
Wait(500+Random(250));
while IsMoving do
Wait(200);
Exit;
end;
if (t >= 2) then
Break;
end;
end;
end;

You could also try out the cluster functions in my signature if you'd like a more advanced way of using multiple colors for npc/object finding :)

putonajonny

2012-06-24 14:22:00

When you say it is inaccurate what do you mean?

cadet54

2012-06-24 14:25:13

Well since the colours are not using hue's and CTS the colours tend to cross over allot, brown cows match the fence though the cows are a lighter colour than the fence, I guess with CTS it would be able to home in on those colours better? or am I getting the wrong end of the stick?

Ah nice thanks for the advice runaway, will give it a go.

putonajonny

2012-06-24 14:37:50

From: cadet54
Well since the colours are not using hue's and CTS the colours tend to cross over allot, brown cows match the fence though the cows are a lighter colour than the fence, I guess with CTS it would be able to home in on those colours better? or am I getting the wrong end of the stick?

Ah nice thanks for the advice runaway, will give it a go.


There are 3 different types of CTS (actually 4 but 1 of them is kind new and not really used) CTS 0 compares colours in a very bad way and is rarely used. CTS 1 is what you are using, is uses a single value to compare colours, it is ok. CTS 2 is normally the best for comparing 2 colours, it uses 3 values for tolerance, the tolerance, a hue modifier and a saturation modifier.

Have you tries using ACA to get the colours of the cows?

This is my object finding function, I think you might find it of some use:
Function FindObject(Colours : array of TColour; UpText : array of String; SortFrom : TPoint; ClickType, ATPAHeight, ATPAWidth, ATPASizeCount : integer; CheckForRedClick, Debug : Boolean) : Boolean;
Var
Points, Points2 : array of TPoint;
ATPA : array of array of TPoint;
i, H, CTS : integer;
begin

CTS := GetColorToleranceSpeed;
SetColorToleranceSpeed(2);
H := high(Colours);
SetArrayLength(Points, 0);
for i := 0 to H do
begin
SetToleranceSpeed2Modifiers(Colours[i].Hue, Colours[i].Sat);
FindColorsTolerance(Points2, Colours[i].Colour, MSX1, MSY1, MSX2, MSY2, Colours[i].Tolerance);
CombineTPAWrap(Points, Points2, Points);
end;
SetColorToleranceSpeed(CTS);
SortTPAFrom(Points, SortFrom);
TPAtoATPAExWrap(Points, ATPAWidth, ATPAHeight, ATPA);

if(Debug)then
begin
SMART_ClearCanvasArea(MSBox);
SMART_DrawDotsEx(False, Points, clGray);
end;

SetArrayLength(Points, GetArrayLength(ATPA));

H := high(Points);
for i := 0 to H do
begin
Points[i] := MiddleTPA(ATPA[i]);
if(Debug)then
SMART_DrawCircle(False, Points[i], 5, GetArrayLength(ATPA[i]) >= ATPASizeCount, Random(clWhite));
end;

H := high(Points);
for i := 0 to H do
begin
if(GetArrayLength(ATPA[i]) < ATPASizeCount)then
Continue;
MouseBox(Points[i].x - 5, Points[i].y - 5, Points[i].x + 5, Points[i].y + 5, mouse_Move);
Wait(Random(20));
if(WaitUpTextMulti(UpText, 200+Random(500)))then
begin
ClickMouse2(ClickType);
if(CheckForRedClick)then
Result := DidRedClick
else
Result := True;
exit;
end;
end;

end;

You will need some other things to use it, put these above the function:
type
TColour = record
Colour, Tolerance : integer;
Hue, Sat : extended;
end;

Function Colour(Col, Tol : integer; Hue, Sat : extended) : TColour;
begin

Result.Colour := Col;
Result.Hue := Hue;
Result.Tolerance := Tol;
Result.Sat := Sat;

end;

Ok this is how you use it:
Function FindObject(Colours : array of TColour; UpText : array of String; SortFrom : TPoint; ClickType, ATPAHeight, ATPAWidth, ATPASizeCount : integer; CheckForRedClick, Debug : Boolean) : Boolean;

Colours are the colours of your object, you get these from ACA, they are defined like this:
[Colour(5132113, 5, 1.12, 0.12), Colour(29472, 8, 0.23, 0.27)]
//Colour(Col, Tolerance, Hue, Saturation) - You get these from ACA
Uptexts are the uptexts of the object, you know how to use these

SortFrom is the point to sort the colours from, if you want to click the object nearest to you this will be
Point(MSCX, MSCY)

ClickType is the mouse button to use, this can be mouse_left, mouse_right or mouse_move

ATPAHeight is the height of the object, ATPA Width is the width (roughly) (best to make these less rather than more)

ATPAMinCount is the minimum number of pixels of the correct colour for the object to check that point

CheckForRed is whether it checks for the redcrosshair to know if it was successful (only put true if using mouse_left)

Debug is whether you want the objects painted on screen


In the end it looks something like this:
if(FindObject([Colour(5132113, 5, 1.12, 0.12), Colour(29472, 8, 0.23, 0.27)], ['ausol', 'eposit', 'leum'], Point(MSCX, MSCY), mouse_Left, 40, 40, 10, True, False))then
//DoSomething;

cadet54

2012-06-24 14:47:38

Bloody hell that is pretty much a whole tutorial in that post, thanks very much that is awesome.