Sub SortTSBags
/echo Doing a brute force sort of all TS materials that are in your TS bags
/declare PN int local
/declare SN int local
/declare U[500] int local
/declare V[500] int local
/declare M int local
/declare N int local
/declare O int local
/declare BestSlot int local
/declare BestIcon int local
/declare BestName string local
/declare Name string local
/declare Icon int local
/declare Better int local
|-- Loop over all inventory slots and items to find all TS item slots
/varset M 0
/for PN 1 to 10
/if (${Me.Inventory[pack${PN}].Name.Equal[Extraplanar Trade Satchel]}) {
|/varset Max ${Me.Inventory[pack${PN}].Container}
/for SN 1 to 32 |-- Will always be 32 slots
/varcalc M ${M} + 1
/varset U[${M}] ${PN}
/varset V[${M}] ${SN}
/next SN
}
/next PN
|-- At this point we have a mapping of all the slots we're going to sort.
/for O 1 to ${M}
/echo Sort Pass ${O} of ${M}
/varset BestIcon 0
/varset BestName 0
/varset BestSlot 0
/for N ${O} to ${M}
/varset Icon ${Me.Inventory[pack${U[${N}]}].Item[${V[${N}]}].Icon}
/varset Name ${Me.Inventory[pack${U[${N}]}].Item[${V[${N}]}].Name}
/if (${Icon}) {
/varset Better 0
/if (!${BestIcon}) /varset Better 1
|/if (${Icon}<${BestIcon}) /varset Better 1
|/if (${Icon}==${BestIcon} && ${Name.Compare[${BestName}]}<0) /varset Better 1
/if (${Name.Compare[${BestName}]}<0) /varset Better 1
/if (${Better}) {
/varset BestIcon ${Icon}
/varset BestName ${Name}
/varset BestSlot ${N}
}
}
/next N
/if (${BestIcon} && ${BestSlot}!=${O}) {
/nomodkey /shift /itemnotify in Pack${U[${BestSlot}]} ${V[${BestSlot}]} leftmouseup
/delay 1
/nomodkey /shift /itemnotify in Pack${U[${O}]} ${V[${O}]} leftmouseup
/delay 1
/autoinv
/delay 1
}
/next O
/return