Code: Select all
;***************************************************************************
;exchange.iss
;
;optional files:
; isxeqmoveit.dll
;
;currently isxeqmoveit is still in development and can cause crashes if misused
;it adds the functionality of being able to exchange items without opening packs
;
;to start:
; extension isxeqmoveit (optional)
; run exchange
;
;commands:
; /exchange <itemname> [slot] [inventorydirection]
; /unequip <itemname|slot> [inventorydirection]
;
;valid slots:
; charm leftear head face rightear neck shoulder arms back leftwrist
; rightwrist ranged hands mainhand offhand leftfinger rightfinger chest
; legs feet waist ammo pack1 pack2 pack3 pack4 pack5 pack6 pack7 pack8
;
;inventorydirection (default is -1)
; 1 = start at pack1 to find open packslot
; -1 = start at pack8 to find open packslot
;
;examples:
; /exchange "singing short sword"
; /exchange "coldain hero" leftfinger
;
; /unequip mainhand
; /unequip "singing short sword"
;
;
;note I use -1 as default so my gear is at bottom of inventory and stuff I loot is at top
;***************************************************************************
variable(global) queue:string Exchange_Cmd
variable(global) queue:string Unequip_Cmd
variable int Exchange_LeaveOpen=1
variable int Exchange_LeaveAnotherOpen=1
variable bool Exchange_KeepRunning=1
variable queue:int Exchange_Packopen
function main()
{
variable string param1
variable string param2
variable string param3
call init
do
{
if "${Exchange_Cmd.Size}"
{
if "${Exchange_Cmd.Peek.Equal[-quit]}"
Exchange_KeepRunning:Set[0]
else
{
if "${Exchange_Cmd.Size}>0"
{
param1:Set[${Exchange_Cmd.Peek}]
Exchange_Cmd:Dequeue
}
if "${Exchange_Cmd.Size}>0"
{
param2:Set[${Exchange_Cmd.Peek}]
Exchange_Cmd:Dequeue
}
else
param2:Set[-1]
if "${Exchange_Cmd.Size}>0"
{
param3:Set[${Exchange_Cmd.Peek}]
Exchange_Cmd:Dequeue
}
else
param3:Set[-1]
call doexchange "${param1}" "${param2}" "${param3}"
}
Exchange_Cmd:Clear
}
if "${Unequip_Cmd.Size}"
{
if "${Unequip_Cmd.Peek.Equal[-quit]}"
Exchange_KeepRunning:Set[0]
else
{
if "${Unequip_Cmd.Size}>0"
{
param1:Set[${Unequip_Cmd.Peek}]
Unequip_Cmd:Dequeue
}
if "${Unequip_Cmd.Size}>0"
{
param2:Set[${Unequip_Cmd.Peek}]
Unequip_Cmd:Dequeue
}
else
param2:Set[-1]
call dounequip "${param1}" "${param2}"
Unequip_Cmd:Clear
}
}
if ${QueuedCommands}
ExecuteQueued
else
WaitFrame
}
while "${Exchange_KeepRunning}"
}
function atexit()
{
deleteatom exchange
deleteatom unequip
deletevariable Exchange_Cmd
deletevariable Unequip_Cmd
EQExecute /stopsong
echo [Bard-o-Matic] Exchange Disengaged
}
function init()
{
echo [Bard-o-Matic] Exchange Engaged
}
global atom exchange(... param)
{
variable int i=1
Exchange_Cmd:Clear
while "${i}<=${param.Size}"
{
Exchange_Cmd:Queue[${param[${i}]}]
i:Inc
}
}
global atom unequip(... param)
{
variable int i=1
Unequip_Cmd:Clear
while "${i}<=${param.Size}"
{
Unequip_Cmd:Queue[${param[${i}]}]
i:Inc
}
}
;***************************************************************
;
; Exchange functions
;
;***************************************************************
function dounequip(fromslotpassed, direction=-1)
{
variable int packcount=29
variable int bagslot=1
variable int putslot=-1
variable bool slotfound=0
variable string validslots="charm:leftear:head:face:rightear:neck:shoulder:arms:back:leftwrist:rightwrist:ranged:hands:mainhand:offhand:leftfinger:rightfinger:chest:legs:feet:waist:ammo:pack1:pack2:pack3:pack4:pack5:pack6:pack7:pack8"
variable bool validate=0
variable string fromslot
variable int i=1
variable bool isnum=0
isnum:Set[${fromslotpassed.Equal[${Int[${fromslotpassed}]}]}]
fromslot:Set[${fromslotpassed}]
if "${validslots.Find[${fromslot}]} && ${fromslot.Length}>3"
{
validate:Set[1]
}
if "${isnum}"
if "${fromslot}<21"
{
validate:Set[1]
}
if "${validate}==0"
{
if "${FindItem[${fromslot}].InvSlot}<22"
{
fromslot:Set[${FindItem[${fromslot}].InvSlot}]
validate:Set[1]
}
}
if "!${InvSlot[${fromslot}].Item.Name(exists)} || ${validate}==0"
{
if "${Bandolier_Cmd.Size}==0"
echo [Bard-o-Matic] Unequip::Nothing to unequip!
return
}
if "${putslot}==-1"
{
call findopenbagslot "${InvSlot[${fromslot}].Item.Name}" ${direction}
if "${Return}>0"
{
putslot:Set[${Return}]
slotfound:Set[1]
}
}
if "${slotfound}"
{
if "${Bandolier_Cmd.Size}==0"
echo [Bard-o-Matic] Exchange::Unequipping ${InvSlot[${fromslot}].Item.Name}
if "${Extension[isxeqmoveit](exists)}==FALSE"
call openpack ${packcount}
if "${Extension[isxeqmoveit](exists)}==FALSE"
call openpack ${Math.Calc[((${putslot}-251)/10)+22].Int}
variable string tempstring
tempstring:Set[${InvSlot[${fromslot}]}]
fromslot:Set[${tempstring}]
call swapit ${fromslot} ${putslot}
if "${Extension[isxeqmoveit](exists)}==FALSE && ${Bandolier_Active}==0"
call closepack ${packcount}
}
else
{
echo [Bard-o-Matic] Unequip::No bag slots available!
}
}
function doexchange(string item, string passedtoslot, direction=-1)
{
variable int inventoryslot
variable string pack
variable int packslot
variable int packnumber=0
variable string toslot
toslot:Set["${InvSlot[${passedtoslot}]}"]
echo [Exchange] ${item},${passedtoslot},${toslot}
;find item and set pack and packslot or inventoryslot
inventoryslot:Set[${FindItem[${item}].InvSlot}]
if "!(${inventoryslot}>0)"
{
return
}
if "${inventoryslot}>250 && ${inventoryslot}<331"
{
packnumber:Set[${Math.Calc[((${inventoryslot}-251)/10)+1].Int}]
packslot:Set[${Math.Calc[(${inventoryslot}-251)%10].Int}]
}
else
{
if "${Bandolier_Cmd.Size}==0"
echo [Bard-o-Matic] Exchange::Item already equipped!
return
}
;verify toslot is set
if "${toslot.Equal["NULL"]}"
if "${FindItem[${item}].WornSlots}>0"
toslot:Set[${FindItem[${item}].WornSlot[1]}]
else
{
echo [Bard-o-Matic] Exchange::No valid destination!
return
}
variable int packcount=29
variable int bagslot=1
variable int putslot=-1
variable bool slotfound=0
if "${Extension[isxeqmoveit](exists)}==FALSE"
call openpack ${Math.Calc[${packnumber}+21]}
if "${InvSlot[${Math.Calc[${packnumber}+21]}].Item.SizeCapacity}>=${InvSlot[${toslot}].Item.Size}"
{
putslot:Set[${inventoryslot}]
slotfound:Set[1]
}
if "${putslot}==-1"
{
do
{
if "!${InvSlot[${packcount}].Item.Name(exists)}"
{
putslot:Set[${packcount}]
slotfound:Set[1]
break
}
}
while "${packcount:Dec}>21"
}
if "${putslot}==-1"
{
call findopenbagslot "${InvSlot[${toslot}].Item.Name}" ${direction}
if "${Return}>0"
{
putslot:Set[${Return}]
slotfound:Set[1]
}
}
if "${slotfound}"
{
if "${Bandolier_Cmd.Size}==0"
echo [Bard-o-Matic] Exchange::Equipping ${InvSlot[${inventoryslot}].Item.Name} to ${InvSlot[${toslot}].Name}
variable string tempstring
tempstring:Set[${InvSlot[${inventoryslot}]}]
inventoryslot:Set[${tempstring}]
tempstring:Set[${InvSlot["${fromslot}"]}]
fromslot:Set[${tempstring}]
call swapit ${inventoryslot} ${toslot} ${putslot}
}
else
{
if "${Bandolier_Cmd.Size}==0"
echo [Bard-o-Matic] Exchange::No bag slots available!
}
if "${Extension[isxeqmoveit](exists)}==FALSE && ${Bandolier_Active}==0"
call closepack
}
function findopenbagslot(searchitem, direction=-1)
{
variable int packcount
variable int finalcount
variable int putslot=-1
variable int bagslot
variable bool slotfound=0
packcount:Set[29]
do
{
if "!${InvSlot[${packcount}].Item.Name(exists)}"
{
putslot:Set[${packcount}]
slotfound:Set[1]
return ${putslot}
}
}
while "${packcount:Dec}>21"
if "${direction}==1"
{
packcount:Set[22]
finalcount:Set[30]
}
else
{
packcount:Set[29]
finalcount:Set[21]
}
do
{
if "${InvSlot[${packcount}].Item.Container}>0"
{
if "${InvSlot[${packcount}].Item.SizeCapacity}>=0${FindItem[${searchitem}].Size}"
{
if "${InvSlot[${packcount}].Item.Items}<${InvSlot[${packcount}].Item.Container}"
{
bagslot:Set[1]
do
{
putslot:Set[${Math.Calc[250+(${packcount}-22)*10+${bagslot}].Int}]
if "!${InvSlot[${putslot}].Item.Name(exists)}"
{
slotfound:Set[1]
return ${putslot}
}
}
while "${bagslot:Inc}<${InvSlot[${packcount}].Item.Container}"
}
}
}
if "${direction}==1"
packcount:Inc
else
packcount:Dec
}
while "${packcount}!=${finalcount}"
return ${putslot}
}
function openpack(packslot)
{
variable int timeout=15
if "!${Window[pack${Math.Calc[${packslot}-21].Int}].Open}"
Exchange_Packopen:Queue[${packslot}]
while "!${Window[pack${Math.Calc[${packslot}-21].Int}].Open} && ${timeout}>0"
{
NoModKey EQItemNotify ${packslot} rightmouseup
WaitFrame
}
}
function closepack()
{
variable int packslot
variable int timeout=15
while "${Exchange_Packopen.Size}"
{
packslot:Set[${Exchange_Packopen.Peek}]
while "${Window[pack${Math.Calc[${packslot}-21].Int}].Open} && ${timeout}>0"
{
NoModKey EQItemNotify ${packslot} rightmouseup
WaitFrame
}
Exchange_Packopen:Dequeue
}
}
function swapit(fromslot, toslot, lastslot)
{
variable string item
variable int timeout=15
; echo [SwapIt] ${fromslot}, ${toslot}, ${lastslot}
item:Set[${Cursor.ID}]
do
{
if "${fromslot}>250 && ${Extension[isxeqmoveit](exists)}==TRUE"
moveitem ${fromslot} 30
else
NoModKey EQItemNotify ${fromslot} leftmouseup
WaitFrame
}
while "${item}==${Cursor.ID} && ${timeout}>0"
timeout:Set[15]
item:Set[${Cursor.ID}]
do
{
if "${toslot}>250 && ${Extension[isxeqmoveit](exists)}==TRUE"
moveitem 30 ${toslot}
else
NoModKey EQItemNotify ${toslot} leftmouseup
WaitFrame
}
while "${item}==${Cursor.ID} && ${timeout}>0"
if "${lastslot.Length}>0"
{
timeout:Set[15]
item:Set[${Cursor.ID}]
do
{
if "!${Cursor.ID(exists)}"
break
if "${lastslot}>250 && ${Extension[isxeqmoveit](exists)}==TRUE"
moveitem 30 ${lastslot}
else
NoModKey EQItemNotify ${lastslot} leftmouseup
WaitFrame
}
while "${item}==${Cursor.ID} && ${timeout}>0"
}
}

