• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Add unit to array...

Status
Not open for further replies.
Level 5
Joined
Mar 17, 2005
Messages
135
How would you go about adding a unit to an array like this.

variable unit_count of type unit with array set to 20.

Each time my loop loops, I want it to set the picked unit to the next number.

lets say pick every unit within range of x unit
set unit_count[0] = picked unit.


How do I make it so that every time it loops, unit_count goes up by 1 but also keeping the last picked unit in the array. Hard for me to explain.

In finalization, I would like to store units that are within range of another unit. Once I aquire all units within range of that particular unit, I want to take the stored unit_count arrays and damage all of those units.

Sorry if i'm confusing. +rep for those who give constructive help please!
 
Level 4
Joined
Jul 28, 2009
Messages
64
I think I know what you are saying.

I would do this by using an integer variable to count, so:

Unit comes within X range of unit
Set CountInteger = CountInteger + 1
Set UnitCount[CountInteger] = Triggering Unit

you may need to use an IF THEN ELSE function to cycle back through to Zero so that your CountInteger doesnt get too high, just check the condition if it is = to 100 or something, then Set countInteger = 1

Hope this helps.

EDIT:

I read your post again, and I think I understand better.

Do what i said above, except instead of using the unit enters range trigger, use a periodic timer, and pick every unit within range of the unit you want.

You can then add the unit to some group, like Already_Selected_Unit_Group or something, and add a condition to only pick groups and add them to the array if they are not in that group.

like this:

Events:
Every 1 second of game time
Conditions:
None
Actions:
Pick Every Unit within 500 of Unit and do Actions
IF
Picked Unit is in Already_Selected_Unit_Group = False
THEN
Add unit to Already_Selected_Unit_Group
Set CountInteger = CountInteger + 1
Set CountUnit[CountInteger] = Picked Unit
ELSE

and to damage, when full or something? you can add

IF
Number of Units in Already_Selected_Unit_Group is = 20
THEN
Pick Every Unit in Already_Selected_Unit_Group and do actions
Damage Picked Unit
Remove Picked Unit from Already_Selected_Unit_Group
ELSE



Remove leaks etc, and this should do the trick (sorry for not doing this in the right trigger format, I'm at work :p)
 
Level 5
Joined
Mar 17, 2005
Messages
135
I think I know what you are saying.

I would do this by using an integer variable to count, so:

Unit comes within X range of unit
Set CountInteger = CountInteger + 1
Set UnitCount[CountInteger] = Triggering Unit

you may need to use an IF THEN ELSE function to cycle back through to Zero so that your CountInteger doesnt get too high, just check the condition if it is = to 100 or something, then Set countInteger = 1

Hope this helps.

I though that too, but then after trying and not working I realise why.

Lets say it loops 10 times, it will now be 11. so now unitcount[countinteger] will equal 10 and therefore, only the 11th picked unit will take damage and not 0-11.
 
Level 4
Joined
Jul 28, 2009
Messages
64
well if you are going to damage the units via the assigned array value you will have to use the "For each Integer Variable, from 1 to 20 do actions" and plug in your Integer Variable into the array spot on your unit array variable, that way it will get all of them.
 
Level 5
Joined
Mar 17, 2005
Messages
135
well if you are going to damage the units via the assigned array value you will have to use the "For each Integer Variable, from 1 to 20 do actions" and plug in your Integer Variable into the array spot on your unit array variable, that way it will get all of them.

this is what i have. Your above post does not seem to make sense, I don't think there is an add function.

  • Gather Units
    • Events
    • Conditions
    • Actions
      • Set ed_caster = (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Energy Being))
      • Unit Group - Pick every unit in ed_caster and do (Actions)
        • Loop - Actions
          • Unit Group - Pick every unit in (Units within 400.00 of (Position of (Picked unit))) and do (Actions)
            • Loop - Actions
              • For each (Integer A) from 0 to 20, do (Actions)
                • Loop - Actions
                  • Set ed_unit_range[(Integer A)] = (Picked unit)
The trigger is turned on when a spell is casted, It's just a rough sketch of what I have and some reason it is not working out.

Edit:

I'll add other part to trigger

  • Cast Energy Disperse
    • Events
      • Unit - A unit Finishes casting an ability
    • Conditions
      • (Ability being cast) Equal to Energy Disperse
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Level of Energy Disperse for (Casting unit)) Equal to 1
        • Then - Actions
          • Unit - Cause (Casting unit) to damage ed_unit_range[(Integer A)], dealing 500.00 damage of attack type Spells and damage type Normal
          • Unit - Set mana of (Casting unit) to 0.00%
        • Else - Actions
          • Do nothing
 
Level 4
Joined
Jul 28, 2009
Messages
64
right. sorry if my response was confusing.

What I was saying was referring to a problem in your second trigger, which doesn't call up the integer A again. You have to do

