SRL Archive - Help and Support

MTA Project - Alchemists' Playground (Need Logic Help)


DannyRS

2013-01-08 23:38:23

If you have never played the game before click here for a guide

Almost solved it now I think, will update the functions once I put it through its paces and make sure theres no errors :p


So to anyone that wants to help with a community MTA script and is good at puzzels/math/arrays,

I last worked on this at like 5am so if i made a mistake in this post or misunderstood how the mini-game works, then please correct me :)

I made a start (finished functions below this one marked by orange title), but i need help making this function to really finish this:

FindItemCupboardPosition(ItemToFind: String): Integer;

It will get the current chat text to see what item is in the cupboard you are standing at, then work out the cupboard position the item with a value is at(using the function i made to get the current item values below)

The problem is I'm crap with arrays and math, so for example, if you are at cupboard 0, and the item is a rune longsword, then the emerald is at 7, and the leather boots are at 4 (because of the empty cupboards)

If you check the cupboard and it is empty then you check one that is 3+ away from you to guarantee you find something to compare

The items move and can be at any cupboard in the room every shift

I believe the item order throughout the room is always the same:
  1. Leather Boots
  2. Adamant Kiteshield
  3. Adamant Helm
  4. Emerald
  5. Rune LongSword
  6. Empty
  7. Empty
  8. Empty


//Currently completely reapproaching it :)

Functions made so far:

GetPlayerCupboard: Integer;

Finds what cupboard the player is currently at(0-7)

Positions like this:



CheckBox: Array of TBox;
SetLength(CheckBox, 8);
CheckBox[0]:=IntToBox(89, 87, 104, 98);
CheckBox[1]:=IntToBox(89, 104, 104, 114);
CheckBox[2]:=IntToBox(89, 117, 104, 130);
CheckBox[3]:=IntToBox(89, 135, 104, 146);
CheckBox[4]:=IntToBox(121, 135, 136, 146);
CheckBox[5]:=IntToBox(121, 117, 136, 130);
CheckBox[6]:=IntToBox(121, 104, 136, 114);
CheckBox[7]:=IntToBox(121, 87, 136, 98);

Function GetPlayerCupboard: Integer;
Var
MPOS: TPoint;
Res,I: Integer;
Begin
Res:=-1;
MPOS:=SPS_GetMyPos;
For I:= 0 To 7 Do
If (PointInBox(MPOS, CheckBox[I])) Then
Res:=I;
Result:=Res;
End;


WalkToCuboard(ToWalk: Integer): Boolean;

Walks to cupboard 0-7


Function WalkToCupboard(ToWalk: Integer): Boolean;
Var
WalkPOS: TPoint;
I: Integer;
Res: Boolean;
Begin
Res:=False;
Case ToWalk Of
0: WalkPOS:=Point(99, 91);
1: WalkPOS:=Point(99, 107);
2: WalkPOS:=Point(99, 123);
3: WalkPOS:=Point(99, 143);
4: WalkPOS:=Point(127, 139);
5: WalkPOS:=Point(127, 123);
6: WalkPOS:=Point(127, 107);
7: WalkPOS:=Point(127, 91);
End;
If SPS_BlindWalk(WalkPOS) Then
Res:=True;
Result:=Res;
End;

GetAlchItemWithValue(Value: Integer): String;

Returns the item(string) that is at a value(e.g. 30) currently

e.g. For this image

GetAlchItemWithValue(30) = adamant helm



Function GetAlchItemWithValue(Value: Integer): String;
Var
Row,Col,TempValue,Res: Integer;
Begin
Res:=-1;
Col:=64;
For Row:= 0 To 4 Do
Begin
TempValue:=StrToIntDef(GetTextAtExWrap(475, Col, 493, Col+15, 0, 5, 2, 52275, 2, 'StatChars'),0);
If (TempValue = Value) Then
Res:=Row;
Col:=Col+23;
End;
Case Res Of
-1: Result:='nothing';
0: Result:='leather boots';
1: Result:='adamant kiteshield';
2: Result:='adamant helm';
3: Result:='emerald';
4: Result:='rune longword';
End;
End;

Full Script if you want to go to the MTA and try things:



Program SRLAlchemistsPlayground;

{$Define SMART}
{$I SRL/SRL.Simba}
{$I Sps/Sps.Simba}
{$I SRL/SRL/Misc/Debug.Simba}

//Setup
Const

Debug = True; //Debuging Mode

DebugATPAImage = False; //Debuging ATPA Images Mode

DMP = True; // *** If the SPS Map is Not found found,
//Download them and save them automatically,
//you should leave this as true ***


ScriptVersion = 'V1.0';


