Log in

View Full Version : Help With a Find NPC Function



Paradoxium
02-21-2012, 10:53 PM
The script tans hides at Ellis in Al Kharid. The problem is that when it goes to trade Ellis, it trades him, tans the leather, and then instead of walking back, it trys to find Ellis again. Thanks for all the help in advance! The problem is between TradewithEllis, FindEllis, and Makeall i believe. I highly doubt it but small chance it could be in the EllisColor(Autocolor func)...

IVE JUST BEEN INFORMED THAT THIS IS THE WRONG SECTION...SORRY!

program RealTanned;
{$DEFINE SMART}
{$i SRL\SRL.simba} //TODO LINE 247 replace with SPS single so that it always find it
{$i ObjectDTM\ObjDTMInclude.simba} //TODO [FAILSAFE] CREATE BITMAP FOR TANNED DRAGONHIDE
//TODO ONCE EVERYTHING IS SMOOTH, CHECK IF WORKS WITH GREEN DRAGONHIDE, MAYBE ADD MORE OPTIONS
{************************************************* ****************************** //ADD REST [MAYBE MAKE IT OPTIONAL]
SetUp Procedures
************************************************** *****************************}
Const
//Options are 'blue' and 'green'
WhichHide = 'blue';

procedure DeclarePlayers;
begin

HowManyPlayers := 1;
CurrentPlayer := 0;
SetLength(Players, HowManyPlayers);

Players[0].Name := '';
Players[0].Pass := '';
Players[0].Nick := '';
Players[0].Member := True;
Players[0].Active := True;
Players[0].Pin := '';

end;

{************************************************* ******************************
Function NothingInInv:Boolean;
By: Lordofballss
Description: Checks if Inventory is Empty
************************************************** *****************************}
function NothingInInv:Boolean;

begin

if (InvCount = 0) then
Result:=True

end;


{************************************************* ******************************
Checking Functions
************************************************** *****************************}
var
x, y,Tanned : Integer;

function AtEllis: Boolean;

begin

if FindSymbol(x, y, 'tanner') then
Result := True;

end;

function AtBank: Boolean;

begin

if FindSymbol(x, y,'bank') or (ObjDTM_InArea('85:76:3:7:7:39:86:7:7:42:72:7:7:11 6:76:4:27:45:30:109:143:110:123:38',True)) then
Result:=True

end;

function InvFullTD: Boolean;

begin

Tanned:= DTMFromString('mbQAAAHicY2VgYGBhYWD4zszAwAakBYGYCY ivMDIwXAPiR4wQ9gkg5uLxZODmDWDg5vFj4OJ2Z+DkdmHABhix YDAAACBuBz8=');

if (InvCount = 28) and (FindDTM(Tanned, x, y, MIX1, MIY1, MIX2, MIY2)) then
Result:= True

else

Result:=False

end;
{************************************************* ******************************
Colors
************************************************** *****************************}
function EllisColor: Integer;
var
arP: TPointArray;
arC: TIntegerArray;
tmpCTS, i, arL: Integer;
X, Y, Z: Extended;
begin
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.16, 1.10);

FindColorsSpiralTolerance(MSCX, MSCY, arP, 4420033, MSX1, MSY1, MSX2, MSY2, 11);
if (Length(arP) = 0) then
begin
Writeln('Failed to find Ellis, no result.');
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
Exit;
end;

arC := GetColors(arP);
ClearSameIntegers(arC);
arL := High(arC);

for i := 0 to arL do
begin
ColorToXYZ(arC[i], X, Y, Z);

if (X >= 16.82) and (X <= 38.72) and (Y >= 13.73) and (Y <= 31.19) and (Z >= 6.75) and (Z <= 14.82) then
begin
Result := arC[i];
Writeln('EllisColor = ' + IntToStr(arC[i]));
Break;
end;
end;

ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);

if (i = arL + 1) then
Writeln('AutoColor failed in finding the Ellis.');
end;




function EllisScreenColor: Integer;
var
arP: TPointArray;
arC: TIntegerArray;
tmpCTS, i, arL: Integer;
X, Y, Z: Extended;
begin
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.01, 0.84);

FindColorsSpiralTolerance(MSCX, MSCY, arP, 5080240, MSX1, MSY1, MSX2, MSY2, 27);
if (Length(arP) = 0) then
begin
Writeln('Failed to find the Screen color, no result.');
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
Exit;
end;

arC := GetColors(arP);
ClearSameIntegers(arC);
arL := High(arC);

for i := 0 to arL do
begin
ColorToXYZ(arC[i], X, Y, Z);

if (X >= 4.75) and (X <= 58.63) and (Y >= 4.85) and (Y <= 58.86) and (Z >= 3.69) and (Z <= 39.29) then
begin
Result := arC[i];
Writeln('EllisScreenColor = ' + IntToStr(arC[i]));
Break;
end;
end;

ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);

if (i = arL + 1) then
Writeln('AutoColor failed in finding the Ellis Screen.');
end;

function CounterColor: Integer;
var
arP: TPointArray;
arC: TIntegerArray;
tmpCTS, i, arL: Integer;
X, Y, Z: Extended;
begin
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.06, 2.02);

