• 🏆 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!

Array question

Status
Not open for further replies.
Level 9
Joined
Dec 6, 2007
Messages
233
I'm trying to make a stealth generator. My method is to draw a region around the generator, and if a unit enters the region, give it permanent invisibility, and if they leave the region, take that invisibility away. To make the trigger recognize the generator, i set it to a variable. To make this multiinstanceable, i made the variable an array (i have a special system that automatically sets new generators to the next number up in the array). But here is where i ran into my problem. I can't seem to be able to take units from an array and use them for actions involving one unit, or at least in the fashion that i am attempting. What i'm trying to do is draw a region around every unit in that array and perform an action when a unit enters any of those regions. Any help?
 
Level 6
Joined
Oct 31, 2008
Messages
229
First of all the most multiinstancable things in a map, do not require array but thinking
Let's talk about the stealth generator.
You can make a trigger that every second picks all the units in the map and if they are generators, it picks all nearby units and turns them invisible means that gives them a buff making them invis for 1sec. Thus as long as they remain near it, they are invis.

You can make a simillar spell using the human sorceress invisibility and the trigger Unit - Issue order targeting a unit
 
Level 9
Joined
Dec 6, 2007
Messages
233
will that be fast enough? there will probably be many units under stealth generators at a time, so will a single target spell be fast enough to apply invis to every unit in 1 sec?
 
Level 9
Joined
Dec 6, 2007
Messages
233
well, it's just whenever i use spell dummys i've always had to give them time to perform their spell animation, unless there is some value you can change that i missed...
 
Level 9
Joined
Dec 6, 2007
Messages
233
nope, doesn't work

  • stealth generator
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units of type Stealth Generator) and do (Actions)
        • Loop - Actions
          • Unit Group - Pick every unit in (Units within 500.00 of (Position of (Picked unit))) and do (Actions)
            • Loop - Actions
              • Unit - Order dummy_stealth to Human Sorceress - Invisibility (Picked unit)
there's my trigger, the dummy_stealth unit is spawned and labeled at the start of game. The stealth is simply never applied, and i checked all of the object editor stuff too. mana cost is zero and all that, so any ideas?
 
Level 19
Joined
Feb 25, 2009
Messages
2,004
So, if the "Stealth Generators" are permanently on map or they are created at the start of the game?

So if they are already on the map, before initiliazation, just make a trigger that have the event "Unit comes within xxx range", and then, add the ability (invisibility in this case), order it to cast it and then remove the ability.

If they are not, using blank "action" trigger, pick every generator, and add event to the trigger with invisiblity "unit comes within xxx range of (picked unit)...

Blah blah.. if you still don't get it, I can make an example.

PS: I suggest you to the make the casting dummy with at least 1,000 mana, and regeneration rate of 1,000. (if they don't use their mana for anything else)
 
Level 9
Joined
Dec 6, 2007
Messages
233
yes, the mana cost is 0. and why would changing it to a hero do anything?

@Mortar the stealth generators are built by players in game, and if the mana cost is 0, why would it need mana?
 
Level 7
Joined
Nov 4, 2006
Messages
153
Well, a couple things.
Is the cast range 9999999999 so it can be cast anywhere (make sure the dummy has sight of the unit of course)? And, I don't know if invis can only be cast on allies(even if you allow enemies) so maybe that. Also, make sure you check that the unit doesn't already have the Invisibility buff so that you don't get a constant invis effect.
You should make the buff last 0 seconds(permanent) in case someone just stands in a generator for 2 minutes...and check if units with the buff are not within range of a generator. Side note, if this is for a bunch of units, it probably might cause some/slight lag depending on how you do it.
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
I'd do it like this:

Old trigger:
  • Invisibility
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Set Temp_Group_2 = (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to InvisibilityGenerator))
      • Unit Group - Pick every unit in Temp_Group_2 and do (Actions)
        • Loop - Actions
          • Set Temp_Loc_2 = (Position of (Picked unit))
          • Set Temp_Group = (Units in (Playable map area) matching (((Unit-type of (Matching unit)) Not equal to InvisibilityGenerator) and (((Matching unit) is A structure) Equal to False)))
          • Unit Group - Pick every unit in Temp_Group and do (Actions)
            • Loop - Actions
              • Set Temp_Loc_1 = (Position of (Picked unit))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Distance between Temp_Loc_1 and Temp_Loc_2) Greater than 512.00
                • Then - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • ((Picked unit) is in Temp_Group_3) Equal to False
                      • ((Picked unit) has buff Invisibility) Equal to True
                    • Then - Actions
                      • Unit - Remove Invisibility buff from (Picked unit)
                    • Else - Actions
                • Else - Actions
                  • Unit Group - Add (Picked unit) to Temp_Group_3
                  • Unit - Order InvisibilityDummy to Human Sorceress - Invisibility (Picked unit)
              • Custom script: call RemoveLocation(udg_Temp_Loc_1)
          • Custom script: call DestroyGroup(udg_Temp_Group)
      • Unit Group - Pick every unit in Temp_Group_3 and do (Actions)
        • Loop - Actions
          • Unit Group - Remove (Picked unit) from Temp_Group_3
      • Custom script: call DestroyGroup(udg_Temp_Group_2)
      • Custom script: call RemoveLocation(udg_Temp_Loc_2)
