SRL Archive - OSR Help

help with procedure


weby

2010-09-02 01:24:17

procedure Cast;
begin
GameTab(28);
if not FindDTMRetry(Enchant, x, y, 556, 214, 731, 426, 0) then
restart('more runes');
begin
Mouse(x, y, 3, 3, True);
Wait(100 + Random(100));
if not FindDTMRetry(diamond, x, y, 560, 210, 725, 317, 0) then
restart('need diamond amulet');
Mouse(x, y, 10, 10, True);
end;
end;

this is what happens, it runs but will only cast the 1st amulet and keep casting on the 1st amulet.. i would like it to cast on the rest of the amulets :P

Blumblebee

2010-09-02 01:42:14

From: weby
procedure Cast;
begin
GameTab(28);
if not FindDTMRetry(Enchant, x, y, 556, 214, 731, 426, 0) then
restart('more runes');
begin
Mouse(x, y, 3, 3, True);
Wait(100 + Random(100));
if not FindDTMRetry(diamond, x, y, 560, 210, 725, 317, 0) then
restart('need diamond amulet');
Mouse(x, y, 10, 10, True);
end;
end;

this is what happens, it runs but will only cast the 1st amulet and keep casting on the 1st amulet.. i would like it to cast on the rest of the amulets :P


Try FindDTMs() or alternatively you can search each slot for the DTM instead of the entire Inventory, as it's finding the closest which is slot one.

Meaning you need to do something like…


for I := 1 to 28 do
begin
m := InvBox(I);
FindDTMRetry(x, y, DTM, M.x1, M.y1, M.x2, M.y2, etc);
end;

or…


var
TPA: tPointArray;
begin
FindDTMS(TPA, DTM, MIx1, MIy1, MIx2, MIy2, etc);
for I := 0 to high(TPA) do
begin
// click each DTM
end;
end;

make sense?

weby

2010-09-02 01:57:38

ok but the dtm for power and diamd amulet are the same :P how would i add upchecktext?

Heavenguard

2010-09-02 02:18:55

Lol UpText is very simple. As blumblebee said, move the mouse onto the DTM. Then call this line.

 
if (WaitUpText({Object UpText}, RandomRange(200, 400))) then
//Do What You Want :D
There are several functions for checking uptext :D

There are plenty of ways of making it know which amulet it is, just gotta use your imagination :)

As for Casting on each amulet, just take your time and think it through :D


function FindItemsInInventory(ItemDTMs:TIntegerArray): TIntegerArray; // ItemDTM's will be the Item DTMs :D The Result will be the slot numbers of all the items it found.
var
a, i, X, Y: Integer;
InventorySlot: TBox;
SlotsFound: Integer;
begin
SlotsFound := 0;
for I := 1 to 28 do // 28 inventory slots. starting from the 1st...
begin
InventorySlot := InvBox(I); // gets the inv slot.
{scans the slot for each dtm in the array}
for a := 0 to High(DTM) do
if FindDTM(ItemDTMs[a], X, Y, InventorySlot.X1, InventorySlot.Y1, InventorySlot.X2, InventorySlot.Y2) then
begin
{SlotsFound is simply used to set the result array length}
Inc(SlotsFound);
SetLength(Result, SlotsFound); // Sets the Results Length to the amount of items it found.
Result[SlotsFound - 1] := i; // saves the slot number to the result array.
Break; // Breaks out of the loop since we can only have 1 item in each slot.
end;
end;
end;

function CastOnAllAmulets(SpellName: string): Boolean;
var
a, CGT: Integer; // CGT = Current Game Tab.
i: TBox; // Used for inventory slots.
AmuletDTM: Integer; // amulet DTM.
Amulets: TIntegerArray; // Our slot array.
begin
{Setup}
CGT := GetCurrentTab;
GameTab(25);
Amulets := FindItemsInInventory([AmuletDTM]); // Saves the Slot Numbers of all the amulets.

{Attempts to cast spell}
try // I like using Try loops ^^.
for a := 0 to High(Amulets) do
begin
{Search for items}
i := InvBox(Amulets[a]); // Gets the Inventory slot of our amulet.
GameTab(28); // switches to magic tab.

{Attempt To Cast Spell}
Result := Cast(SpellName, False); // casts spell.
if (not(Result)) then
begin
srl_Warn('CastOnAllAmulets', 'Failed to activate spell ' +SpellName, 0);
Exit;
end;

{Uhm.. Casts the spell on the item?? I think <.<}
GameTab(25); // switches back to Inv.
MouseBox(i.X1, i.Y1, i.X2, i.Y2, 1); // I dunno how enchanting/magic works =P But MouseBox clicks on a random point in a TBox, so this should work.. i think =/ lol
end;
finally // Regardless of what happens..
GameTab(CGT); // Switch back to the initial gametab.
end;

end;

Just an example, i don't know if that will compile or not xD, or if that will work in theory, but its just to give some ideas :P. Plenty of ways of doing this :D. Blumblebee's methods work very well for this situation ^^. Pretty much any method for anything can do a job :D just make your you failsafe it ^^.

i luffs yeww

2010-09-02 02:20:21

Change Mouse to MMouse (and change the parameters accordingly) and then do something like.. if(IsUpText('iamon'))then Mouse(x, y, 0, 0, True);.