Ninjadvloot.inc v1.3

A forum for macro code snippets to be used in writing other macros. Post routines or .inc files here only, completed macros go to the Macro Depot. MQ2Data format only!

Moderator: MacroQuest Developers

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

Ninjadvloot.inc v1.3

Post by A_Druid_00 » Mon Dec 19, 2005 11:43 am

Not to steal away toomanynames's or mystikule's thunder, since I borrowed heavily from both of their work before settling on making my own. This version is a little more intelligent than any of the other looting incs I've been able to find. This version uses MQ2MoveUtils to move to corpses, so if you aren't a VIP, you should either donate, or write up your own /moveto code.

1/26
v1.3 Fixed stuff
12/19
v1.1 Changed the keep routine so that it will right click to put the item in inventory instead of left clicking. It's a pretty good bit faster this way.
v1.0 Allows you 3 options for every item; Keep, Destroy, and Ignore. Tradeable items default to Keep, No Drop items default to Ignore. If you want to alter the items from the default values, you can set them in your loot.ini, which groups each item into sections based on the first letter of the item's name (It doesn't create them in alpha order for you, if you want it to look nice and pretty, do it yourself).
If you already have a Lore item in your inventory, it will link it in your LootChannel if you set ReportLoot to TRUE. It will also link any No Drop items left on a corpse. If you have a full stack of an item, and no free inventory space available, it will also link it in your LootChannel.
It will not loot if there are mobs inside your MobsTooClose radius.
It will loot any corpses within your CorpseRadius.
It will wait until your CorpseRotTime timer has expired before trying to loot again. The CorpseRotTimer gets reset anytime you encounter a new corpse that you can't loot from, so there will be some lag in the times you start re-looting corpses you leave items on.
It will not loot stackable items unless there's room on a stack for it, or you have a slot in your inventory free to put it in.

Code: Select all

| Ninjadvloot.inc v1.3
#Event ALCantLoot         "#*#may not loot this corpse#*#"

Sub SetupAdvLootVars
/declare ALDontLoot      int    outer
/declare CorpseRotTimer  timer  outer
/call ALLoadVar Settings LootMobs      TRUE  bool
/call ALLoadVar Settings CorpseRadius  100   int
/call ALLoadVar Settings MobsTooClose  50    int
/call ALLoadVar Settings CorpseRotTime 440s  string
/call ALLoadVar Settings ReportLoot    FALSE bool
/call ALLoadVar Settings LootChannel   echo  string
/if (!${Defined[${AlertList}]}) /declare AlertList int outer 1
/squelch /alert clear 25
/return

Sub ALLoadVar(IniSection,IniVar,IniValue,VarType)
/if (!${Defined[${IniVar}]} && ${Defined[VarType]}) /declare ${IniVar} ${VarType} outer
/declare IniString string local ${Ini[Loot.ini,${IniSection},${IniVar},NOTFOUND]}
/varset ${IniVar} ${IniString}
/if (${IniString.Equal["NOTFOUND"]}) {
  /if (${IniString.Equal["NOTFOUND"]}) /varset ${IniVar} ${IniValue}
  /ini "Loot.ini" "${IniSection}" "${IniVar}" "${${IniVar}}"
}
/return