New trigger:
  • Invisibility
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Set Temp_Group = (Units in (Playable map area) matching (((Unit-type of (Matching unit)) Not equal to InvisibilityGenerator) and (((Matching unit) is A structure) Equal to False)))
      • Unit Group - Pick every unit in Temp_Group and do (Actions)
        • Loop - Actions
          • Set Temp_Integer_2 = 0
          • Set Temp_Unit_1 = (Picked unit)
          • Set Temp_Loc_2 = (Position of Temp_Unit_1)
          • -------- -------------------- --------
          • Set Temp_Group_2 = (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to InvisibilityGenerator))
          • Unit Group - Pick every unit in Temp_Group_2 and do (Actions)
            • Loop - Actions
              • Set Temp_Loc_1 = (Position of (Picked unit))
              • Set Temp_Integer_1 = (Number of units in Temp_Group_2)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Distance between Temp_Loc_1 and Temp_Loc_2) Greater than 512.00
                • Then - Actions
                  • Set Temp_Integer_2 = (Temp_Integer_2 + 1)
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Temp_Integer_2 Equal to Temp_Integer_1
                      • (Temp_Unit_1 has buff Invisibility) Equal to True
                    • Then - Actions
                      • Unit - Remove Invisibility buff from Temp_Unit_1
                    • Else - Actions
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Temp_Integer_2 Less than Temp_Integer_1
                      • (Temp_Unit_1 has buff Invisibility) Equal to False
                    • Then - Actions
                      • Unit - Order Rifleman 0023 <gen> to Human Sorceress - Invisibility Temp_Unit_1
                    • Else - Actions
              • Custom script: call RemoveLocation(udg_Temp_Loc_1)
          • Custom script: call DestroyGroup(udg_Temp_Group_2)
          • Custom script: call RemoveLocation(udg_Temp_Loc_2)
      • Custom script: call DestroyGroup(udg_Temp_Group)
The dummy has custom non-hero invisibilty ability. Cast range and duration are at max values, mana cost is zero, dependencies are not checked and targets allowed are enemies, neurtal, friend etc. The dummy unit has animation cast point and cast backswing at zero which allows very fast casting.

This trigger works quite nicely. It checks if any unit is within a range of any generator. If it is, and the unit does not yet have the buff, it gets applied. If the unit is not inside the range of any generator and it has the buff, the buff gets removed.
 
