Counting mobs

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

GeoffreyF67
a lesser mummy
a lesser mummy
Posts: 70
Joined: Tue Nov 04, 2003 6:07 pm

Counting mobs

Post by GeoffreyF67 » Tue Nov 25, 2003 4:54 pm

I'm trying to find the number of npc's within a certain range of my target. Anyone have any sample code that does this? I don't need to cycle through the mobs or anything. I just want a count.

G-Man

P.S. I did try the $Searchspawn command but can't seem to get it working.

User avatar
Undies
a ghoul
a ghoul
Posts: 94
Joined: Mon Oct 20, 2003 9:12 pm

Post by Undies » Mon Dec 08, 2003 9:35 am

I'm trying to do exactly the same thing but I can't get it to work either.

It looks like $searchspawn is indeed the correct thing to use for this but it sure beats me how it is used (or it is bugged).

GeoffreyF67
a lesser mummy
a lesser mummy
Posts: 70
Joined: Tue Nov 04, 2003 6:07 pm

Post by GeoffreyF67 » Mon Dec 08, 2003 11:25 am

I still haven't managed to do it. If you figure it out let me know.

G-Man

EqMule
Developer
Developer
Posts: 2697
Joined: Fri Jan 03, 2003 9:57 pm
Contact:

Post by EqMule » Mon Dec 08, 2003 11:27 am

$searchspawn was bugged, and I fixed it, but then it became bugged again, so I fixed it again (today)... I tested it today with latest dev cvs and it works, I dont have time to update the zip, so you have to wait for one of the other devs to do it, then this will work:

Code: Select all

Sub Main
:start
/declare stupidnewbID global
/declare mymerchant global
/varset mymerchant "Guntak Mulehead"
/call NewbCheck
/delay 4
/goto :start
/return

Sub NewbCheck
:init
/if n $searchspawn(pc,loc:$spawn($searchspawn("@mymerchant"),x):$spawn($searchspawn("@mymerchant"),y),radius:101)!=0 {
	/varset stupidnewbID $searchspawn(pc,loc:$spawn($searchspawn("@mymerchant"),x):$spawn($searchspawn("@mymerchant"),y),radius:101)
	/echo waiting for $spawn(@stupidnewbID,name) to clear out... $spawn(@stupidnewbID,distance)
	/delay 1s
	/goto :init
}
/return
to count them... well for that I dont know, but this will nail the closest player to your prefered npc...
My status o/
If you like MQ2 and would like to contribute, please do. My goal is 25 donations per month.
So far I've received Image donations for this month's patches.

Bitcoin: 1Aq8ackjQ4f7AUvbUL7BE6oPfT8PmNP4Zq
Krono: PM me.
I can always use characters for testing, PM me if you can donate one.

EqMule
Developer
Developer
Posts: 2697
Joined: Fri Jan 03, 2003 9:57 pm
Contact:

Post by EqMule » Mon Dec 08, 2003 11:34 am

oops, just read that you wanted npcs around your target...

hmm

how about

Code: Select all

/echo $searchspawn(npc,loc:$target(x):$target(y),radius:40)
that will get you the id of the closest npc to your target.

I think its possible to loop it somehow to figure out if there are more npc's around him, this example looks for the closest one within 40 "feet"
My status o/
If you like MQ2 and would like to contribute, please do. My goal is 25 donations per month.
So far I've received Image donations for this month's patches.

Bitcoin: 1Aq8ackjQ4f7AUvbUL7BE6oPfT8PmNP4Zq
Krono: PM me.
I can always use characters for testing, PM me if you can donate one.

GeoffreyF67
a lesser mummy
a lesser mummy
Posts: 70
Joined: Tue Nov 04, 2003 6:07 pm

Post by GeoffreyF67 » Mon Dec 08, 2003 12:16 pm

It's the looping part using searchspawn that i'm not sure how to do...

G-Man

nimblefoot
a lesser mummy
a lesser mummy
Posts: 33
Joined: Sun Jun 29, 2003 11:50 am

Post by nimblefoot » Mon Dec 08, 2003 12:19 pm

I've always just used an alert list to cycle through nearby mobs until it has no target when I want to get all IDs from mobs within a certain range. I suppose you could just add a loop counter to that to get the total count.

Tell me if you want the code. Each cycle just /alert add x id $target(id), using /target noalert x whatever to get the players/mobs you want.