//LOGIN INFO STUFF
Procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;
Players[0].Name :='';
Players[0].Pass :='';
Players[0].Nick :='';
Players[0].Active:=True;
WORLDSWITCHERENABLED:=False;
end;

//dont touch below here unless you know what you are doing

Var
CheckBox: Array of TBox;
ItemOrder: Array of Integer;
CheckBoxOffMap: TBox;
StartingExperience,XPCheck,PlayerActivityTimer: Integer;

{*******************************************************************************

All of these mouse movements and typing are credited to benland100 and flight.
thanks to Ashaman88 for his awesome scripts, i used his as a template

*******************************************************************************}


//By Bandland100, modified by Ashaman88 to shift mouse speeds after every step
//
procedure SuperWindMouse(xs, ys, xe, ye, gravity, wind, minWait, maxWait, maxStep, targetArea: extended);
var
veloX,veloY,windX,windY,veloMag,dist,randomDist,lastDist,step: extended;
lastX,lastY,MSP,W: integer;
sqrt2,sqrt3,sqrt5: extended;
begin
MSP := MouseSpeed;
sqrt2:= sqrt(2);
sqrt3:= sqrt(3);
sqrt5:= sqrt(5);
while hypot(xs - xe, ys - ye) > 1 do
begin
dist:= hypot(xs - xe, ys - ye);
wind:= minE(wind, dist);
if dist >= targetArea then
begin
windX:= windX / sqrt3 + (random(round(wind) * 2 + 1) - wind) / sqrt5;
windY:= windY / sqrt3 + (random(round(wind) * 2 + 1) - wind) / sqrt5;
end else
begin
windX:= windX / sqrt2;
windY:= windY / sqrt2;
if (maxStep < 3) then
begin
maxStep:= random(3) + 3.0;
end else
begin
maxStep:= maxStep / sqrt5;
end;
end;
veloX:= veloX + windX;
veloY:= veloY + windY;
veloX:= veloX + gravity * (xe - xs) / dist;
veloY:= veloY + gravity * (ye - ys) / dist;
if hypot(veloX, veloY) > maxStep then
begin
randomDist:= maxStep / 2.0 + random(round(maxStep) div 2);
veloMag:= sqrt(veloX * veloX + veloY * veloY);
veloX:= (veloX / veloMag) * randomDist;
veloY:= (veloY / veloMag) * randomDist;
end;
lastX:= Round(xs);
lastY:= Round(ys);
xs:= xs + veloX;
ys:= ys + veloY;

case Random(50) of
1..25: W := (MSP + (Random((MSP/4))));
26..50: W := (MSP - (RandomRange((MSP/2), MSP-1)));
end;
if (W < 1) then
W := 1;

if (lastX <> Round(xs)) or (lastY <> Round(ys)) then
MoveMouse(Round(xs), Round(ys));

step:= hypot(xs - lastX, ys - lastY);
//W := round((maxWait - minWait) * (step / maxStep) + minWait);
wait(W);
lastdist:= dist;
end;

if (Round(xe) <> Round(xs)) or (Round(ye) <> Round(ys)) then
MoveMouse(Round(xe), Round(ye));

MouseSpeed := MSP;
end;

Procedure HumanMMouse(eX, eY, ranX, ranY: Integer);
var
randSpeed: extended;
X,Y,X2,Y2,j,Dist,MP: integer;
begin
j := MouseSpeed;
GetMousePos(X, Y);
Dist := Distance(X, Y, eX, eY);
MP := Round(Dist/150);
if MP < 0 then
MP := 1;

randSpeed := (random(MouseSpeed) / 2.0 + MouseSpeed) / 10.0;
X2 := RandomRange(eX-(j*MP), eX+(j*MP));
Y2 := RandomRange(eY-(j*MP), eY+(j*MP));
SuperWindMouse(X, Y, X2, Y2, 11, 8, 10.0 / randSpeed, 12.0 / randSpeed, 10.0 * randSpeed, 10.0 * randSpeed);
GetMousePos(X, Y);
MMouse(eX, eY, ranX, ranY);
MouseSpeed := j;
end;

Procedure HumanMouseBox(X1, Y1, X2, Y2: Integer);
Var
FX, FY: Integer;
Begin
GaussBox(FX,FY,X1,Y1,X2,Y2);
HumanMMouse(FX,FY,0,0)
End;

{*******************************************************************************
procedure FastClick(button: Integer);
By: Flight
Description: Quickly click the mouse.
*******************************************************************************}
procedure FastClick(button: variant);
var
x, y: integer;
ibutton: Integer;
begin
if VariantIsBoolean(button) then
begin
if (button) then
iButton := mouse_left
else
iButton := mouse_right;
end else
iButton := button;

if (iButton = mouse_move) then Exit;
GetMousePos(x, y);
HoldMouse(x, y, iButton);

