SRL Archive - OSR Help

Looting with reflection?


Rare Scripts

2014-12-11 20:37:45

Working on a private script atm but cant get the looting to work..
Hope to get it working so i can release combat scripts later on for public.

Can anyone give me a example on how to loot with reflection?

Many thanks.
-Baws.

Frement

2014-12-11 21:21:05

Iterate the ground items and pick up the ones you want.

rj

2014-12-11 21:38:25

Yea, I'm not familiar with the OSR-reflection include but pretty much what you would do is get the TGroundItemArray and loop through it, give me a second i'll write up some code

EDIT:

{$DEFINE SMART8}
{$I SRL-OSR/SRL.Simba}
{$i SRL-OSR/SRL/Reflection/Reflection.simba}

procedure lootItems(ID, dist:integer;name:string);
var
items:TGroundItemArray;
i:integer;
begin
items := r_getGroundItemsDistance(dist);
for i := 0 to high(items) do
if (items[i].ID = ID) then
begin
r_interactTile(items[i].Tile, name);
break;
end;
end;

begin
lootItems(993, 5, 'Take Coins');
end.

There could be more fails safes to be added, but this is a starting point let me know if it works

Rare Scripts

2014-12-12 05:17:37

From: Robert
Yea, I'm not familiar with the OSR-reflection include but pretty much what you would do is get the TGroundItemArray and loop through it, give me a second i'll write up some code

EDIT:

{$DEFINE SMART8}
{$I SRL-OSR/SRL.Simba}
{$i SRL-OSR/SRL/Reflection/Reflection.simba}

procedure lootItems(ID, dist:integer;name:string);
var
items:TGroundItemArray;
i:integer;
begin
items := r_getGroundItemsDistance(dist);
for i := 0 to high(items) do
if (items[i].ID = ID) then
begin
r_interactTile(items[i].Tile, name);
break;
end;
end;

begin
lootItems(993, 5, 'Take Coins');
end.

There could be more fails safes to be added, but this is a starting point let me know if it works


Many thanks, will try this when im at home.

Edit: working perfect! Many thanks, is there also a way possible to right click and select correct ID (if have more items on top) and also repeat the looting until it has all items it needed from ground?

Its the last part of code i need, I barly use Reflection for things, so im new to it.

Flight

2014-12-12 08:07:37

Using Robert's example, here's what you could do:

procedure lootItems(ID, dist:integer;name:string);
var
items:TGroundItemArray;
i:integer;
BreakLoop:boolean;
begin
repeat
items := r_getGroundItemsDistance(dist);
for i := 0 to high(items) do
begin
if (items[i].ID = ID) then
begin
BreakLoop := False;
r_interactTile(items[i].Tile, name);
break;
end;
BreakLoop := True;
end;
until(BreakLoop);
end;

Of course within the first loop you'll want to put some failsafes (timers, loggedin check, randoms checker).

Edit:
By the way, that's untested as I don't use reflection. The logic seems fine to me but if you don't understand what I did just ask me here.

Fitta

2014-12-12 10:21:58


procedure lootItems(Dist: Integer; IDs: TIntegerArray; Names: TStringArray);
var
items:TGroundItemArray;
i:integer;
begin
items := r_getGroundItemsDistance(dist);
for i := 0 to high(items) do
if InIntArray(IDs, Items.ID) then
r_interactTile(items[i].Tile, Names[I]);
end;

lootItems(25, [995, 318], ['Take Coins', 'Take Lobster']);

  • Will pick-up all selected items in order(if in the same pile)
  • IDs and Names must be in the same order, as in example.
  • Happy bottin :)

Rare Scripts

2014-12-12 10:39:03

Many thanks all! :)


EDIT:

From: Fitta

procedure lootItems(Dist: Integer; IDs: TIntegerArray; Names: TStringArray);
var
items:TGroundItemArray;
i:integer;
begin
items := r_getGroundItemsDistance(dist);
for i := 0 to high(items) do
if InIntArray(IDs, Items.ID) then
r_interactTile(items[i].Tile, Names[I]);
end;

lootItems(25, [995, 318], ['Take Coins', 'Take Lobster']);

  • Will pick-up all selected items in order(if in the same pile)
  • IDs and Names must be in the same order, as in example.
  • Happy bottin :)



give me error:

[Error] C:\….. - Baws Scripts…..simba(442:30): Semicolon (';') expected at line 443


EDIT 1:

Somethimes it has another item (in case, diffrent unid herbs (all other ID)) on top, how do i make it right click to loot?