# [Trigger]General formula or function...

Status
Not open for further replies.

Level 6
I have encountered a problem, either that or I am thinking too complex.

I have made a trigger that adds a lightning to a unit as soon as it is contructed, then I name it ,using arrays, to (x+1) where x is the previous number + a new unit. Now for the problem. Unit 1, 2 and 3 is alive, Unit 2 dies.
The next time a new Unit is constructed it will be named to Unit 2.
Another trigger, Unit X dies, is supposed to get the dying unit's "name" (Unit 1, Unit 2 Unit x...) and then remove the lightning accordingly. And as far as I know, there is no function for getting a unit's name.

Please post any solutions or other ideas that does not include copy + paste, these units array goes up to 75. I need a general formula, or a function that gives me the dying unit's variable name.

Thanks in beforehand for any help

#### redmarine

Level 19
I don't understand your problem but couldn't this work?
• Set Get_Dying_Unit_Name = (Name of (Dying unit))

Level 6
Lets see if I can explain further, I suck at this >.<

Lets do like this:

[1] [2] [3] [4] [5] These are my buildings, they are alive and running.
x for some odd reason, building nr 2 dies.

[1] [x] [3] [4] [5] [6] My builder decides to build another building, this building's name should be 2, but is the sixth in building order.

[1] [2] [3] [4] [5] [6] My builder decides yet again to build another building, the 7th in building order, this shall be named 6.

[1] [2] [3] [4] [5] [6] [7] [8] My builder creates 2 more buildings, named 7 and 8. x x 5 and 7 dies.

The next two buildings, in the 9th building order, shall be named 5 and 7.

These names corresponds to another trigger that removes a certain lightning from it. E.g building nr 2 dies, remove nr 2's lightning.
But instead of saying "If building nr 2 dies then remove building nr 2's lightning", I want the trigger to find out which unit variable[x] died, return the value x and then remove the lightning.

If Building[x] dies
Then
(Find out Building[Nr] of who/what died)
Lightning - Remove Lightning[Nr]<--- same number

Edit:
Maybe it is impossible... >.<

#### Xelephant

Level 6
Na its not =)

You could use the custom unit value for it

• TrickyTrigger
• Events
• Unit - A unit Finishes construction
• Conditions
• (Unit-type of (Constructed structure)) Equal to YourStructure
• Actions
• For each (Integer A) from 1 to 75, do (Actions)
• Loop - Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• Death[Interger A] = true
• Then - Actions
• Unit - Set the custom value of (Constructed structure) to (Integer A)
• ->Create Your Lighning here <-
• Set Lightning = Last Created Unit
• Set Death[Integer A] = false
• Else - Actions
• TrickyTrigger
• Events
• Unit - A unit dies
• Conditions
• (Unit-type of (Triggering Unit)) Equal to YourStructure
• Actions
• Unit - Kill Lightning[custom value of (Triggering Unit)]
• Set Death[custom value of (Triggering Unit)] = true
Variables:
Death is a boolean array default = true
Lightning is a unit array for the Lightnings

This should do the Trick. Note didn't test it. It would be easier if i had seen your Trigger

Last edited:

Level 6
Very clever! I have never worked with custom values on units before, because I saw no use in it, now I do.

The triggers you suggested works very well. I had to add a second condition on the integer loop, a boolean that stops it from looping the rest.
Conditions
boolStopLoop = false
Death[Integer A] =true
actions
loop
set boolStopLoop = true
set boolStopLoop = false (after exiting loop)

Also, how do you write the code for triggers in the comments? >.<

P.S +rep

Level 6
Hm, why does this not work?
• Lul
• Actions
• Unit - Create 1 Ability Dummy (Power Effect) for Player 1 (Red) at Position of MainHall) facing Default building
• Set PowerAbiDummy = (Last Created Unit)
• Unit - Create 1 Effect Dummy (Power Effect) for Neutral Hostile (Red) at Position of (Constructed Structure) facing Default building
• Set PowerEffectDummy = (Last Created Unit)
• Unit - Order PowerAbiDummy to Neutral Dark Ranger - Life Drain PowerEffectDummy

Edit:
Eh, how does the Targets Allowed work? -.-

Last edited:

#### Need_O2

Level 19
one of dummies is invulnurable ?
Check for Mana Cost and Available targets

Level 6
OK, I solved it.

Apparently, when using Drain Life you Have to have drain interval and how much is drained each time. Otherwise the spell is considered both hostile and friendly.

Status
Not open for further replies.

Replies
16
Views
1K
Replies
16
Views
2K
Replies
14
Views
1K
Replies
3
Views
832
[Solved] Bugged Maths
Replies
16
Views
802