Page 1 of 1

Item Restocking

Posted: Sun Sep 05, 2004 9:18 am
by Alisandra
Quick restocking macro, target merchant and run.

Code: Select all

Sub Main
        /if (!${Target.ID} && !${Merchant.Open}) {
                /echo Target a merchant!
                /endmacro
        }
        /if (${Target.ID} && !${Merchant.Open}) {
                /click right target
                /delay 1s
        }
        /if (${Ini[Restock.ini,${Me.Name}].Length}) /call ProcessIni
        /if (${Merchant}) {
                /keypress esc
                /keypress esc
        }
        /return
        
Sub ProcessIni
        /declare index int local
        /declare KeyNames string local ${Ini[Restock.ini,${Me.Name}]}
        /declare ItemName string local
        /declare ItemQty int local
        
        /for index 1 to 100
                /if (${KeyNames.Arg[${index},|].Length} > 2) {
                        /varset ItemName ${KeyNames.Arg[${index},|]} 
                        /varset ItemQty ${Ini[Restock.ini,${Me.Name},"${ItemName}"]}
                        /echo Checking: ${ItemName} (${FindItemCount[=${ItemName}]}/${ItemQty})
                        /if (${FindItemCount[=${ItemName}]} < ${ItemQty}) /call Restock "${ItemName}" ${ItemQty}
                }
        /next index
        /return
        
Sub Restock(ItemName,Qty)
        /declare ItemSlot int local

        /if (${Merchant.Item[=${ItemName}].InvSlot}) /call BuyItems "${ItemName}" ${Qty}
        
        /return

Sub BuyItems(ItemName,Qty)
        /declare StartCash int local ${Me.Cash}
        /declare QtyStart int local ${FindItemCount[=${ItemName}]}
        /declare QtyNeeded int local
        
        /if (!${Merchant.Open}) {
                /echo No Merchant open to buy from
                /return
        }
        
        /if (${FindItemCount[=${ItemName}]} >= ${Qty}) {
                /echo Already have all the ${ItemName}(s) needed.
                /return
        }
        
        /itemnotify ${Merchant.Item[=${ItemName}].InvSlot} leftmouseup
        
        /varset QtyNeeded ${Math.Calc[${Qty} - ${FindItemCount[=${ItemName}]}].Int}
        :BuyItemLoop0
        /doevents
        /if (${QtyNeeded} >= 20) {
                /call CheckFunds "${ItemName}"  ${Merchant.Item[=${ItemName}].BuyPrice} 20
                /if (${Me.FreeInventory[${Merchant.Item[=${ItemName}].Size}]}) {
                        /buyitem 20
                } else {        
                        /echo No space to buy more ${ItemName}, exiting
                        /endmacro
                }
                /varset QtyNeeded ${Math.Calc[${QtyNeeded}-20]}
        } else {
                /call CheckFunds "${ItemName}"  ${Merchant.Item[=${ItemName}].BuyPrice} ${QtyNeeded}
                /buyitem ${QtyNeeded}
        }
        /delay 1s
        /if (${FindItemCount[=${ItemName}]} < ${Qty}) /goto :BuyItemLoop0
        
        /echo Purchased ${Math.Calc[${Qty} - ${QtyStart}].Int} ${ItemName}(s) for ${Math.Calc[(${StartCash}-${Me.Cash})/1000].Int}pp ${Math.Calc[((${StartCash}-${Me.Cash})/100)%10].Int}gp ${Math.Calc[((${StartCash}-${Me.Cash})/10)%10].Int}sp ${Math.Calc[((${StartCash}-${Me.Cash})%10)].Int}cp 
        
        /return

Sub CheckFunds(ItemName,Price,Qty)
        /if (${Me.Cash} < ${Math.Calc[${Price} * ${Qty}]}) {
                /echo Insufficient funds to purchase: ${Qty} x ${ItemName}
                /keypress esc
                /keypress esc
                /endmacro
        }
        /return

Ini File (Restock.ini) is in the form:

Code: Select all


[Character Name]
Item1=Qty
Item2=Qty
....
for example

Code: Select all

[Some Mage]
Pearl=160
Malachite=80
Star Ruby=20
Misty Thicket Picnic=20
Kaladim Constitutional=20

[SomeCleric]
Peridot=120
Emerald=20
Pearl=40
Star Ruby=20
Misty Thicket Picnic=20
Fuzzlecutter Formula 5000=20

Posted: Mon Sep 06, 2004 1:02 am
by in_training
Think ya can add a Quantity on-hand check?

EG: when I go to a raid, i want to have 20 jasper, 60 peridots, 40 Emeralds, 17 Small jade coffins, and 100 pearls..


I have 10 jasper, i only need to buy 10 more.

It would be perfect for me since I carry the components for the casters in my guild, and I have to carry so much crap to every raid.. but that's another rant.

Posted: Mon Sep 06, 2004 9:44 am
by Alisandra
It already does that. It only buys however many items are needed to reach the qty set in the ini file. So if you have 119 peridots, and the ini file said 120 peridots it would just buy 1.

Posted: Mon Sep 06, 2004 11:15 am
by in_training
You are a god send! Thank you!

(I have been awake for about 29 hours right now. I skimmed the code, but didn't read it. I apologize.

Posted: Mon Sep 06, 2004 11:42 am
by Night Hawk
Nice job on this. Pretty much what I 'tried' to do with my food.mac but this works for an unlimited ammount of variety (pretty much).