Log in

View Full Version : Reflection/Simba Finding/Clicking Objects



HarryJames
02-24-2011, 01:55 AM
I'm tired, it's late.

How do I correctly implement finding an object and then clicking it?

program FightCaveRunner;
{$DEFINE SMART}
{$i SRL/SRL.scar}
{$i Reflection/Reflection.simba}

procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;

with Players[0] do
begin
Name := '';
Pass := '';
Nick := 'ake';
Active:=True;
end;
end;

var
playerAtCaves : boolean;
tmp : integer;



Procedure atCaves;
begin
if (DistanceFrom(Tile(2438, 5168)) < 6) then
begin
writeln('We''re at the caves!');
playerAtCaves := True;
end else
begin
writeln('looks like we''re not at the caves');
playerAtCaves := False;
end;
end;

Procedure findCaveEntrace;
var
entrance: TNPCArray;
cavePoint: TPoint;

Begin

// tmp := GetObjectAt(Point(2439,5167),0).ID;
// writeln(tmp);// Gets object ID at a certain point
entrance := SortNPCs(GetNPCs(9356));
cavePoint := Tile(2439,5167);
Mouse(cavePoint.x, cavePoint.y, 10, 10, False);


End;


{
Notes for me!

ID: 9356 should be the entrace
writeln('Object ID:'+ GetObjectAt(Point(2438,5167),0).ID); Gets object ID at a certain point



}

Procedure MainLoop;
Begin
Smart_Signed := true;
Smart_Server := 34;
Smart_SuperDetail := false;
SetupSRL;
DeclarePlayers;
LoginPlayer;
findCaveEntrace;
//writeln(GetMyPos);
//wait(3000);
//writeln(GetMyPos);
end;

begin
MainLoop;
end.

Why is this not working?
Thanks <3

TomTuff
02-24-2011, 02:07 AM
It's not working for several reasons

The "CavePoint" you've designated is the Reflection tile, not the onscreen coordinate. Use TileToMS or TileToMSEx to make an onscreen coordinate from a TTile.
There's no point in using a TNPCArray if you already know the tile.
Are you sure it's an NPC? I'm pretty sure the cave entrance would be an Object (TRSObject).



function EnterCave: Boolean;
var
i: Integer;
Objs: TRSObjectArray;
Pt: TPoint;
begin
if not(LoggedIn) then
Exit;
Objs := SortObjects(GetObjectsByID(9356, OBJECT_TYPE_INTERACTABLE,10));
for i := 0 to High(Objs) do
begin
if (Objs[i].Tile <> Tile(2439, 5167)) then
Continue;
if not(TileOnMS(Objs[i].Tile, 0)) then //May have to use Objs[i].RealTile instead
if not(WalkToTile(Objs[i].Tile, 2, 0)) then
Continue;
Pt := TileToMS(Objs[i].Tile, 0);
MMouse(Pt.x - 10, Pt.y - 10, 20, 20);
if R_WaitUptextMulti(['your uptexts here'], 900) then
begin
Wait(50 + Random(80));
ClickMouse2(False);
Wait(50 + Random(80));
Result := r_WaitOptionMulti(['your choose options here'], 900);
end;
if Result then
Break;
end;
for i := 0 to High(Objs) do //
Objs[i] := NULL_RSOBJECT; //These 3 lines should prevent memory leaks
SetLength(Objs, 0); //
end;

HarryJames
02-24-2011, 02:19 AM
Yeah sorry, I totally forgot about objects!

I'm reasonably new to reflection, and I didn't know how each 'thing' (entity?) was treated.

I'm gonna copy/paste (edit uptext etc) to suit my needs, then i'll credit you if that's alright?

TomTuff
02-24-2011, 02:23 AM
Yeah sorry, I totally forgot about objects!

I'm reasonably new to reflection, and I didn't know how each 'thing' (entity?) was treated.

I'm gonna copy/paste (edit uptext etc) to suit my needs, then i'll credit you if that's alright?

Sure, but read through the code and make sure you understand it, you need to know arrays to properly use reflection.

HarryJames
02-24-2011, 03:32 AM
I'm pretty good with Java/C++/Python so I know how Arrays work, I think i'm about there when it comes to the reflection arrays.

I'm presuming that 'High(array)' in a loop will do it until the last array object?

Echo_
02-27-2011, 02:08 PM
That's correct, "0 to High" just iterates through each array value and performs the procedure. Also, you should take a look through this tutorial, it is good for people who are beginning to learn reflection.

http://villavu.com/forum/showthread.php?t=59400