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

[Trigger] General formula or function...

Status
Not open for further replies.
Level 6
Joined
Jul 25, 2005
Messages
221
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. :p

Thanks in beforehand for any help

// ShadowMan
 
Level 6
Joined
Jul 25, 2005
Messages
221
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... >.<
 
Level 6
Joined
Feb 2, 2005
Messages
205
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
Joined
Jul 25, 2005
Messages
221
Very clever! I have never worked with custom values on units before, because I saw no use in it, now I do. :D

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 :p
 
Level 6
Joined
Jul 25, 2005
Messages
221
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
:huh:

Edit:
Eh, how does the Targets Allowed work? -.-
 
Last edited:
Level 6
Joined
Jul 25, 2005
Messages
221
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.
Top