Drakan
2010-05-28 18:22:49
Hello everyone! I've been very busy today working on our new Inventory.simba! Most of the functions I was able to just write in notepad during study hall today becuase I forgot my flashdrive :P But none-the-less, I finished Inventory.simba up and committed it to the SVN.
I have also changed Reflection.simba. Now it will run the SetupSRL and check if the hooks are outdated. It's now easier to add reflection to your script than before! Here is a test script to show you how simple it is:
Drop by the SVN and check these new files out! For those of you too lazy, here's Inventory.simba:
I have also changed Reflection.simba. Now it will run the SetupSRL and check if the hooks are outdated. It's now easier to add reflection to your script than before! Here is a test script to show you how simple it is:
program Test;
{$i srl/srl/reflection/Reflection.simba}
begin
SetupReflection;
R_DropItemsButPartName('pickaxe');
end.
Drop by the SVN and check these new files out! For those of you too lazy, here's Inventory.simba:
type
TInvItem = record
ID, StackSize, Slot: integer;
Name: String;
Actions: TStringArray;
end;
TInvItemArray = array of TInvItem;
{*******************************************************************************
function NullInvItem: TInvItem;
By: Drags111
Description: Returns a "null" inventory item.
*******************************************************************************}
function NullInvItem: TInvItem;
begin
Result.ID := 0;
Result.StackSize := 0;
Result.Name := '';
Result.Actions := [];
end;
{*******************************************************************************
function TrimInvName(Name: string): String;
By: Drags111
Description: Gets rid of the <col=42c3df> crap from the names of items.
*******************************************************************************}
function TrimInvName(Name: string): String;
begin
Result := (Copy(Name, Pos('>', Name)+1, Length(Name) - Pos('>', Name)+1));
end;
{*******************************************************************************
function GetActionList(Itm, Actions: integer): TStringArray;
By: Drags111
Description: Returns the list of actions you can do with specific items.
(Does not return "Use").
*******************************************************************************}
function GetActionList(Itm, Actions: integer): TStringArray;
var
i, l, temp: integer;
str: string;
begin
l := (SmartGetFieldArraySize(Actions, '', 1));
for i := 0 to l-1 do
begin
temp := SmartGetFieldArrayObject(Itm, hook_interface_GetActions, i);
str := GetJavaString(temp, 255);
if not(str = '')then
begin
SetLength(Result, Length(Result)+1);
Result[High(Result)] := str;
end;
end;
end;
{*******************************************************************************
function GetInvItemAt(slot: integer): TInvItem;
By: Drags111
Description: Returns a TInvItem from the specific slot. If slot is empty, it
returns NullInvItem;
*******************************************************************************}
function GetInvItemAt(slot: integer): TInvItem;
var
Inv, Itm, Name, acts: integer;
begin
if not ValidInterface(149)then exit;
GameTab(25);
Inv := GetInterface(149, 0);
Itm := SmartGetFieldArrayObject(Inv, hook_interface_GetChildren, slot-1);
Result.ID := SmartGetFieldInt(Itm, hook_interface_GetID);
if(Result.ID > 0)then
begin
Result.StackSize := SmartGetFieldInt(Itm, hook_interface_GetStack);
Result.Slot := slot;
Name := SmartGetFieldObject(Itm, hook_interface_GetName);
Result.Name := TrimInvName(GetJavaString(Name, 255));
acts := SmartGetFieldObject(Itm, hook_interface_GetActions);
Result.Actions := GetActionList(Itm, acts);
end else
Result := NullInvItem;
SmartFreeObject(Inv);
SmartFreeObject(Itm);
SmartFreeObject(Name);
SmartFreeObject(Acts);
end;
{*******************************************************************************
function GetInventoryItems: TInvItemArray;
By: Drags111
Description: Returns an array of all of the inv items in the inventory.
*******************************************************************************}
function GetInventoryItems: TInvItemArray;
var
i: integer;
begin
for i := 1 to 28 do
if not(GetInvItemAt(i) = NullInvItem)then
begin
SetLength(Result, Length(Result)+1);
Result[High(Result)] := GetInvItemAt(i);
end;
end;
{*******************************************************************************
function GetItemStackSizeAt(slot: integer): integer;
By: Drags111
Description: Gets the stack size at the specific slot.
*******************************************************************************}
function GetItemStackSizeAt(slot: integer): integer;
var
Temp: TInvItem;
begin
Temp := GetInvItemAt(slot);
Result := Temp.StackSize;
end;
{*******************************************************************************
function GetItemIDAt(slot: integer): integer;
By: Drags111
Description: Gets the ID of an item at a specific slot.
*******************************************************************************}
function GetItemIDAt(slot: integer): integer;
var
Temp: TInvItem;
begin
Temp := GetInvItemAt(slot);
Result := Temp.ID;
end;
{*******************************************************************************
function GetItemNameAt(slot: integer): String;
By: Drags111
Description: Gets the name of an item at a specific slot.
*******************************************************************************}
function GetItemNameAt(slot: integer): String;
var
Temp: TInvItem;
begin
Temp := GetInvItemAt(slot);
Result := Temp.Name;
end;
{*******************************************************************************
function R_InvCount: integer;
By: Drags111
Description: Counts the number of items in the inventory.
*******************************************************************************}
function R_InvCount: integer;
begin
Result := Length(GetInventoryItems);
end;
{*******************************************************************************
function R_ItemIDExists(ID: Integer): boolean;
By: Drags111
Description: Returns true if the ID is found at least once in the inventory.
*******************************************************************************}
function R_ItemIDExists(ID: Integer): boolean;
var
i: integer;
Temp: TInvItem;
begin
Result := true;
for i := 1 to 28 do
begin
Temp := GetInvItemAt(i);
if(Temp.ID = ID)then
exit;
end;
Result := false;
end;
{*******************************************************************************
function R_ItemNameExists(Name: String): boolean;
By: Drags111
Description: Returns true if the name is found at least once in the inventory.
*******************************************************************************}
function R_ItemNameExists(Name: String): boolean;
var
i: integer;
Temp: TInvItem;
begin
Result := true;
for i := 1 to 28 do
begin
Temp := GetInvItemAt(i);
if(Lowercase(Temp.Name) = Lowercase(Name))then
exit;
end;
Result := false;
end;
{*******************************************************************************
function R_ItemPartNameExists(PartName: String): boolean;
By: Drags111
Description: Returns true if a partial name is found in the inventory.
EXAMPLE: R_ItemPartNameExists('pickaxe') will search for any item
that has the word 'pickaxe' in it's name. (iron pickaxe, bronze
pickaxe, etc.)
*******************************************************************************}
function R_ItemPartNameExists(PartName: String): boolean;
var
i: integer;
Temp: TInvItem;
begin
Result := true;
for i := 1 to 28 do
begin
Temp := GetInvItemAt(i);
if(Pos(lowercase(PartName), lowercase(Temp.Name)) > 0)then
Exit;
end;
Result := false;
end;
{*******************************************************************************
function R_ItemExists(Slot: integer): boolean;
By: Drags111
Description: Returns true if an item exists at the specified slot.
*******************************************************************************}
function R_ItemExists(Slot: integer): boolean;
var
Temp: TInvItem;
begin
Temp := GetInvItemAt(slot);
Result := not(Temp = NullInvItem);
end;
{*******************************************************************************
function R_ClickItemID(ID: Integer; Left: Boolean; Action: String): boolean;
By: Drags111
Description: Clicks the first item in the inventory with the ID, and if left is
set to true, Left clicks and performs the action. Otherwise, right
clicks. Ex: R_ClickItemID(123, false, 'Wield');
OR
R_ClickItemID(123, true, ''); //Left clicks (use).
*******************************************************************************}
function R_ClickItem(Slot: Integer; Left: Boolean; Action: String): boolean;
var
i: integer;
item: TInvItem;
begin
Result := false;
Item := GetInvItemAt(i);
if(Item = NullInvItem)then Exit;
case Left of
true: begin
MouseItem(i, true);
Result := True;
end;
false: begin
MouseItem(i, false);
Result := R_ChooseOption(Action);
end;
end;
end;
{*******************************************************************************
function R_ClickItemID(ID: Integer; Left: Boolean; Action: String): boolean;
By: Drags111
Description: Clicks the first item in the inventory with the ID, and if left is
set to true, Left clicks and performs the action. Otherwise, right
clicks. Ex: R_ClickItemID(123, false, 'Wield');
OR
R_ClickItemID(123, true, ''); //Left clicks (use).
*******************************************************************************}
function R_ClickItemID(ID: Integer; Left: Boolean; Action: String): boolean;
var
i: integer;
item: TInvItem;
begin
for i := 1 to 28 do
begin
Item := GetInvItemAt(i);
if(Item.ID = ID)then
begin
case Left of
true: begin
MouseItem(i, true);
Result := True;
Exit;
end;
false: begin
MouseItem(i, false);
Result := R_ChooseOption(Action);
if Result then Exit;
end;
end;
end;
end;
end;
{*******************************************************************************
function R_ClickItemName(Name: String; Left: boolean; Action: String): boolean;
By: Drags111
Description: Clicks the first item in the inventory with the Name, and if left is
set to true, Left clicks and performs the action. Otherwise, right
clicks. Ex: R_ClickItemName('iron ore', false, 'drop');
OR
R_ClickItemName(bucket, true, ''); //Left clicks (use).
*******************************************************************************}
function R_ClickItemName(Name: String; Left: boolean; Action: String): boolean;
var
i: integer;
item: TInvItem;
begin
for i := 1 to 28 do
begin
Item := GetInvItemAt(i);
if(Lowercase(Item.Name) = lowercase(name))then
begin
case Left of
true: begin
MouseItem(i, true);
Result := True;
Exit;
end;
false: begin
MouseItem(i, false);
Result := R_ChooseOption(Action);
if Result then Exit;
end;
end
end;
end;
end;
{*******************************************************************************
procedure R_DropItem(Slot: integer);
By: Drags111
Description: Drops the item at the slot.
*******************************************************************************}
procedure R_DropItem(Slot: integer);
var
mt, t: integer;
begin
MarkTime(mt);
while(R_ItemExists(slot) and (TimeFromMark(mt) < 5000))do
begin
MouseItem(slot, false);
R_ChooseOption('drop');
MarkTime(t);
while(R_ItemExists(slot) and (TimeFromMark(t) < 1500))do
wait(25+Random(25));
end;
end;
{*******************************************************************************
procedure R_DropAllItems;
By: Drags111
Description: Drops all items in the inventory.
*******************************************************************************}
procedure R_DropAllItems;
var
i: integer;
begin
for i := 1 to 28 do
R_DropItem(i);
end;
{*******************************************************************************
procedure R_DropAllItemsID(id: integer);
By: Drags111
Description: Drops all items in the inventory with the specified ID.
*******************************************************************************}
procedure R_DropAllItemsID(id: integer);
var
i: integer;
item: TInvItem;
begin
for i := 1 to 28 do
begin
item := GetInvItemAt(i);
if(item.ID = ID)then
R_DropItem(i);
end;
end;
{*******************************************************************************
procedure R_DropAllItemsName(Name: String);
By: Drags111
Description: Drops all items in the inventory with the specified name.
*******************************************************************************}
procedure R_DropAllItemsName(Name: String);
var
i: integer;
item: TInvItem;
begin
for i := 1 to 28 do
begin
item := GetInvItemAt(i);
if(lowercase(item.Name) = lowercase(Name))then
R_DropItem(i);
end;
end;
{*******************************************************************************
procedure R_DropAllItemsPartName(PartName: String);
By: Drags111
Description: Drops all items in the inventory that contain the specified name.
Example: R_DropAllItemsPartName('ore');
*******************************************************************************}
procedure R_DropAllItemsPartName(PartName: String);
var
i: integer;
item: TInvItem;
begin
for i := 1 to 28 do
begin
item := GetInvItemAt(i);
if(Pos(lowercase(PartName), lowercase(item.Name)) > 0)then
R_DropItem(i);
end;
end;
{*******************************************************************************
procedure R_DropItemsButSlotEx(slots: TIntegerArray);
By: Drags111
Description: Drops all items in the inventory except those in the specified slots.
*******************************************************************************}
procedure R_DropItemsButSlotEx(slots: TIntegerArray);
var
i: integer;
begin
for i := 1 to 28 do
begin
if(InIntArray(slots, i))then
continue;
R_DropItem(i);
end;
end;
{*******************************************************************************
procedure R_DropItemsButSlot(slot: integer);
By: Drags111
Description: Drops all items in the inventory except the one in the specified slot.
*******************************************************************************}
procedure R_DropItemsButSlot(slot: integer);
begin
R_DropItemsButSlotEx([slot]);
end;
{*******************************************************************************
procedure R_DropItemsButIDEx(ids: TIntegerArray);
By: Drags111
Description: Drops all items in the inventory except those w/ the specified IDs.
*******************************************************************************}
procedure R_DropItemsButIDEx(ids: TIntegerArray);
var
i: integer;
item: TInvItem;
begin
for i := 1 to 28 do
begin
Item := GetInvItemAt(i);
if(InIntArray(IDs, Item.ID))then
continue;
R_DropItem(i);
end;
end;
{*******************************************************************************
procedure R_DropItemsButID(id: integer);
By: Drags111
Description: Drops all items in the inventory except those w/ the specified ID.
*******************************************************************************}
procedure R_DropItemsButID(id: integer);
begin
R_DropItemsButIDEx([id]);
end;
{*******************************************************************************
procedure R_DropItemsButNameEx(Names: TStringArray);
By: Drags111
Description: Drops all items in the inventory except those w/ the specified Names.
*******************************************************************************}
procedure R_DropItemsButNameEx(Names: TStringArray);
var
i: integer;
item: TInvItem;
begin
for i := 1 to 28 do
begin
Item := GetInvItemAt(i);
if(InStrArr(Item.Name, Names, false))then
continue;
R_DropItem(i);
end;
end;
{*******************************************************************************
procedure R_DropItemsButName(Name: String);
By: Drags111
Description: Drops all items in the inventory except those w/ the specified Name.
*******************************************************************************}
procedure R_DropItemsButName(Name: String);
begin
R_DropItemsButNameEx([Name]);
end;
{*******************************************************************************
procedure R_DropItemsButPartNameEx(PartNames: TStringArray);
By: Drags111
Description: Drops all items in the inventory except those w/ the specified
partial names. Example: R_DropItemsButPartNameEx('pickaxe');
*******************************************************************************}
procedure R_DropItemsButPartNameEx(PartNames: TStringArray);
var
i, z: integer;
Item: TInvItem;
Cont: boolean;
begin
for i := 1 to 28 do
begin
Item := GetInvItemAt(i);
cont := false;
for z := 0 to High(PartNames) do
if(Pos(PartNames[z], Item.Name)> 0)then
cont := true;
if cont then
continue;
R_DropItem(i);
end;
end;
{*******************************************************************************
procedure R_DropItemsButPartName(PartName: String);
By: Drags111
Description: Drops all items in the inventory except those w/ the specified
partial name. Example: R_DropItemsButPartNameEx('pickaxe');
*******************************************************************************}
procedure R_DropItemsButPartName(PartName: String);
begin
R_DropItemsButPartNameEx([PartName]);
end;
{*******************************************************************************
procedure R_DumpItems(Items: TInvItemArray);
By: Drags111
Description: Prints out the TInvItemArray nice and neatly.
*******************************************************************************}
procedure R_DumpItems(Items: TInvItemArray);
var
i: integer;
begin
for i := 0 to High(Items)do
begin
Writeln('Slot: '+ToStr(Items[i].Slot));
Writeln(' '+Items[i].Name);
Writeln(' ID:'+ToStr(Items[i].ID));
Writeln(' Stack Size:'+ToStr(Items[i].ID));
Writeln(' Actions:'+ToStr(Items[i].Actions));
end;
end;