Sub LootCorpse
/declare i          int    local
/declare LootList   string local
/call CheckCursor
/loot
/delay 3s ${Corpse.Open}
/doevents CantLoot
/if (${Target.ID}==${ALDontLoot} && ${Spawn[${ALDontLoot}].ID}) /squelch /alert add 25 id ${ALDontLoot}
/delay 3s ${Corpse.Items} || ${Target.ID}==${ALDontLoot}
/if (${Corpse.Open} && ${Corpse.Items}) {
 /declare loottotal  int    local
  :ALlootlag
  /varset loottotal ${Corpse.Items}
  /delay 1s ${loottotal}!=${Corpse.Items}
  /if (${loottotal}!=${Corpse.Items}) /goto :ALlootlag
  /for i 1 to ${loottotal}
  /if (${Corpse.Item[${i}].ID} && !${Select[${Ini[Loot.ini,"${Corpse.Item[${i}].Name.Left[1]}","${Corpse.Item[${i}]}"]},Ignore,Keep,Destroy]}) {
    /if (${Corpse.Item[${i}].NoDrop}) /ini "loot.ini" "${Corpse.Item[${i}].Name.Left[1]}" "${Corpse.Item[${i}]}" Ignore
    /if (!${Corpse.Item[${i}].NoDrop}) /ini "loot.ini" "${Corpse.Item[${i}].Name.Left[1]}" "${Corpse.Item[${i}]}" Keep
  }
  /if (${Ini[Loot.ini,"${Corpse.Item[${i}].Name.Left[1]}","${Corpse.Item[${i}]}"].NotEqual[Destroy]} && !${Me.FreeInventory} && (!${FindItemCount[=${Corpse.Item[${i}].Name}]} || (${FindItemCount[=${Corpse.Item[${i}].Name}]} && ${Corpse.Item[${i}].Stackable} && !${Corpse.Item[${i}].FreeStack})) || (${Corpse.Item[${i}].Lore} && ${FindItem[${Corpse.Item[${i}]}].ID}) || ${Ini[Loot.ini,"${Corpse.Item[${i}].Name.Left[1]}","${Corpse.Item[${i}]}"].Equal[Ignore]}) /varset LootList ${LootList}${Corpse.Item[${i}]},
  /if ((!${Corpse.Item[${i}].Lore} || !${FindItem[${Corpse.Item[${i}]}].ID}) && (${Me.FreeInventory} || (${FindItemCount[=${Corpse.Item[${i}].Name}]} && ${Corpse.Item[${i}].Stackable} && ${Corpse.Item[${i}].FreeStack})) && ${Ini[Loot.ini,"${Corpse.Item[${i}].Name.Left[1]}","${Corpse.Item[${i}]}"].Equal[Keep]}) /call LootItem ${i} Keep right
  /if (${Ini[Loot.ini,"${Corpse.Item[${i}].Name.Left[1]}","${Corpse.Item[${i}]}"].Equal[Destroy]}) /call LootItem ${i} Destroy left
  /next i
  /if (${Corpse.Items}) {
    /if (${ReportLoot}) /${LootChannel} ${LootList} left on corpse.
    /if (${Target.ID}) /squelch /alert add 25 id ${Target.ID}
    /varset CorpseRotTimer ${CorpseRotTime}
  }
}
:clickdoneffs
/nomodkey /notify LootWnd LW_DoneButton leftmouseup
/delay 5s !${Corpse.Open}
/if (${Corpse.Open}) /goto :clickdoneffs
/return

Sub LootItem(int i,DoWhat,WhichButton)
/declare CorpseItemID int local ${Corpse.Item[${i}].ID}
/nomodkey /itemnotify loot${i} ${WhichButton}mouseup
/delay 5s ${Window[ConfirmationDialogBox].Open} || !${Corpse.Item[${i}].NoDrop}
/if (${Window[ConfirmationDialogBox].Open}) /nomodkey /notify ConfirmationDialogBox Yes_Button leftmouseup
/delay 5s ${Cursor.ID} || ${WhichButton.NotEqual[left]}
/if (${DoWhat.Equal[Destroy]} && ${Cursor.ID}==${CorpseItemID}) /destroy
/delay 3s !${Corpse.Item[${i}].ID} && !${Cursor.ID}
/return

