Checking for open inventory containers

Need help with a macro you are writing? Ask here!

Moderator: MacroQuest Developers

horseshoecrabs
a ghoul
a ghoul
Posts: 89
Joined: Fri Jun 10, 2005 6:35 pm

Checking for open inventory containers

Post by horseshoecrabs » Tue Oct 25, 2005 7:31 pm

Edit: the include file is now updated and seems to address the open and closed bag assignments I was trying to achieve. Feel free to play with it and post any feedback. Once it's determined to be properly cool, I'll repost it in either macro depot or macro snippets.

Basic usage is to tell your regular script that you want to find an item, then pass along the name of the item (variable) via a subroutine call to the include file. See Concussion macro below for a straightforward example.

------------------------

Hi there,

I'm trying to expand my working knowledge of MQ yet some more (use of an include file, passing parameters from one subroutine to another) and decided to take my working concussion.mac or manarobe.mac and modify them to use an include file for certain repetitive tasks.

The other reason for doing this was that after the most recent MQ2 distribution, I was having some problems with item notification lag. To get around this, I made all of these repetitive tasks do a cyclical check to make sure the state of the window, mouse cursor, etc. was what I need it to be before allowing the script to continue.

Specifically, I viewed those tasks as follows:

find the bag an item is in
open the bag if it isn't already open
grab the item from the bag
close the bag
notify the equipment slot the clicky item can be used in
use item
notify the slot again to equip original item
/autoinv the clicky item

Breaking these tasks down made me realize this would be useful for other stuff too such as coldain ring, jboots, etc.

First, here's a revised concussion.mac:

Code: Select all

|Concussion.mac by Horseshoecrabs 
|Useage: This Macro requires Maelin's Pants of Lore 
| 
|This macro will grab your Maelin's Pants from inventory for those of us not 
|wearing them, cast them once, and puts them away. 

#include generic_tools.inc
#event StopRoutine "You must be standing to cast a spell." 
#event StopRoutine "Your spell is interrupted." 

Sub Main(int ConcussionCounter) 

/declare BagLegs int outer
/declare IncrementalWait int outer
/declare MyCounter int outer 
/declare ConcPants string outer "Maelin's Leggings of Lore"
/declare PriLegs string outer "Merciless Enslaver's Britches"

   /call UnloadCursor 

   /varset BagLegs ${FindItem[${ConcPants}].InvSlot.Pack}
   /Call OpenBag ${BagLegs}
   /Call GrabItem ${ConcPants}
   /Call CloseBag ${BagLegs}
   /Call LeftClickSwap Legs ${ConcPants}

   /For MyCounter 1 to ${ConcussionCounter}
     /cast item ${ConcPants}
     /call CastWait
   /Next MyCounter

   /call LeftClickSwap Legs ${PriLegs}

   /call UnloadCursor

   /endmac

Sub Event_StopRoutine 
   /doevents flush 
   /call LeftClickSwap Legs ${PriLegs}
   /call UnloadCursor 
   /if (${AlreadyMounted}==0) /dism 
   /endmac 
/return
And here is the relevant section of the include file:

Code: Select all

Sub CastWait 
   :Casting 
   /delay ${SpellWait} 
   /if (${Me.Stunned} && !${Me.Sitting}) /sit 
   /if (${Me.Stunned}) /goto :Casting 
   /if (${Me.Casting.ID}) /goto :Casting 
/return 

Sub CloseBag(BagToClose)
    :CloseBagWait
    /if (${BagToClose}) {
      /if (${Window[${InvSlot[${BagToClose}].Name}].Open}) {
        /nomodkey /itemnotify ${InvSlot[${BagToClose}]} rightmouseup
        /delay ${IncrementalWait}
        /varcalc IncrementalWait ${IncrementalWait}+1 
        /goto :CloseBagWait
        }
    }
  /varset IncrementalWait 0 
/return

Sub GrabItem(ItemToGrab)
   :ItemToGrabWait
   /if (!${Cursor.ID}) {
      /nomodkey /itemnotify ${FindItem[${ItemToGrab}].InvSlot} leftmouseup
      /varcalc IncrementalWait ${IncrementalWait}+1
      /delay ${IncrementalWait}
      /goto :ItemToGrabWait
      } 
  /varset IncrementalWait 0 
/return

