• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Help with unit range...

Status
Not open for further replies.
Level 1
Joined
Aug 6, 2007
Messages
4
Help with unit-in-range trigger...

Hi, I'm wondering how to make it so if a unit-type comes near another unit-type class it will activate an event. Anyone know how? :eekani:
 
Last edited:
Level 2
Joined
Aug 12, 2007
Messages
18
Zomg lol it's u :)

Depending on what you're trying to do you probably don't need to find that type of thing.

You can use Unit - Unit Within Range if you have a specific unit to deal with, but if this is on a grand scale you'll likely want to use spells with spell range to trigger it, along with a triggered spell effect that checks unit type with a unit-type comparison condition.
 
First, create 2 Point Variables.
Lets call them Attacker Position and Target Position.

Second, create a dummy unit with the damage that you wish to deal on the melee attack.
Set this unit's hit points to 3 with -1reg so it can be removed without triggers.
Also set it untargeteable.

  • Events:
  • Unit - An unit is attacked.
  • Conditions:
  • Unit type of Attacking Unit equal to Archer
  • Actions:
  • Variable - Set (Attacker Point) Position of attacking unit.
  • Variable - Set (Target Position) Position of attacked unit.
  • If Then Do else
    • Conditions:
    • If distance betwen Attacker Point and Target Position is lesser than or equal than 100.
    • Actions:
    • Move attacked unit to position of attacked unit (To prevent to use both attacks)
    • Create 1 Melee Dummy Attacker at position of attacking unit.
    • Order last created unit to attack attacked unit.
 
Level 1
Joined
Aug 6, 2007
Messages
4
Haha what a coincidence for you to pop in here Yush :p.

I thank you for your help Ham Ham, but I'm sorry I was not more specific. Basically I'm working on a project that will kind of be like Zeus: Master of Olympus for those who have played that game.

Basically, I'm working on the first system, the Immigration system.

You build a build called the 'Immigration Shipyard'

I have the trigger down for when it's created and you have more then one vacant house, then people will start moving to your city. However, I need to make it so when the Immigration Ship is in range of a Dock, it creates a Villager near said dock.

So Basically, if A Unit-Type comes near another Unit-Type something will happen.
 
Last edited:
Level 21
Joined
Aug 21, 2005
Messages
3,699
If they're constantly created, I assume the previous "wave" will be removed when the next wave is created, is that right?

Assuming I'm right:

"Ships" is an empty unit group variable
"Shipyards" is an empty unit group variable
"TempShipyardGroup" is an empty unit group
" TempShipyard" is a unit variable

Trigger 1:
Events: every 70 seconds
Actions:
Unit group - pick every unit in "Ships" and do: remove picked unit from unit group
Create a "Ship" for "neutral" at "region 001"
Unit Group - Add last created unit to "Ships"

Trigger 2:
Events: unit finished constructing
Conditions: constructed unit type = Shipyard
Actions: Unit group - add last created unit to "Shipyards"

Trigger 3:
Events: a unit dies
conditions: unit type of dying unit = Shipyard
Actions: remove dying unit from "Shipyards"

Trigger 4:
Events: Every 1 seconds
Actions:
Pick every unit in "Ships" and do actions:
--- Set "TempShipyardGroup" = "Shipyards"
--- Loop : for each Integer A from 1 to (number of units in Shipyards) do actions:
------ Set "TempShipyard" = random unit in "TempUnitGroup"
------ Unit Group - remove "Tempshipyard" from "TempShipyardGroup"
------ If (real) range between Position of "Tempshipyard" and Position of "picked unit" = 200, Create a "Peasant" for owner of "Tempshipyard", else: do nothing.

The last trigger leaks 2 point variables and 1 unit group every second. I didn't include the custom scripts / variables because it's not up to me to fix leaks in your map.
The first trigger probably leaks a unit group too - not sure of that

I hope the trigger works, but I'm not sure if the loop works though

Note that if ships are destructible, you need to remove them from the 'Ships' unit group. Also note that every second the ship remains at the shipyard, a peasant will be created. Therefor it'd be useful to check if there are peasants near the shipyard, and if that's true, no new peasant should be created.
 
Level 1
Joined
Aug 6, 2007
Messages
4
That worked, much thanks! I'm going to be using this kind of trigger alot more then that so it's very useful.
 
Status
Not open for further replies.
Top