FindExactSpawnID and TargetExact, finding spawns by name

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

User avatar
blueninja
a grimling bloodguard
a grimling bloodguard
Posts: 541
Joined: Thu Aug 28, 2003 7:03 am
Location: Göteborg, Sweden

FindExactSpawnID and TargetExact, finding spawns by name

Post by blueninja » Fri Aug 06, 2004 1:12 pm

FindExactSpawnID will return the spawn id of the spawn that matches the exact name passed to it, TargetExact will target the spawn matching the exact name.

The reason for this is that if you have two players with names that contain the same string, for example you have a toon Joe and a second toon Joey and you want to target Joe. Typing '/target joe' will target joey if he happens to be closer to you. These will match Joe no matter what.

Code: Select all

Sub FindExactSpawnID(string Name)
	/declare CurrentID int local
	/declare FirstID int local
	/declare Counter int local 1

	/varset CurrentID ${Spawn[${Name}].ID}
	
	:FESI_FindNext
		/if (!${CurrentID} || ${Spawn[id ${CurrentID}].CleanName.Equal[${Name}]}) /return ${CurrentID}
		/varset CurrentID ${Spawn[id ${Me.ID}].NearestSpawn[${Counter},${Name}].ID}
		/varcalc Counter ${Counter}+1
	/goto :FESI_FindNext
	
/return 0

Code: Select all

Sub TargetExact(string Name)
	/declare CurrentID int local
	/declare FirstID int local
	/declare Counter int local 1
	/varset CurrentID ${Spawn[${Name}].ID}
	
	:TE_FindNext
		/if (!${CurrentID}) /return 0
		/if (${Spawn[id ${CurrentID}].CleanName.Equal[${Name}]}) {
			/target id ${CurrentID}
			/return
		}
		/varset CurrentID ${Spawn[id ${Me.ID}].NearestSpawn[${Counter},${Name}].ID}
		/varcalc Counter ${Counter}+1
	/goto :TE_FindNext
	
/return
Last edited by blueninja on Fri Aug 13, 2004 9:57 am, edited 1 time in total.

User avatar
SukMage
a ghoul
a ghoul
Posts: 88
Joined: Fri Jun 04, 2004 5:08 pm

Post by SukMage » Fri Aug 06, 2004 4:10 pm

That's great... I did notice that problem a few times but it's generally when grabbing a toon to CoH. Generally I know the people who I cross zone target/CoH and I would /tar joe and get joey then /tar clr joe and get the right one... That's not 100% effective but close to 80%. :) Thanks for the great sub to play with.

Gameross
a lesser mummy
a lesser mummy
Posts: 46
Joined: Mon May 03, 2004 10:11 am

Great routine that solves a problem for me. One suggestion.

Post by Gameross » Fri Aug 13, 2004 7:52 am

Have the routine return a NULL if nothing found or the targets ID. Below is the code to do that. You can access the returned value via ${Macro.Return}

Thanks for the routine, took care of a targetting issue I was having with a macro I've been working on and was a low priority to get fixed. :D

Code: Select all

Sub TargetExact(string Name)
   /declare CurrentID int local
   /declare FirstID int local
   /declare Counter int local 1
   /varset CurrentID ${Spawn[${Name}].ID}

   :TE_FindNext
      /if (!${CurrentID}) /return NULL
      /if (${Spawn[id ${CurrentID}].CleanName.Equal[${Name}]}) {
         /target id ${CurrentID}
         /return ${CurrentID}
      }
      /varset CurrentID ${Spawn[id ${Me.ID}].NearestSpawn[${Counter},${Name}].ID}
      /varcalc Counter ${Counter}+1
   /goto :TE_FindNext
Yes, I didn't post the unneccesary /return as this should never reach it.

User avatar
blueninja
a grimling bloodguard
a grimling bloodguard
Posts: 541
Joined: Thu Aug 28, 2003 7:03 am
Location: Göteborg, Sweden

Post by blueninja » Fri Aug 13, 2004 10:02 am

Ok, good point, changed the post above.

Oh and yes, I know the /return never would be reached, for some reason I always end a sub with /return no matter what, probably because I think it looks better. :)