Wait(RandomRange(60, 150));

GetMousePos(x, y);
ReleaseMouse(x, y, iButton);
end;

Procedure OffMM(RedTu, LeWait, rWait: Integer);
Var
W,H,RX,RY,T,RT: Integer;
Begin
GetClientDimensions(W,H);
H:=H+50;
RX := RandomRange(0, W);
RY := RandomRange(0, H);
Case (RedTu) Of
0..1: HumanMMouse(W/2, RandomRange(-110,-60), RX, 0);
2: HumanMMouse(RandomRange(-50,-10), H/2, 0, RY);
3: HumanMMouse(W/2, h+RandomRange(10,50), RX, 0);
4: HumanMMouse(W+RandomRange(10,50), H/2, 0, RY);
End;
RT:=(Random(rWait));
MarkTime(T);
Repeat
Wait(Random(100));
Until TimeFromMark(T)>(LeWait+RT);
End;

Procedure UseKey(Text: String);
Var
I: Integer;
Begin
For I:=1 To Length(Text) Do
SendKeys(Text[I],RandomRange(90,160),RandomRange(90,160));
Wait(RandomRange(10,50));
End;

Function WaitLoggedIn(Time:Integer): Boolean;
Var
T: Integer;
Begin
MarkTime(T);
Repeat
SRL_ResetNavBar;
If TimeFromMark(T)>Time Then
Begin
Result:=False;
Exit;
End;
Until (GetColor(472, 490) = 16777215);
Result:=True;
End;

//
{*******************************************************************************

DannyRS's Part

*******************************************************************************}
//

Procedure LeftClickSpot(X1, Y1, X2, Y2: Integer);
var Y1NOBanner, Y2NOBanner: Integer;
Begin
Y1NOBanner:=Y1 - 50; Y2NOBanner:=Y2 - 50;
HumanMMouse(RandomRange(X1,X2),RandomRange(Y1NOBanner,Y2NOBanner),0,0);
Wait(9+Random(37));
FastClick(True);
Wait(124+Random(163));
End;

Procedure RightClickSpot(X1, Y1, X2, Y2: Integer);
var Y1NOBanner, Y2NOBanner: Integer;
Begin
Y1NOBanner:=Y1 - 50; Y2NOBanner:=Y2 - 50;
HumanMMouse(RandomRange(X1,X2),RandomRange(Y1NOBanner,Y2NOBanner),0,0);
Wait(9+Random(37));
FastClick(False);
Wait(124+Random(163));
End;

Procedure DragMouseSpot(X1, Y1, X2, Y2: Integer);
var Y1NOBanner, Y2NOBanner: Integer;
Begin
Y1NOBanner:=Y1 - 50; Y2NOBanner:=Y2 - 50;
Wait(150+Random(600));
HumanMMouse(RandomRange(X1,X2),RandomRange(Y1NOBanner,Y2NOBanner),0,0);
Wait(9+Random(37));
End;

Procedure ClickCurrent(ToDo: Boolean);
Begin
Wait(7+Random(37));
FastClick(ToDo);
Wait(124+Random(163));
End;

Procedure DeBugMessage(ToWrite: String);
Begin
If(Debug)Then
Writeln(ToWrite);
End;

Procedure LogOutGame;
Var
x, y: Integer;
Begin
LeftClickSpot(750, 55, 760, 65);
LeftClickSpot(575, 405, 710, 420);
End;

Procedure MinimizeEoCBar(ToDo: Boolean);
Var x, y: Integer;
Begin
If (ToDo) Then
If (FindColorTolerance(x, y, 13224393, 517, 263, 517, 263, 5)) Then
LeftClickSpot(505,318,510,324);
If (Not ToDo) Then
If (Not FindColorTolerance(x, y, 13224393, 517, 263, 517, 263, 5)) Then
LeftClickSpot(505,382,510,385);
End;

Function GetPlayerCupboard: Integer;
Var
MPOS: TPoint;
Res,I: Integer;
Begin
Res:=-1;
MPOS:=SPS_GetMyPos;
For I:= 0 To 7 Do
If (PointInBox(MPOS, CheckBox[I])) Then
Res:=I;
Result:=Res;
End;

Function GetAlchItemWithValue(Value: Integer): String;
Var
Row,Col,TempValue,Res: Integer;
Begin
Res:=-1;
Col:=64;
For Row:= 0 To 4 Do
Begin
TempValue:=StrToIntDef(GetTextAtExWrap(475, Col, 493, Col+15, 0, 5, 2, 52275, 2, 'StatChars'),0);
If (TempValue = Value) Then
Res:=Row;
Col:=Col+23;
End;
Case Res Of
-1: Result:='nothing';
0: Result:='leather boots';
1: Result:='adamant kiteshield';
2: Result:='adamant helm';
3: Result:='emerald';
4: Result:='rune longword';
End;
End;