Last edited:
Level 7
Joined
Nov 4, 2006
Messages
153

  • Invisibility
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Set Temp_Group = (Units in (Playable map area) matching (((Unit-type of (Matching unit)) Not equal to InvisibilityGenerator) and (((Matching unit) is A structure) Equal to False)))
      • Unit Group - Pick every unit in Temp_Group and do (Actions)
        • Loop - Actions
          • Set Temp_Integer_2 = 0
          • Set Temp_Unit_1 = (Picked unit)
          • Set Temp_Loc_2 = (Position of Temp_Unit_1)
          • -------- -------------------- --------
          • Set Temp_Group_2 = (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to InvisibilityGenerator))
          • Unit Group - Pick every unit in Temp_Group_2 and do (Actions)
            • Loop - Actions
              • Set Temp_Loc_1 = (Position of (Picked unit))
              • Set Temp_Integer_1 = (Number of units in Temp_Group_2)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Distance between Temp_Loc_1 and Temp_Loc_2) Greater than 512.00
                • Then - Actions
                  • Set Temp_Integer_2 = (Temp_Integer_2 + 1)
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Temp_Integer_2 Equal to Temp_Integer_1
                      • (Temp_Unit_1 has buff Invisibility) Equal to True
                    • Then - Actions
                      • Unit - Remove Invisibility buff from Temp_Unit_1
                    • Else - Actions
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Temp_Integer_2 Less than Temp_Integer_1
                      • (Temp_Unit_1 has buff Invisibility) Equal to False
                    • Then - Actions
                      • Unit - Order Rifleman 0023 <gen> to Human Sorceress - Invisibility Temp_Unit_1
                    • Else - Actions
              • Custom script: call RemoveLocation(udg_Temp_Loc_1)
          • Custom script: call DestroyGroup(udg_Temp_Group_2)
          • Custom script: call RemoveLocation(udg_Temp_Loc_2)
      • Custom script: call DestroyGroup(udg_Temp_Group)
Eh. That works but to me, isn't that great of a method. Say he has 500 units on the map(for whatever reason). Every second, that creates 500 points + 500 for each generator just to check the distances between them. A better way would be to check each generator first(I think there will be less generators than units) so that it does not create so many points. Then it will check non-generator units within 500 range, make the dummy use invisibility if they don't have the buff, and add them to a temporary group TempUGroup (any unit, even ones that already had the buff). After, it will check all units with the invisiblity buff and see if they are in the group TempUGroup; if not, remove the buff. Hope that was understandable.

i thought about a invis remove buff too. But there must b better ways
What's wrong with that way?
 
Level 6
Joined
Oct 31, 2008
Messages
229
Eh. That works but to me, isn't that great of a method. Say he has 500 units on the map(for whatever reason). Every second, that creates 500 points + 500 for each generator just to check the distances between them. A better way would be to check each generator first(I think there will be less generators than units) so that it does not create so many points. Then it will check non-generator units within 500 range, make the dummy use invisibility if they don't have the buff, and add them to a temporary group TempUGroup (any unit, even ones that already had the buff). After, it will check all units with the invisiblity buff and see if they are in the group TempUGroup; if not, remove the buff. Hope that was understandable.


What's wrong with that way?
\

i was talking about the makers method and 500 units wont make this triiger leak but there are sure bettr ways
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
Like this?

  • Invisibility2
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Set Temp_Group_3 = (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Not equal to Rifleman))
      • Set Temp_Group = (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Rifleman))
      • Unit Group - Pick every unit in Temp_Group and do (Actions)
        • Loop - Actions
          • Set Temp_Loc_1 = (Position of (Picked unit))
          • Set Temp_Group_2 = (Units within 512.00 of Temp_Loc_1 matching ((Unit-type of (Matching unit)) Not equal to Rifleman))
          • Unit Group - Pick every unit in Temp_Group_2 and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Picked unit) has buff Invisibility) Equal to False
                • Then - Actions
                  • Unit - Order Rifleman 0023 <gen> to Human Sorceress - Invisibility (Picked unit)
                • Else - Actions
          • Custom script: call RemoveLocation(udg_Temp_Loc_1)
      • Unit Group - Pick every unit in Temp_Group_3 and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) is in Temp_Group_2) Equal to False
              • ((Picked unit) has buff Invisibility) Equal to True
            • Then - Actions
              • Unit - Remove Invisibility buff from (Picked unit)
            • Else - Actions
      • Custom script: call DestroyGroup(udg_Temp_Group)
      • Custom script: call DestroyGroup(udg_Temp_Group_2)
      • Custom script: call DestroyGroup(udg_Temp_Group_3)
Rifleman -> generator
 
