Help with drag.mac (GrimJack version)

For questions regarding conversion of scripts from the old, parm style to the new MQ2Data format. Conversion questions only!

Moderator: MacroQuest Developers

User avatar
ieatacid
Developer
Developer
Posts: 2727
Joined: Wed Sep 03, 2003 7:44 pm

Help with drag.mac (GrimJack version)

Post by ieatacid » Sat May 01, 2004 9:17 pm

I loved this drag macro but I'm having a tough time getting it to work. I think it's something with the array. Any help is appreciated.

Here's what I have so far (old version posted below it for reference)

Code: Select all

|drag.mac 
|Usage /macro drag.mac name name name... ect ect 
|Version 2.5, based on GrimJack's version 
|Version 2.5a, gf getting happy. 
|Version 2.6, De-Happified it. 

#turbo
Sub Main
   /declare CorpseID
   /declare i
   /declare CorpseCount
   /declare Bodies[10,10]
   
   /if (!${Defined[Param0]}) /if (${Target.State.NotEqual[DEAD]}) {
      /echo Usage:  /macro drag.mac corpse1 corpse2 corpse3 ect.
      /echo         /macro drag.mac <target>
      /end
   }
   /if (${Defined[Param0]}) {
      /if (${Target.State.Equal[DEAD]}) /varset Bodies ${Target.ID}
      /goto :CorpseCheck
   }
   /varset i 0
   /varset CorpseCount 0
   :CountCorpses
      /target corpse ${Param${i}}
      /varcalc i ${i}+1
      /if (${Target.ID}>0) {
        /varset Bodies[${CorpseCount}] ${Target.ID}
        /varcalc CorpseCount ${CorpseCount}+1
      }
   /if (${Defined[Param${i}]}) /goto :CountCorpses
   /varcalc CorpseCount ${CorpseCount}+1
   /echo ${CorpseCount}

   :CorpseCheck
   /if (!${Defined[Bodies]}) {
     /echo No corpses are targetable.
     /delay 1
     /end
   }
   /varset i 0
   :DragThem
      /if (${Spawn[${Bodies[${i}]}].Distance}>25) {
         /if (!${Target.ID[Bodies${i}]}) /target id ${Bodies${i}}
         :WaitforTarget
            /delay 0
         /if (!${Target.ID[Bodies${i}]}) /goto :WaitforTarget
         /corpse
      }
      /varcalc i ${i}+1
      /delay 0
      /if (${i} > ${CorpseCount}) /varset i 0
   /goto :DragThem
/return
Original

Code: Select all

|drag.mac 
|Usage /macro drag.mac name name name... ect ect 
|Version 2.5, based on GrimJack's version 
|Version 2.5a, gf getting happy. 
|Version 2.6, De-Happified it. 

#turbo 
Sub Main 
   /declare CorpseID local 
   /declare i local 
   /declare CorpseCount local 
   /declare Bodies array 

   /if $defined(Param0)==FALSE /if "$target(type)"!="CORPSE" { 
      /echo Usage:  /macro drag.mac corpse1 corpse2 corpse3 ect. 
      /echo         /macro drag.mac <target> 
      /end 
   } 

   /if $defined(Param0)!=TRUE { 
      /if "$target(type)"=="CORPSE" /varset Bodies(0) $target(id) 
      /goto :CorpseCheck 
   } 
    
   /varset i 0 
   /varset CorpseCount 0 
   :CountCorpses 
      /target corpse @Param$int(@i) 
      /varadd i 1 
      /if n $target(id)>0 { 
        /varset Bodies(@CorpseCount) $target(id) 
        /varadd CorpseCount 1 
      } 
   /if $defined(Param$int(@i))==TRUE /goto :CountCorpses 
   /varsub CorpseCount 1 
   /echo @CorpseCount 
    
   :CorpseCheck 
   /if $defined(Bodies(0))==UNDEFINED-ARRAY-ELEMENT { 
     /echo No corpses are targetable. 
     /end 
   } 
   /varset i 0 
   :DragThem 
      /if n $spawn(@Bodies(@i),distance)>25 { 
         /if n $target(id)!=@Bodies(@i) /target id @Bodies(@i) 
         :WaitforTarget 
            /delay 0 
         /if $target(id)!=@Bodies(@i) /goto :WaitforTarget 
         /corpse 
      } 
      /varadd i 1 
      /delay 0 
      /if n @i>@CorpseCount /varset i 0 
   /goto :DragThem 
/return

s16z
a ghoul
a ghoul
Posts: 97
Joined: Thu Apr 01, 2004 12:03 pm

Post by s16z » Sun May 02, 2004 3:22 am

