SRL Archive - Help and Support

[R] [Request] Need help with a function


TomTuff

2011-03-02 02:58:10

I bought 10k clay, law runes, and water runes to make 10k falador tabs. I'm redoing the teletabber I made, but this time with SRL/Simba-reflection. I want it to enter the house (building mode so no doors to open), talk to the NPC Butler (this makes it follow you around), then walk to the lectern. I tried what I could, but I couldn't get it working :\ Any help appreciated! See code below.


First off, some functions used inside the functions I need help with:
function GetClosestNPCByIDEx(IDs: TIntegerArray{; Dist: Integer}): TNPC;
var
i: Integer;
NPCs: TNPCArray;
begin
NPCs := GetNPCs(IDs);
if (Length(NPCs) < 1) then
Exit;
NPCs := SortNPCs(NPCs);
Result := NPCs[0];
for i := 0 to High(NPCs) do
NPCs[i] := NULL_NPC;
SetLength(NPCs, 0);
end;

function GetClosestRSObjectByIDEx(IDs: TIntegerArray; Dist: Integer): TRSObject;
var
Objs: TRSObjectArray;
i: Integer;
begin
Objs := GetObjectsByIDEx(IDs, OBJECT_TYPE_INTERACTABLE, Dist);
if (Length(Objs) < 1) then
Exit;
Objs := SortObjects(Objs);
Result := Objs[0];
for i := 0 to High(Objs) do
Objs[i] := NULL_RSOBJECT;
SetLength(Objs, 0);
end;

function WaitForTextAt(Txt: string; TheInterface, TheComponent, MaxTime: Integer): Boolean;
var
T: Integer;
begin
T := GetSystemTime + MaxTime;
while (GetSystemTime < T) and (LoggedIn) do
begin
Result := (Pos(Txt, GetInterfaceText(TheInterface, TheComponent)) > 0);
if Result then
Exit;
Wait(100 + Random(50));
end;
end;

function GetClosestRSObjectByID(ID, Dist: Integer): TRSObject;
begin
Result := GetClosestRSObjectByIDEx([ID], Dist);
end;

And here are the functions I need help with:
function GetToLect: Boolean;
var
Lect: TRSObject;
I: Integer;
begin
if not(LoggedIn) then
Exit;
Lect := NULL_RSOBJECT;
I := 5;
repeat
Lect := GetClosestRSObjectByIDEx(LecternIDs, I);
if (Lect <> NULL_RSOBJECT) then
Break;
IncEx(I, 4);
until(I >= 99);
if (Lect = NULL_RSOBJECT) then
Exit;
Result := r_WebWalk(Lect.Tile);
Lect := NULL_RSOBJECT;
end;

function HaveButlerFollow: Boolean;
label ProcStart;
var
Butler: TNPC;
Pt: TPoint;
OldSpeed: Integer;
begin
if not(LoggedIn) then
Exit;
ProcStart:
Butler := NULL_NPC;
Butler := GetClosestNPCByIDEx(ButlerIDs);
if (Butler = NULL_NPC) then
Exit;
if not(TileOnMS(Butler.Tile, 0)) then
if not(WalkToTile(Butler.Tile, 0, 0)) then //also tried r_WebWalk here
Exit
else
goto ProcStart;
Pt := TileToMS(Butler.Tile, RandomRange(1/3, 2/3) * Butler.Height);
OldSpeed := MouseSpeed;
IncEx(MouseSpeed, RandomRange(3, 5));
Mouse(Pt.x - 5, Pt.y - 5, 10, 10, False);
MouseSpeed := OldSpeed;
if r_WaitOption('alk-', 900) then
begin
R_Flag;
Result := WaitForTextAt('thy', 241, 4, 1500);
end;
Butler := NULL_NPC;
end;

P.S. Some of the parameters (e.g. ButlerIDs) are defined elsewhere in the script

JPHamlett

2011-03-02 22:14:09

function GetClosestNPCByIDEx(IDs: TIntegerArray{; Dist: Integer}): TNPC;
var
i: Integer;
NPCs: TNPCArray;
begin
NPCs := GetNPCs(IDs);
if (Length(NPCs) < 1) then
Exit;
NPCs := SortNPCs(NPCs);
closest := DistanceFrom(NPCS[0].Tile);
for i := 0 to High(NPCs) do
begin
Dist := DistanceFrom(NPCS[i].Tile);
if (closest < Dist) then
begin
closest := Dist;
Result := NPCS[i];
end;
end;
end;

untested

TomTuff

2011-03-02 22:37:48

The last two functions are the ones I need help with, sorry. The other ones were used in those functions that weren't working are the ones i need help with.

Thanks though :L

Main

2011-03-03 08:42:28

change your style to fremneck or something, then color alone is good enough. i did it before.