switch.mac - Equipment Switcher, ini driven. Version 2

A forum for you to dump all the macros you create, allowing users to use, modify, and comment on your work.

Moderator: MacroQuest Developers

Preocts
a snow griffon
a snow griffon
Posts: 312
Joined: Thu Jan 29, 2004 1:02 pm

switch.mac - Equipment Switcher, ini driven. Version 2

Post by Preocts » Thu Apr 22, 2004 9:51 am

This macro uses a set of defined keys in an ini file to allow you to switch out one or more items from your inventory to your equipment.

To Use:

Code: Select all

/macro switch.mac <keyname1>;<2>;<3>;<4>;.....
/macro switch.mac <SetName>#
Set up your INI before you run this. Duh. Use the example to get yourself started.


Notes:
1) The new <SetName># parameter needs a # ending it. This is how I tell you want to do a set of switches, not just one. :wink:

04/24/04: Last update I'm making on this. Turned it into an include for my druid's macro. maybe sometime I'll post that.
Added a few fixes here and there. Now makes switches as fast as possible. Runs very smooth.
04/23/04: Yay Lax, slotnames now should be fixed
04/22/04: Added SwitchSets to make it easier to work with.
Added some defined checks, this should fix a few param errors
Now it checks to make sure a pack isn't already open.

Code: Select all

|  Switch.mac Version 3 <<By: Preocts>> Updated 04-23-2004   | 
|-------------------------------------------------------------
|**

 Using an ini file this macro will switch any item in inventory
 with an equiped item. INI options allow for a one-way switch
 or a toggle switch.
 This include file is set to use druid.ini by default.

 Usage: /macro Switch switch.mac <Switch1Name>;[Switch2Name];[Switch3Name]....
 Usage: /macro Switch <SwitchSetName>#  <--The # after the name is really important


 INI Structure:

[ItemSwitch]
<SwitchName>=<SlotName>;<ItemName>;[ItemName]
ArmDot=arm;Elder Spiritist's Vambraces;Elysian Armplates
NormalNeck=neck;Broken Shore Shell Necklace
 + If two items are given the macro will toggle between the two
 + If one item is given the macro will equip that item.

+Example One: /macro Switch ArmDot  --Toggle Switch my ARM slot
	[ItemSwitch]
	ArmDot=arms;Elder Spiritist's Vambraces;Elysian Armplates

+Example Two: /macro Switch SeeIvis  --Equips given item to my neck slot.
	[ItemSwitch]
	SeeInvis=neck;Qeynos Badge of Honor

+Example Three: /macro Switch ArmDot;SeeInvis  -- Does both one and two
	[ItemSwitch]
	ArmDot=arms;Elder Spiritist's Vambraces;Elysian Armplates
	SeeInvis=neck;Qeynos Badge of Honor


[SwitchSets]
<SwitchSetName>=<SwitchName1>;[SwitchName2];[SwitchName3];.......
 + This let's you do the multiple switch thing with only one param.
 + In theory this would let you switch every equipment slot with one param.
   **YOU CANNOT SEND MULTIPLE SWITCHSETS!**

+Example One: /macro Switch simple#  -- Does both one and two
	[SwitchSets]
	simple=ArmDot;SeeInvis
	[ItemSwitch]
	ArmDot=arms;Elder Spiritist's Vambraces;Elysian Armplates
	SeeInvis=neck;Qeynos Badge of Honor
**|

|**
  SLOT NAMES GODDAMNIT!!
  mainhand, offhand, range, charm, leftear, rightear, leftwrist, rightwrist, arm, head
  neck, face, shoulder, chest, legs, waist, rightfinger, leftfinger, feet, ammo, back
**|