Level 7
Joined
Nov 4, 2006
Messages
153
- Looks good but TempGroup_3 initially could be like: Set Temp_Group_3 = Units in (Playable Area) matching (Unit is Alive) and (UnitType isn't Riflemen) and (Unit has buff of Invisibility). This just narrows down how many units it checks. Oh and hopefully invis can cast on spell immune people, which I think it can.

- I'm not sure but can 1 unit really cast, say, invis on 5 units instantly (like if within that 1 second, 5 units without invis went in range)?

- I think you need a fourth group. It should hold the units within range. You currently set Temp_Group_2 to a new group everytime. Then later it checks is the last created group has the invis buff etc., not the previous groups. So I suggest making an empty group at first, then adding the units within range into that group and using that one instead of Temp_Group_2 for everything else.
  • Unit Group - Pick every unit in Temp_Group and do (Actions)
    • Loop - Actions
      • Set Temp_Loc_1 = (Position of (Picked unit))
      • Set Temp_Group_2 = (Units within 512.00 of Temp_Loc_1 matching ((Unit-type of (Matching unit)) Not equal to Rifleman))
      • Unit Group - Pick every unit in Temp_Group_2 and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) has buff Invisibility) Equal to False
            • Then - Actions
              • Unit - Order Rifleman 0023 <gen> to Human Sorceress - Invisibility (Picked unit)
            • Else - Actions
      • Custom script: call RemoveLocation(udg_Temp_Loc_1)
This leaks Temp_Group_2. You need to destroy the group in the loop, not after.


  • Remove all units from Temp_Group_4 //just makes sure units aren't in it
  • Set Temp_Group_3 = (Units in (Playable map area) matching (UnitType isn't Riflemen) (Unit is alive) (Unit has buff of Invisibility)
  • Set Temp_Group = (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Rifleman))
  • Unit Group - Pick every unit in Temp_Group and do (Actions)
    • Loop - Actions
      • Set Temp_Loc_1 = (Position of (Picked unit))
      • Set Temp_Group_2 = (Units within 512.00 of Temp_Loc_1 matching ((Unit-type of (Matching unit)) Not equal to Rifleman) and (Unit is alive)) //always check for aliveness
      • Unit Group - Pick every unit in Temp_Group_2 and do (Actions)
        • Loop - Actions
          • Add unit to Temp_Group_4 //these are units within range
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) has buff Invisibility) Equal to False
            • Then - Actions
              • Unit - Order Rifleman 0023 <gen> to Human Sorceress - Invisibility (Picked unit)
            • Else - Actions
      • Custom script: call RemoveLocation(udg_Temp_Loc_1)
      • Custom script: call DestroyGroup(udg_Temp_Group_2)
  • Unit Group - Pick every unit in Temp_Group_3 and do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Picked unit) is in Temp_Group_4) Equal to False //Using Group 4 now
          • ((Picked unit) has buff Invisibility) Equal to True
        • Then - Actions
          • Unit - Remove Invisibility buff from (Picked unit)
        • Else - Actions
  • Custom script: call DestroyGroup(udg_Temp_Group)
  • Custom script: call DestroyGroup(udg_Temp_Group_2)
  • Custom script: call DestroyGroup(udg_Temp_Group_4)
- Cheers!
 
Level 9
Joined
Dec 6, 2007
Messages
233
- I'm not sure but can 1 unit really cast, say, invis on 5 units instantly (like if within that 1 second, 5 units without invis went in range)?

agree, is there a better way than a dummy caster? like giving the unit perma invis when it's within 500 and taking it away when it's not? that would also solve the magic immune issue

sorry for late response, was on vacation

@everyone: thanks for help so far

@slaydon:

you say:
check that the unit got mana..

when i've already said:
yes, the mana cost is 0

READ PREVIOUS POSTS
 
Level 9
Joined
Dec 6, 2007
Messages
233
sorry for double post, but i'm going to just temporarily give them perma invis instead of cast a spell on them. Just one road block: how to check whether a unit has perma invis or not?
 
