Simba Code:
program UndergroundHerbalist;
{$DEFINE SMART}
{.include SRL/SRL.simba}
//{$DEFINE DEBUG} //uncomment if you need debug info
{$DEFINE DEBUG_DRAW} //uncomment if you need debug info
{$IFDEF DEBUG_DRAW}
{$I SRL/SRL/misc/debug.simba}
{$I SRL/SRL/misc/paintsmart.simba}
{$ENDIF}
const
NumbOfPlayers= 1;
StartPlayer= 0;
//Dung slots
DUNG_CASH_SLOT = 1;
DUNG_SEED_SLOT = 2;
//SMART Setup
SmartWorld = 7;
Members = False;
SignedClient = True;
HighDetail = False;
procedure DeclarePlayers; //Already forgot where I copied this :(
var i:integer;
begin
NumberOfPlayers(NumbOfPlayers);
CurrentPlayer := StartPlayer;
for i := 0 to NumbOfPlayers-1 do
Players[i].BoxRewards := ['mote', 'ostume', 'XP', 'Gem', 'ithril', 'oal', 'une', 'oins'];
with Players[0] do
begin
Name := ''; //Player username.
Pass := ''; //Player password.
Nick := ''; //Player nickname - 3-4 letters of Player username.
Active := True;
end;
end;
procedure DoLogin;
var t: integer;
begin
MarkTime(t);
while (not LoggedIn) do
begin
if LogInPlayer then
break;
wait(10000+random(500));
if (TimeFromMark(t) > 180000) then
begin
writeln('Failed to login after 180s... Terminating');
TerminateScript;
end;
end;
end;
function objFind(color, tol: integer; hmod, smod: extended; w,h, minc: integer;
left: boolean; uptext, option: string): boolean;
var tcts, i, x, y: integer;
tpa: TPointArray;
atpa: T2DPointArray;
begin
Result:=False;
tcts:= getToleranceSpeed;
setColorToleranceSpeed(2);
setColorSpeed2Modifiers(hmod, smod);
if FindColorsSpiralTolerance(MSCX, MSCY, tpa, color, MSX1, MSY1, MSX2, MSY2, tol) then
begin
atpa:= TPAtoATPAEx(tpa, 20, 20);
{$IFDEF DEBUG_DRAW}
debugATPABounds(atpa);
{$ENDIF}
for i:=0 to high(atpa) do
begin
writeln('atpa['+IntToStr(i)+']: '+IntToStr(length(atpa[i])));
if (minc > 0) and (length(atpa[i]) < minc) then continue;
MiddleTPAEx(atpa[i], x, y);
Mouse(x, y, 3, 3, mouse_move);
if waitUptext(uptext, 1000) then
begin
if left then
begin
ClickMouse2(mouse_left);
Result:= DidRedClick;
end
else
begin
ClickMouse2(mouse_right);
Result:= WaitOption(option, 1000);
end;
if Result then
begin
writeln('objfind success!');
break;
end;
end;
end;
end;
setColorToleranceSpeed(tcts);
end;
//Returns true if *object* in question should exist based on the threshold
function objScan(color, tol: integer; hmod, smod: extended;
w,h, minc: integer): boolean;
var tcts, i, x, y: integer;
tpa: TPointArray;
atpa: T2DPointArray;
begin
Result:=False;
tcts:= getToleranceSpeed;
setColorToleranceSpeed(2);
setColorSpeed2Modifiers(hmod, smod);
if FindColorsSpiralTolerance(MSCX, MSCY, tpa, color, MSX1, MSY1, MSX2, MSY2, tol) then
begin
atpa:= TPAtoATPAEx(tpa, 20, 20);
{$IFDEF DEBUG_DRAW}
debugATPABounds(atpa);
{$ENDIF}
for i:=0 to high(atpa) do
begin
Result:= (length(atpa[i]) >= minc);
if Result then break;
end;
end;
setColorToleranceSpeed(tcts);
end;
function PlantSeed: boolean;
var t, c: integer;
v: TVariantArray;
begin
Result:=False;
if ExistsItem(DUNG_SEED_SLOT) then
begin
//Select seed
MarkTime(t);
while (TimeFromMark(t) < 10000) do
begin
MouseItem(DUNG_SEED_SLOT, mouse_left);
v:=[DUNG_SEED_SLOT];
if WaitFuncEx('itemActivated', v, 500, 3000) then
break;
end;
//Timeout, something is wrong?
if TimeFromMark(t) > 10000 then Exit;
c:= GetAmountBox(InvBox(DUNG_SEED_SLOT));
if ObjFind(5334906, 12, 0.05, 1.23, 20, 20, 100, true, 'atc', '') then
begin
MarkTime(t);
while TimeFromMark(t) < 5000 do
begin
Result:= GetAmountBox(InvBox(DUNG_SEED_SLOT)) < c;
if Result then Exit;
end;
end;
end;
end;
procedure AddArray(var a: TIntegerArray; n: integer);
var i: integer;
t: TIntegerArray;
begin
setLength(t, length(a)+1);
for i:=0 to high(a) do
t[i]:=a[i];
t[length(t)-1]:=n;
a:=t;
end;
function HerbPosition(dtm: integer): TIntegerArray;
var i, x, y: integer;
tb: TBox;
begin
setLength(result, 0);
for i:=1 to 28 do
begin
tb:= InvBox(i);
if ExistsItem(i) then
if FindDTM(dtm, x, y, tb.X1, tb.Y1, tb.X2, tb.Y2) then
AddArray(result, i);
end;
if length(result) = 0 then
writeln('no herbs found')
else
begin
for i:=0 to high(result) do
writeln(result[i]);
end;
end;
procedure CleanHerb(dtm: integer);
var i, x, y: integer;
tb: TBox;
da: TIntegerArray;
dropArr: array [0..27] of integer;
begin
//Set an array to mark where our herbs are
for i:=0 to 27 do
dropArr[i]:=0;
//Locate herbs using DTM
da:= HerbPosition(dtm);
//Finally clean them
for i:=0 to high(da) do
MouseItem(da[i], mouse_left);
end;
function Invtab(ttab: integer): boolean;
begin
result:= (GetCurrentTab = ttab);
end;
procedure AlchHerb(dtm: integer);
var i: integer;
v: TVariantArray;
da: TIntegerArray;
begin
da:= HerbPosition(dtm);
v:=[tab_magic];
//Switch to spell tab
if WaitFuncEx('FTab', v, 1000, 5000) then
begin
for i:=1 to length(da) do
begin
//select high alch
//todo
Mouse(570, 300, randomRange(-5, 5), randomRange(-5, 5), mouse_left);
v:=[tab_inv];
if WaitFuncEx('Invtab', v, 500, 5000) then
begin
MouseItem(da[i-1], mouse_left);
wait(3000+random(100)); //high alch takes 3s for casting
v:=[tab_magic];
WaitFuncEx('Invtab', v, 500, 5000);
end;
end;
end;
//Switch back to inventory
v:=[tab_inv];
WaitFuncEx('FTab', v, 500, 5000);
end;
function FinishCollection: boolean;
var s:string;
begin
s:= getBlackChatMessage;
Result:= ExecRegExpr('thing', s);
writeln('debug: '+s);
end;
procedure FarmHerbs(dtm, dtm2: integer);
var action: string;
begin
action:='plant';
while LoggedIn do
begin
writeln({padts}('current action is ' + action));
case action of
'plant': begin
if PlantSeed then action:= 'collect';
end;
'collect': begin
if objScan(6789997, 13, 0.06, 1.04, 20, 20, 50) then
if ObjFind(5334906, 12, 0.05, 1.23, 20, 20, 100, false, 'atc', 'vest') then
begin
WaitFunc(@FinishCollection, 500, 10000);
action:='alch';
end;
end;
'alch': begin
CleanHerb(dtm);
wait(3000);
AlchHerb(dtm2);
action:= 'plant';
end;
'buy':;
end;
wait(50);
writeln({padts}('current action is ' + action));
end;
end;
var DTM, dtm2: integer;
var t: TIntegerArray;i: integer;
begin
Smart_Server := SmartWorld;
Smart_Members := Members;
Smart_Signed := SignedClient;
Smart_SuperDetail := HighDetail;
setupSRL();
DeclarePlayers;
DoLogin;
dtm:= DTMFromString('mrAAAAHic42BgYJBkY2CQAmJ5IFYBYg0oDRIXBeKpTAwMvUA8AYgnAfEUIJ4BxPOAeBEQO3o5AE1hwon/M+AHjAQwDAAAlCsHyQ==');
dtm2:= DTMFromString('mrAAAAHic42BgYEhkY2BIBuJ0IC4E4hwgTgXiFCj/OBMDw0Eg3gfEB4D4GBBfAuJrQHwYiM3szICmMOHE/xnwA0YCGAYApjELgQ==');
FarmHerbs(dtm, dtm2);
// PlantSeed;
// if ObjFind(5334906, 12, 0.05, 1.23, 20, 20, 100, false, 'atc', 'vest') then
;
// WaitFunc(@FinishCollection, 500, 10000);
// AlchHerb(dtm2);
// mouse(570,300,0,0,mouse_move);
FreeDTM(dtm);
FreeDTM(dtm2);
end.