Help with a radial pet attack mod with looting.

Need some help with that macro you're working on or aren't quite sure how to get your macro to do something? Ask here!

Moderator: MacroQuest Developers

DyvimTvar
orc pawn
orc pawn
Posts: 16
Joined: Wed Oct 22, 2003 1:21 pm

Help with a radial pet attack mod with looting.

Post by DyvimTvar » Fri Feb 20, 2004 11:48 am

Greetings all,

I am hesitant to ask since BK just reemed the last guy who posted a macro help request(heh), but I have tested what I am posting quite a bit and am at a block.

I took the radial pet attack macro in the depot and modified it a bit taking some loot code from farm.mac and trying to return to my starting point each time so I don't rove too much.

When I run it it seems to run but nothing happens, even if mobs are in range, and the machine lags up hugely. Any insight into the facrom would be helpful, as this would be great for farming for faction.

Code: Select all

| - Radius pet attack macro by DyvimTvar 
| - 
| - Mucho Code borrowed from all over 
| - To all who wittingly or unwittingly
| - helped me ... thanks.
| - 
| - Particular thanks to Lestor for his radial pet attack macro from which I started.
| -               and to Scrime for his farm macro from which stole heavily.
| - 
| - 
| - You must have a pet up to begin. This will then begin killing everything in the 
| - radius you specify.
| - 
| - 
| - Syntax: /macro petattack [radius] 
| - 
| - 
|  Features: 
|   + Selective auto-looting.  Only keeps the items that you want it to.  Also has a 
|     destroy list, in the case that you are looting all "lightstones", but still want 
|     to destroy "Burned Out Lightstones" (for example) 
|   + Debugging code.  Set DEBUG to "1==1" to show debugging code, set to "0==1" to turn 
|     it off. 
|   + Buff tracking.  Keeps track of buffs up on you and your pet, refreshes as nescessary. 
|   + Heals your pet once it drops below 50% health. 
|   + Light Obstruction avoidance.  Should back up and try to go around something if it gets stuck. 
|   + Origination spor returning, will return to the spot you started at after each looting, 
|     so you don't "rove" because of moving to loot.
| 
|  Known Issues/Limitations/Bugs: 
|   - No anti KS code, just kills everything in sight, it presumes you have the area to yourself. 
|   - Does not know when to stop hunting.  $freeinv works for some people, crashes the client for 
|     other people.  Until it is fixed, the script will not know when you bags are full. 
|   - Does not stop to med up, stops casting spells once below 20% mana. 
|   - Obstruction detection needs some tweaking, maybe an "allowance" value for being in the same spot 
|     instead of waiting for the x/y locs to be the same. 
|   - Some of the global variables need to be turned in to locals. 
|      

#turbo 

| Change this number to specify the maximum number of mobs to que up. 
#define QEUCOUNT          20 
| Used to echo debugging messages.  set to 1==1 if you want to see them, 0==1 if you dont 
#define DEBUG             1==1 
| Spell names, change to suit you pet environment
#define SelfShieldSpell   "Force Shield" 
#define PetBuffSpell      "Rune of Death" 
#define PetHealSpell      "Touch of Death" 

Sub Main 
   /zapvars 
   /call DeclareGlobals 

   | clear target, et al 
   /press esc 
   /press esc 
   /press esc 
   /press shift 
   /press alt 
   /press ctrl 

   | never confirm looting nodrop items 
   /lootn never 

|   /call FlushDB 

   | set up the loot array 
   /call AddToLootList "salt" 
   /call AddToLootList "skin" 
   /call AddToLootList "peridot" 
   /call AddToLootList "ore" 
    
   | set up the dont loot array 
   |/call AddToDontLootList "ruined" 
   |/call AddToDontLootList "low" 
   |/call AddToDontLootList "medium" 

   /varset AnchorX $char(x)
   /varset AnchorY $char(y)

   /varset range @Param0 
   /echo Radius set to @range 

   /if $defined(Param0)==FALSE { 
      /echo Usage /macro petattack [range] 
      /echo Default range is 200. 
      /varset range 200 
      } 

   /varset count2 0 
   /varset targetID $char(id) 

   :Loop 
      /doevents 
      /if n @count2>QEUCOUNT /call FlushDB 
      /call AttackTarget 
      /doevents 
      /delay 1 

   | Re-Buff with SelfShieldSpell
      /if $char(buff,"SelfShieldSpell")==0 {  
         /call BuffShield 
         } 

   | check to see if we need to buff our pet 
      /if $pet(buff,"PetBuffSpell")==0 {  
    	 /call BuffPet
      } 

   | check to see if we need to heal our pet 
      /if n $spawn($char(pet),hp,pct)<50 {  
    	 /call HealPet
      } 

      /varset targetID $char(id) 
      /goto :Loop 

   | Always confirm looting nodrop items 
   /lootn Always