Sub LootMobs
/if (!${LootMobs} || ${SpawnCount[npc radius ${MobsTooClose} zradius 100 noalert ${AlertList}]} || !${SpawnCount[corpse radius ${CorpseRadius} zradius 100 noalert 25]} || ${Me.Combat} || (${Cursor.NoDrop} && !${Me.FreeInventory})) /return
/if (!${CorpseRotTimer}) /squelch /alert clear 25
/declare i int local
/declare CorpseList string local |
/for i 1 to ${SpawnCount[corpse radius ${CorpseRadius} zradius 100 noalert 25]}
/varset CorpseList ${CorpseList}${NearestSpawn[${i},corpse radius ${CorpseRadius} noalert 25].ID}|
/next i
/declare DeadCount int local ${SpawnCount[corpse radius ${CorpseRadius} zradius 100 noalert 25]}
/if (${Me.Mount.ID}) /dismount
/for i 1 to ${DeadCount}
/if (${Spawn[${CorpseList.Arg[${i},|]}].Deity.ID} && ${Spawn[${CorpseList.Arg[${i},|]}].ID}) /squelch /alert add 25 id ${Spawn[${CorpseList.Arg[${i},|]}].Deity.ID}
/if (!${Spawn[${CorpseList.Arg[${i},|]}].Deity.ID}) {
  /if (${Target.ID}!=${Spawn[${CorpseList.Arg[${i},|]}].ID}) /target id ${Spawn[${CorpseList.Arg[${i},|]}].ID}
  /if (!${Me.Standing}) /stand
  /delay 2s ${Target.ID}==${Spawn[${CorpseList.Arg[${i},|]}].ID} && ${Me.Standing}
  /if (${Spawn[${CorpseList.Arg[${i},|]}].Distance}>10) /moveto loc ${Spawn[${CorpseList.Arg[${i},|]}].Y} ${Spawn[${CorpseList.Arg[${i},|]}].X}
  /delay 10s ${Spawn[${CorpseList.Arg[${i},|]}].Distance}<10
  /if (${Spawn[${CorpseList.Arg[${i},|]}].Distance}<15) /call LootCorpse
  /stick off
}
/next i
/return

Sub Event_ALCantLoot
/varset ALDontLoot ${Target.ID}
/return

Sub CheckCursor
:ALauto_inv
/if (${Cursor.ID}) {
  /if (${Cursor.NoDrop} && !${Me.FreeInventory}) /return
  /timed 5 /autoinventory
  /delay 2s !${Cursor.ID}
  /goto :ALauto_inv
}
/return
Last edited by A_Druid_00 on Thu Jan 26, 2006 10:36 pm, edited 7 times in total.
[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]

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 » Mon Dec 19, 2005 11:45 am

Merry Christmas again. If you don't have VIP, you'll need to get it in order for the /moveto stuff to work. Either that or write your own /moveto code.
[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]

nytemyst
a grimling bloodguard
a grimling bloodguard
Posts: 578
Joined: Mon Oct 25, 2004 2:29 pm
Location: florida

Post by nytemyst » Mon Dec 19, 2005 2:35 pm

Would you recommend using a clean loot.ini if someone was using a ini from advloot?

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 » Mon Dec 19, 2005 2:47 pm

Most of the "Settings" variables carry over (Not that there were many to begin with). But the ini is no longer grouped by zone name, instead they're grouped by letter. You can use both inc files and technically it won't make any difference since they're both looking in a different place for the data they need.

If you have access to Excel or another spreadsheet editing program, I'd recommend alphabetizing your current loot.ini entries and putting them in sections [A], , [C], etc. IIRC advloot only uses Keep and Destroy as options, so you can now go through and set some items to Ignore if you'd like.
[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]

nils
a grimling bloodguard
a grimling bloodguard
Posts: 565
Joined: Wed Jul 30, 2003 10:02 pm

Post by nils » Mon Dec 19, 2005 2:58 pm

Has this changed in any way from what was posted in VIP? Don't have time to look at the code at the moment but the reason I ask is because I was having a problem with the one you posted in VIP not doing auto inventory on some stackable stuff, just holds it on the cursor. I did make one small change to all the "Loot.ini" changed to "${LootINIFile}" since I have it declared in my macro's that way so I hope that isn't causing it to not autoinventory sometimes.

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 » Mon Dec 19, 2005 3:02 pm

The one I have posted in the advloot post was completely untested. I used this one all day sunday with only one issue, which was resolved. I found that /autoinventory does not work very well on a line all by itself. I had to use /timed 5 /autoinventory for it to reliably fire. The same issue existed with my spell_routines ClearCursor sub, which I fixed as well.
[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]

nils
a grimling bloodguard
a grimling bloodguard
Posts: 565
Joined: Wed Jul 30, 2003 10:02 pm

Post by nils » Mon Dec 19, 2005 3:05 pm

Thanks AD00 and nice work by the way. I will switch to this one after work today.

