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
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