Plugin A plugin that can sort any sequence of integer number

KingArthur

AutoBots
Joined
Dec 15, 2009
Messages
525
Reaction score
31
Points
28
Ok, this botheres me for a long time, can we get a plugin that can sort any sequence of integer please? (can name it MQ2NumSort or sth..)

Current Math.Min, Math.Max or using /for loop to obtain the max/min of a series numerical value, somehow I'm not only want to obtain the extreme point but also the 2nd min/max, 3rd min/max etc...

Practical application example:

In raid, I box some tanks let's say 4 , one of my friends box let's say 3, and one other box let's say 3 too.

And I wanna sort bunch mobs' distance(let's say 6) to a FIX POINT (not to Me since I'm moving all the time so my loc varies..), then so the tanks to grab each respectively..

I can't simply use NearestSpawn TLO, since it's based on MY LOC, I can even add "loc ${someX} ${someY}" to the parameter, somehow if we fire it from different clients and the clients are keep moving all the time, well, then there is a good possibility that our target mob get some overlapsed.

And we also can't rely on Me.XTarget since the etw of each toon is pretty unpredictable, the order may vary between different clients.

So I'm now able to find the min distance to a FIX POINT by this loop:

Code:
  /for n 1 to ${SpawnCount[npc ${CharmMob} loc ${Ini[..\waypoints.ini,${Zone.ShortName},Charmer].Arg[2]} ${Ini[..\waypoints.ini,${Zone.ShortName},Charmer].Arg[1]} radius 200]}
    /if (${Math.Distance[${Ini[..\waypoints.ini,${Zone.ShortName},Charmer].Arg[2]},${Ini[..\waypoints.ini,${Zone.ShortName},Charmer].Arg[1]}:${NearestSpawn[${n},npc ${CharmMob} loc ${Ini[..\waypoints.ini,${Zone.ShortName},Charmer].Arg[2]} ${Ini[..\waypoints.ini,${Zone.ShortName},Charmer].Arg[1]} radius 200].X},${NearestSpawn[${n},npc ${CharmMob} loc ${Ini[..\waypoints.ini,${Zone.ShortName},Charmer].Arg[2]} ${Ini[..\waypoints.ini,${Zone.ShortName},Charmer].Arg[1]} radius 200].Y}].Int}<=${neardis}) {
	 /varset neardis ${Math.Distance[${Ini[..\waypoints.ini,${Zone.ShortName},Charmer].Arg[2]},${Ini[..\waypoints.ini,${Zone.ShortName},Charmer].Arg[1]}:${NearestSpawn[${n},npc ${CharmMob} loc ${Ini[..\waypoints.ini,${Zone.ShortName},Charmer].Arg[2]} ${Ini[..\waypoints.ini,${Zone.ShortName},Charmer].Arg[1]} radius 200].X},${NearestSpawn[${n},npc ${CharmMob} loc ${Ini[..\waypoints.ini,${Zone.ShortName},Charmer].Arg[2]} ${Ini[..\waypoints.ini,${Zone.ShortName},Charmer].Arg[1]} radius 200].Y}].Int}
	 /varset nearcm ${NearestSpawn[${n},npc ${CharmMob} loc ${Ini[..\waypoints.ini,${Zone.ShortName},Charmer].Arg[2]} ${Ini[..\waypoints.ini,${Zone.ShortName},Charmer].Arg[1]} radius 200].ID}
	}
   /next n
   /echo now nearest mob is ${Spawn[id ${nearcm}].Name} with ID: ${nearcm}, dis to charmer point is ${neardis}

But I still lack the information of 2nd near, 3rd near mob etc...

I hope I made myself clear and thanks for reading.
 
Last edited:
Interesting question.

Answer to the first part - yes, it would be fairly trivial to take a string of numbers and sort it.

But I don't think that is really what you want since most of the time when you sort something there is additional data that you want tied to the primary value you're sorting. In your example it might be the ID of the mob you're calculating the range to.

TypePun wrote a plugin that implements some standard data types that you might find useful

GitHub - TypePun/MQ2Collections: Collection types for MQ2 -- useful for scripts to create stacks, queues, maps, lists.

List: a flexible sequence of items * TypePun/MQ2Collections Wiki * GitHub

If you don't have access to that you may be able to solve your specific problem using alerts.