PDA

View Full Version : Items, examples..



Fitta
01-20-2015, 04:37 PM
If you haven't read about items, then please, go here first (https://villavu.com/forum/showthread.php?t=111669&p=1326793#post1326793)

With the latest release of itemDefs we no longer have to work with ID's.
Everytime you run a function regarding items, itemDefs will be loaded and stored.
Accessing your item names can be done by Items.Name!

As TReflectGroundItem is an extension to TReflectItem there's two new variable that can be accessed,

Tile: TTile
Quantity: Integer


Tile obviously showing us where the item is located.
Quantity for the amount. (None stackable items = 1).

program TutorialGroundItems;
{$DEFINE SMART}
{$i Reflection/Reflection.simba}


{
All grounditems functions have a parameter for the distance it'll search.
The less the better, as you'll almost never try to find a item outside your
minimap range.
}
const
GroundItems_Dist = 20;

{
Drops are names of items I want to pick-up
DropsCount will keep track of my pick-ups
}
var
Drops: TStringArray;
DropsCount: TIntegerArray;

{
setupDrops will declare my variables
Run this before the actuall pick-up function..
}
Procedure setupDrops;
begin
{Drops will always be case sensetive and will always need a full name}
Drops := ['Bronze arrow',
'Bones',
'Rune chainbody', {This would work}
'RuNe ChainBody', {This wouldn't}
'Thread'];

SetLength(DropsCount, Length(Drops));
end;


{
After you've declared your drops it's time to search for them!
}
procedure handle_Drops;
var
Pile: TReflectGroundItemArray;
I, Ind: Integer;
begin
Pile.GetAll(GroundItems_Dist); {Notice how I use GroundItems_Dist here}

{If there's no items on the ground, Exit.}
If Length(Pile) = 0 then
Exit;

{Searching through our items for the correct names given in the
setup.}
For I:=0 to High(Pile)do
If InStrArrEx(Pile[I].Name, Drops, Ind)then {Tries to match grounditem name with our names for a match}
begin
Writeln(Pile[I].Name + ' found..');
{We found a drop, and can now access it's location via Pile[I].Tile and pick it up}


{To keep track of how many we picked up, we can simply do}
DropsCount[Ind] := DropsCount[Ind] + Pile[I].Quantity;
end;
end;

begin
Reflect.Setup;
setupDrops;

handle_Drops;
end.




When finished you can print it out like I did :)
http://i.gyazo.com/996b5f522a1f0685deba0a1e00767c27.png

Fitta
01-20-2015, 04:57 PM
Name: String
ID: Integer
HighAlchValue: Integer
InvActions: TStringArray
GroundActions: TStringArray



Everytime you're handling items in any format,

Bank
Inventory
Grounditems

These variables will ALWAYS be access-able via itemDefs.

So what does this mean?

By using any .Get function you'll get all this information about the item.
An example would be my small tutorial on grounditems using item names instead of ID's. (https://villavu.com/forum/showthread.php?t=111668)

Notice, just because SIMBA's codehint doesn't show all the variables in the type doesn't mean that they're not there. Instead try the code, compile it, and you'll see that it works!

Your mind is the limit :)

Zace
04-19-2015, 04:39 AM
procedure handle_Drops;
var
Pile: TReflectGroundItemArray;
I, Ind: Integer;

begin
Pile.GetAll(GroundItems_Dist); {Notice how I use GroundItems_Dist here}
If Length(Pile) = 0 then
Exit;
For I:=0 to High(Pile)do
If InStrArrEx(Pile[I].Name, Drops, Ind)then {Tries to match grounditem name with our names for a match}
begin
Writeln(Pile[I].Name + ' found..');
DropsCount[Ind] := DropsCount[Ind] + Pile[I].Quantity;
end;
end;

So I get this error and can't figure it out.
Error: Unknown declaration "Name" at line 186, column 26 at line 186
Compiling failed.

Also your small tutorial link you posted doesn't work.

I got it working, nevermind.

EZ41
05-02-2015, 02:22 AM
Why take the time to edit your post to say you've worked it out and then not bother typing two lines to tell everyone else how to fix it?

Edit: I figured it out, here's so the next guy doesn't have to waste their time on this.. you have to replace

Pile[I].Name

with

Pile[I].GetName

BigRedJapan
05-09-2015, 07:18 PM
Nice script. Need to get 75+ Slayer so I can work on a project like this.