/return 

| ============================================================== 

Sub DeclareGlobals 
   /declare count1 global 
   /declare count2 global 
    
   /declare AnchorX global 
   /declare AnchorY global 

   /declare targetID global 
   /declare range global 
    
   /declare LootArraySize global 
   /declare DontLootArraySize global 
   /declare LootArrayIndex global 
   /declare DontLootArrayIndex global 
    
   | array number defines, dont change 
   /declare LootArray array 
   /declare DontLootArray array 
/return 

| ============================================================== 

Sub AddToLootList 
   /if "@Param0"!="" { 
      /varadd LootArraySize 1 
      /varset LootArray(@LootArraySize) "@Param0" 
      /if DEBUG /echo Added @Param0 to the LootArray at position $int(@LootArraySize). 
   } 
/return 

| ============================================================== 

Sub AddToDontLootList 
   /if "@Param0"!="" { 
      /varadd DontLootArraySize 1 
      /varset DontLootArray(@DontLootArraySize) "@Param0" 
      /if DEBUG /echo Added @Param0 to the DontLootArray at position $int(@DontLootArraySize). 
   } 
/return 

| ============================================================== 

sub AttackTarget 
   :Loop 
      /doevents 
      /if n $spawn($searchspawn(npc,id:@targetID,next),distance)>@range /return 
      /call CheckTargetID $searchspawn(npc,id:@targetID,next) 
      /varset targetID $searchspawn(npc,id:@targetID,next) 
      /if $return==EXSISTS /goto :Loop 
   /delay 1 

   /target id @targetID 
   /echo Attacking '$target(name)'... 
   /face
   /pet attack 
/return 

| ============================================================== 

Sub FlushDB 
   /zapvars novars notimers 
   /varset count1 0 
   /varset count2 0 
   /echo Flushing database... 
   /declare targetDB array 
   /delay 10 
/return 

| ============================================================== 

Sub CheckTargetID(id) 
   /varset count1 0 
   :Loop 
      /if n @targetDB(@count1)==$searchspawn(npc,id:@targetID,next) /return EXSISTS 
      /if @targetDB(@count1)==UNDEFINED-ARRAY-ELEMENT { 
         /call AddTargetID @id 
         /varadd count2 1 
         /return ADDED 
         } 
      /varadd count1 1 
      /goto :Loop 
/return 

| ============================================================== 

Sub AddTargetID(id) 
   /varset targetDB(@count1) @id 
/return 

| ============================================================== 

Sub BuffShield 
   /cast "SelfShieldSpell"
   /delay $int($calc($spell("SelfShieldSpell",casttime)*10+5)) 
/return 

| ============================================================== 

Sub BuffPet 
   /cast "PetBuffSpell"
   /delay $int($calc($spell("PetBuffSpell",casttime)*10+5)) 
/return 

| ============================================================== 

Sub HealPet 
   /target id $char(pet)   
   /cast "PetHealSpell"
   /delay $int($calc($spell("PetHealSpell",casttime)*10+5)) 
/return 

| ============================================================== 

Sub LootTarget 
:StartLootTarget 
   /if DEBUG /echo Entering LootTarget... 
    
   | target the corpse of the nearest mob in range 
   /target corpse range "range"
    
   | move up to it 
   /face 
:CheckCorpseDistance 
   /call CheckForObst 
   /if n $target(distance)>15 { 
      /face 
      /sendkey down up 
      /goto :CheckCorpseDistance 
   } else { 
      /sendkey up up 
   } 

   | open the loot window 
   /loot 
   /delay 2s 
    
   | check each slot (0-7) to see if its something we want to keep 
   /for LootSlot 0 to 7 
      /click left corpse @LootSlot 
      /delay 1s 

      | if there is nothing on the cursor, then we are out of loots, stop the loop 
      /if "$cursor()"=="NULL" /goto :EndLootTarget 
      
      /if DEBUG /echo Checking loot slot #@LootSlot: $cursor(name) 

      | check whats on our cursor against the list of things we DONT want to keep 
      /for LootArrayIndex 1 to @DontLootArraySize 
         /if "$cursor(name)"=="@DontLootArray(@LootArrayIndex)" { 
            /if DEBUG /echo $cursor(name) matches @DontLootArray(@LootArrayIndex), destroying. 
               /click left destroy 
               /delay 1s 
             /goto :NextLoot 
         } 
      /next LootArrayIndex 

      | check whats on our cursor against the list of things we want to keep 
      /for LootArrayIndex 1 to @LootArraySize 
         /if "$cursor(name)"~~"@LootArray(@LootArrayIndex)" { 
            /if DEBUG /echo $cursor(name) matches @LootArray(@LootArrayIndex), keeping. 
               /click left auto 
               /delay 1s 
             /goto :NextLoot 
         } 
      /next LootArrayIndex 
      
      | if we make it to here, it means that the loot didnt match anything in our list 
      | so, we destroy the object. 
      /if DEBUG /echo $cursor(name) doesn't match anything in our list, destroying. 
      /click left destroy 
      /delay 1s 
      