FindColorsSpiralTolerance(382, 252, arP, 10010851, 0, 0, 765, 502, 12);
if (Length(arP) = 0) then
begin
Writeln('Failed to find the Counter color, no result.');
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
Exit;
end;

arC := GetColors(arP);
ClearSameIntegers(arC);
arL := High(arC);

for i := 0 to arL do
begin
ColorToXYZ(arC[i], X, Y, Z);

if (X >= 53.82) and (X <= 58.63) and (Y >= 53.81) and (Y <= 58.86) and (Z >= 35.96) and (Z <= 39.29) then
begin
Result := arC[i];
Writeln('Counter = ' + IntToStr(arC[i]));
Break;
end;
end;

ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);

if (i = arL + 1) then
Writeln('AutoColor failed in finding the Counter.');
end;

{************************************************* ******************************
Making Procedure
************************************************** *****************************}
Procedure Makeall;

Begin
ChooseOption('rade');
Wait(500 + Random(300));

Case (lowercase(WhichHide)) of
'blue': MouseBox(161, 201, 245, 266, mouse_Right);
'green': MouseBox(48, 200, 361, 278, mouse_Right);
'': Begin ClearDebug; WriteLn('You have not filled out which type of leather to make! Please read the instructions and do so!'); TerminateScript; End;
end;

ChooseOption('ll');
Exit;
end;


{************************************************* ******************************
Walking Procedures
************************************************** *****************************}
procedure WalktoEllis;

begin
If (AtBank) then

begin
Writeln('Walking to Ellis');
ObjDTM_Walk('94:76:5:7:7:37:84:7:7:41:70:7:7:103:1 17:7:7:117:78:7:7:43:120:5:33:56:8:119:125:127:133 :53:75:55',4,100,60,True);
ObjDTM_WalkPath(['108:38:3:7:7:47:117:0:7:139:80:7:7:114:78:6:96:31 :18:96:49:143:147:111:150:65:138:36', '79:22:3:7:7:37:58:7:7:86:122:0:7:111:124:5:39:32: 7:75:90:143:136:130:136:96'],4,100,60,False,True);
Wait(RandomRange(1500,700));
end;

end;

procedure Walktobank;

begin

if (AtEllis) {and (InvFullTD)} then

begin
Writeln('Walking to Bank')
ObjDTM_WalkPath(['98:123:3:7:7:44:118:7:7:98:52:7:7:80:32:5:73:13:2 2:103:29:135:75:144:118:50', '69:119:3:7:7:21:79:10:7:62:31:10:7:65:58:4:58:8:7 :71:20:110:106:64', '50:115:3:7:7:83:115:7:7:31:50:0:7:110:117:6:39:24 :11:50:43:138:128:131:129:108:69:78'],6,100,100,False,True);

end else
//TODO PUT IN HERE, IF COULDNT FIND NODE 0 THEN WALK OVER (MAKE A NEW DTM FOR THAT FLAG) AND REPEAT
end;

{************************************************* ******************************
Finding and Trading with Ellis the Tanner
************************************************** *****************************}
function FindEllis : Boolean; //Credit to Naum
Var
Bx, By : Integer;
TPA : Array Of TPoint;
ATPA : T2DPointArray; //Used to contain TPA after splitting;
I : Integer; // Set the Point Array Length

Begin

FindColorsSpiralTolerance(Bx, By, TPA, EllisColor, MSX1, MSY1, MSX2, MSY2, 12)

begin
ATPA := SplitTPA(TPA, 10);
for I := 0 to High(ATPA) do

if MiddleTPAEX(ATPA[i], Bx, By) then
MMouse(Bx, By, 1, 1);
Wait(RandomRange(300,400));

if (IsUpText('llis')) then
begin
Mouse(Bx, By, 1, 1, False);
Result := True;
Exit;
end;
end;
end;




procedure TradeWithEllis;

begin
if (FindEllis) then
begin
Wait(300 + Random(300));
Writeln('Found Ellis');
MakeAll;
end else

if (not(FindEllis)) then
begin
Writeln('Could not find Ellis')
end;

end;


{************************************************* ******************************
Banking Functions and Procedures
************************************************** *****************************}
function FindCounter(x, y: Integer): Boolean;
var
CTS, I: Integer;
TPA: TPointArray;
ATPA: Array of TPointArray;
begin
Writeln('looking for banker');
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.02,4.01);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, CounterColor, MSX1, MSY1, MSX2, MSY2, 15);
ColorToleranceSpeed(CTS);
ATPA := TPAToATPAEx(TPA, 15, 15);

For I := 0 to High(ATPA) do
begin
MiddleTPAEx(ATPA[i], x, y);
MMouse(x, y, 0, 0);
Wait(200 + Random(300));

If(IsUpText('ank booth')) then
begin
Wait(200 + Random(300));
Result := True;
GetMousePos(x,y);
Break;
end;
end;
end;

procedure OpenBankCounter;

begin
If (AtBank) then

begin
if FindCounter(x,y) then
Writeln('Found Banker');
ClickMouse2(mouse_left);
Wait(1500 + Random(200));
end;
Exit;
end;