Sub LeftClickSwap(SlotToSwitch, ItemToWear)
   :ItemToSwitchWait
      /if (!${Me.Inventory[${SlotToSwitch}].Name.Equal[${ItemToWear}]}) {
      /nomodkey /itemnotify ${SlotToSwitch} leftmouseup
      /varcalc IncrementalWait ${IncrementalWait}+1
      /delay ${IncrementalWait}
      /goto :ItemToSwitchWait
      } 
  /varset IncrementalWait 0 
/return

Sub OpenBag(int BagToOpen)
    :OpenBagWait
    /if (${BagToOpen}) {
      /if (!${Window[${InvSlot[${BagToOpen}].Name}].Open}) {
        /nomodkey /itemnotify ${InvSlot[${BagToOpen}]} rightmouseup
        /delay ${IncrementalWait}
        /varcalc IncrementalWait ${IncrementalWait}+1 
        /goto :OpenBagWait
        }
      }
  /varset IncrementalWait 0 
/return

Sub UnloadCursor 
  :loop 
  /autoinv 
  /delay ${IncrementalWait} 
  /if (${Cursor.ID}) {
   /varcalc IncrementalWait ${IncrementalWait}+1 
   /goto :loop 
   } 
  /varset IncrementalWait 0 
/return 
Here's my problem that I couldn't figure out how to solve directly without a hack. On the OpenBag subroutine, my variable ${BagLegs} is taking on a value of say 27 (it's the 28th overall inventory slot, counting from 0). I can't figure out a way to write a statement that says something along the lines of:

/if invslot[$BagLegs} is a container /do this
/if invslot[$BagLegs} is an open container /do this

Instead, I am having to make a new variable, make it equal to ${BagLegs}-21, and then use the Pack function. For purposes of aesthetics, can I do it the way I want? If so, how?

The thing that's got me stymied is that I can use the ${BagLegs} variable to send a successful /itemnotify to open and close the bag, but I just can't figure out how to check to see if it is a bag (or it's open/close state) in the first place.

http://www.macroquest2.com/wiki/index.p ... m#Examples
It also occurred to me that SelectedItem TLO may be the correct function to use but I'm not sure. The link above now has information copied into it from the html documenation.

And if it's EBS that answers, please note that I do have quotation marks around my declared variables above until I can iron out a completely different bug. :shock:

Thanks!
Last edited by horseshoecrabs on Fri Oct 28, 2005 3:24 am, edited 3 times in total.

A_Druid_00
Macro Maker Extraordinaire
Posts: 2378
Joined: Tue Jul 13, 2004 12:45 pm
Location: Rolling on the Lawn Farting

Post by A_Druid_00 » Tue Oct 25, 2005 7:59 pm

http://www.macroquest2.com/phpBB2/viewtopic.php?t=9994

My Feedme.inc in the above link deals with opening and closing bags. Seeing how much you've managed to learn so far, I'm guessing you'll be able to figure it out without too much help.

If you have any other questions though, feel free to ask. It's good to see more active macro writers around.

Edit: Also, this entry of TFM has info on containers: http://www.macroquest2.com/includes/was ... hp#refitem
[quote]<DigitalMocking> man, A_Druid_00 really does love those long ass if statements
<dont_know_at_all> i don't use his macro because i'm frightened of it[/quote]
[quote][12:45] <dont_know_at_all> never use a macro when you can really fuck up things with a plugin[/quote]

horseshoecrabs
a ghoul
a ghoul
Posts: 89
Joined: Fri Jun 10, 2005 6:35 pm

Post by horseshoecrabs » Wed Oct 26, 2005 2:55 am

Great link on the feedme. I think I understand what I did wrong and will try to roll in a similar implentation in the next day or two. Thanks so much.

horseshoecrabs
a ghoul
a ghoul
Posts: 89
Joined: Fri Jun 10, 2005 6:35 pm

Post by horseshoecrabs » Wed Oct 26, 2005 1:27 pm

Of all the stupid, moronic, idiotic, @#$% gaffes....

Before (not working):

Code: Select all

/if (!${Window[${InvSlot[${BagToOpen}].Open}])
After (working):

Code: Select all

/if (!${Window[${InvSlot[${BagToOpen}].Name}].Open})
Sigh...can you spot the difference?!

Thank you for linking to the "feedme" post. It's exactly what I needed!

Next step is to test the crap out of the include file with a series of different tasks such as mana robe, concussion, damage shield items, and anything else I can think of in high-lag environments. Will post it to the Depot when I'm satisfied it's a solid and lag-proof concept.

A_Druid_00
Macro Maker Extraordinaire
Posts: 2378
Joined: Tue Jul 13, 2004 12:45 pm
Location: Rolling on the Lawn Farting

Post by A_Druid_00 » Wed Oct 26, 2005 1:49 pm

Yeah, it takes some time to get used to the syntax needed for all of MQ's objects. Give it another year or so, and you too could be a pro!
[quote]<DigitalMocking> man, A_Druid_00 really does love those long ass if statements
<dont_know_at_all> i don't use his macro because i'm frightened of it[/quote]
[quote][12:45] <dont_know_at_all> never use a macro when you can really fuck up things with a plugin[/quote]

horseshoecrabs
a ghoul
a ghoul
Posts: 89
Joined: Fri Jun 10, 2005 6:35 pm

Post by horseshoecrabs » Wed Oct 26, 2005 2:12 pm

Ok another question.

In the first post I alluded to the fact that some of my string variable declarations are surrounded by quotation marks. I am also told that this is generally considered bad form and EBS gave an explanation of why that is so. However, I can't figure out how to make this stuff work without doing it the way I did.

The problem I'm running into (when not quoting the vars at the declaration) is that the name of the item gets truncated when the variable is passed off to the subroutine. For example, "Maelin's Leggings of Lore becomes "Maelin's". I tried putting quotes around the variable I'm passing off in the /call, I tried putting them in the include file at the top of the subroutine (is that a declaration?) and also around the surrogate variables within the include file's relevant subroutine, all to no avail.

Any ideas?

A_Druid_00
Macro Maker Extraordinaire
Posts: 2378
Joined: Tue Jul 13, 2004 12:45 pm
Location: Rolling on the Lawn Farting

Post by A_Druid_00 » Wed Oct 26, 2005 2:21 pm

In general, you need to use quotes for string /declares with multiple words. But, other commands, such as "/varset SomeVar a string with spaces" do not need quotes. Searching a string variable with ${SomeString.Find[Some String With Spaces]} does not require quotes.

Come to think of it, the only place you really should be using quotes is for /declares, and when passing Args from one sub to another a la /call Cast "Some Spell Name With More Than One Word"

I assume you don't have VIP access, or I'd tell you to check out my AutoBot, fearless's AdvBot, or one of DigitalMocking's many macros for some good examples. The stuff in Macro Depot 3.0 is pretty ghetto in comparison, no offense to the people who still maintain macros there. AutoBot does pretty much everything you've been doing in your macro, and more. You'd be amazed how trimmed down it is in comparison though.

Edit:
This is my canni routine, which allows you to define any type of canni spell, item, or alt. It also covers things such a Lich, and HArvest type spells and will even click off Lich if you get below your HP threshold. It also allows you to define as many of these "Canni" type spells as you want, so you can have your wizard for example, set up Harvest, Druzzil's Harvest, and Mana Robe if the first 2 aren't up.

Code: Select all

/if (${DoCanni} && ${CanniTotal} && !${Me.Casting.ID} && ${Me.PctMana}<${MedPct}) {
  /for i 1 to ${CanniTotal}
  /if (((${Me.SpellReady[${CanniSpell${i}}]} || (!${Me.Gem[${CanniSpell${i}}]} && ${Me.Book[${CanniSpell${i}}]})) || ${Me.AltAbilityReady[${CanniSpell${i}}]} || ${CanniGem${i}.Equal[item]}) && ${Me.PctHPs}>${CanniHPs${i}} && !${Me.Buff[${CanniSpell${i}}].ID}) /call Cast "${CanniSpell${i}}" ${CanniGem${i}} 10s Check4Pad
  /if (${Me.Buff[${CanniSpell${i}}].ID} && ${Me.PctHPs}<${CanniHPs${i}}) /nomodkey /notify BuffWindow buff${Me.Buff[${CanniSpell${i}}].ID} leftmouseup
  /next i
}
[quote]<DigitalMocking> man, A_Druid_00 really does love those long ass if statements
<dont_know_at_all> i don't use his macro because i'm frightened of it[/quote]
[quote][12:45] <dont_know_at_all> never use a macro when you can really fuck up things with a plugin[/quote]