Accept trades if no items will drop

devestator

Lifetime Member
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.

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
 
Because having it in macro form has it's advantages. It's more versatile and easier to make modifications to suit your needs.

You might not want to auto accept trades when you aren't running a specific macro, but with the plugin you would even if you aren't running the macro. And there are plenty of other reasons I could think of, but thats not really the point of the thread :)

The code is here for those that want to use it.