Function FindItemCupboardPosition(ItemToFind: String): Integer;
Var
ItemCupboardPOS,Count,FoundItemPOSInOrder,Row,Col,TempValue,Res,FoundItem,CheckItem: Integer;
Begin
Res:=-1;
Case GetBlackChatMessage Of
'You found? Leather boots': FoundItem:=0;
'You found? Adamant kiteshield': FoundItem:=1;
'You found? Adamant helm': FoundItem:=2;
'You found? Emerald': FoundItem:=3;
'You found? Rune longsword': FoundItem:=4;
'The cupboard is empty': FoundItem:=-2;
'You have no free space to hold any more items': FoundItem:=-1;
End;
Case ItemToFind Of
'leather boots': CheckItem:=0;
'adamant kiteshield': CheckItem:=1;
'adamant helm': CheckItem:=2;
'emerald': CheckItem:=3;
'rune longword': CheckItem:=4;
End;
For Count:=0 To 7 Do
If FoundItem = ItemOrder[Count] Then
FoundItemPOSInOrder:=ItemOrder[Count];

Result:=Res;
End;

Function WalkToCupboard(ToWalk: Integer): Boolean;
Var
WalkPOS: TPoint;
I: Integer;
Res: Boolean;
Begin
Res:=False;
Case ToWalk Of
0: WalkPOS:=Point(99, 91);
1: WalkPOS:=Point(99, 107);
2: WalkPOS:=Point(99, 123);
3: WalkPOS:=Point(99, 143);
4: WalkPOS:=Point(127, 139);
5: WalkPOS:=Point(127, 123);
6: WalkPOS:=Point(127, 107);
7: WalkPOS:=Point(127, 91);
End;
If SPS_BlindWalk(WalkPOS) Then
Res:=True;
Result:=Res;
End;

Procedure ProgressReport;

Var
XP, XPH, PointsPH: Integer;

Begin
ClearDebug;

If (GetXPBarTotal > XPCheck) Then
MarkTime(PlayerActivityTimer);
XPCheck:= GetXPBarTotal;

XP := (XPCheck - StartingExperience);
XPH := Round(XP * (3600.0 / (GetTimeRunning / 1000.0)));

Writeln('=========SRL-MTA-AP=========================');
Writeln('=========Version: '+ScriptVersion+'=======================');
Writeln('Time Running: ' + TimeRunning);
Writeln('Experience Earned: ' + IntToStr(XP));
Writeln('Experience / Hour: ' + IntToStr(XPH));
Writeln('=============================================');
End;

Procedure MainLoop;
Var
x, y: Integer;
Done,Check: Boolean;
MPOS: TPoint;
num: Integer;
txt: String;
Begin
//Writeln('Welcome to SRL Alchemists Playground');
//Writeln('Start Experience: ' + IntToStr(GetXPBarTotal));
//Pause Before Start Script
//Writeln('Starting in 3...');
//Wait(1000);
//Writeln('Starting in 2...');
//Wait(1000);
//Writeln('Starting in 1...');
//Wait(1000);
MarkTime(PlayerActivityTimer);
//XPCheck:= GetXPBarTotal;

Repeat Begin
Done:= False;
Check:= False;

Writeln(GetAlchItemWithValue(30));
Writeln(IntToStr(GetPlayerCupboard));
Writeln(GetBlackChatMessage);

Done:=True; //DeBuging Only
DeBugMessage('Reached End of Main Loop');
End; Until (Done);
End;


{*******************************-CREDIT-***************************************

All Credit To Ashaman and where ever he learned it, For the map grabbing !!

*******************************************************************************}

Procedure DownloadSPSImage(ImageName: String; Location: String);
Var
Image, Path: string;
FP: Integer;
Begin
If(Debug)Then Begin Writeln('Downloading SPS Map Image'); End;
Image:= GetPage(Location);
Path:= IncludePath + 'SPS\img\runescape_other\' + ImageName + '.png';
Path:= Trim(Path);
FP:= CreateFile(Path);
WriteFileString(FP, Image);
CloseFile(FP);
End;

Function GrabSPSMaps: Boolean;
Var
SPSMMap,SPSMName: String;
Begin
SPSMName:= 'DRAPGSPS';

SPSMMap:= 'http://img33.imageshack.us/img33/9949/drapgsps.png';

If DMP Then
Begin
If (Not FileExists(IncludePath + 'SPS\img\runescape_other\DRAPGSPS.png')) Then
DownloadSPSImage(SPSMName, SPSMMap);
End;
Result:= (FileExists(IncludePath + 'SPS\img\runescape_other\DRAPGSPS.png'));
End;