nimblefoot
a lesser mummy
a lesser mummy
Posts: 33
Joined: Sun Jun 29, 2003 11:50 am

Post by nimblefoot » Mon Dec 08, 2003 12:19 pm

This is off the top of my head, so it may not work.

Code: Select all

Sub Count
   |Usage -- /call Count <npc|pc> <radius>
   /declare mobcounter local
   /varset mobcounter 0
   /alert clear 1
   /alert add 1 id -1 |This line circumvents some bugginess with alerts.
   /if $target()=="TRUE" /press esc
   :CountLoop
	/target @Param0 radius @Param1 noalert 1
	/delay 3 |Tweakable.
	/if $target()=="TRUE" {
		/alert add 1 id $target(id)
		/varadd mobcounter 1
		/press esc
		/goto :CountLoop
	}
   /echo @mobcounter mobs within @Param1 radius.
/return
Tell me if it works.

Thanks.
Last edited by nimblefoot on Mon Dec 08, 2003 1:47 pm, edited 4 times in total.

GeoffreyF67
a lesser mummy
a lesser mummy
Posts: 70
Joined: Tue Nov 04, 2003 6:07 pm

Post by GeoffreyF67 » Mon Dec 08, 2003 12:25 pm

Yah if you could either post the source or pm it to me that would be great!

Thanks!

G-Man

nimblefoot
a lesser mummy
a lesser mummy
Posts: 33
Joined: Sun Jun 29, 2003 11:50 am

Post by nimblefoot » Mon Dec 08, 2003 5:15 pm

I put this line

Code: Select all

 /alert add 1 id -1 |This line circumvents some bugginess with alerts. 
in there because of a problem I keep running into if I clear a list and attempt a /target npc noalert # it would seem to exclude everything. I could only solve it by adding a dummy to the alert list first.

Maybe I just need the latest MQ2...

EqMule
Developer
Developer
Posts: 2697
Joined: Fri Jan 03, 2003 9:57 pm
Contact:

Post by EqMule » Mon Dec 08, 2003 5:46 pm

nimblefoot, you REALLY dont wanna use /target in a loop to target a whole bunch of mobs... every single /target you issue is sent to the server... try finding a way to accomplish this using $searchspawn instead, unless you are looking for a dead give away, "I can target 1000 mobs from where I stand look at me Im using MQ!!!" ;)
My status o/
If you like MQ2 and would like to contribute, please do. My goal is 25 donations per month.
So far I've received Image donations for this month's patches.

Bitcoin: 1Aq8ackjQ4f7AUvbUL7BE6oPfT8PmNP4Zq
Krono: PM me.
I can always use characters for testing, PM me if you can donate one.

nimblefoot
a lesser mummy
a lesser mummy
Posts: 33
Joined: Sun Jun 29, 2003 11:50 am

Post by nimblefoot » Mon Dec 08, 2003 5:57 pm

Hehe okay thanks for the tip EQMule - I never used it in an area with more than 4 mobs...but yeah, I should probably stop spreading my plague and learn the real code. ;)

User avatar
Undies
a ghoul
a ghoul
Posts: 94
Joined: Mon Oct 20, 2003 9:12 pm

Post by Undies » Mon Dec 08, 2003 8:03 pm

Thanks, best thing seems to wait for searchspawn to be fixed.
I want to work out how many friends an NPC has with him during pulling and combat so targeting them is not the answer anyway.

I'm glad it was bugged, I was beginning to think I was a real newb moron...

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 » Mon Dec 08, 2003 9:21 pm

To cycle through the mobs you send the id of the current mob (or 0 for the first one) with "id:xx" and "next" to the $searchspawn function. It returns the id of the next spawn it finds (or the same as last time if no more were found) which you can in turn send to the next call to $searchspawn.

User avatar
Undies
a ghoul
a ghoul
Posts: 94
Joined: Mon Oct 20, 2003 9:12 pm

Post by Undies » Mon Dec 08, 2003 10:22 pm

$searchspawn was bugged, and I fixed it, but then it became bugged again, so I fixed it again (today)... I tested it today with latest dev cvs and it works, I dont have time to update the zip, so you have to wait for one of the other devs to do it
Sigh... I give up... I just tried to use CVS to DL the latest MQ2 source but cannot find the connect string anywhere, seems the devs want us to use the zip file with MQ2.

I am using the latest zip (December 06 2003 15:58:18) and the info says it includes the $searchspawn feature, but I gather this is still bugged?