HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Pick unit that is FARTHEST?

02-07-2003, 07:47 AM#1
Hakujin
My budding triggering skills are letting me down here. Here is what I want to do:

Spawn item X at the position of a Player-controlled unit which is the FARTHEST from unit Y.

I've been elbow deep in the triggers and nothing seems to work. I don't want to create a real-time distance array because 1) it will lag and 2) players will be summoning / raising dead

Any ideas?

If this is impossible, how about just picking a random hero belonging to a human player. Hehe I don't know how to do that either! Thanks in advance!
02-07-2003, 11:53 AM#2
Guest
make a grid of 4000 regions of the map
give every region a value depending on how far they are away from X
and done :-)
02-07-2003, 12:59 PM#3
Hivemind
Picking a random unit of type or owned by player is possable. You need to set up a special trigger to do it. Use a unit group array. As a unit is created add it to the array as unitgroup[i+1]. So that each unit has its own index number. When you want to pick the random unit genorate a random number from 1 to i to use as the index for the picked unit.

There are problems with adding a unit to to a unit group index. There are several ways to work around this but the simplest is when the unit enters map remove it and then create a copy then use the last created unit function to add it to the array. Replace may work as well tho we havent tried it.

We used this in Hive's Revenge TD to pick a random trade center and add resources or units to one player.
02-07-2003, 01:27 PM#4
rwxr-xr-x
Quote:
Originally posted by Hakujin
My budding triggering skills are letting me down here. Here is what I want to do:

Spawn item X at the position of a Player-controlled unit which is the FARTHEST from unit Y.

I've been elbow deep in the triggers and nothing seems to work. I don't want to create a real-time distance array because 1) it will lag and 2) players will be summoning / raising dead

Any ideas?

If this is impossible, how about just picking a random hero belonging to a human player. Hehe I don't know how to do that either! Thanks in advance!


You could do the following:

1) Create a variable of type Unit Group, and add all players heros to it (the example trigger uses a variable named heroGroup).

2) Create a variable of type Unit (the example trigger uses a variable named distanceUnit).

3) Create the following trigger...

[FarthestUnit]
EVENTS
* <whatever event you are triggering on>
CONDITIONS
* <whatever conditions you require>
ACTIONS
* Set distanceUnit = (Random unit from heroGroup)
* Unit Group - Pick every unit in heroGroup and do (If ((Distance between (Position of (Picked unit)) and (Position of (UNIT))) Greater than (Distance between (Position of distanceUnit) and (Position of (UNIT))) then do (Set distanceUnit = (Picked unit)) else do (Do nothing)
* Item - Create ITEM at (Position of distanceUnit)

*NOTE* The UNIT is a reference to the unit you are wanting to check the distance from, and ITEM is the item you wish to create for them.
02-08-2003, 03:57 AM#5
CBWhiz
Ive done somethign like this, but for the losest unit, so its easy to change.

basicly you loop through all possible units and when one is further, you store him as temp. then you compare the next units to temp.
02-08-2003, 05:13 AM#6
rwxr-xr-x
Quote:
Originally posted by CBWhiz
Ive done somethign like this, but for the losest unit, so its easy to change.

basicly you loop through all possible units and when one is further, you store him as temp. then you compare the next units to temp.


That is exactly what the trigger I wrote above does.
02-08-2003, 02:47 PM#7
Hakujin
Amazing help. I really learned how to use "distance between two X" from this thread. Major thanks!