Procedure RequirementsCheck;
Begin
If (Not GrabSPSMaps) Then
RaiseException(erCustomError, 'SPS Maps Do Not Exist OR They Are Named Incorrectly!');
End;

Procedure SetMyGlobals;
Var Count: Integer;
Begin
if(Debug)then begin
Writeln('Loading Globals'); end;
SetLength(ItemOrder, 8);
SetLength(CheckBox, 8);

For Count:=0 To 7 Do
ItemOrder[Count]:=Count;

CheckBox[0]:=IntToBox(89, 87, 104, 98);
CheckBox[1]:=IntToBox(89, 104, 104, 114);
CheckBox[2]:=IntToBox(89, 117, 104, 130);
CheckBox[3]:=IntToBox(89, 135, 104, 146);
CheckBox[4]:=IntToBox(121, 135, 136, 146);
CheckBox[5]:=IntToBox(121, 117, 136, 130);
CheckBox[6]:=IntToBox(121, 104, 136, 114);
CheckBox[7]:=IntToBox(121, 87, 136, 98);
CheckBoxOffMap:=IntToBox(-2, -2, 1, 1);

End;

Procedure FreeMyGlobals;
Begin

End;

Procedure PollPos;
Var Done: Boolean;
Begin
Repeat
Begin
Writeln(toStr(SPS_GetMyPos));
Wait(1000+Random(50));
End;
Until Done;
End;

Procedure Setup;
Begin

{$IFDEF SIMBAMAJOR980}
SMART_SERVER := 10;
SMART_MEMBERS := TRUE;
SMART_SIGNED := TRUE;
SMART_SUPERDETAIL := FALSE;
SRL_SIXHOURFIX := TRUE;
{$ELSE}
SRL_SIXHOURFIX := TRUE;
SMART_FIXSPEED := TRUE;
{$ENDIF}

SetupSRL;

ClearDebug;

DeclarePlayers;

RequirementsCheck;

SPS_Setup(RUNESCAPE_OTHER, ['DRAPGSPS']);

If Not LoggedIn Then
Begin
Writeln('Not In-Game Trying Log-In');
If Not WaitLoggedIn(1000) Then
LoginPlayer;
Wait(1583+Random(3293));
End;

//ClickNorth(SRL_ANGLE_HIGH);

//ToggleXPBar(True);
//StartingExperience := GetXPBarTotal;

MinimizeEoCBar(False);

MarkTime(PlayerActivityTimer);

SetMyGlobals;

AddOnTerminate('FreeMyGlobals');

SmartSetRefresh(90);
End;

begin
Setup;
ActivateClient;
ClearDebug;
//PollPos;
MainLoop;
//LogOutGame;
end.

Awkwardsaw

2013-01-13 16:35:04

Do you think looking at the logic that I used for my reflection script would help?

anyways, here it is(Might be hard to read, lol):
const
I_BOOTS = 0;
I_SHIELD = 1;
I_HELM = 2;
I_EMERALD = 3;
I_SWORD = 4;

C_BOOTS = 9;
C_SHIELD = 10;
C_HELM = 11;
C_EMERALD = 12;
C_SWORD = 13;

function GetItemToAlch : integer; //finds item that is valued 30 gp
var
i : integer;
childarr : TIntegerArray;
amount : string;
begin
result := -1;
childarr := [C_BOOTS, C_SHIELD, C_HELM, C_EMERALD, C_SWORD];
for i := I_BOOTS to I_SWORD do
begin
amount := R_GetInterfaceText(194, childarr[i])
if amount = '30' then
result := i;
end;
end;



function A_Relocate(tile : ttile; uptext : TStringArray) : boolean; //walks + clicks tile
begin
if not R_TileOnMS(Tile,0) then
if not R_TileOnMM(Tile) then
r_WindWalk(tile)
else
R_WalkToTile(tile, 0, 0);
while ismoving do wait(100);
MouseTileUptext(Tile, 2, 4, true, uptext)
while ismoving do wait(100);
result := TileOnMS(Tile, 0);
end;

function DepositCoins(checkcoins : boolean) : boolean; //deposit coins if you have enough
var
item : TInvItem;
depositobj : TRSObject;
begin
result := true;
if checkcoins then
begin
writeln('checking coins');
if R_ItemExists('Coins', Item) then
if item.StackSize < 1000 then
exit
else
if not inrange(item.StackSize mod 100, 0, 18) then
exit;
end;
depositobj := GetObjectByIDEx([alchemy_deposit], 0, 30);
if not a_relocate(depositobj.Tile, ['eposit', 'oin', 'ollector']) then
begin
result := false;
exit;
end;
while not ClickToContinue do wait(10);
result := true;
end;