function FindDragonHide:Boolean;
var
Inbank: Integer;
begin


InBank := DTMFromString('mwQAAAHic42RgYOADYiEGCGAGYkEglgZiGS CWBGJWIOaFivEDMTtULQuULwrE4kDMye0GJJnwYn6oHnyYkQgM BwD3mwIK');

if FindDTM(Inbank, X, Y, MSX1,MSY1,MSX2,MSY2) Then
Begin
Writeln('Found it');
MMouse(x,y,5,5);
ClickMouse2(mouse_right);
Wait(RandomRange(400,600));
ChooseOption('ll');
Wait(1000 + Random(600));
ClickMouse2(mouse_left);
Writeln('Withdrew it');
Result:= True
end else
if (Result=False) then
Writeln('Could not find dragonhide in bank');
FreeDTM(Inbank);
end;


procedure WithdrawEm;

begin

if (FindDragonHide) then
Writeln('found banked dragonhide');
Wait(400 + Random(400));
CloseBank;
Exit;
end;


procedure WithdrawHides;

begin

if (NothingInInv) and (BankScreen) then
begin
WithdrawEm;
end else

if (Invfull) and (BankScreen) then
begin
QuickDeposit(SRL_DEPOSIT_ALL);
Wait(RandomRange(400,600));
WithdrawEm;
end;

Exit;

end;
{************************************************* ******************************
Main Loop
************************************************** *****************************}

begin
Smart_Server := 10;
Smart_Members := True;
Smart_Signed := True;
ClearDebug;
SetupSRL;
ObjDTM_Setup;
DeclarePlayers;
MouseSpeed:=15;
if (not LoggedIn) then
LoginPlayer;
repeat
OpenBankCounter;
WithdrawHides;
WalkToEllis;
TradewithEllis;
WalktoBank;
until(not(loggedin))
end.

Hobbit
02-28-2012, 06:53 AM
Moved + free bump ;)

No time to look over, sorry.

Brandon
02-28-2012, 07:56 AM
Nice bump.. Was just about to go watch a movie.. Anyway.. Please don't put spaces between every single line like that.. It makes it easy to read without them as well.. when u have a for loop and then u go and put spaces like that, how can u tell what does what?

Also..

For I:= 0 To High(Blah) do
MMouse(........); <---- This is the only line that gets executed in the for loop..
Wait(...);


UNLESS you do..

For I:= 0 To High(Blah) do
begin
MMouse(.....); //Now both the mouse and the wait get executed.. thus after every mouse movement, it will wait.
Wait(....);
end;


Now for your next problem:


procedure TradeWithEllis;

begin
if (FindEllis) then
begin
Wait(300 + Random(300));
Writeln('Found Ellis');
MakeAll;
end else

if (not(FindEllis)) then
begin
Writeln('Could not find Ellis')
end;
end;


That is your problem.. Now you see, when the:

if (FindEllis) then
begin
Wait(300 + Random(300));
Writeln('Found Ellis');
MakeAll;
end;


Gets Executed, We already know that elis was not found.. thus there is no need to do:

end else
if (not(FindEllis)) then //<---- The problem is there.. when u do that, ur searching for elis again and checking the result
begin
Writeln('Could not find Ellis')
end;


Thus the answer to your problem is:

procedure TradeWithEllis;
begin
if (FindEllis) then
begin
Wait(300 + Random(300));
Writeln('Found Ellis');
MakeAll;
end else
Writeln('Could not find Ellis');
end;

Paradoxium
02-29-2012, 01:43 AM
Nice bump.. Was just about to go watch a movie.. Anyway.. Please don't put spaces between every single line like that.. It makes it easy to read without them as well.. when u have a for loop and then u go and put spaces like that, how can u tell what does what?

Also..

For I:= 0 To High(Blah) do
MMouse(........); <---- This is the only line that gets executed in the for loop..
Wait(...);


UNLESS you do..

For I:= 0 To High(Blah) do
begin
MMouse(.....); //Now both the mouse and the wait get executed.. thus after every mouse movement, it will wait.
Wait(....);
end;


Now for your next problem:


procedure TradeWithEllis;

begin
if (FindEllis) then
begin
Wait(300 + Random(300));
Writeln('Found Ellis');
MakeAll;
end else

if (not(FindEllis)) then
begin
Writeln('Could not find Ellis')
end;
end;


That is your problem.. Now you see, when the:

if (FindEllis) then
begin
Wait(300 + Random(300));
Writeln('Found Ellis');
MakeAll;
end;


Gets Executed, We already know that elis was not found.. thus there is no need to do:

end else
if (not(FindEllis)) then //<---- The problem is there.. when u do that, ur searching for elis again and checking the result
begin
Writeln('Could not find Ellis')
end;


Thus the answer to your problem is:

procedure TradeWithEllis;
begin
if (FindEllis) then
begin
Wait(300 + Random(300));
Writeln('Found Ellis');
MakeAll;
end else
Writeln('Could not find Ellis');
end;


Thank you so much! Ill implement these changes :D, I gotta work on my standards lol -_-