Quick conversion, haven't tested it.

Code: Select all

|drag.mac
|Usage /macro drag.mac name name name... ect ect
|Version 2.5, based on GrimJack's version
|Version 2.5a, gf getting happy.
|Version 2.6, De-Happified it.
|Version 2.7, Converted to new DataVars - Small changes in logic to 
|                   reduce the number of /if statements. Limit of 10 corpses

Sub Main
    /declare i int inner 0
    /declare CorpseCount int inner 1
    /declare Bodies[10] int inner 0

    /if (!${Defined[Param0]}) {
        /if (${Target.Type.NotEqual[Corpse]}) {
            /echo Usage:  /macro drag.mac corpse1 corpse2 corpse3 ect.
            /echo         /macro drag.mac <target>
            /end
        } else {
            /varset Bodies[1] ${Target.ID}
            /goto :CorpseCheck
        }
    }

  
  :CountCorpses
    /target corpse ${Param${i}}
    /varcalc i ${i}+1
    /if (${Target.ID}) {
        /varset Bodies[${CorpseCount}] ${Target.ID}
        /varcalc CorpseCount ${CorpseCount}+1
    }
    /if ({Defined[Param${i}]}) /goto :CountCorpses
    /varcalc CorpseCount ${CorpseCount}-1
    /echo ${CorpseCount}
   
  :CorpseCheck
    /if (!${Bodies[1]}) {
        /echo No corpses are targetable.
        /end
    }
    /varset i 1
  :DragThem
    /if (${Spawn[${Bodies[${i}]}].Distance}>25) {
        /if (${Target.ID}!=${Bodies[${i}]}) /target id ${Bodies[${i}]}
      :WaitforTarget
        /delay 0
        /if (${Target.ID)!=${Bodies[${i}]}) /goto :WaitforTarget
        /corpse
    }
    /varcalc i ${i}+1
    /delay 0
    /if (${i}>${CorpseCount}) /varset i 1
    /goto :DragThem
    /return

User avatar
ieatacid
Developer
Developer
Posts: 2727
Joined: Wed Sep 03, 2003 7:44 pm

Post by ieatacid » Sun May 02, 2004 1:15 pm

Great, that's further than I got with it. Still getting the error "/varset 'Bodies[-1]' failed, out of bounds on array" on line 30. Also had to add a dollar sign in line 33. This is if I do "/mac drag <char name>". If I target the corpse and and just use "/mac drag" I get an error in line 48

Code: Select all

/if (${Target.ID)!=${Bodies[${i}]}) /goto :WaitforTarget
Correction in red, error in blue:

Code: Select all

|drag.mac
|Usage /macro drag.mac name name name... ect ect
|Version 2.5, based on GrimJack's version
|Version 2.5a, gf getting happy.
|Version 2.6, De-Happified it.
|Version 2.7, Converted to new DataVars - Small changes in logic to
|                   reduce the number of /if statements. Limit of 10 corpses

Sub Main
/mqlog
    /declare i int inner 0
    /declare CorpseCount int inner 1
    /declare Bodies[10] int inner 0

    /if (!${Defined[Param0]}) {
        /if (${Target.Type.NotEqual[Corpse]}) {
            /echo Usage:  /macro drag.mac corpse1 corpse2 corpse3 ect.
            /echo         /macro drag.mac <target>
            /end
        } else {
            /varset Bodies[1] ${Target.ID}
            /goto :CorpseCheck
        }
    }

  :CountCorpses
    /target corpse ${Param${i}}
    /varcalc i ${i}+1
    /if (${Target.ID}) {
        [color=cyan]/varset Bodies[${CorpseCount}] ${Target.ID}[/color]
        /varcalc CorpseCount ${CorpseCount}+1
    }
    /if ([color=red]$[/color]{Defined[Param${i}]}) /goto :CountCorpses
    /varcalc CorpseCount ${CorpseCount}-1
    /echo ${CorpseCount}
   
  :CorpseCheck
    /if (!${Bodies[1]}) {
        /echo No corpses are targetable.
        /end
    }
    /varset i 1
  :DragThem
    /if (${Spawn[${Bodies[${i}]}].Distance}>25) {
        /if (${Target.ID}!=${Bodies[${i}]}) /target id ${Bodies[${i}]}
      :WaitforTarget
        /delay 0
        [color=cyan]/if (${Target.ID)!=${Bodies[${i}]}) /goto :WaitforTarget[/color]
        /corpse
    }
    /varcalc i ${i}+1
    /delay 0
    /if (${i}>${CorpseCount}) /varset i 1
    /goto :DragThem
    /return