function CanAlch : boolean; //true = item in inventory worth 30 gp
var
itemtoalch : Integer;
idarr : TIntegerArray;
begin
itemtoalch := GetItemToAlch;
idarr := [boots_inv, shield_inv, helm_inv, emerald_inv, sword_inv];
result := R_CountItem(idarr[itemtoalch]) > 0;
end;

function findalchitem : boolean; //fills inventory with items, hopefully not to much of one item
var
CupboardIDs1, CupboardIDs2: TIntegerArray;
ri, ri1, c, itemtoalch, i, a, d, resets : integer;
cupboard : TRSObject;
text : string;
TextArr : TStringArray;
b, f : boolean;
label
here, comeback;
begin
result := false;

resets := 0;

cupboardIDs1 := [10783, 10785, 10787, 10789, 10791, 10793, 10795, 10797]; //cupboard id when closed
cupboardIDs2 := [10784, 10786, 10788, 10790, 10792, 10794, 10796, 10798]; //cupboard id when open

here:
if CanAlch then //if can alch exit, no need to waste time if you can :)
begin
result := true;
exit;
end;
if R_InvFull then //^ usually means that inv full, but no items that you can alch.
begin
result := true;
exit;
end;

inc(c); //failsafe, don't repeat loop to much
if c > 15 then
begin
a_debug('attempted to find starting cupboard to many times, reseting');
depositcoins(false);
exitarena;
reenterarena;
c := 0;
inc(resets);
if resets > 2 then
begin
result := false
a_debug('Reset twice, terminating');
ExitArena;
TerminateScript;
end;
goto here;
end;

if CanAlch then //if can alch exit, no need to waste time if you can :)
begin
result := true;
exit;
end;

ri := random(high(cupboardids1)); //random index for cupboard array,
writeln('1 ri ' + inttostr(ri)); //used to find a random cupboard

itemtoalch := GetItemToAlch; //gets the current item that is valued at 30gp

a := 0; //resets a
comeback:

inc(a); //failsafe

b := false; //resets
try
cupboard := GetObjectByIDEx([cupboardIDs1[ri], cupboardIDs2[ri]], 0, 30); //finds random cupboard
except
a_debug('out of range avoided, reseting random index');
//goto here;
end;
if not A_Relocate(cupboard.Tile, ['earch', 'Cupboard']) then //goes to cupboard, takes item
if reenterarena then
goto here //if it is out of arena, and re-enters arena, it starts procedure over
else
begin
a_debug('For some reason cannot enter arena. terminating');
logout;
terminatescript;
end;

r_WaitToMove(2000);
while R_Moving or R_Animating do wait(1000); //waits to go to cupboard, and take item
wait(1000 + random(500));


text := GetBlackChatMessage; //gets last system message
TextArr := ['boots', 'kiteshield', 'helm', 'Emerald', 'longsword', 'empty']; //possible items in cupboard

for i := 0 to high(textarr) do //loops through to find item in TextArr in 'text'
begin
if Pos(textarr[i], text) > 0 then //if it finds item in text
begin
if i < high(textarr) then
begin
writeln(i);
i := i - GetItemToAlch;
writeln('i ' + inttostr(i)); //try to relocate cupboards, doesnt really work
ri1 := ri - i;
if ri1 > high(cupboardIDs1) then
ri1 := (ri1 - ri) + ri;
if ri1 < 0 then
ri1 := (ri1 * -1) - high(cupboardIDs1);
writeln('ri ' + inttostr(ri));
//break;
end;
if i = high(textarr) then
begin
f := true;
break;
end;
if ri = ri1 then
begin //if cupboard item = alch item, get 6 more of them
for d := 0 to 5 do
begin

if r_invfull then
begin
result := true;
exit;
end;
MouseTileUptext(cupboard.Tile, 4, 4, true, ['pen', 'earch', 'oard']);
wait(200 + random(300));
end;
end;

ri := ri1; //sets new cupboard index

if a <= 5 then //if the item valued 30 hasnt changed, and this is no more than the 5th loop
b := true //it restarts the comehere: loop
else
c := 0; //if it already looped 5 times, or the item changed, restart the procedure

//writeln(TextArr[i]);
if CanAlch then //if can alch exit, no need to waste time if you can :)
begin
result := true;
exit;
end;
break; //breaks out of loop if it found the item
end;
end;
if f then goto here;
if b then goto comeback;
goto here;

end;

function waittoalch : boolean; //waits about 1min to alch if inv full, and cannot alch
var
t : integer;
begin
marktime(t);
writeln('Invfull, cannot alch any items. waiting about 1min');
while (TimeFromMark(t) < (1000 * randomrange(50, 70))) or not canalch do
begin
if canalch then break;
akwardantiban;
end;
result := canalch;
end;