Moeymoejoe
a snow griffon
a snow griffon
Posts: 363
Joined: Sun Jul 18, 2004 10:17 pm

Post by Moeymoejoe » Fri Dec 30, 2005 11:00 am

Could you add a Drop option?

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 » Fri Dec 30, 2005 11:14 am

I'm currently sitting on a release waiting for the next zip. I'll throw drop in there. There's an issue with the FreeStack option and items that do not stack causing an error. It doesn't end the macro or anything, but I don't want people posting about the debug spam, which will inevitably happen regardless of whether I warn everyone or not.
[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]

User avatar
dont_know_at_all
Developer
Developer
Posts: 5450
Joined: Sun Dec 01, 2002 4:15 am
Location: Florida, USA
Contact:

Post by dont_know_at_all » Sun Jan 01, 2006 2:53 am

Code: Select all

/if (${Corpse.Item[${i}].NoDrop}) /delay 1s ${Window[ConfirmationDialogBox].Open} 
This will always wait 1s. All the variables on an /if line are evaluated before the clause statement is executed. Do this instead:

Code: Select all

/if (${Corpse.Item[${i}].NoDrop}) {
    /delay 1s ${Window[ConfirmationDialogBox].Open}
}
There are a few lines that have this problem...

Thanks to moeymoejo for pointing out the problem.

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 Jan 03, 2006 7:28 am

Interesting. Could I do a

Code: Select all

/if (${Corpse.Item[${i}].NoDrop} && !${Window[ConfirmationDialogBox].Open}) /delay 1s ${Window[ConfirmationDialogBox].Open} 
instead? If the window's open it will return FALSE and thereby skip the /delay, correct?
[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]

Agripa
a ghoul
a ghoul
Posts: 97
Joined: Tue Nov 23, 2004 10:16 pm

Post by Agripa » Tue Jan 03, 2006 7:57 am

If I understand the issue correctly, it would skip the delay if the window was open but if not, it would still always wait the entire 1 second which defeats the purpose of having an early exit from the delay itself.

Moeymoejoe
a snow griffon
a snow griffon
Posts: 363
Joined: Sun Jul 18, 2004 10:17 pm

Post by Moeymoejoe » Tue Jan 03, 2006 8:19 am

Code: Select all

/delay 1s ${Window[ConfirmationDialogBox].Open} || !${Corpse.Item[${i}].NoDrop} || !${Corpse.Item[${i}].ID}
will work i think. Last boolean added for agripa, so it blows out fast if the item gets looted without dialogbox (fastloot).

drzoon
a hill giant
a hill giant
Posts: 239
Joined: Tue May 04, 2004 5:38 pm

Post by drzoon » Tue Jan 17, 2006 1:14 am

Two things I've noticed which I thought I'd point out:

Code: Select all

/doevents CantLoot
Shouldn't this be:

Code: Select all

/doevents ALCantLoot
since that's the event at the bottom?

Also:

Code: Select all

/if (${DoWhat.Equal[Destroy]}) {
  /destroy
  /delay 1s ${Window[ConfirmationDialogBox].Open}
  /if (${Window[ConfirmationDialogBox].Open}) /nomodkey /notify ConfirmationDialogBox Yes_Button leftmouseup
} 
Using /destroy never pops up a confirmation box, even if you have "confirm destroy" active in your options, so you can safely remove the two lines after that.

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 Jan 17, 2006 8:10 am

Two things I've noticed which I thought I'd point out:

Code: Select all

/doevents CantLoot
Shouldn't this be:

Code: Select all

/doevents ALCantLoot
since that's the event at the bottom?
Doh, dunno how I missed that for so long.
Also:

Code: Select all

/if (${DoWhat.Equal[Destroy]}) {
  /destroy
  /delay 1s ${Window[ConfirmationDialogBox].Open}
  /if (${Window[ConfirmationDialogBox].Open}) /nomodkey /notify ConfirmationDialogBox Yes_Button leftmouseup
} 
Using /destroy never pops up a confirmation box, even if you have "confirm destroy" active in your options, so you can safely remove the two lines after that.
Are you 100% sure about that? I swear in my testing the confirmation box was popping up.
[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]