Sub Main
  /if (!${Defined[Param0]}) /return

  /declare InputParam local
  /declare IniInput local
  /declare InvState local
  /declare ItemOne local
  /declare SlotName local
  /declare ItemTwo local
  /declare PackNum local
  /declare SlotNum local
  /declare WorkWith local
  /declare CursorCheck local

  /declare Switches array
  /declare ArrayCount local
  /varset ArrayCount 1

  |Open the inventory window if not already open.
  /if (${Window[InventoryWindow].Open}) {
    /varset InvState 0
  } else {
    /keypress inventory
    /varset InvState -1
  }

  /if (${String[@Param0].Find["#"]}) {
    /if (!${Ini[druid.ini,SwitchSets,${String["@Param0"].Arg[1,#]}].Length}) {
      /echo NOT FOUND: @Param0
      /goto :EndSwitch
    }
    /varset InputParam ${Ini[druid.ini,SwitchSets,${String["@Param0"].Arg[1,#]}]}
  } else {
    /varset InputParam @Param0
  }

  :FillArray
    /varset Switches(@ArrayCount) ${String["@InputParam"].Arg[@ArrayCount,;]}
    /if (!${Ini[druid.ini,ItemSwitch,${String["@Switches(@ArrayCount)"]}].Length}) {
      /echo NOT FOUND: @Switches(@ArrayCount)
      /goto :EndSwitch
    }
    /varadd ArrayCount 1
    /if (!${String["@InputParam"].Arg[@ArrayCount,;].Length}) {
      /call HandlePacks 1
      /varset ArrayCount 1
      /goto :StartSwitch
    }
  /goto :FillArray

  :StartSwitch
  
  /if (${String[@Switches(@ArrayCount)].Equal["UNDEFINED-ARRAY-ELEMENT"]}) /goto :EndSwitch

  /varset IniInput "${Ini[druid.ini,ItemSwitch,${String["@Switches(@ArrayCount)"]}]}"
  /varset SlotName "${String["@IniInput"].Arg[1,;]}"
  /varset ItemOne "${String["@IniInput"].Arg[2,;]}"
  /varset ItemTwo "${String["@IniInput"].Arg[3,;]}"

  | Crap that is being straightened out with the new MQData. Thanks Devs for all the work!
  /if (${String[@SlotName].Equal["arm"]}) /varset SlotName "arms"
  /if (${String[@SlotName].Equal["mainhand"]}) /varset SlotName "primary"
  /if (${String[@SlotName].Equal["offhand"]}) /varset SlotName "secondary"
  /if (${String[@SlotName].Equal["range"]}) /varset SlotName "ranged"
  
  | Check for single arg given in ini
  /if (${String[@ItemTwo].Equal["NULL"]}) {
    |Make sure the item we want in the slot isnt already there. If it is no work is needed.
    /if (${Me.Inventory["@SlotName"].Name.Equal["@ItemOne"]}) {
      /goto :NextSwitch
    }
    |Make sure the item is present in inventory
    /if (!${FindItem["@ItemOne"].ID}) {
      /goto :NextSwitch
    }
  } else { 
    |Two items to toggle. Make sure at least one is in the given slot.
    /if (${Me.Inventory["@SlotName"].Name.NotEqual["@ItemOne"]} && ${Me.Inventory["@SlotName"].Name.NotEqual["@ItemTwo"]}) {
      /goto :NextSwitch
    }
    |Make sure both items are present in inventory
    /if (!${FindItem["@ItemOne"].ID} || !${FindItem["@ItemTwo"].ID}) {
      /goto :NextSwitch
    }
  }
  |Now we can assume a switch is needed, a switch is possible, and one or both items are present.
  
  |Find out where the hell the item not equiped is.  

  /if (!${Me.Inventory["@SlotName"].Name.Equal["@ItemOne"]}) {
    | no not redunant, just checking which item is in inventory and which is equiped (in case of toggle)
    /varset WorkWith "@ItemOne"
  } else {
    /varset WorkWith "@ItemTwo"
  }

  |Work with is the item in the inventory. For single switch we'd start with this one anyway
  |but for toggle switching we must start with the one of two items in the inventory.
  
  | Crap that is being straightened out with the new MQData. Thanks Devs for all the work!
  /if (${String[@SlotName].Equal["arms"]}) /varset SlotName "arm"
  /if (${String[@SlotName].Equal["primary"]}) /varset SlotName "mainhand"
  /if (${String[@SlotName].Equal["secondary"]}) /varset SlotName "offhand"  
  /if (${String[@SlotName].Equal["ranged"]}) /varset SlotName "range"

  /varset CursorCheck ${Cursor.ID}
  /if (${InvSlot[${FindItem["@WorkWith"].InvSlot.ID}].Pack}) {
    |It's in a pack.
    /varset PackNum ${InvSlot[${FindItem["@WorkWith"].InvSlot.ID}].Pack}    
    /varset SlotNum ${Math.Calc[${FindItem["@WorkWith"].InvSlot.Slot}+1]}

    /if (!${Window[${InvSlot[@PackNum].Name}].Open}) { 
      /itemnotify @PackNum rightmouseup
      :Wait1
      /if (!${Window[${InvSlot[@PackNum].Name}].Open}) /goto :Wait1
    }

    /itemnotify in ${InvSlot[@PackNum].Name} @SlotNum leftmouseup
    /call WaitForIt @CursorCheck
    /varset CursorCheck ${Cursor.ID}
    /itemnotify @SlotName leftmouseup
    /call WaitForIt @CursorCheck
    /varset CursorCheck ${Cursor.ID}
    /itemnotify in ${InvSlot[@PackNum].Name} @SlotNum leftmouseup
    /call WaitForIt @CursorCheck
    /varset CursorCheck ${Cursor.ID}

|    /delay 5
|    /itemnotify @PackNum rightmouseup

  } else {
    |It's in the main inventory. Same as above, just simpler
    /varset SlotNum ${FindItem["@WorkWith"].InvSlot.ID}
    /itemnotify @SlotNum leftmouseup
    /call WaitForIt @CursorCheck
    /varset CursorCheck ${Cursor.ID}
    /itemnotify @SlotName leftmouseup
    /call WaitForIt @CursorCheck
    /varset CursorCheck ${Cursor.ID}
    /itemnotify @SlotNum leftmouseup
    /call WaitForIt @CursorCheck
    /varset CursorCheck ${Cursor.ID}
  }
  
  :NextSwitch
  /varadd ArrayCount 1
  /goto :StartSwitch

  :EndSwitch
  /call HandlePacks 0
  /if (@InvState) /keypress inventory
  /zapvars
/return

Sub WaitForIt
  /if (!${Defined[Param0]}) /return
  :WaitForitLoop
  /if (${Cursor.ID}==@Param0) /goto :WaitForitLoop
/return

Sub HandlePacks
  /if (!${Defined[Param0]}) /return
  | 1 to open 0 to close
  /declare TempLoop local
  /for TempLoop 22 to 29 
    /if (${FindItem[${InvSlot[@TempLoop].Item}].Container}) {
      /if (@Param0) {
        /if (!${Window[${InvSlot[@TempLoop].Name}].Open}) /itemnotify @TempLoop rightmouseup
      } else {
        /if (${Window[${InvSlot[@TempLoop].Name}].Open}) /itemnotify @TempLoop rightmouseup
      }
      /delay 1
    }
  /next TempLoop
/return

Example INI (switch.ini)

Code: Select all

[SwitchSets]
Fight=FightNeck;FightPrim;FightSec;FightRange
Normal=NormalPrim;NormalSec;NormalRange;NormalNeck
Shop=ShopPrim;ShopSec;ShopRange

[ItemSwitch]
ArmDot=arms;Elder Spiritist's Vambraces;Elysian Armplates
HasteNeck=neck;Initiate Symbol of Tunare
ShopPrim=mainhand;Opal Encrusted Stein
ShopSec=offhand;Opal Encrusted Stein
ShopRange=range;Grandmaster Baker's Spoon
FightNeck=neck;Broken Shore Shell Necklace
FightPrim=mainhand;Scimitar of the Emerald Dawn
FightSec=offhand;Tactician's Bulwark
FightRange=range;Bloodstained Memoirs
NormalNeck=neck;Qeynos Badge of Honor
NormalPrim=mainhand;Foraging Machette
NormalSec=offhand;Grandmaster Baker's Spoon
NormalRange=range;Bloodstained Memoirs
Examples using the above INI.

Code: Select all

/macro switch ArmDot
Will toggle between the two items listed in ArmDot

Code: Select all

/macro switch SeeInvis
Will place my seeinvis neck item in the neck slot if it isn't there. (one way switch)

Code: Select all

/macro switch ArmDot;SeeInvis
Does both of the above.

Code: Select all

/macro switch Fight#
Same as

Code: Select all

/macro switch FightNeck;FightPrim;FightSec;FightRange
Last edited by Preocts on Sat Apr 24, 2004 7:11 am, edited 4 times in total.

Flea
a lesser mummy
a lesser mummy
Posts: 55
Joined: Fri Dec 26, 2003 4:56 am

Post by Flea » Thu Apr 22, 2004 10:28 am

Values for specific items where there are two? (e.g. Wrist, Finger, Ear)

Is it Wrist or wrists? finger or fingers? etc.

Preocts
a snow griffon
a snow griffon
Posts: 312
Joined: Thu Jan 29, 2004 1:02 pm

Post by Preocts » Thu Apr 22, 2004 4:02 pm

Values for specific items where there are two? (e.g. Wrist, Finger, Ear)
Specific or partial should work for both cases.
Is it Wrist or wrists? finger or fingers? etc.
All the slotname information is in the Readme