function alch : boolean; //alchs items that = 30 gp
var
idarr : TIntegerArray;
b : boolean;
begin
b := false;
idarr := [boots_inv, shield_inv, helm_inv, emerald_inv, sword_inv];
//R_ItemExistsEx(idarr, invitem);
gametab(tab_magic);
repeat
result := false;
writeln(0);
if not Cast(spellused, false) then
begin
a_debug('Cannot cast spell, attempting to deposit money and then leave');
result := false;
depositcoins(false);
ExitArena;
logout;
exit;
end;


wait(200 + random(300));
writeln(GetUpText);
if IsUpTextMultiCustom(['Cast','evel', 'Level', 'Alchemy', 'ow', 'igh']) then
begin
writeln(1);
//b := R_InvCount < 16;
if not canalch then
begin
if r_invcount < 23 then
begin
a_debug('done alching, exiting now');
result := true;
exit;
end else
if not waittoalch then
begin
depositcoins(false);
//exitarena;
//reenterarena;
result := true;
exit;
end;
end;
R_ClickItemBy(idarr[GetItemToAlch], 'Cast');
wait(800 + random(700));
//while not GetCurrentTab = tab_Magic do wait(10);
//wait(100);
stats_IncVariable('Magic EXP (Gained)', round(Main.exp));
exp := exp + main.exp;
end;
result := true;
until b;

end;

function AlchemyMainLoop : boolean;
var
done, points1, points2, time : integer;
col : TColor;
me :TPlayer;
begin
marktime(time);
if getpoints >= Players[currentplayer].Integers[0] then
begin
result := true;
alchemyp := getpoints;
exitarena;
exit;
end;
repeat

result := false;
points1 := getpoints;
col := RGBtoColor(3, 237, 232);
me := R_GetMe;
PrintOnSmart(['Time running: ' + TimeRunning,
'Points gained: ' + inttostr(getpointsgained),
'Loads done: ' + inttostr(done),
'Current Level: ' + inttostr(R_GetSkillLevel(SKILL_MAGIC)),
'Points/H: ' + inttostr(floor(NumPerHour(getpointsgained))),
'EXP/H: ' + inttostr(floor(NumPerHour(exp)))], point(5, 5), col);
writeln('Item to alch: ' + inttostr(GetItemToAlch));
if not FindAlchItem then exit;
if not alch then exit;
AkwardAntiBan;
writeln('hello');
if not DepositCoins(true) then
exit
else
if timefrommark(time) > 1000 * 60 * 6 then
begin
if stats_Commit then
begin
a_debug('Commited to stats');
marktime(time);
end;
end;
result := true;
points2 := getpoints;
stats_IncVariable('Alchemy Points (Gained)', points2 - points1);

inc(done);
alchemyp := getpoints;
PrintProgress;
until getpoints >= Players[currentplayer].Integers[0];
ExitArena;
end;

DannyRS

2013-01-13 22:41:35

From: Awkwardsaw
Do you think looking at the logic that I used for my reflection script would help?



EDIT - NEED A PARTNER WHO HAS EXPERIENCE HOW TO DO THIS ROOM EFFICIENTLY THEN I'LL FINISH ROOM

Think i got it:

cba atm to finish room tho, heres two more functions


Function FindItemCupboardPosition(ItemToFind,ChatMessage: String): Integer;
Var
CupboardPosition,FCounts,SCounts,I,Res,AddValue: Integer;
FoundItem: String;
FoundItemDistance,FoundCupboardPosition: Boolean;
Begin
Res:=-1;
FCounts:=0;
SCounts:=0;
I:=0;
Case ChatMessage Of
'Leather boots': FoundItem:='leather boots';
'Adamant kiteshield': FoundItem:='adamant kiteshield';
'Adamant helm': FoundItem:='adamant helm';
'Emerald': FoundItem:='emerald';
'Rune longsword': FoundItem:='rune longsword';
'rrd is empty': FoundItem:='nothing';
'o free space to hold any more items': FoundItem:='nothing';
End;
Case FoundItem Of
'leather boots': I:=4;
'adamant kiteshield': I:=3;
'adamant helm': I:=2;
'emerald': I:=1;
'rune longsword': I:=0;
End;
Writeln('We Found ' + FoundItem);
Writeln('Looking For ' + ItemToFind);
Writeln('Item Is At ' + IntToStr(I) + ' In OrderList');

