• 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.

Unit's perish while building {making constructing units vanish, like Night Elf Wisps}

Status
Not open for further replies.
Level 2
Joined
Apr 13, 2009
Messages
11
Is there any way to make constructing units perish while building, like night elf or starcraft zerg, without basing the building and/or unit of a night elf building?
 
Level 14
Joined
Aug 30, 2004
Messages
909
Maybe in Jass there is an easier way, but here's my advice:

EASY WAY

Event
Unit - A unit Finishes construction

Condition (if you only want to apply to some buildings, do that here)

Action
Set constructor = (Random unit from (Units within 120.00 of (Position of (Constructed structure)) matching ((Unit-type of (Matching unit)) Equal to Peasant)))
Unit - Remove constructor from the game
Unit - Kill constructor

Replace "Peasant" with whatever builds the building. You may need to change the "120" to a larger number depending on pathing. This trigger works by picking a random peasant near any finished building and killing it. It's imprecise and you may end up killing the wrong peasant unfortunately. That won't be a big deal unless the other peasant is constructing something. It will also only remove one peasant if you have multiple peasants building

HARD WAY

I did this for humans, because you didn't mention which race you were working with. Make a trigger that detects every time a human peasant casts "repair." Every human building starts with a peasant casting repair. Then set the custom value of the peasant and the building to the same integer. Something like this:

event - a unit casts an ability
condition -
ability = repair
action =
set custom value of casting unit to X
set custom value of target of cast ability to X
set X = X+1
if X = 100 then set X = 1 else do nothing

That trigger links peasants and the buildings they create by giving them the same custom value. Then another trigger runs when the building is complete.

Event
Unit - A unit Finishes construction

Action
set TotalPeasants = number of living peasants owned by owner of constructed unit
For each interger A from 1 to TotalPeasants
set TempUnit = random unit of TotalPeasants
If custom value of TempUnit = custom value of constructed unit,
then: set constructor = TempUnit
else: do nothing
Unit - Remove constructor
Unit - Kill constructor

That second trigger will go through all your peasants until it finds the one with the same custom value (set in trigger 1) as the constructed building. It then removes and kills the unit.

Now let's see if someone can find a way of doing all this with one line...
 
Status
Not open for further replies.
Top