- Joined
- Oct 25, 2006
- Messages
- 1,550
- Reaction score
- 15
- Points
- 38
This is a little routine that is in my devCommon.inc now but I figured others might find a use for this particularly more than some of my other routines. It's purpose is it checks for a trade, and that the person trading to you has clicked trade already. It then maps out the open inventory slots in your inventory and decides if it is safe to accept the trade.
I could not find any situation where it resulted in an item dropping to the ground. If you find one just let me know.
The way it is currently set up it accepts trades from anyone, if you need something customized to accept trades only in particular conditions or something like that then let me know and I'll see what I can do.
I could not find any situation where it resulted in an item dropping to the ground. If you find one just let me know.
The way it is currently set up it accepts trades from anyone, if you need something customized to accept trades only in particular conditions or something like that then let me know and I'll see what I can do.
Code:
Sub TradeCheck
/declare intContainer int local 0
/declare intLoop int local 0
/declare intILoop int local 0
/declare openSize[80] int local
/declare openTrack int local 0
/declare slotFound bool local
/if (${Window[TradeWnd].Open}) {
/if (${Window[TradeWnd].HisTradeReady}) {
/call EchoLog "Trade detected, checking if we can accept" true
/for intLoop 1 to 80
/varset openSize[${intLoop}] -1
/next intLoop
/for intLoop 23 to 30
/if (!${InvSlot[${intLoop}].Item.ID}) {
/varcalc openTrack ${openTrack} + 1
/varset openSize[${openTrack}] 5
}
/next intLoop
/for intLoop 23 to 30
/if (${InvSlot[${intLoop}].Item.ID} && ${InvSlot[${intLoop}].Item.Container}) {
/varcalc intContainer ${InvSlot[${intLoop}].Item.Container} - ${InvSlot[${intLoop}].Item.Items}
/if (${intContainer}) {
/for intILoop 1 to ${intContainer}
/varcalc openTrack ${openTrack} + 1
/varset openSize[${openTrack}] ${InvSlot[${intLoop}].Item.SizeCapacity}
/next intILoop
}
}
/next intLoop
/for intLoop 9 to 16
/if (${InvSlot[trade${intLoop}].Item.ID}) {
/if (${InvSlot[trade${intLoop}].Item.Container}) {
/if (${openSize[${Math.Calc[${intLoop} - 8]}]} < 5) {
/call EchoLog "Cannot complete trade because there aren't enough primary inventory slots open, or the items are in a bad order." true
/goto :cancelTrade
} else {
/varset openSize[${Math.Calc[${intLoop} - 8]}] -1
}
} else {
/varset slotFound false
/for intILoop 1 to 80
/if (${openSize[${Math.Calc[${intLoop} - 8]}]} >= ${InvSlot[trade${intLoop}].Item.Size}) {
/varset openSize[${Math.Calc[${intLoop} - 8]}] -1
/varset slotFound true
}
/if (!${slotFound}) /next intILoop
/if (!${slotFound}) {
/call EchoLog "Cannot complete trade because there aren't enough open inventory slots of size ${InvSlot[trade${intLoop}].Item.Size}, or the items are in a bad order" true
/goto :cancelTrade
}
}
}
/next intLoop
/goto :acceptTrade
} else {
/return ABORT_NOTREADY
}
} else {
/return ABORT_NOTRADE
}
:cancelTrade
/notify TradeWnd TRDW_Cancel_Button leftmouseup
/delay 2s !${Window[TradeWnd].Open}
/if (${Window[TradeWnd].Open}) /goto :cancelTrade
/return ABORT_CANCEL
:acceptTrade
/notify TradeWnd TRDW_Trade_Button leftmouseup
/delay 2s !${Window[TradeWnd].Open}
/if (${Window[TradeWnd].Open}) /goto :acceptTrade
/return COMPLETED_SUCCESS