Repeat Begin
Writeln('Count Is At ' + IntToStr(FCounts));
If ItemToFind = ItemOrder[I+FCounts] Then
Begin
FoundItemDistance:=True;Writeln('Matched At ItemOrder[' + IntToStr(I+FCounts) + '] [' + ItemOrder[I+FCounts] + ']');
End
Else
FCounts:=FCounts+1;
If I+FCounts = 8 Then
Begin
SCounts:=FCounts;
I:=0;FCounts:=0;
End;
End; Until (FoundItemDistance)
AddValue:=FCounts+SCounts;
Writeln('Item Is ' + IntToStr(AddValue) + ' Positions To The Right');
Writeln('We Are At ' + IntToStr(GetPlayerCupboard));
CupboardPosition:=GetPlayerCupboard+AddValue;
If CupboardPosition > 7 Then
CupboardPosition:=CupboardPosition-8;
Res:=CupboardPosition;
Writeln('Item Is At ' + IntToStr(Res));
Result:=Res;
End;

Procedure SetMyGlobals;
Var Count: Integer;
Begin
if(Debug)then begin
Writeln('Loading Globals'); end;
SetLength(ItemOrder, 8);
SetLength(CheckBox, 8);

ItemOrder[0]:='rune longsword';
ItemOrder[1]:='emerald';
ItemOrder[2]:='adamant helm';
ItemOrder[3]:='adamant kiteshield';
ItemOrder[4]:='leather boots';
ItemOrder[5]:='empty cupboard';
ItemOrder[6]:='empty cupboard';
ItemOrder[7]:='empty cupboard';

CheckBox[0]:=IntToBox(89, 135, 104, 146);
CheckBox[1]:=IntToBox(89, 117, 104, 130);
CheckBox[2]:=IntToBox(89, 104, 104, 114);
CheckBox[3]:=IntToBox(89, 87, 104, 98);
CheckBox[4]:=IntToBox(121, 87, 136, 98);
CheckBox[5]:=IntToBox(121, 104, 136, 114);
CheckBox[6]:=IntToBox(121, 117, 136, 130);
CheckBox[7]:=IntToBox(121, 135, 136, 146);
CheckBoxOffMap:=IntToBox(-2, -2, 1, 1);

End;



Function FindObjReturnBounds(HM, SM, TOL, COL, VD: Variant):Tbox;
Var
tmpCTS:integer;
CustomObjTPA:TPointArray;
CustomObjATPA:T2DPointArray;
TB:Tbox;
Begin
tmpCTS := GetToleranceSpeed;

SetColorToleranceSpeed(2);
SetToleranceSpeed2Modifiers(HM, SM);
FindColorsTolerance(CustomObjTPA, COL, MSCX-65, MSCY-40, MSCX+65, MSCY+40, TOL);
SplitTPAWrap(CustomObjTPA, VD, CustomObjATPA);
SortATPAFrom(CustomObjATPA, Point(MSCX, MSCY));

//If DebugATPAImage Then
//DebugATPABounds(CustomObjATPA);

SetColorToleranceSpeed(tmpCTS);
SetToleranceSpeed2Modifiers(0.02, 0.02);

//return largest ATPA on screen
TB := GetTPABounds(CustomObjATPA[0]);

Result:=TB;
End;

Function ClickCupboard: Boolean;
Var
tmpCTS, i, l,counter:integer;
CustomObjTPA:TPointArray;
CustomObjATPA:T2DPointArray;
x,y:integer;
TB:Tbox;
Begin
TB := FindObjReturnBounds(0.00,0.07,16,6842479,50);
tmpCTS := GetToleranceSpeed;

SetColorToleranceSpeed(2);
SetToleranceSpeed2Modifiers(0.38, 0.17);

FindColorsTolerance(CustomObjTPA, 9607832, TB.X1+5, TB.Y1, TB.X2-5, TB.Y2, 11);

SplitTPAExWrap(CustomObjTPA, 10, 20, CustomObjATPA);
SortATPASize(CustomObjATPA,True);
SortATPAFrom(CustomObjATPA, Point(MSCX, MSCY));

If DebugATPAImage Then
DebugATPABounds(CustomObjATPA);

SetColorToleranceSpeed(tmpCTS);
SetToleranceSpeed2Modifiers(0.02, 0.02);

L := High(CustomObjATPA)
MarkTime(Counter);
for i := 0 to L do
begin
MiddleTPAEx(CustomObjATPA[i], x, y);
HumanMMouse(RandomRange(x-5,x+5), RandomRange(y-5,y+8), 0, 0);

If (WaitUptextMulti(['earch','upboard','ard','ston','ppin'], RandomRange(300,400))) Then
Begin
DebugMessage('We Saw The Cupboard, Clicking');
ClickCurrent(True);
Result:=True;
Exit;
End;

Wait(RandomRange(30, 160));

if (TimeFromMark(Counter) > 1300) then
begin
if(Debug)then begin Writeln('We Failed to See The Cupboard Stones'); end;
Break;
end;
end;
Result:=False;
End;