auto tl macro

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

Moderator: MacroQuest Developers

Diamondmine
a lesser mummy
a lesser mummy
Posts: 73
Joined: Mon Aug 23, 2004 3:14 pm

Post by Diamondmine » Sun Jan 09, 2005 3:47 am

this particular macro was created for my guild


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

it works perfectly, there is nothing wrong with it

the wizard was set up at the time portal and anytime a raid was called the wizard was put up. works well, I dont see a difference in anything that you are trying to do

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 » Sun Jan 09, 2005 6:06 am

I already linked that earlier. He only wants it to respond to hails and port to one location. Quite a bit different really
[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
Cr4zyb4rd
Plugins Czar
Posts: 1449
Joined: Tue Jul 20, 2004 11:46 am

Post by Cr4zyb4rd » Sun Jan 09, 2005 9:43 am

Diamondmine seems to have misspelled "MEMEMEMEME!! ME! ME ME! LOVE ME! LOVEMELOVEMELOVEME! ME ME MEE ME ME!! ME! ME! MEMEME! LOVE ME!"

weezurd
orc pawn
orc pawn
Posts: 19
Joined: Sat Jan 08, 2005 1:38 am

Post by weezurd » Sun Jan 09, 2005 6:12 pm

Diamondmine wrote:the wizard was set up at the time portal and anytime a raid was called the wizard was put up. works well, I dont see a difference in anything that you are trying to do
there is a huge difference. the macro i created (with the help from a few ppl here, thanks!) resonds to hails and doesnt require letting ppl know you are running a macro magus service.

weezurd
orc pawn
orc pawn
Posts: 19
Joined: Sat Jan 08, 2005 1:38 am

Post by weezurd » Sun Jan 09, 2005 7:40 pm

tested the macro. as of now if someone hails for a tl while im in the middle of tling and someone hails me when it finishes, it will skip the previous person and tl the last person to hail me.

any advice on fixing this?

User avatar
aChallenged1
a grimling bloodguard
a grimling bloodguard
Posts: 1804
Joined: Mon Jun 28, 2004 10:12 pm

Post by aChallenged1 » Sun Jan 09, 2005 8:14 pm

As someone said earlier, array.
Fuck writing MQ2 macros. Go with IS scripts; IS Rules!

Zeus
a hill giant
a hill giant
Posts: 180
Joined: Wed Feb 19, 2003 10:03 am
Contact:

Post by Zeus » Sun Jan 09, 2005 9:19 pm

Solution would be a Queue hmm let me see if I can write something that slightly resembles one and works for what you need.

Edit: I'm not 100% sure it works, haven't tested it in game but looks right:

Edit 2: Dumb me forgot to explain in case you aren't familiar with Queues, call Enqueue to add people to the Queue when they hail you, and to target them to tl use Dequeue and target with the return value if the call.

Code: Select all

/declare QueueMaxSize int outer
/declare QueueSize int outer

| Change size as needed
/varset QueueMaxSize 10
/varset QueueSize 0

/declare QueueArray[${QueueMaxSize}]


Sub EnQueue(string Element)

|Adds an element to the Queue
|returns 1 on succes 0 on failure

	/if (${QueueSize}<${QueueMaxSize}) {
		/varset QueueArray(QueueSize) Element
		/varset QueueSize ${QueueSize} + 1
		/return 1
	} else {
		/return NULL
	}

Sub DeQueue 

|Retrieves an element from the Queue
|Returns the first element on success, null on failure

	/declare ReturnValue
	/declare Counter int

	/if (${QueueSize}>0) {
		/varset ReturnValue QueueArray(0)
		/for Counter 0 to ${QueueSize} - 1
			/varset QueueArray(${Counter}) QueueArray(${Counter} + 1)
		/next Counter
		/varset QueueSize ${QueueSize} - 1
		/return ${ReturnValue}
	} else {
		/return null
	}

weezurd
orc pawn
orc pawn
Posts: 19
Joined: Sat Jan 08, 2005 1:38 am

Post by weezurd » Sat Jan 15, 2005 8:51 pm

thanks for the queue code, but i've been trying to understand it and just can't figure out how to incorperate it and have it do what i would like it to do.

would anyone be so kind to explain how it works for me or possibly help me piece this together. would greatly appreciate the help

JJ
a hill giant
a hill giant
Posts: 227
Joined: Thu Nov 11, 2004 5:50 am

Post by JJ » Sun Jan 16, 2005 5:55 am

Quick explanation:
Read Edit 2 and his comments

Slightly more than quick explanation:
Basically what he has done is written the meat of the macro that you want. He has an Enqueue event that will store whatever you want (like names of who hailed you) and a Dequeue event that returns the next name in order. At this point, you probably don't need to know the internal works of the queue, just how to call the subs and what to pass to them or what they return.

Here's what you will need to do with it. Create a main sub that loops through doing the following:
call your DeQueue (So that you can cast TL on the next person in line)
doevents (So it will queue the people that hailed you)

You need to set up the event handler that calls the enqueue sub to add the name of the hailer to the queue.

As part of dequeueing, you may want to have an if statement that checks if SpellReady then call WhateverSub WhateverName

He has it set for a size of 10, so that may be the only thing you may want to tweak for your liking.

weezurd
orc pawn
orc pawn
Posts: 19
Joined: Sat Jan 08, 2005 1:38 am

Post by weezurd » Sun Jan 16, 2005 7:00 am

ok thanks.

having a little trouble, not sure if i'm going about this correctly. i think im understanding the concept, but i'm getting errors. the error im getting is varset failed, variable QueueArray(QueueSize) not found. when i try to declare the variable QueueArray(QueueSize) it just does nothing, no errors or anything.

here is the code:

Code: Select all


#include spell_routines.inc 
#event Hailed "#1# says, 'Hail, <Your-Name-Here>'" 

Sub Main 

/echo Raid TL Macro has now started..

/declare transspell string outer
/declare RequestorID int outer
/declare spellgem int outer 9

/declare QueueMaxSize int outer 
/declare QueueSize int outer 

/varset QueueMaxSize 10 
/varset QueueSize 0 

/declare QueueArray[${QueueMaxSize}]


/if (!${Defined[Param0]}) {    
  /echo Error, You must specify the translocate spell you wish to use.
  /echo Syntax: /mac tl Natimbi
  /end
} else {
  /echo You have chosen to use: Translocate: ${Param0}
  /varset transspell Translocate: ${Param0}
  /if (!${Me.SpellReady["${transspell}"]}) {
    /echo Now meming ${transspell}
    /memspell ${spellgem} "${transspell}"
  }
}


:loop 
/doevents
/delay 2s 
/goto :loop 

Sub Event_Hailed(string line,string RequestorName) 

/varset RequestorID ${Spawn[pc ${RequestorName}].ID}
/squelch /target id ${RequestorID}
/delay 1s ${Target.ID}==${RequestorID}

/echo Adding {$RequestorName} to queue for translocation

/call EnQueue ${RequestorName}

/return 


Sub Trans(string PersonToTrans)

/if (${Me.SpellReady["${transspell}"]}) {
  /if (${FindItemCount[Small Portal Fragments]}>0) { 
    /echo Now translocating: ${PersonToTrans}
    /call cast "${transspell}" ${spellgem} 1s
  } else { 
    /echo Out of portal fragments, ending macro.
    /end
  } 
}

/return



Sub EnQueue(string Element) 

|Adds an element to the Queue 
|returns 1 on succes 0 on failure 

   /if (${QueueSize}<${QueueMaxSize}) { 
      /varset QueueArray(QueueSize) Element 
      /varset QueueSize ${QueueSize} + 1 
      /return 1 
   } else { 
      /return NULL 
   } 

Sub DeQueue 

|Retrieves an element from the Queue 
|Returns the first element on success, null on failure 

   /declare ReturnValue 
   /declare Counter int 

   /if (${QueueSize}>0) { 
      /varset ReturnValue QueueArray(0) 
      /for Counter 0 to ${QueueSize} - 1 
         /varset QueueArray(${Counter}) QueueArray(${Counter} + 1) 
      /next Counter 
      /varset QueueSize ${QueueSize} - 1 
      /return ${ReturnValue} 

      /if (!${Me.SpellReady["${transspell}"]}) /call Trans ${ReturnValue}

   } else { 
      /return null 
   } 
thanks again

weezurd
orc pawn
orc pawn
Posts: 19
Joined: Sat Jan 08, 2005 1:38 am

Post by weezurd » Sun Jan 16, 2005 1:23 pm

ok i think i got the add to queue part working but im stuck on the dequeue part.

could anyone pls tell me what im doing wrong?

Code: Select all


#include spell_routines.inc 
#event Hailed "#1# says, 'Hail, <Your-Name-Here>" 

Sub Main 

/echo Raid TL Macro has now started..

/declare transspell string outer
/declare RequestorID int outer
/declare spellgem int outer 9

/declare QueueMaxSize int outer 
/declare QueueSize int outer
/declare Num int local 0

/varset QueueMaxSize 10
/varset QueueSize 0 

/declare QueueArray[${QueueMaxSize}] string outer


/if (!${Defined[Param0]}) {    
  /echo Error, You must specify the translocate spell you wish to use.
  /echo Syntax: /mac tl Natimbi
  /end
} else {
  /echo You have chosen to use: Translocate: ${Param0}
  /varset transspell Translocate: ${Param0}
  /if (!${Me.SpellReady["${transspell}"]}) {
    /echo Now meming ${transspell}
    /memspell ${spellgem} "${transspell}"
  }
}


:loop 
/doevents
/delay 2s 
/if (${QueueSize}>1) /call DeQueue

/goto :loop 

Sub Event_Hailed(string line,string RequestorName) 

/varset RequestorID ${Spawn[pc ${RequestorName}].ID}
/squelch /target id ${RequestorID}
/delay 1s ${Target.ID}==${RequestorID}

/echo Adding ${RequestorName} to translocation queue

/call EnQueue ${RequestorName}

/return 


Sub Trans(string PersonToTrans)

/if (${Me.SpellReady["${transspell}"]}) {
  /if (${FindItemCount[Small Portal Fragments]}>0) { 
    /echo Now translocating: ${PersonToTrans}
    /call cast "${transspell}" ${spellgem} 1s
  } else { 
    /echo Out of portal fragments, ending macro.
    /end
  } 
}

/return

Sub EnQueue(string Element) 

   /if (${QueueSize}<${QueueMaxSize}) { 
      
      /varcalc QueueSize ${QueueSize} + 1
      /varset QueueArray[${QueueSize}] ${Element}
            
      /echo Successfully added ${Element} to slot ${QueueSize} of the queue

      /return 1
   } else { 
      /echo Add to queue failed
      /return NULL 
   } 

Sub DeQueue 

   /declare ReturnValue string local
   /declare Counter int local 0

   /if (${QueueSize}>0) { 

      /varset ReturnValue QueueArray[0]

      /for Counter 0 to ${QueueSize}
         /varset QueueArray[${Counter}] QueueArray[${Counter}+1]
      /next Counter 
      
      /return ${ReturnValue} 

      /echo Retrieved: ${ReturnValue}

|      /if (!${Me.SpellReady["${transspell}"]}) /call Trans ${ReturnValue}

   } else { 
      /return null 
   } 


JJ
a hill giant
a hill giant
Posts: 227
Joined: Thu Nov 11, 2004 5:50 am

Post by JJ » Sun Jan 16, 2005 2:04 pm

Once you hit this line:

Code: Select all

/return ${ReturnValue}
the sub returns the value and ends the sub, so it never hits your spell casting part. If you want to include it as part of the dequeue, you should remove that line and put a /return at the end.

Couple other things:

Code: Select all

/if (${QueueSize}>1) /call DeQueue
should be changed to > 0 and then in your dequeue event, you can remove that if statement because it would never trigger dequeue unless the queue had an item in it to begin with.

Also, in your dequeue event, it doesn't seem to decrement your queue after retrieving the next queue item.

Lastly, looking at this, not sure if you need quotes or not:

Code: Select all

/varset transspell Translocate: ${Param0}

weezurd
orc pawn
orc pawn
Posts: 19
Joined: Sat Jan 08, 2005 1:38 am

Post by weezurd » Sun Jan 16, 2005 6:21 pm

JJ wrote:Also, in your dequeue event, it doesn't seem to decrement your queue after retrieving the next queue item.
this is the problem i am having now.. i am not sure what i am doing wrong in the dequeue sub.

right now this is what it says when testing the macro:
[MQ2] Retrieved: QueueArray[0]
/varset 'QueueArray[-1] failed, out of bounds of array
tl.mac@93 (DeQueue): /varset QueueArray[${Counter}] QueueArray[${Counter} + 1]

Code: Select all

#include spell_routines.inc 
#event Hailed "#1# says, 'Hail, <Your-Name-Here>'" 

Sub Main 

/echo Raid TL Macro has now started..

/declare transspell string outer
/declare RequestorID int outer
/declare spellgem int outer 9

/declare QueueMaxSize int outer 
/declare QueueSize int outer
/declare Num int local 0

/varset QueueMaxSize 10
/varset QueueSize 0 

/declare QueueArray[${QueueMaxSize}] string outer


/if (!${Defined[Param0]}) {    
  /echo Error, You must specify the translocate spell you wish to use.
  /echo Syntax: /mac tl Natimbi
  /end
} else {
  /echo You have chosen to use: Translocate: ${Param0}
  /varset transspell Translocate: ${Param0}
  /if (!${Me.SpellReady["${transspell}"]}) {
    /echo Now meming ${transspell}
    /memspell ${spellgem} "${transspell}"
  }
}


:loop 
/doevents
/delay 2s 
/if (${QueueSize}>0) /call DeQueue
/goto :loop 

Sub Event_Hailed(string line,string RequestorName) 

/varset RequestorID ${Spawn[pc ${RequestorName}].ID}
/squelch /target id ${RequestorID}
/delay 1s ${Target.ID}==${RequestorID}

/echo Adding ${RequestorName} to translocation queue

/call EnQueue ${RequestorName}

/return 


Sub Trans(string PersonToTrans)

/if (${Me.SpellReady["${transspell}"]}) {
  /if (${FindItemCount[Small Portal Fragments]}>0) { 
    /echo Now translocating: ${PersonToTrans}
    /call cast "${transspell}" ${spellgem} 1s
  } else { 
    /echo Out of portal fragments, ending macro.
    /end
  } 
}

/return

Sub EnQueue(string Element) 

/if (${QueueSize}<${QueueMaxSize}) { 
      
  /varcalc QueueSize ${QueueSize} + 1
  /varset QueueArray[${QueueSize}] ${Element}
            
  /echo Successfully added ${Element} to slot ${QueueSize} of the queue

  /return 1

} else { 
   /echo Add to queue failed
   /return NULL 
} 

Sub DeQueue 

/declare ReturnValue string local
/declare Counter int local 0

/varset ReturnValue QueueArray[0]

/for Counter 0 to ${QueueSize} -1
  /varset QueueArray[${Counter}] QueueArray[${Counter} + 1]
/next Counter 
      
/echo Retrieved: ${ReturnValue}

/if (!${Me.SpellReady["${transspell}"]}) /call Trans ${ReturnValue}

/return


JJ
a hill giant
a hill giant
Posts: 227
Joined: Thu Nov 11, 2004 5:50 am

May need encapsulation

Post by JJ » Sun Jan 16, 2005 9:52 pm

You may need encapsulation on your for statement.

Code: Select all

/for Counter 0 to ${QueueSize} -1
seems to be the problem area. According to the error returned, it's trying to access QeueArray[-1]. I haven't worked much with the calculations portion of it, but you could try:

Code: Select all

/for Counter 0 to (${QueueSize}-1)
or if that doesn't work, try to create a new integer and /varcalc it to be QueueSize - 1

And glancing through, you still haven't fixed the decrementing. Somewhere after this for loop you need to decrement your queue size.
Maybe right here:

Code: Select all

/varcalc ${QueueSize} (${QueueSize}-1)
/echo Retrieved: ${ReturnValue}

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

Post by ieatacid » Sun Jan 16, 2005 9:58 pm

Code: Select all

/for Counter 0 to (${QueueSize}-1)
I never tried parentheses in /for loops, but if that doesn't work

Code: Select all

/for Counter 0 to ${Math.Calc[${QueueSize}-1]}
should.