:NextLoot 
   /next LootSlot 

:EndLootTarget 
   /press esc 
   
   /call MoveToAnchor
 
   | if our bags are full, its time to stop hunting and go sell.  For now, end the macro. 
   | /if n $freeinv(space)==0 /varset BagsFull 1 
   | /if DEBUG /echo Inventory space remaining: $freeinv(space) slots. 
    
   /if DEBUG /echo Leaving LootTarget... 
/return 

| ============================================================== 

Sub MoveToAnchor 
:AnchorMoveLoop 
  /if "$char(state)"=="SIT" /stand 
   /face nolook loc AnchorX,AnchorY 
    /if n $distance(AnchorX,AnchorY)>11 /sendkey down up 
    /if n $distance(AnchorX,AnchorY)<=11 { 
     /sendkey up up 
      /return 
} 
/goto :AnchorMoveLoop 

/return 

| ============================================================== 

Sub CheckForObst 
   /if n $char(x)==@LastPosX /if n $char(y)==@LastPosY { 
      /varadd ObstCount 1 
   } else { 
      /varset ObstCount 0 
   } 
    
   /varset LastPosX $char(x) 
   /varset LastPosY $char(y) 
    
   /if n @ObstCount>3 { 
      /call GoAroundObst 
   } 
/return 

| ============================================================== 

Sub GoAroundObst 
   /if DEBUG /echo Entering GoAroundObst... 
   | back up some 
   /sendkey up up 
   /sendkey down down 
   /delay 1s 
   /sendkey up down 
    
   | go left or right a bit, randomly 
   /if n $rand(2)==1 { 
      /sendkey down left 
      /delay 5 
      /sendkey up left 
   } else { 
      /sendkey down right 
      /delay 5 
      /sendkey up right 
   } 
    
   | move forward a bit 
   /sendkey down up 
   /delay 1s 
   /sendkey up up 
    
   /if DEBUG /echo Leaving GoAroundObst...    
/return 
DyvimTvar

User avatar
Bad Karma
a snow griffon
a snow griffon
Posts: 346
Joined: Sat Nov 22, 2003 9:34 pm
Contact:

Re: Help with a radial pet attack mod with looting.

Post by Bad Karma » Fri Feb 20, 2004 6:01 pm

DyvimTvar wrote:I am hesitant to ask since BK just reemed the last guy who posted a macro help request(heh), but I have tested what I am posting quite a bit and am at a block.
LOL....thanks!

Actually, that one wasn't directed so much to him (after all, I did spend a bit of time and posted a rather long help for him....which I wrote BEFORE posting the mild flame). I was mainly posting that to all of the recent people who are just expecting handouts and obviously not putting any time or effort into their own work. I just happened to post it on his request. It could have been anyone's. Even yours. lol

:wink:

Before I actually fire this up and see what it's doing or not doing (and haven't read the actual script itself yet)....I do notice that you're running this at full #turbo. Does it make any difference if you set that to, say, #turbo 50? At the least, it should free some of the lag. I'll dig into the rest later. Gotta run for now.
[b]- Bad Karma
________________________________________[/b]

In our own quest for excellence, we should strive to take the time to help those who help themselves.

All others should [b]RTFM[/b]!!!!!!!!!

DyvimTvar
orc pawn
orc pawn
Posts: 16
Joined: Wed Oct 22, 2003 1:21 pm

Update

Post by DyvimTvar » Tue Feb 24, 2004 10:02 am

Before I actually fire this up and see what it's doing or not doing (and haven't read the actual script itself yet)....I do notice that you're running this at full #turbo. Does it make any difference if you set that to, say, #turbo 50? At the least, it should free some of the lag. I'll dig into the rest later. Gotta run for now.
Thanks for the pointer. I have gone so far as to turn #turbo off which does help the lag, with #turbo off it is fine on lag, but the macro still doesn't do anything. I am sure I am missing something simple, but I can't see it. Any insight is welcome.

I was thinking a good snippet would be a loot routine, goes and loots corpses with an all or named option, and either stays there or returns to a starting point. I may take a crack at it, unless someone point me at one sooner. ;)
DyvimTvar

daerck
a ghoul
a ghoul
Posts: 134
Joined: Mon Jan 12, 2004 8:44 pm

Post by daerck » Tue Feb 24, 2004 6:08 pm

You need to declare targetDB before accessing it.

Also, you need to rework that Sub FlushDB as it will clear your Loot and destroy array as well.