# SlotInterface Methods to interact slotted interfaces. "Slotted interfaces" in WaspLib refers to any interface that is an item container. In other words, if an interface has holds items, it's both a {ref}`SlotInterface` and {ref}`ItemInterface`. Examples of "item containers" are: - {ref}`Inventory` - {ref}`Equipment` - {ref}`Bank` - {ref}`DepositBox` - {ref}`CollectBox` Just because an interface is an "item container", does not mean it uses {ref}`SlotInterface`, but all the examples above do and you can access it through their `Slots` variable, for example: ```pascal Inventory.Slots; Equipment.Slots; Bank.Slots; ``` ```{note} Throughout this page examples, {ref}`Inventory` will be used in most of them but any interface that has a {ref}`TRSSlotInterface` variable can used instead. ``` - - - ## TRSSlotInterface Main record to handle a {ref}`SlotInterface`. ```{note} Throughout this page `Slots` will always refer to a `TRSSlotInterface` variable unless specified otherwise. ``` - - - ## Slots.Setup ```pascal procedure TRSSlotInterface.Setup(name: String; slots: TBoxArray; slotsFunction: function (): TBoxArray of object = nil); ``` Setup method of the {ref}`SlotInterface`. All interfaces included in WaspLib that use a {ref}`SlotInterface` already call this automatically for you. Unless you create your own, you don't need to use it. You have 3 parameters: - `name`, simply used for debugging if something goes wrong, it will tell you which {ref}`SlotInterface` raised an exception. - `slots` which should be a static `TBoxArray`. - `slotsFunction` which should be a function that returns a `TBoxArray` useful for dynamic slot boxes. Whatever boxes are passed to `slots` are only ever used if you `slotsFunction` is `nil`. In other words, if you set a `slotsFunction` that will always be the prefered way that `TRSSlotInterface` will use internally. So if you are going to setup a function, you can leave `slots` as an emtpy array if you want. For example, here is how the {ref}`TRSBank` `TRSSlotInterface` could be setup: ```pascal Bank.Slots.Setup('Bank.Slots', [], @Bank.FindItemBoundaries); ``` In reality it's setup like this: ```pascal Bank.Slots.Setup('Bank.Slots', Bank.SlotBoxes, @Bank.FindItemBoundaries); ``` Just in case people would like to access the bank's static slots through it's `Slots` variable. - - - ## Slots.Boxes ```pascal function TRSSlotInterface.Boxes(): TBoxArray; function TRSSlotInterface.Boxes(slots: TIntegerArray): TBoxArray; overload; ``` Functions to return the slot boxes of the {ref}`SlotInterface`. Example: ```pascal {$I WaspLib/osrs.simba} begin ShowOnTarget(Inventory.Slots.Boxes()); end. ``` ```{figure} ../../images/slotboxes.png ``` You can optionally return only some of the boxes as well: ```pascal {$I WaspLib/osrs.simba} begin ShowOnTarget(Inventory.Slots.Boxes([2,3,4,12,13,15,16])); end. ``` ```{figure} ../../images/slotboxes2.png ``` - - - ## Slots.Box ```pascal function TRSSlotInterface.Box(slot: Integer): TBox; ``` Return the box of the specified slot on the {ref}`SlotInterface`. Example: ```pascal {$I WaspLib/osrs.simba} begin ShowOnTarget(Inventory.Slots.Box(6)); end. ``` ```{figure} ../../images/slotbox.png ``` - - - ## Slots.Near ```pascal function TRSSlotInterface.Near(slot: Integer; slots: TIntegerArray; maxDist: Single = 60): TIntegerArray; ``` From the `slots` array which should be an array of indices for `Slots.Boxes`, return the indices that are "near" `slot` based on the `maxDist` value. Example: ```pascal {$I WaspLib/osrs.simba} var indices: TIntegerArray; begin indices := Inventory.Slots.Near(15, [0..27]); ShowOnTarget(Inventory.Slots.Boxes(indices)); end. ``` ```{figure} ../../images/slotsnear.png ``` - - - ## Slots.RandomNear ```pascal function TRSSlotInterface.RandomNear(slot: Integer; slots: TIntegerArray; maxDist: Single = 60; distribution: ERandomDistribution = ERandomDistribution.GAUSS): Integer; ``` From the `slots` array which should be an array of indices for `Slots.Boxes`, return a random index that is "near" `slot` based on the `maxDist` value. Example: ```pascal {$I WaspLib/osrs.simba} var idx: Integer; begin while True do begin idx := Inventory.Slots.RandomNear(13, [0..27]); ShowOnTarget(Inventory.Slots.Boxes([13, idx])); Sleep(100); end; end. ``` ```{figure} ../../images/slotsrandomnear.gif ``` - - - ## Slots.GetUnder ```pascal function TRSSlotInterface.GetUnder(pt: TPoint): Integer; ``` Returns the index of the box that is under `pt`. Example: ```pascal {$I WaspLib/osrs.simba} begin WriteLn Inventory.Slots.GetUnder(Mouse.Position); end. ``` - - - ## Slots.GetUsed ```pascal function TRSSlotInterface.GetUsed(): TIntegerArray; ``` Returns the indices of the slots that contain an item. Example: ```pascal {$I WaspLib/osrs.simba} var indices: TIntegerArray; begin indices := Inventory.Slots.GetUsed(); ShowOnTarget(Inventory.Slots.Boxes(indices)); end. ``` ```{figure} ../../images/slotsgetused.png ``` - - - ## Slots.GetUsed ```pascal function TRSSlotInterface.GetUsed(): TIntegerArray; ``` Returns the indices of the slots that don't have an item. Example: ```pascal {$I WaspLib/osrs.simba} var indices: TIntegerArray; begin indices := Inventory.Slots.GetEmpty(); ShowOnTarget(Inventory.Slots.Boxes(indices)); end. ``` ```{figure} ../../images/slotsgetempty.png ``` - - - ## Slots.IsUsed ```pascal function TRSSlotInterface.IsUsed(slot: TBox): Boolean; function TRSSlotInterface.IsUsed(slot: Integer): Boolean; overload; ``` Returns True/False if the specified `slot` contains an item. Example: ```pascal {$I WaspLib/osrs.simba} begin WriteLn Inventory.Slots.IsUsed(5); end. ``` - - - ## Slots.IsEmpty ```pascal function TRSSlotInterface.IsEmpty(slot: TBox): Boolean; function TRSSlotInterface.IsEmpty(slot: Integer): Boolean; overload; ``` Returns True/False if the specified `slot` doesn't have an item. Example: ```pascal {$I WaspLib/osrs.simba} begin WriteLn Inventory.Slots.IsEmpty(5); end. ``` - - - ## Slots.IsFaded ```pascal function TRSSlotInterface.IsFaded(slot: TBox): Boolean; function TRSSlotInterface.IsFaded(slot: Integer): Boolean; overload; ``` Returns True/False if the specified `slot` has an item and is faded. An item is usually faded for a few frames when you click it or when you drag it. Example: ```pascal {$I WaspLib/osrs.simba} begin WriteLn Inventory.Slots.IsFaded(5); end. ``` - - - ## Slots.WaitFade ```pascal function TRSSlotInterface.WaitFade(slot: TBox; time: Integer = 200): Boolean; function TRSSlotInterface.WaitFade(slot: Integer; time: Integer = 200): Boolean; overload; ``` Waits `time` milliseconds for {ref}`Slots.IsFaded` to return False for the specified `slot`. Example: ```pascal {$I WaspLib/osrs.simba} begin WriteLn Inventory.Slots.WaitFade(5); end. ``` - - - ## Slots.Count ```pascal function TRSSlotInterface.Count(): Integer; ``` Returns the amount of slots that contain items. Example: ```pascal {$I WaspLib/osrs.simba} begin WriteLn Inventory.Slots.Count(); end. ``` - - - ## Slots.CountEmpty ```pascal function TRSSlotInterface.CountEmpty(): Integer; ``` Returns the amount of slots that do not contain items. Example: ```pascal {$I WaspLib/osrs.simba} begin WriteLn Inventory.Slots.CountEmpty(); end. ``` - - - ## Slots.WaitCount ```pascal function TRSSlotInterface.WaitCount(count: Int32; time: Int32 = 600; interval: Int32 = -1): Boolean; ``` Waits for `time` milliseconds for {ref}`Slots.Count` to return `count`. Example: ```pascal {$I WaspLib/osrs.simba} begin WriteLn Inventory.Slots.WaitCount(2); end. ``` - - - ## Slots.ReadStack ```pascal function TRSSlotInterface.ReadStack(slot: TBox): Integer; function TRSSlotInterface.ReadStack(slot: Integer): Integer; overload; ``` Reads the stack amount of a slot. If the slot has no item in it `-1` is returned. If `0` is returned it means the slot has an item but has no stack number. This is important to keep in mind because in most interfaces, even if an item is stackable, if there's only a quantity of 1 available, it won't have a stack number. Example: ```pascal {$I WaspLib/osrs.simba} begin WriteLn Inventory.Slots.ReadStack(0); end. ``` - - - ## Slots.Hover ```pascal procedure TRSSlotInterface.Hover(slot: Integer); ``` Hover the specified `slot` with the mouse. Example: ```pascal {$I WaspLib/osrs.simba} begin Inventory.Slots.Hover(0); end. ``` - - - ## Slots.Click ```pascal procedure TRSSlotInterface.Click(slot: Integer; button: EMouseButton = EMouseButton.LEFT); ``` Clicks the specified `slot` with the specified `button`. Example: ```pascal {$I WaspLib/osrs.simba} begin Inventory.Slots.Click(0); end. ``` - - - ## Slots.Move ```pascal function TRSSlotInterface.Move(slot, destination: Integer): Boolean; ``` If `slot` has an item, move it to slot `destination`. Example: ```pascal {$I WaspLib/osrs.simba} begin Inventory.Slots.Move(0, 6); end. ``` - - - ## Slots.Interact ```pascal function TRSSlotInterface.Interact(slot: Integer; option: String = ''): Boolean; ``` Interacts with `slot` if it has an item, with the specified `option`. If `option` is empty or if `option` is the default {ref}`UpText` for the item this will simply left click it. Example: ```pascal {$I WaspLib/osrs.simba} begin Inventory.Slots.Interact(0, 'Drink'); end. ```