Minor modification to alllow you to search for non-stackable items.
Code: Select all
sub main
| Example calls
/call freeInventory
/echo FreeInventory = ${Macro.Return}
/call freeInventory e
/echo FreeInventory(e) = ${Macro.Return}
/call freeInventory NULL "Arctic Scallop"
/echo FreeInventory(Arctic Scallops) = ${Macro.Return}
/return
| Name: freeInventory
| Purpose: Return number of available slots in inventory
| Version: 1.0.0.1
| Date: 23 Apr 04
| Author: Kaitain Heavy Industries
|
| Function: freeInventory([PackNumber],[ItemName])
|
| Inputs: PackNumber The inventory pack to look in, optional
| ItemName What item to look for (stackable or not)
|
| Returns: Number of free slots. This can be:
| Total number of slots
| Free slots in an enviromental container
| Total number of slots for a particular item (for stackable items this includes all stackable space)
| Number of free slots in a pack
| Number of slots for an item in a specific pack (for stackable items this includes all stackable space)
|
| Usage Examples:
|
| /call freeInventory
| Returns all free non-stackable space
|
| /call freeInventory 1
| Returns free non-stackable space for pack number 1
|
| /call freeInventory 1 "Arctic Scallop"
| Returns free stackable space in pack number 1 for Arctic Scallops
|
| /call freeInventory NULL "Arctic Scallop"
| Returns all free stackable space for Arctic Scallops
|
| /call freeInventory e
| Returns free non-stackable space for the enviromental container
|
| Notes:
| Enviromental packs cannot currently be checked for free stackable space
|
sub freeInventory(PackNumber,ItemName)
/declare freeSlots local | How many slots are available
/declare iPack local | Used for looping through inventory pack nunbers
/declare iSlot local | Used for looping through pack slots
/declare startSlot local | Used with iPack to limit checking the contents of just one pack
/declare endSlot local | Used with iPack to limit checking the contents of just one pack
/varset freeSlots 0
/varset startSlot 1
/varset endSlot 8
| If no pack number is defined, we need to define it and set it to null
/if (${Defined[PackNumber]}) {
| /echo PackNumber defined
} else {
/declare PackNumber local
/varset PackNumber NULL
}
| Are we looking at an enviromental container or in our inventory
/if (${String[@PackNumber].Equal[e]}) {
/if (${Window[Enviro].Open}==NULL) {
/echo freeInventory Error: You must have the enviromental container open before testing it for available space
/return -1
}
/if (${Defined[ItemName]}) {
/echo freeInventory Error: Currently this sub does not support checking for stackable ItemName space in an enviromental container
/return -1
}
|This is REALLY crappy and slow, but right now there is no way (that I know of) to examine the contents of an enviromental container
/for iPack 0 to 9
/click left enviro @iPack
/if (${Cursor.ID}==NULL) {
/varadd freeSlots 1
} else {
/click left enviro @iPack
}
/next iPack
} else {
| Not enviromental container
/if (${String[@PackNumber].NotEqual[Null]}) {
/varset PackNumber ${String[@PackNumber].Arg[0,.]} | Just in case it got mangled into a float
/varset startSlot @PackNumber
/varset endSlot @PackNumber
}
/for iPack @startSlot to @endSlot
| /echo iPack = @iPack
| Check to see if there is a bag in this slot
/if (${Me.Inventory[Pack@iPack].Container}==0) {
| No bag, see if there is anything
/if (${String[${Me.Inventory[21+@iPack]}].Equal[Me]}) {
| Nothing in this slot
/if (${Defined[ItemName]}) {
| /echo Empty Pack slot
/varadd freeSlost 20
} else {
/varadd freeSlots 1
}
} else {
| See if this ItemName is what we are looking for, and see if there is free stackable space
/if (${Defined[ItemName]}) {
| /echo Name = ${Me.Inventory[21+@iPack].Name} : iPack = @iPack
if (${Me.Inventory[21+@iPack].Name.Equal[@ItemName]}) {
| See how many stackable slots are available
/if (${Me.Inventory[21+@iPack].Stackable}) {
/varcalc freeSlots @freeSlots+(20-${Me.Inventory[21+@iPack].Stack})
}
}
}
}
} else {
| This is a bag
| Are we looking for item space or just free space
/if (${Defined[ItemName]}) {
/for iSlot 1 to ${Me.Inventory[Pack@iPack].Container}
| /echo Looking at item: ${Me.Inventory[Pack@iPack].Item[@iSlot].Name}
| /echo ItemName = @ItemName
/if (${Me.Inventory[Pack@iPack].Item[@iSlot].Name.Equal[@ItemName]}) {
| /echo Found item @ItemName
| Make sure it's stackable
/if (${Me.Inventory[Pack@iPack].Item[@iSlot].Stackable}) {
/varcalc freeSlots @freeSlots+(20-${Me.Inventory[Pack@iPack].Item[@iSlot].Stack})
}
} else {
/if (${String[${Me.Inventory[Pack@iPack].Item[@iSlot]}].Equal[null]}) {
/varadd freeSlots 20
}
}
/next iSlot
} else {
| This is a bag, but item name is not given
/varcalc freeSlots @freeSlots+(${Me.Inventory[Pack@iPack].Container}-${Me.Inventory[Pack@iPack].Items})
}
}
/next iPack
}
/return @freeSlots
