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

Counting units (storing them as Integer)

Status
Not open for further replies.
Level 4
Joined
Jul 20, 2012
Messages
83
Hi guys, I've got this little "moment of no idea" right now with my trigger...
This spell is a Blizzard-based AoE thing with Entagling Roots dummies:
  • Rooting Field
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Rooting Field
    • Actions
      • Unit Group - Pick every unit in (Units within (281.25 + (31.25 x (Real((Level of Rooting Field for (Triggering unit)))))) of (Target point of ability being cast) matching ((((Matching unit) is A structure) Equal to False) and (((Matching unit) belongs to an enemy of (Owner of (Triggering u and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Picked unit)) Not equal to Meat Wagon (Release Disease)
              • (Unit-type of (Picked unit)) Not equal to Bone Prison
              • (Unit-type of (Picked unit)) Not equal to Mailbox
              • (Unit-type of (Picked unit)) Not equal to Guardian
              • ((Picked unit) is Magic Immune) Equal to False
              • ((Picked unit) is alive) Equal to True
            • Then - Actions
              • Set Skill_RootingField[(Player number of (Owner of (Triggering unit)))] = (Skill_RootingField[(Player number of (Owner of (Triggering unit)))] + 1)
              • If (Skill_RootingField[(Player number of (Owner of (Triggering unit)))] Greater than 10) then do (Set Skill_RootingField[(Player number of (Owner of (Triggering unit)))] = 10) else do (Do nothing)
              • Unit - Create 1 Mammoth Tree (Dummy) for (Owner of (Triggering unit)) at (Position of (Triggering unit)) facing (Position of (Picked unit))
              • Unit - Add a 0.50 second Generic expiration timer to (Last created unit)
              • Unit - Set level of Rooting Field (Dummy) for (Last created unit) to (Level of Rooting Field for (Triggering unit))
              • Unit - Order (Last created unit) to Night Elf Keeper Of The Grove - Entangling Roots (Picked unit)
              • Unit - Cause (Triggering unit) to damage (Picked unit), dealing ((Real((Strength of (Triggering unit) (Include bonuses)))) x (0.10 x (Real((Level of Thorns Aura (Mammoth Tree) for (Triggering unit)))))) damage of attack type Magic and damage type Magic
              • Unit - Create 1 Mammoth Tree (Dummy) for (Owner of (Triggering unit)) at (Position of (Triggering unit)) facing (Position of (Triggering unit))
              • Unit - Add a 0.50 second Generic expiration timer to (Last created unit)
              • Unit - Set level of Root Hastening (Dummy) for (Last created unit) to (1 - 1)
              • Unit - Set level of Root Hastening (Dummy) for (Last created unit) to Skill_RootingField[(Player number of (Owner of (Triggering unit)))]
              • Unit - Pause (Last created unit)
              • Unit - Unpause (Last created unit)
              • Unit - Order (Last created unit) to Orc Shaman - Bloodlust (Triggering unit)
              • Set Skill_RootingField[(Player number of (Owner of (Triggering unit)))] = 0
            • Else - Actions
The point of this is that (forget leaks now) the spell should count units in that area rooting all valid enemy units and then it creates a set of the same dummies which have the ability of speeding up the caster by the number of enemies caught, this is done by the integer which should store the number of units in the area up to maximum of 10 and then it sets the level of the Bloodlust ability equal to it to be cast upon the caster.
I've done the counting by
  • Set Skill_RootingField[(Player number of (Owner of (Triggering unit)))] = (Skill_RootingField[(Player number of (Owner of (Triggering unit)))] + 1)
because it should perform this function for each valid unit in the area and after the whole process it returns 0 to not screw up next spell attempts...
Notes:
  • Unit - Set level of Root Hastening (Dummy) for (Last created unit) to (1 - 1)
- it is there for security because if the spell is cast on blank field without units it casts a spell with level of 0
- pausing and unpausing functions are there as a test but it didn't work either

It always casts level 1 Bloodlust on caster no matter the number of units (still if it's bigger than 0 units)
So, any ideas where I went wrong? I'd like to have it finished as soon as possible to move on to the next stuff, thanks in advance...
 
Level 8
Joined
May 7, 2008
Messages
108
I know it's to test, but pausing and unpausing Last created unit isn't going to fix anything
Are you sure that the spell is being correctly cast by the dummies ?
Try to add a longer generic expiration timer if it's not the case

And try to remove that "1-1" security, because if there isn't any unit in the targeted area, it just won't be counted in the Pick every unit action

First of all, you are leaking locations.

He asked help on how to solve his problem, not to know if it leaks...
 
Level 4
Joined
Jul 20, 2012
Messages
83
Solved!

Aaalright, digging deeper into it and removing the Hastening ability from the unit first and adding it by trigger under a condition works pretty well...
And next time somebody asks for something (the title was pretty clear), stop taking your Leak Nazi attitude too serious...
Here's the correct version of how I did it (leaky for now):
  • Rooting Field
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Rooting Field
    • Actions
      • Unit Group - Pick every unit in (Units within (281.25 + (31.25 x (Real((Level of Rooting Field for (Triggering unit)))))) of (Target point of ability being cast) matching ((((Matching unit) is A structure) Equal to False) and (((Matching unit) belongs to an enemy of (Owner of (Triggering u and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Picked unit)) Not equal to Meat Wagon (Release Disease)
              • (Unit-type of (Picked unit)) Not equal to Bone Prison
              • (Unit-type of (Picked unit)) Not equal to Mailbox
              • (Unit-type of (Picked unit)) Not equal to Guardian
              • ((Picked unit) is Magic Immune) Equal to False
              • ((Picked unit) is alive) Equal to True
            • Then - Actions
              • Set Skill_RootingField[(Player number of (Owner of (Triggering unit)))] = (Skill_RootingField[(Player number of (Owner of (Triggering unit)))] + 1)
              • If (Skill_RootingField[(Player number of (Owner of (Triggering unit)))] Greater than 10) then do (Set Skill_RootingField[(Player number of (Owner of (Triggering unit)))] = 10) else do (Do nothing)
              • Unit - Create 1 Mammoth Tree (Dummy) for (Owner of (Triggering unit)) at (Position of (Triggering unit)) facing (Position of (Picked unit))
              • Unit - Add a 0.50 second Generic expiration timer to (Last created unit)
              • Unit - Set level of Rooting Field (Dummy) for (Last created unit) to (Level of Rooting Field for (Triggering unit))
              • Unit - Order (Last created unit) to Night Elf Keeper Of The Grove - Entangling Roots (Picked unit)
              • Unit - Cause (Triggering unit) to damage (Picked unit), dealing ((Real((Strength of (Triggering unit) (Include bonuses)))) x (0.10 x (Real((Level of Thorns Aura (Mammoth Tree) for (Triggering unit)))))) damage of attack type Magic and damage type Magic
            • Else - Actions
      • Unit - Create 1 Mammoth Tree (Dummy) for (Owner of (Triggering unit)) at (Position of (Triggering unit)) facing (Position of (Triggering unit))
      • Unit - Add a 0.50 second Generic expiration timer to (Last created unit)
      • If (Skill_RootingField[(Player number of (Owner of (Triggering unit)))] Greater than 0) then do (Unit - Add Root Hastening (Dummy) to (Last created unit)) else do (Do nothing)
      • Unit - Set level of Root Hastening (Dummy) for (Last created unit) to Skill_RootingField[(Player number of (Owner of (Triggering unit)))]
      • Unit - Order (Last created unit) to Orc Shaman - Bloodlust (Triggering unit)
      • Set Skill_RootingField[(Player number of (Owner of (Triggering unit)))] = 0
Thanks for an interest to help guys, much appreciated ;)
 
Level 4
Joined
Jul 20, 2012
Messages
83
That's why I use arrays, there's no way you can cast a spell more than once per player in my map so it suits me...
And Zwiebelchen, it was resetting the variable AFTER all the stuff happened so I didn't know why it wasn't working the first attempt.
 
That's why I use arrays, there's no way you can cast a spell more than once per player in my map so it suits me...
And Zwiebelchen, it was resetting the variable AFTER all the stuff happened so I didn't know why it wasn't working the first attempt.
You used this line at the end inside the picking loop:
  • Set Skill_RootingField[(Player number of (Owner of (Triggering unit)))] = 0
This basicly means every iteration, the counter is set back to 0. Then incremented again for the next unit, and then set back to 0, etc.
 
Level 4
Joined
Jul 20, 2012
Messages
83
Why would I do that? I mean for what reason? I think it's unnecessary and if you mean it's not MPI I can tell you that it's far from possible that two units but different players would overlap this trigger (the only way would be that both of them would be attacking one and the same unit and have this ability shifted to cast it near each other after they kill the unit or some other command before and I think that casual player who's not gonna play the map only to find bugs intentionally and prove that he's better than the mapmaker is ever gonna find out).
Zwiebelchen, yeah but it also increases the integer by one for every unit picked, creates unit for every unit picked giving him the ability and setting its level to the mentioned integer and makes every unit to cast that ability on every unit, then after it's done it sets the integer to 0... after all of this, but whatever I fixed it and nobody's gonna doubt me I dare you :D
 
Why would I do that? I mean for what reason? I think it's unnecessary and if you mean it's not MPI I can tell you that it's far from possible that two units but different players would overlap this trigger (the only way would be that both of them would be attacking one and the same unit and have this ability shifted to cast it near each other after they kill the unit or some other command before and I think that casual player who's not gonna play the map only to find bugs intentionally and prove that he's better than the mapmaker is ever gonna find out).
Zwiebelchen, yeah but it also increases the integer by one for every unit picked, creates unit for every unit picked giving him the ability and setting its level to the mentioned integer and makes every unit to cast that ability on every unit, then after it's done it sets the integer to 0... after all of this, but whatever I fixed it and nobody's gonna doubt me I dare you :D
Yeah but you set it back to zero directly inside the picking loop.
So your whole incrementation thing is pointless.

The way you have it in your first trigger is this:
For every unit:
set index = index + 1
do stuff for this unit
set index = 0

The index value will never reach the value 2, as it gets reset after every unit.

The set index = 0 must be outside the pick loop, like you did in your second trigger.

Just saying, as you seem to not completely understand why your second trigger works, but not the first. This is why.
 
Status
Not open for further replies.
Top