Level 9
Joined
Dec 6, 2007
Messages
233
Gah, still not working. Here's code

  • stealth generator
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Set Temp_Group_3 = (Units in (Playable map area) matching (((Unit-type of (Picked unit)) Not equal to Stealth Generator) and ((((Picked unit) is alive) Equal to True) and ((Level of Permanent Invisibility for (Picked unit)) Greater than 0))))
      • Set Temp_Group_1 = (Units in (Playable map area) matching ((Unit-type of (Picked unit)) Equal to Stealth Generator))
      • Unit Group - Pick every unit in Temp_Group_1 and do (Actions)
        • Loop - Actions
          • Set Temp_Loc_1 = (Position of (Picked unit))
          • Set Temp_Group_2 = (Units within 500.00 of Temp_Loc_1 matching (((Unit-type of (Picked unit)) Not equal to Stealth Generator) and (((Picked unit) is alive) Equal to True)))
          • Unit Group - Pick every unit in Temp_Group_2 and do (Actions)
            • Loop - Actions
              • Unit Group - Add (Picked unit) to Temp_Group_4
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of (Picked unit)) Not equal to Scout
                  • (Level of Permanent Invisibility for (Picked unit)) Equal to 0
                • Then - Actions
                  • Unit - Add Permanent Invisibility to (Picked unit)
                • Else - Actions
          • Custom script: call RemoveLocation(udg_Temp_Loc_1)
          • Custom script: call DestroyGroup(udg_Temp_Group_2)
      • Unit Group - Pick every unit in Temp_Group_3 and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) is in Temp_Group_2) Equal to False
              • (Level of Permanent Invisibility for (Picked unit)) Greater than 0
              • (Unit-type of (Picked unit)) Not equal to Scout
            • Then - Actions
              • Unit - Remove Permanent Invisibility from (Picked unit)
            • Else - Actions
      • Custom script: call DestroyGroup(udg_Temp_Group_1)
      • Custom script: call DestroyGroup(udg_Temp_Group_3)
      • Custom script: call DestroyGroup(udg_Temp_Group_4)
The scout in there already has perma invis, so i excluded him from the actions. Nothing happens at all when a generator is built. Ideas?

EDIT: code revision, but still not working
 
Level 7
Joined
Nov 4, 2006
Messages
153
  • Actions
    • // ----- When setting group, use Matching unit not Picked Unit -----
    • Set Temp_Group_3 = (Units in (Playable map area) matching (((Unit-type of (Picked unit)) Not equal to Stealth Generator) and ((((Picked unit) is alive) Equal to True) and ((Level of Permanent Invisibility for (Picked unit)) Greater than 0))))
      • // ----- Same thing -----
    • Set Temp_Group_1 = (Units in (Playable map area) matching ((Unit-type of (Picked unit)) Equal to Stealth Generator))
    • Unit Group - Pick every unit in Temp_Group_1 and do (Actions)
      • Loop - Actions
        • Set Temp_Loc_1 = (Position of (Picked unit))
          • // ----- Group thing again -----
        • Set Temp_Group_2 = (Units within 500.00 of Temp_Loc_1 matching (((Unit-type of (Picked unit)) Not equal to Stealth Generator) and (((Picked unit) is alive) Equal to True)))
        • Unit Group - Pick every unit in Temp_Group_2 and do (Actions)
          • Loop - Actions
            • Unit Group - Add (Picked unit) to Temp_Group_4
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • (Unit-type of (Picked unit)) Not equal to Scout
                • (Level of Permanent Invisibility for (Picked unit)) Equal to 0
              • Then - Actions
                • Unit - Add Permanent Invisibility to (Picked unit)
              • Else - Actions
        • Custom script: call RemoveLocation(udg_Temp_Loc_1)
        • Custom script: call DestroyGroup(udg_Temp_Group_2)
    • Unit Group - Pick every unit in Temp_Group_3 and do (Actions)
      • Loop - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • // ----- Temp_Group_4 is your group with all units in range. Group_2 is only a temp group from earlier: no units in it. Change it to Group_4 -----
            • ((Picked unit) is in Temp_Group_2) Equal to False
            • (Level of Permanent Invisibility for (Picked unit)) Greater than 0
              • // ----- Don't really need this because Scout is already checked as a condition when giving the ability to units -----
            • (Unit-type of (Picked unit)) Not equal to Scout
          • Then - Actions
            • Unit - Remove Permanent Invisibility from (Picked unit)
          • Else - Actions
    • Custom script: call DestroyGroup(udg_Temp_Group_1)
    • Custom script: call DestroyGroup(udg_Temp_Group_3)
    • Custom script: call DestroyGroup(udg_Temp_Group_4)
When creating groups, you use "Picked Unit" instead of "Matching Unit"
Also When you pick through UnitGroup_3, your conditions: Picked Unit is in UnitGroup_2 should be Group_4. And Unit-Type is Scout there is unnecessary because you never give it the Invisibility ability anyways (in the part where you give the ability)
 
Level 9
Joined
Dec 6, 2007
Messages
233
The only place I used matching unit was here:

Set Variable = units in playable map area matching condition

The scout is excluded from the give invis and remove invis actions because it already has invis
 
Status
Not open for further replies.
Top