SCAR Code:
//-----------------------------------------------------------------//
//-- Scar Standard Resource Library --//
//-- ยป Inventory Routines --//
//-----------------------------------------------------------------//
// * function GetInven(Inven : Integer) : TInvenItem; // * by Sky Scripter
// * function GetInventoryArray : array of TInvenItem; // * by Sky Scripter
// * function InvBox(i :Integer): TBox; // * by Boreas, coords by Ogre
// * function ItemCoords(i: Integer): TPoint; // * by RsN
// * Function CoordsToItem(X, Y: Integer): Integer; // * by Boreas
// * function GetInvItemBounds(InvSpot: Integer; T: TBox): Boolean; // * by Wizzup?
// * procedure InvMouse(InvSlot, Action: Byte); // * by EvilChicken!
// * procedure MMouseItem(i: Integer); // * by WT-Fakawi/EvilChicken!
// * procedure MouseItem(i: Integer; left: Boolean); // * by WT-Fakawi/EvilChicken!, edit by NaumanAkhlaQ
// * procedure DragItem(Inv1, Inv2: Integer); // * by NaumanAkhlaQ
// * function ExistsItem(i: Integer): Boolean; // * by RsN
// * function InvCount: Integer; // * by RsN
// * function InvEmpty: Boolean; // * by WT-Fakawi
// * function InvFull: Boolean; // * by RsN
// * function CountItems(identifier: Integer; identifiertype: string; tol: TIntegerArray): Integer; // * by WT-Fakawi / Sumilion
// * function ClickAllItemsExcept(identifier: Integer; identifiertype, option: string; SlotIgnores: TIntegerArray; waitnum: Integer; tol: TIntegerArray):Integer; // * by WT-Fakawi / Sumilion & Nava2
// * function ClickAllItems(identifier: Integer; identifiertype, option: string; waitnum: Integer; tol: TIntegerArray):Integer; // * by Nava2
// * procedure DropItem(i: Integer); // * by Lorax
// * Procedure DropPattern(which: integer); // * by Rasta Magician
// * procedure DropAll; // * by Rasta Magician
// * procedure DropAllExcept(IgnoreInvSlots: array of Byte); // * by R1ch
// * procedure DropItemsByIdentifier; // * by EvilChicken!
// * procedure ArrangeInv; // * by Cheesehunk
// * function CountItemsBlackLine(Count, Tol: Integer): Integer; // * by n3ss3s
// * function ClickAllItemsBlackLine(Count, Tol: Integer; Option: String): Integer; // * by n3ss3s
// * function ItemActivated(Slot: Integer): Boolean; // * by marpis
// * function FindActiveItemSlot: TBox; // * by EvilChicken!
{ type TInvenItem;
Description: Holds data regarding an inventory item }
type
TInvenItem = record
Width, Height : Integer; // the width and height of the item
Count : Integer; // the count of the item
ItemBox : TBox; // the exact box around the item
CenterPoint: TPoint; // the center point inside the item
ExistsItem : Boolean; // to define the item Exists
end;
{*******************************************************************************
function GetInven(Inven: Integer): TInvenItem;
By: SKy Scripter
Description: Returns The Width, Height, Count, ItemBox and CenterPoint of the
Given Item Slot.
*******************************************************************************}
function GetInven(Inven: Integer): TInvenItem;
var
Slot, Row, Ix, Iy, I, Cx, Cy: Integer;
P: TPointArray;
MinP, MaxP: TPoint;
begin
if (not BankScreen) then
GameTab(tab_Inv);
Inven := Inven - 1;
Slot := Inven mod 4;
Row := Inven div 4;
IX := 560 + (Slot * 42);
IY := 210 + (Row * 36);
FindColorsTolerance(P, srl_outline_black, IX, IY, IX + 41, IY + 35, 0);
Result.Count := Length(P);
if (Result.Count = 0) then Exit;
Result.ExistsItem := True;
MinP := P[0];
MaxP := P[Result.Count-1];
Cx := P[0].x + P[Result.Count-1].x;
Cy := P[0].y + P[Result.Count-1].y;
for I := 1 to Result.Count - 2 do
begin
if (P[i].x < MinP.x) then MinP.x := P[i].x;
if (P[i].y < MinP.y) then MinP.y := P[i].y;
if (P[i].x > MaxP.x) then MaxP.x := P[i].x;
if (P[i].y > MaxP.y) then MaxP.y := P[i].y;
Cx := Cx + P[i].x;
Cy := Cy + P[i].y;
end;
Cx := Cx / Result.Count;
Cy := Cy / Result.Count;
Result.CenterPoint := Point(Cx, Cy);
Result.Width := MaxP.x - MinP.x;
Result.Height := MaxP.y - MinP.y;
Result.ItemBox := PointToBox(MinP, MaxP);
end;
{*******************************************************************************
function GetInventoryArray : array of TInvenItem;
By: SKy Scripter
Description: Returns The Width, Height, Count, ItemBox and CenterPoint
in array [0..27] of all Items in the inventory.
*******************************************************************************}
function GetInventoryArray : array of TInvenItem;
var
I: Byte;
begin
SetArrayLength(Result, 28);
for I := 0 to 27 do
Result[I] := GetInven(i + 1);
end;
{*******************************************************************************
Function InvBox(i :Integer): TBox;
By: Boreas. Coords by Ogre July 15th 2009.
Description: Returns TBox of surrounding Inventory SlotBox
1-2-3-4
5-6-7-8
etc.
*******************************************************************************}
function InvBox(I :Integer): TBox;
var
Slot1, Slot6: TBox;
begin
if not InRange(I, 1, 28) then
begin
srl_Warn('InvBox', 'Incorrect index: ' + IntToStr(i), warn_AllVersions);
Exit;
end;
Slot1 := IntToBox(563, 213, 594, 244);
Slot6 := IntToBox(605, 249, 31415, 92653);
Result.x1 := Slot1.X1 + ((((i + 3) mod 4)) * (Slot6.X1 - Slot1.X1));
Result.y1 := Slot1.Y1 + ((((i - 1) / 4)) * (Slot6.Y1 - Slot1.Y1));
Result.x2 := Result.x1 + (Slot1.X2 - Slot1.X1);
Result.y2 := Result.y1 + (Slot1.Y2 - Slot1.Y1);
end;
{*******************************************************************************
function ItemCoords(i: Integer): TPoint;
By: RsN
Description: Returns X and Y of Specified Inventory Spot
*******************************************************************************}
function ItemCoords(i: Integer): TPoint;
var
Box: TBox;
begin
Box := InvBox(i);
Result.X := (Box.X1 + Box.X2) Shr 1;
Result.Y := (Box.Y1 + Box.Y2) Shr 1;
end;
{*******************************************************************************
function CoordsToItem(X, Y: Integer): Integer;
By: Boreas
Description: Returns which Inventory slot the X and Y coords are in. If the
coords are between slots (or not in the inventory area at all) it will return 0.
*******************************************************************************}
function CoordsToItem(X, Y: Integer): Integer;
var
tmpBox: TBox;
begin
if not PointInBox(Point(X, Y), IntToBox(MIX1, MIY1, MIX2, MIY2)) then exit;
for Result := 1 to 4 do
begin
tmpBox := InvBox(result);
if InRange(X, tmpBox.x1, tmpBox.x2) then break;
end;
while (not InRange(Y, tmpBox.y1, tmpBox.y2)) do
begin
IncEx(Result, 4);
if (Result > 28) then
Break;
tmpBox := InvBox(Result);
end;
if (not PointInBox(Point(X, Y), tmpBox)) then
Result := 0;
end;
{*******************************************************************************
Function GetInvItemBounds(InvSpot: Integer; T: TBox): Boolean;
By: Wizzup?
Description: If item exists, returns TBox of the item, else returns the normal InvBox.
*******************************************************************************}
function GetInvItemBounds(InvSpot: Integer; var T: TBox): Boolean;
var
TPA: TPointArray;
begin
Result := False;
if (not BankScreen) then
GameTab(tab_Inv);
T := InvBox(InvSpot);
if (not FindColors(TPA, srl_outline_black, T.x1, T.y1, T.x2, T.y2)) then
begin
T := InvBox(InvSpot);
Exit;
end;
Result := True;
T := GetTPABounds(TPA);
end;
{*******************************************************************************
function ExistsItem(i: Integer): Boolean;
By: WT-Fakawi
Description: Checks if item in inventory at specified position exists
*******************************************************************************}
function ExistsItem(I: Integer): Boolean;
var
X, Y: Integer;
TB: TBox;
begin
if (not BankScreen) then
GameTab(tab_Inv);
TB := InvBox(I);
Result := FindColor(x, y, srl_outline_black, TB.x1, TB.y1, TB.x2, TB.y2);
end;
{*******************************************************************************
procedure InvMouse(InvSlot, Action: Byte);
By: EvilChicken!
Description: A combined MouseItem & MMouseItem, will hopefully replace both
procedures one day. Usage is like SRL's MouseBox, Action determines what to do:
1: Leftclick
2: Rightclick
3: Move mouse to item
*******************************************************************************}
procedure InvMouse(InvSlot, Action: Byte);
var
TB: TBox;
begin
if (not InRange(Action, 1, 3)) then
begin
srl_Warn('InvMouse', 'Action #' + IntToStr(Action) + ' is not a valid action', warn_AllVersions);
Exit;
end;
if (not InRange(InvSlot, 1, 28)) then
begin
srl_Warn('InvMouse', 'Inventory slot #' + IntToStr(InvSlot) + ' is not a valid slot', warn_AllVersions);
Exit;
end;
if (not BankScreen) then
GameTab(tab_Inv);
TB := InvBox(InvSlot);
MouseBox(TB.X1, TB.Y1, TB.X2, TB.Y2, Action);
end;
{*******************************************************************************
procedure MMouseItem(i: Integer);
By: WT-Fakawi/EvilChicken!
Description: Moves mouse to specified inventory spot.
*******************************************************************************}
procedure MMouseItem(I: Byte);
begin
InvMouse(I, 3);
end;
{*******************************************************************************
procedure MouseItem(i: Byte; Left: Boolean);
By: WT-Fakawi/EvilChicken!, edit by NaumanAkhlaQ
Description: Moves Mouse to inv spot then clicks left or right.
*******************************************************************************}
procedure MouseItem(I: Byte; Left: Boolean);
begin
InvMouse(I, Integer(not Left) + 1);
end;
{*******************************************************************************
procedure DragItem(Inv1, Inv2: Integer);
By: NaumanAkhlaQ
Description: Drags Item from first position Inv1 to Inv2 (Inventory Slots)
*******************************************************************************}
procedure DragItem(Inv1, Inv2: Integer);
var
InvAr: array [0..1] of TBox;
begin
InvAr[0] := InvBox(Inv1);
InvAr[1] := InvBox(Inv2);
DragMouse(InvAr[0].x1, InvAr[0].y1, InvAr[0].x2, InvAr[0].y2,
InvAr[1].x1, InvAr[1].y1, InvAr[1].x2, InvAr[1].y2);
end;
{*******************************************************************************
Function InvCount: Integer;
By: RsN
Description: Returns amount of items in your inventory
*******************************************************************************}
function InvCount: Byte;
var
I: Byte;
begin
Result := 0;
for I := 1 to 28 do
if (ExistsItem(I)) then
Inc(Result);
end;
{*******************************************************************************
function InvEmpty: Boolean;
By: WT-Fakawi
Description: Returns True if inventory is empty
*******************************************************************************}
function InvEmpty: Boolean;
var
X, Y: Integer;
begin
Result := False;
if (not BankScreen) then
GameTab(tab_Inv);
Result := (not FindColor(X, Y, srl_outline_black, MIX1, MIY1, MIX2, MIY2));
end;
{*******************************************************************************
function InvFull: Boolean;
By: n3ss3s
Description: Returns True if inventory is full
*******************************************************************************}
Function InvFull: Boolean;
Begin
Result := (InvCount = 28);
End;
{*******************************************************************************
function CountItems(ItemType: string; Identifier: Integer; tol: TIntegerArray): Integer;
By: WT-Fakawi / Sumilion
Description: Counts Items in the inventory.
ItemType - 'dtm', 'bitmap', 'bitmap mask', 'color'
Item - name/value of your dtm/bmp/color/bmpmask.
Tol - 'dtm' - [] (dtm's can't have tolerance).
'bmp' - [BMPTol].
'color' - [COLOUR Tol, Colour Count].
'bmpmask' - [BMPTol, ContourTol].
*******************************************************************************}
function CountItems(ItemType: string; Identifier: Integer; tol: TIntegerArray): Integer;
begin
Result := -1;
if (not BankScreen) then
GameTab(tab_Inv);
Result := CountItemsIn('inv', ItemType, Identifier, Tol);
end;
{*******************************************************************************
function ClickAllItemsExcept(ItemType: String; Identifier: Integer; option: string; SlotIgnores: TIntegerArray; waitnum: Integer; tol: TIntegerArray):Integer;
By: WT-Fakawi, Sumilion & Nava2
Description: Performs "option" popup menu action on all items with:
ItemType - 'dtm', 'bitmap', 'bitmap mask', 'color'
Identifier - name/value of your dtm/bmp/color/bmpmask.
Tol - 'dtm' - [] (dtm's can't have tolerance).
'bmp' - [BMPTol].
'color' - [COLOUR Tol, Colour Count].
'bmpmask' - [BMPTol, ContourTol].
Will not click items in slots SlotIgnores
*******************************************************************************}
function ClickAllItemsExcept(ItemType: String; Identifier: Integer; option: string; SlotIgnores: TIntegerArray; waitnum: Integer; tol: TIntegerArray):Integer;
var
arr: TIntegerArray;
I, X, Y: Integer;
TB: Tbox;
begin
Result := 0;
arr :=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,
18,19,20,21,22,23,24,25,26,27,28];
for i := 1 to 28 - 4 do
Swap(arr[RandomRange(i - 1, i + 4)], arr[RandomRange(i - 1, i + 4)] );
SetLength(Tol, 2);
if (not BankScreen) then
GameTab(tab_Inv);
for i := 0 to 27 do
begin
if InIntArray(SlotIgnores, arr[i] + 1) then Continue;
TB := InvBox(arr[i]);
if ExistsItem(arr[i]) then
try
if not FindItemEx(x, y, ItemType, Identifier, TB, Tol) then Continue;
if (Option <> '') then
begin
MouseItem(arr[i], False);
WaitOption(Option, waitnum);
Inc(Result);
end
else
MouseItem(arr[i], True);
Wait(waitnum);
except end;
end;
end;
{*******************************************************************************
function ClickAllItems(Identifier: Integer; ItemType, option: string; waitnum: Integer; tol: TIntegerArray):Integer;
By: Nava2
Description: See ClickAllItemsExcept, this doesn't ignore any slots.
*******************************************************************************}
function ClickAllItems(ItemType: String; Identifier: Integer; option: string; waitnum: Integer; tol: TIntegerArray):Integer;
begin
Result := ClickAllItemsExcept(ItemType, Identifier, option, [], waitnum, tol);
end;
{*******************************************************************************
procedure DropItem(i: Integer);
By: Lorax
Description: Drops item at given position (1-28)
*******************************************************************************}
function DropItem(i: Integer): Boolean;
begin
Result := False;
if ExistsItem(i) then
begin
MouseItem(i, False);
if (WaitOptionEx('rop', 'action', ClickLeft, 250)) then
begin
Result := True;
Wait(RandomRange(50, 200));
end;
end;
end;
{*******************************************************************************
procedure DropArray(InvSlots: TIntegerArray);
By: Lorax/EvilChicken!, Tickyy for idea.
Description: Drops item positioned equivalent to numbers in "InvSlots" array.
Example: "DropArray([2, 4, 9, 12]);" would drop items in InvSlot 2, 4, 9 and 12.
*******************************************************************************}
procedure DropArray(InvSlots: TIntegerArray);
var
I, Len: Byte;
begin
Len := Length(InvSlots);
for I := 1 to Len - 4 do
Swap(InvSlots[RandomRange(I - 1, I + 4)], InvSlots[RandomRange(I - 1, I + 4)]);
for I := 0 to Len - 1 do
DropItem(InvSlots[I]);
end;
const
dp_UpToDown = 1;
dp_Snake = 2;
dp_Random = 3;
{*******************************************************************************
Procedure DropPattern(Which: Integer);
By: Rasta Magician
Description: Drops all items in inventory according to pattern which.
*******************************************************************************}
Procedure DropPattern(Which: Integer);
var
Col, A, I: Integer;
Arr: TIntegerArray;
Turn: Boolean;
begin
SetLength(Arr, 28);
A := 0;
if (Which = 0) then
Which := Random(2) + 1; //ignores complete randomness, unless scripter chooses to use it
writeln('Dropping by pattern: ' + IntToStr(Which));
case which of
dp_UpToDown:
for Col := 1 to 4 do
if InIntArray([2, 4], Col) then
begin
for i := 6 Downto 0 do
begin
Arr[a] := Col + i*4;
Inc(a);
end;
end else
for i := 0 to 6 do
begin
Arr[a] := Col + i*4;
Inc(a);
end;
dp_Snake:
repeat
if (not Turn) then
begin
for i:= 1 to 4 do
Arr[a + I - 1] := A + I;
IncEx(a, 4);
Turn := True;
end else begin
for I := 4 Downto 1 do
Arr[a-i+4] := a + i;
IncEx(a, 4);
Turn := false;
end;
until (a >= 28);
dp_Random:
begin
DropArray([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28]);
Exit;
end;
end;
if Random(2) = 1 then
InvertTIA(Arr);
Gametab(tab_inv);
for i:= 0 to 27 do
DropItem(Arr[i]);
end;
{*******************************************************************************
procedure DropAll;
By: Rasta Magician
Description: Drops all items in inventory.
*******************************************************************************}
procedure DropAll;
var i: integer;
begin
for i:= 0 to 2 do
begin
DropPattern(Random(2) + 1);
if InvCount = 0 then
break;
end;
end;
{*******************************************************************************
procedure DropAllExcept(IgnoreInvSlots: TIntegerArray);
By: Nava2
Date: Dec 06, 2009
Description: Drops everything in inventory. Ignores slots specified by
DontDrop array.
*******************************************************************************}
procedure DropAllExcept(DontDrop: TIntegerArray);
var
inv, i, h: Integer;
begin
h := high(DontDrop);
for i := 0 to h do
{ Set the bit associated with the DontDrop Array }
inv := inv or (1 shl DontDrop[i]);
for i := 1 to 28 do
{ Check the bit at i, and if its high, then we dont drop. }
if (((inv shr i) and 1) = 0) then
DropItem(i);
end;
{*******************************************************************************
procedure DropItemsByIdentifier;
By: EvilChicken! Fixed by Coh3n
Description: See description of ClickAllItemsExcept.
*******************************************************************************}
procedure DropItemsByIdentifier(ItemType: string; Identifier: Integer; Tol: TIntegerArray);
begin
ClickAllItems(ItemType, Identifier, 'rop', 250, Tol);
end;
{*******************************************************************************
procedure ArrangeInv;
By: Cheesehunk
Description: Arrange's inventory in an orderly fashion.
*******************************************************************************}
procedure ArrangeInv;
var
InvSpace, i, c, OpenSpace: Integer;
InvSpotFull: array[1..28] of Boolean;
begin
InvSpace := InvCount;
if (InvSpace <= 0) or (InvSpace >= 28) then
Exit;
for i := 1 to 28 do
InvSpotFull[i] := ExistsItem(i);
for i := 1 to 28 do
if InvSpotFull[i] then
for c := 1 to 28 do
if not ExistsItem(c) then
begin
OpenSpace := c;
if (i > 1) and (c < i) then
begin
DragItem(i, c);
Break;
end;
end;
end;
{*******************************************************************************
Function CountItemsBlackLine(Count, Tol: Integer): Integer;
By: n3ss3s
Description: Returns the number of items in inventory with Count amount of
blackline points and Tol tolerance in the amount of points.
*******************************************************************************}
function CountItemsBlackLine(Count, Tol: Integer): Integer;
var
TPA: TPointArray;
I, H: Integer;
TPAA: T2DPointArray;
begin
if (not BankScreen) then
GameTab(tab_Inv);
FindColors(TPA, srl_outline_black, MIX1, MIY1, MIX2, MIY2);
TPAA := TPAToATPAEx(TPA, 42, 36);
H := High(TPAA);
for I := 0 to H do
if InRange(GetArrayLength(TPAA[i]), Count - Tol, Count + Tol) then
Inc(Result);
end;
{*******************************************************************************
function ClickAllItemsBlackLine(Count, Tol: Integer; Option: String): Integer;
By: n3ss3s
Description: Finds all items in inventory with blackline points amount of Count
with Tol tolerance, and returns the amount of items could choose the
option Option to. Waits the WaitT amount of millisecs between items, with
WaitR randomness of milliseconds.
*******************************************************************************}
function ClickAllItemsBlackLine(Count, Tol, WaitT, WaitR: Integer; Option: String): Integer;
var
TPA: TPointArray;
X, Y, Z, H: Integer;
TPAA: T2DPointArray;
begin
if (not BankScreen) then
GameTab(tab_Inv);
FindColorsTolerance(TPA, srl_outline_black, MIX1, MIY1, MIX2, MIY2, 0);
TPAA := TPAToATPAEx(TPA, 42, 36);
H := High(TPAA);
for z := 0 to H do
if InRange(GetArrayLength(TPAA[z]), Count - Tol, Count + Tol) then
begin
MiddleTPAEx(TPAA[z], X, Y);
Mouse(X, Y, 2, 2, False);
if WaitOption(Option, 300) then
begin
Inc(Result);
Wait(WaitT + Random(WaitR));
end;
end;
end;
{*******************************************************************************
function ItemActivated(Slot: Integer): Boolean;
By: marpis
Description: Checks if item in specified inventory slot has a white outline.
Returns True if the item has a white outline, otherwise returns false.
*******************************************************************************}
function ItemActivated(Slot: Integer): Boolean;
var
X, Y: Integer;
B: TBox;
begin
GameTab(tab_Inv);
B := InvBox(Slot);
Result := FindColor(X, Y, 16777215, B.X1, B.Y1, B.X2, B.Y2);
end;
{*******************************************************************************
function FindActiveItemSlot: TBox;
By: EvilChicken!
Description: Checks if any items in the inventory have a white outline. If a
white outline is found around an item, it returns the TBox surrounding that item.
*******************************************************************************}
function FindActiveItemSlot: TBox;
var
X, Y: Integer;
begin
GameTab(tab_Inv);
if (FindColor(X, Y, 16777215, MIX1, MIY1, MIX2, MIY2)) then
Result := InvBox(CoordsToItem(X, Y));
end;
I think I got all the right ones. I left out the ones that you wouldn't/can't use while the bank is open. Comment/feedback?