THEN -Actions
For each Integer A from 1 to 20 do Actions:
Unit- Cause unit to damage ed_unit_range[Integer A]
Etc.

Then you are closer to getting it to work. The other problem is though, that you are assigning the Integer A from 0 to 20 for every unit picked, which is going to just set all of those integers to the same unit.

What you need to do is get rid of the for each integer A from 0 to 20 in your first trigger and instead create an integer variable, and do

Pick every unit within 400 of picked unit
set IntegerVar = IntegerVar + 1
Set Ed_Unit_Range[IntegerVar] = Picked Unit

I wish I could just do the triggers :p
 
Level 5
Joined
Mar 17, 2005
Messages
135
like this?
  • dsad
    • Events
      • Time - Every 0.30 seconds of game time
    • Conditions
    • Actions
      • Set ed_caster = (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Energy Being))
      • Unit Group - Pick every unit in ed_caster and do (Actions)
        • Loop - Actions
          • Unit Group - Pick every unit in (Units within 400.00 of (Position of (Picked unit))) and do (Actions)
            • Loop - Actions
              • Set count_unit = (count_unit + 1)
              • Set ed_unit_range[count_unit] = (Picked unit)
Cause i did that and still not working. This was the first thing i tried and it doesn't work because of what we both said in earlier post. Only damages 1 unit.
 
Level 4
Joined
Jul 28, 2009
Messages
64
Ok I tried to format it, and this is what I got.


  • Gather Units
    • Events
    • Conditions
    • Actions
      • Set ed_caster = (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Energy Being))
      • Unit Group - Pick every unit in ed_caster and do (Actions)
        • Loop - Actions
          • Unit Group - Pick every unit in (Units within 400.00 of (Position of (Picked unit))) and do (Actions)
            • Loop - Actions
              • Set Integer_Variable = ((Integer_Variable) + 1)
              • Set ed_unit_range[Integer_Variable] = (Picked unit)
  • Cast Energy Disperse
    • Events
      • Unit - A unit Finishes casting an ability
    • Conditions
      • (Ability being cast) Equal to Energy Disperse
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Level of Energy Disperse for (Casting unit)) Equal to 1
        • Then - Actions
          • For Each Integer A from 1 to 20 Do Actions
            • Unit - Cause (Casting unit) to damage ed_unit_range[(Integer A)], dealing 500.00 damage of attack type Spells and damage type Normal
          • Unit - Set mana of (Casting unit) to 0.00%
        • Else - Actions
          • Do nothing
The other problem I see now is that your array is actually going to be the number of ed_casters multiplied by 20, so you will have to do each integer from 1 to (20 x number of ed_casters)

well.. not by 20, but by however many units are within 400 of of that unit.... Id suggest making these all variable (if you haven't already in the real version :p)
 
Level 5
Joined
Mar 17, 2005
Messages
135
First trigger is what I did above unless I'm missing something.

Second trigger why use integer a? I tried with integer a and it didn't even damage 1 unit.

Edit: Nvm i see why integer a... sorry let me try that
 
Level 4
Joined
Jul 28, 2009
Messages
64
because you have to add a conditional to the unit group,


pick every unit,
Bolean - Unit is an enemy of (owner of (casting unit))

people also sometimes add unit is alive too, depending on the spell

like with pushbacks, sometimes its weird to see a corpse being pushed back.
 
Level 5
Joined
Mar 17, 2005
Messages
135
Can you tell me what you're trying to do so I can make it in a "better" way?

From what I understand you DON'T need any kind of linked list.

Are you able to use vJass in your map (JH or JNGP)?

I think there is a better way because I made a spell very similar to this a long time ago before I knew "advanced" triggering like so.

I'm just making a spell that channels for about 5 seconds. When a unit comes in 400/500/600 range of it, after the 5 seconds it will take damage equal to casters mana. Casters mana will be set to a percent of 0/10/20.

Currently I have it based off of starfall to give it effects on caster and surrounding units. Using the trigger work above. The problem I'm having is that I need to make it so that the don't get added to the array when they leave or they get removed when they die.
 
Level 4
Joined
Jul 28, 2009
Messages
64
so basically, a unit channels an ability for 5 seconds, then damages everything nearby for their mana pool?

I'll look into it.
 

Cokemonkey11

Code Reviewer
Level 29
Joined
May 9, 2006
Messages
3,516
I think there is a better way because I made a spell very similar to this a long time ago before I knew "advanced" triggering like so.

I'm just making a spell that channels for about 5 seconds. When a unit comes in 400/500/600 range of it, after the 5 seconds it will take damage equal to casters mana. Casters mana will be set to a percent of 0/10/20.

Currently I have it based off of starfall to give it effects on caster and surrounding units. Using the trigger work above. The problem I'm having is that I need to make it so that the don't get added to the array when they leave or they get removed when they die.

Sounds like you need a group; not a unit array.
 
Status
Not open for further replies.
Top