ne lg
2012-06-12 05:46:30
Hi, so heres the low down;
Im creating a death walker for this script and I need to detect death then walkback and restart the script from the beginning
Is there anyway to universally detect death? and when detected exits out of the procedure/function and does the deathwalk then RESTARTS from the beginning of the scripts.
From the way the script is set up im having difficulties figuring out how to do it, The script did have a logout on death but it didn't really detect death well at all because it would end up in edgeville searching for the exit to the dungeon or similar objects,
So im wondering if its possible to have a universal death detector so that no matter when it is in the script it will do the deathwalker and restart?
Is this possible? Thanks for your help :)
Im creating a death walker for this script and I need to detect death then walkback and restart the script from the beginning
Is there anyway to universally detect death? and when detected exits out of the procedure/function and does the deathwalk then RESTARTS from the beginning of the scripts.
program WAR;
{$DEFINE SMART}
{.include SRL/SRL.simba}
{.include custom/DDTM.simba}
{$i ObjectDTM\ObjDTMInclude.simba}
//{$DEFINE DEBUG} //uncomment if you need debug info
//{$DEFINE DEBUG_DRAW} //uncomment if you need debug info
type EObj = record
color, tol, w, h, minc, maxtry: integer;
hmod, smod: extended;
uptexts, options: TStringArray;
left: boolean;
end;
var courseObjs: array of EObj;
ddtms: array [0..1] of integer;
food: integer; //food dtm
foodslots: TIntegerArray; //food locations
startXP: integer;
wasInDung: boolean;
const
//SMART Setup
SmartWorld = 7;
Members = False;
SignedClient = True;
HighDetail = False;
//Player Setup
HEAL_AT = 130;
FOOD_DTM = 'mrAAAAHic42BgYHjIysDwGohfAfEzIH4AxNeB+AYQ3wfiC8wMDIeB+BQQXwHie0B8DYjPAfEJILbQYGcwVWNnMFBQYOgsKweayMQwNUeUwUGPE8zmApL4MCMBDAMAD48SZg==';
//DDTM Setup
PIT_BLACK = 66566;
LOG_BROWN = 2049116;
DOOR_RED = 1009;
OUTLINE_WHITE = 16049649;
procedure DeathsWalk;
begin;
if FindTextTPA(0, 2, MCX1, MCY1, MCX2, MCY2, 'dear', SmallChars, Nothing) then
if FindTextTPA(0, 2, MCX1, MCY1, MCX2, MCY2, 'dead', SmallChars, Nothing) then
begin
end else
exit;
end;
procedure DeclareObjects;
begin
setLength(courseObjs, 6);
//Pipe
with courseObjs[0] do
begin
color:= 6447197;
tol:= 18;
hmod:= 0.25;
smod:= 0.05;
w:= 20; h:= 20; minc:= 100; maxtry:= 3;
uptexts:=['rou'];
options:=['rou'];
left:=true;
end;
//Swing
with courseObjs[1] do
begin
color:= 1060661;
tol:= 10;
hmod:= 0.14;
smod:= 0.87;
w:= 10; h:= 10; minc:= 30; maxtry:= 5;
uptexts:=['wing', 'ing'];
options:=['wing', 'ing'];
left:=false;
end;
//Lava
with courseObjs[2] do
begin
color:= 2306419;
tol:= 7;
hmod:= 0.05;
smod:= 0.40;
w:= 30; h:= 30; minc:= 40; maxtry:= 2;
uptexts:=['ross'];
options:=['ross'];
left:=false;
end;
//Log
with courseObjs[3] do
begin
color:= 5002072;
tol:= 6;
hmod:= 0.34;
smod:= 0.10;
w:= 20; h:= 20; minc:= 40; maxtry:= 2;
uptexts:=['acro'];
options:=['acro'];
left:=true;
end;
//Cliff
with courseObjs[4] do
begin
color:= 5197651;
tol:= 2;
hmod:= 0.0;
smod:= 0.27;
w:= 30; h:= 30; minc:= 100; maxtry:= 3;
uptexts:=['iff'];
options:=['iff'];
left:=false;
end;
//Ladder
with courseObjs[5] do
begin
color:= 3555138;
tol:= 7;
hmod:= 0.20;
smod:= 0.55;
w:=10; h:=10; minc:=40; maxtry:=3;
uptexts:=['imb'];
options:=['imb'];
left:=true;
end;
{
with courseObjs[4] do
begin
color:=;
tol:=;
hmod:=;
smod:=;
w:=; h:=; minc:=; maxtry:=;
uptexts:=;
options:=;
end;
}
end;
procedure ProgressReport(var startXP: integer);
var gain: integer;
begin
gain := GetXPBarTotal- startXP;
writeln('Time running: ' + TimeRunning);
writeln('Exp Gained: ' + IntToStr(gain));
writeln('Est XP/H: ' + IntToStr(round(3600000 * 1.0 / GetTimeRunning * gain)));
end;
procedure FreeDDTM;
var i: integer;
begin
for i:=0 to high(ddtms) do
FreeDTM(ddtms[i]);
end;
procedure DeclareDDTM;
var DTMSubPoints: array of TDTMPointDef;
DTMMainPoint: TDTMPointDef;
begin
//Log DDTM
setLength(DTMSubPoints, 4);
DTMMainPoint:= DTMPoint(9, 0, 1, 0, 16777215, 255);
DTMSubPoints[0] := DTMPoint(9, 6, 1, 0, PIT_BLACK, 25);
DTMSubPoints[1] := DTMPoint(19, 3, 1, 0, PIT_BLACK, 25);
DTMSubPoints[2] := DTMPoint(0, 3, 1, 0, PIT_BLACK, 25);
DTMSubPoints[3] := DTMPoint(0, 12, 1, 0, LOG_BROWN, 25);
ddtms[0] := AssembleDDTM(DTMMainPoint, DTMSubPoints);
//Gate DDTM
setLength(DTMSubPoints, 3);
DTMMainPoint:= DTMPoint(4, 0, 1, 0, 16777215, 255);
// DTMSubPoints[0] := DTMPoint(4, 0, 1, 0, 1009, 25); //red
DTMSubPoints[0] := DTMPoint(10, 0, 1, 0, 15268071, 25); //white
DTMSubPoints[1] := DTMPoint(7, 0, 1, 0, 1009, 25); //red
DTMSubPoints[2] := DTMPoint(0, 0, 1, 0, 1009, 25); //''
ddtms[1] := AssembleDDTM(DTMMainPoint, DTMSubPoints);
//Hook FreeDTM
AddOnTerminate('FreeDDTM');
end;
procedure DeclarePlayers;
var i:integer;
begin
NumberOfPlayers(1);
CurrentPlayer := 0;
for i := 0 to 0 do
Players[i].BoxRewards := ['mote', 'ostume', 'XP', 'Gem', 'ithril', 'oal', 'une', 'oins'];
with Players[0] do
begin
Name := ; //Player username.
Pass := '; //Player password.
Nick := 'Euz'; //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;
procedure GetLocationOffset(location: string; var dx, dy: integer);
begin
//Change the global offsets here!
case location of
'pipe' : begin
dx:=27;
dy:=50;
end;
'swing' : begin
dx:=31;
dy:=-19;
end;
'lava' : begin
dx:=18;
dy:=-48;
end;
'log' : begin
dx:=15;
dy:=13;
end;
'cliff' : begin
dx:=-16;
dy:=38;
end;
end;
end;
function CalibratePosition(location: string): boolean;
var d, x, y, dx, dy: integer;
e: extended;
begin
if not LoggedIn then Exit;
result := false;
FindNormalRandoms;
d:=ddtms[0];
//eat
if FindDTMRotated(d, x, y, MMX1, MMY1, MMX2, MMY2, -Pi/6, Pi/6, 0.05, e) then
begin
GetLocationOffset(location, dx, dy);
writeln('dxdy: ' + inttostr(dx) + ' ' + inttostr(dy));
mouse(x+dx, y+dy, 4, 4, mouse_left);
// mouse(x, y, 4, 4, mouse_move);
end;
end;
function CalibratePositionB(location: string; var p: TPoint): boolean;
var d, x, y, dx, dy: integer;
e: extended;
begin
if not LoggedIn then Exit;
result := false;
FindNormalRandoms;
d:=ddtms[0];
//eat
result:= FindDTMRotated(d, x, y, MMX1, MMY1, MMX2, MMY2, -Pi/6, Pi/6, 0.05, e);
p:= Point(x,y);
end;
function objFind(color, tol: integer; hmod, smod: extended; w,h, minc, maxtry: integer;
left: boolean; uptexts, options: TStringArray): boolean;
var tcts, i, x, y, c: 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;
if (c > maxtry) then continue;
Inc(c);
MiddleTPAEx(atpa[i], x, y);
Mouse(x, y, 3, 3, mouse_move);
if WaitUptextMulti(uptexts, 1000) then
begin
if left then
begin
ClickMouse2(mouse_left);
Result:= DidRedClick;
end
else
begin
ClickMouse2(mouse_right);
Result:= WaitOptionMulti(options, 1000);
end;
if Result then
begin
writeln('objfind success!');
break;
end;
end;
end;
end;
setColorToleranceSpeed(tcts);
end;
function objFindW(obj: EObj): boolean;
begin
result:= objFind(obj.color, obj.tol, obj.hmod, obj.smod,
obj.w, obj.h, obj.minc, obj.maxtry, obj.left, obj.uptexts, obj.options);
end;
function InDungeon: boolean;
var tpa: TPointArray;
begin
if not LoggedIn then Exit;
SetColorToleranceSpeed(1);
FindMMColorsSpiralTolerance(tpa, 2574684, 25);
writeln(length(tpa));
result := length(tpa) > 1200;
if result then writeln('in dungeon');
end;
function InSurface: boolean;
var tpa: TPointArray;
begin
FindMMColorsSpiralTolerance(tpa, 5222643, 25);
result:= length(tpa) >= 200;
end;
function DetermineAction(var action: string): boolean;
var d, x, y, dx, dy: integer;
e: extended;
p: TPoint;
begin
if not LoggedIn then Exit;
FindNormalRandoms;
//Dungeon
if InDungeon then
begin
action:= 'dungeon';
result:= true;
Exit;
end;
//Detect where we are on the surface!
d:=ddtms[0];
result:= FindDTMRotated(d, x, y, MMX1, MMY1, MMX2, MMY2, -Pi/6, Pi/6, 0.05, e);
if result then
begin
//Calculate our position offsets
dx:= MMCX - x;
dy:= MMCY - y;
//Determine action based on these offsets
//pipe
if dy > 38 then
begin
action:= 'pipe';
Exit;
end;
//swing
if (dx > 27) and (dy < 0) and (dy > -40) then
begin
action:= 'swing';
Exit;
end;
//lava
if (dx > -5) and (dy < -35) then
begin
action:= 'lava';
Exit;
end;
//log
if (dx < 20) and (dy > -35) and (dy < 25) then
begin
action:= 'log';
Exit;
end;
//cliff
if (dy > 0) and (dy < 38) and (dx < 0) then
begin
action:= 'cliff';
Exit;
end;
end;
end;
procedure AddArray(var a: TIntegerArray; v: integer);
var i: integer;
begin
for i:=0 to high(a) do
if a[i] = v then
exit;
setLength(a, length(a) + 1);
a[high(a)] := v;
end;
procedure SetupInventory;
var i, x, y: integer;
tb: TBox;
begin
setLength(foodslots, 0);
for i:=1 to 28 do
if ExistsItem(i) then
begin
tb:= InvBox(i);
if FindDTM(food, x, y, tb.X1, tb.Y1, tb.X2, tb.Y2) then
AddArray(foodslots, i);
end;
end;
procedure EatFood;
var hp: integer;
temp: string;
begin
if not LoggedIn then Exit;
FindNormalRandoms;
hp:= getMMLevels('hp', temp);
if hp <= HEAL_AT then
begin
writeln('HP low');
if length(foodslots) = 0 then
begin
writeln('No food');
Exit;
end;
MouseItem(foodslots[0], mouse_left);
wait(500+random(250));
SetupInventory;
end;
end;
function EscapeDungeon: boolean;
var tpa: TPointArray;
r, a, x, y: integer;
begin
if not LoggedIn then Exit;
result := false;
FindNormalRandoms;
//Eat
if InDungeon then
begin
writeln('Player in dungeon. Trying to escape...');
wasInDung:= true;
// FindMMColorsSpiralTolerance(tpa, 123, 456); //ladder
// if length(tpa) < 100 then
if true then
begin
r:= randomRange(65, 72);
a:= randomRange(60, 75);
Mouse(MMCX + round(r*cos(a*pi/180.0)), MMCY -round(r*sin(a*pi/180.0)), 4, 4, mouse_left);
wait(2000+random(500));
while IsMoving do
wait(100+random(50));
end;
{ FindMMColorsSpiralTolerance(tpa, 123, 456); //find Ladder again
if length(tpa) > 100 then
begin
MiddleTPAEx(tpa, x, y);
Mouse(x, y, 4, 4, mouse_left);
wait(1000+random(500));
while IsMoving do
wait(100+random(50));
end;
}
result:=ObjFindW(courseObjs[5]);
if result then
if WaitFunc(@InSurface, 500, 5000) then
begin
result:=true;
wait(1000+random(250));
end
else
result:=false;
end;
end;
function CheckObstacle(success, fail: string): boolean;
var t: integer;
begin
result:= false; //silent update 2
if FindBlackChatMessage(success) or FindBlackChatMessage(fail) then
wait(5000);
MarkTime(t);
repeat
if FindBlackChatMessage(success) then
begin
result:= true;
break;
end;
if FindBlackChatMessage(fail) then
begin
result:= false;
break;
end;
wait(500+random(150));
until TimeFromMark(t) > 10000;
if timefrommark(t) <= 10000 then
if result then
writeln('success message detected!')
else writeln('failure message detected!')
end;
function DoObstacleEx(location: string): boolean;
var obj, initXP, lastXP, t: integer;
v: TVariantArray;
begin
if not LoggedIn then Exit;
result := false;
FindNormalRandoms;
initXP := getXPBarTotal;
writeln('init xp is ' + inttostr(initxp));
case location of
'pipe' : obj:= 0;
'swing' : obj:= 1;
'lava' : obj:= 2;
'log' : obj:= 3;
'cliff' : obj:= 4;
end;
writeln(obj);
result := ObjFindW(courseObjs[obj]);
if result then
begin
case location of
'lava' : begin
Wait(1000);
result:= CheckObstacle('safe', 'fall');
if not result then
begin
wait(1000+random(250));//stall the animation
Exit;
end;
end;
'log' : begin
result:= CheckObstacle('skil', 'fall');
if not result then
if WaitFunc(@InDungeon, 500, 5000) then
Exit
else result:= true; //false positive!
end;
'swing': begin
MarkTime(t);
repeat
if ClickContinue(true, true) then //someone is using
begin
result:=false;
Exit;
end;
if FindBlackChatMessage('wing') then //success
begin
writeln('success');
result:=true;
break;
end;
if InDungeon then //Fell into pit
begin
writeln('failure');
result:=false;
WaitFunc(@InDungeon, 500, 2000); //improve walking
Exit;
end;
wait(500+random(150));
until TimeFromMark(t) > 10000;
end;
end;
end;
if result then
begin
MarkTime(t);
repeat
lastXP:= GetXPBarTotal;
wait(100+random(100));
until (TimeFromMark(t) > 10000) or (lastXP > initXP);
if (TimeFromMark(t) <= 15000) then
writeln('XP gain detected!');
case location of
'swing': wait(2000+random(500));
'log' : wait(1000+random(500));
end;
end;
end;
function DoObstacle(location: string): boolean;
var obj, dx, dy: integer;
p: TPoint;
v: TVariantArray;
begin
if not LoggedIn then Exit;
result := false;
FindNormalRandoms;
EatFood;
//Immediate Exit if we're in dungeon
if ((location = 'log') or (location = 'swing')) and InDungeon then
begin
result:= false;
exit;
end;
//Now just try to do it
if (location <> 'pipe') then //this we don't need to relocate
result:= DoObstacleEx(location);
// if ((location = 'swing') or (location = 'log')) and not wasInDung then
// result:= DoObstacleEx(location);
if result then
begin
writeln('DoObstacle: ' + booltostr(result));
Exit;
end;
//Calibrate position because previous find is not successful
if CalibratePositionB(location, p) then
begin
GetLocationOffset(location, dx, dy);
writeln('distance is '+ inttostr(Distance(MMCX, MMCY, p.x+dx, p.y+dy)));
if Distance(MMCX, MMCY, p.x+dx, p.y+dy) > 15 then
begin
CalibratePosition(location);
wait(2000+random(250));
while IsMoving do
wait(50+random(50));
end;
end;
result:= DoObstacleEx(location);
writeln('DoObstacle: ' + booltostr(result));
end;
procedure DoCourse;
var action: string;
begin
action:= 'pipe';
SetupInventory;
ClickNorth(SRL_ANGLE_HIGH);
while LoggedIn do
begin
FindNormalRandoms;
writeln('current action is ' + action);
case action of
'pipe' : begin
if DoObstacle(action) then action := 'swing';
end;
'swing': begin
// if true then
// begin
if DoObstacle(action) then //found success
begin
action:='lava';
wasInDung:= false;
end
else EscapeDungeon;
// end;
end;
'lava' : begin
if DoObstacle(action) then
action:= 'log'
else
writeln('return to lava');//return to starting lava
end;
'log' : begin
if DoObstacle(action) then
begin
action:='cliff';
wasInDung:= false;
end
else EscapeDungeon;
end;
'cliff': begin
if DoObstacle(action) then action:='pipe';
ProgressReport(startXP);
end;
'dung': begin //failsafe if lost
if EscapeDungeon then
action:='lava';
end;
end;
EatFood;
wait(500+random(250));
end;
end;
procedure FreeDTMz;
begin
FreeDTM(food);
end;
var d,x, y: integer;
e: extended;
begin
Smart_Server := SmartWorld;
Smart_Members := Members;
Smart_Signed := SignedClient;
Smart_SuperDetail := HighDetail;
setupSRL();
DeclarePlayers;
DoLogin;
DeclareDDTM;
ObjDTM_Setup;
food:=DTMFromString(FOOD_DTM);
AddOnTerminate('FreeDTMz');
Reincarnate := true;
DeclareObjects;
d:= ddtms[0];
writeln(booltostr(FindDTMRotated(d, x, y, MMX1, MMY1, MMX2, MMY2, -Pi/6, Pi/6, 0.05, e) ));
ToggleXPBar(true);
startXP:= GetXPBarTotal;
DoCourse;
end.
From the way the script is set up im having difficulties figuring out how to do it, The script did have a logout on death but it didn't really detect death well at all because it would end up in edgeville searching for the exit to the dungeon or similar objects,
So im wondering if its possible to have a universal death detector so that no matter when it is in the script it will do the deathwalker and restart?
Is this possible? Thanks for your help :)