• 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.
  • Create a faction for Warcraft 3 and enter Hive's 19th Techtree Contest: Co-Op Commanders! Click here to enter!
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 21st Texturing Contest: Upgrade is now concluded, time to vote for your favourite set of icons! Click here to vote!

Units Within Range variable?

Status
Not open for further replies.
Level 3
Joined
Mar 21, 2020
Messages
35
Which variable do I need to create for this event?
HZlz7T.jpg

Tried making every single variable type but it won't show up D':
 

Uncle

Warcraft Moderator
Level 74
Joined
Aug 10, 2018
Messages
7,961
That's a specific unit event, unfortunately you cannot choose a Variable in these Events.

However, there is a workaround. You can add Events to your triggers via actions. Here's an example of creating a Footman, storing it as a UNIT Variable, and adding that unit to the Events to the Comes Within Range trigger.
  • Actions
    • Unit - Create 1 Footman for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing degrees
    • Set VariableSet YourUnit = (Last created unit)
    • Trigger - Add to RangeTrigger <gen> the event (Unit - A unit comes within 256.00 of YourUnit)
Note that there can be some limitations with this method, as I've seen people run into issues where they added 100's of units to Events this way and eventually the trigger stopped working. However, that may not be the case here.
 

Attachments

  • example.png
    example.png
    8.5 KB · Views: 47
Level 3
Joined
Mar 21, 2020
Messages
35
That's a specific unit event, unfortunately you cannot choose a Variable in these Events.

However, there is a workaround. You can add Events to your triggers via actions. Here's an example of creating a Footman, storing it as a UNIT Variable, and adding that unit to the Events to the Comes Within Range trigger.
  • Actions
    • Unit - Create 1 Footman for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing degrees
    • Set VariableSet YourUnit = (Last created unit)
    • Trigger - Add to RangeTrigger <gen> the event (Unit - A unit comes within 256.00 of YourUnit)
Note that there can be some limitations with this method, as I've seen people run into issues where they added 100's of units to Events this way and eventually the trigger stopped working. However, that may not be the case here.

How would your RangeTrigger look?

I have 44 units, all declared to a Unit array. However, only 1 unit will be activating this trigger at all times.

// EDIT: Every time any other unit comes within range of Unit[0-44] it should do something to itself (change Vertex for example).
  • Animation - Change (Entering Unit)'s vertex coloring to (100.00%, 85.00%, 85.00%) with 85.00% transparency
 
Last edited:
Level 12
Joined
Jan 30, 2020
Messages
875
Hello there.

Completing @Uncle 's suggestion, I would advise you to use a trigger array.

Thats right, rather than adding all your unit specific events to a trigger, just create a similar trigger for each unit, and store it in an array.

This way, if anything happens to your unit, like death or anything else that would make the trigger not useful anymore, you will be able to disable the trigger and then alleviate the game engine a bit.

Now reading your last message, if only 1 unit needs to trigger the event, thats even easier with a trigger array ; you only activate the trigger related to your unit.

Of course, to make this practical, make sure the unit and its trigger share the same index :)
 
Level 3
Joined
Mar 21, 2020
Messages
35
Hello there.

Completing @Uncle 's suggestion, I would advise you to use a trigger array.

Thats right, rather than adding all your unit specific events to a trigger, just create a similar trigger for each unit, and store it in an array.

This way, if anything happens to your unit, like death or anything else that would make the trigger not useful anymore, you will be able to disable the trigger and then alleviate the game engine a bit.

Now reading your last message, if only 1 unit needs to trigger the event, thats even easier with a trigger array ; you only activate the trigger related to your unit.

Of course, to make this practical, make sure the unit and its trigger share the same index :)

All 44 units need to have this trigger and they need to work asynchronously/simultaneously. I was just saying that in-game only 1 will be activates pretty much all of the time (so no problem with flooded trigger queues).

So my goal is:
  • Event
    • If any unit comes within range of UnitVar[0-44]
  • Conditions
  • Actions
    • Animation - Change (UnitVar[i])'s vertex coloring to (100.00%, 85.00%, 85.00%) with 85.00% transparency
Still trying meanwhile.. :)
 

Uncle

Warcraft Moderator
Level 74
Joined
Aug 10, 2018
Messages
7,961
Maybe something like this:
  • Setup
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • Set VariableSet Triggers[1] = Range1 <gen>
      • Set VariableSet Triggers[2] = Range2 <gen>
      • Set VariableSet Triggers[3] = Range3 <gen>
      • -------- --------
      • Set VariableSet Units[1] = Circle of Power 0002 <gen>
      • Set VariableSet Units[2] = Circle of Power 0000 <gen>
      • Set VariableSet Units[3] = Circle of Power 0001 <gen>
      • -------- --------
      • For each (Integer A) from 1 to 3, do (Actions)
        • Loop - Actions
          • Trigger - Add to Triggers[(Integer A)] the event (Unit - A unit comes within 256.00 of Units[(Integer A)])
  • Range1
    • Events
    • Conditions
    • Actions
      • Animation - Change Units[1]'s vertex coloring to (0.00%, 0.00%, 0.00%) with 0.00% transparency
      • -------- --------
      • Game - Display to (All players) for 2.00 seconds the text: ((Name of (Triggering unit)) + came within range of Circle 1)
      • Special Effect - Create a special effect at (Position of Units[1]) using Abilities\Spells\Human\DispelMagic\DispelMagicTarget.mdl
      • Special Effect - Destroy (Last created special effect)
Triggers Range2 and Range3 reference their corresponding Units[].

Note that it would be a lot better to do this in Jass/Lua as you can avoid having to manually create each Trigger and instead create the triggers inside the Loop.
 

Attachments

  • Range Example.w3m
    17.4 KB · Views: 24
Level 12
Joined
Jan 30, 2020
Messages
875
Well @Uncle : I was investigating these GUI triggers giving me headaches everytime I try to help someone.

The issue is you can't seem to be able to add trigger actions with the trigger editor in GUI !!!

But I found a workaround :

First he needs to create his unit array and assign the units to the array. I called the array MyUnit for this test.
Then I created a trigger array called MyUnitTrig.
Then create a trigger with no events and no conditions called for example "ChangeColor"

Then give this trigger an action :
  • ChangeColor
    • Events
    • Conditions
    • Actions
      • Animation - Change MyUnit[(Integer A)]'s vertex coloring to (100.00%, 85.00%, 85.00%) with 85.00% transparency
Note that this will create a function called "Trig_ChangeColor_Actions" that we can use in the main trigger

Now here is the main trigger to create the 44 triggers for the 44 units:
  • RangeColor
    • Events
      • Map initialization
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 44, do (Actions)
        • Loop - Actions
          • Trigger - Add to MyUnitTrig[(Integer A)] the event (Unit - A unit comes within 800.00 of MyUnit[(Integer A)])
          • Custom script: call TriggerAddAction( udg_MyUnitTrig[GetForLoopIndexA()], function Trig_ChangeColor_Actions )
          • Trigger - Turn off MyUnitTrig[(Integer A)]
The custom script line allows to add the function Trig_ChangeColor_Actions to the actions of each trigger MyUnitTrig with the same index as MyUnit.

Of course I disable the triggers once created, so every time the trigger for a unit needs to be activate, he will just need toi use Trigger- Turn on MyUnitTrig[*index of the unit*]

That seems much easier this way, doesn't it ?
 
Level 3
Joined
Mar 21, 2020
Messages
35
Well @Uncle : I was investigating these GUI triggers giving me headaches everytime I try to help someone.

The issue is you can't seem to be able to add trigger actions with the trigger editor in GUI !!!

But I found a workaround :

First he needs to create his unit array and assign the units to the array. I called the array MyUnit for this test.
Then I created a trigger array called MyUnitTrig.
Then create a trigger with no events and no conditions called for example "ChangeColor"

Then give this trigger an action :
  • ChangeColor
    • Events
    • Conditions
    • Actions
      • Animation - Change MyUnit[(Integer A)]'s vertex coloring to (100.00%, 85.00%, 85.00%) with 85.00% transparency
Note that this will create a function called "Trig_ChangeColor_Actions" that we can use in the main trigger

Now here is the main trigger to create the 44 triggers for the 44 units:
  • RangeColor
    • Events
      • Map initialization
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 44, do (Actions)
        • Loop - Actions
          • Trigger - Add to MyUnitTrig[(Integer A)] the event (Unit - A unit comes within 800.00 of MyUnit[(Integer A)])
          • Custom script: call TriggerAddAction( udg_MyUnitTrig[GetForLoopIndexA()], function Trig_ChangeColor_Actions )
          • Trigger - Turn off MyUnitTrig[(Integer A)]
The custom script line allows to add the function Trig_ChangeColor_Actions to the actions of each trigger MyUnitTrig with the same index as MyUnit.

Of course I disable the triggers once created, so every time the trigger for a unit needs to be activate, he will just need toi use Trigger- Turn on MyUnitTrig[*index of the unit*]

That seems much easier this way, doesn't it ?

Yep, this is exactly what I did after the feedback from this post. Best solution, thanks bro!!
 
Level 3
Joined
Mar 21, 2020
Messages
35
Hehe I know I like to cheat a bit ;-)

Getting undefined function error though:
jUTtYd.jpg

So here's my setup:
1. Stores all regions to a Region Array
  • declareRegions
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set VariableSet regionsPlayfield[0] = 00 <gen>
      • Set VariableSet regionsPlayfield[1] = 01 <gen>
      • Set VariableSet regionsPlayfield[2] = 02 <gen>
      • Set VariableSet regionsPlayfield[3] = 03 <gen>
      • Set VariableSet regionsPlayfield[4] = 04 <gen>
      • Set VariableSet regionsPlayfield[5] = 05 <gen>
      • Set VariableSet regionsPlayfield[6] = 06 <gen>
      • Set VariableSet regionsPlayfield[7] = 07 <gen>
      • Set VariableSet regionsPlayfield[8] = 08 <gen>
      • Set VariableSet regionsPlayfield[9] = 10 <gen>
      • Set VariableSet regionsPlayfield[10] = 11 <gen>
      • Set VariableSet regionsPlayfield[11] = 12 <gen>
      • Set VariableSet regionsPlayfield[12] = 13 <gen>
      • Set VariableSet regionsPlayfield[13] = 14 <gen>
      • Set VariableSet regionsPlayfield[14] = 15 <gen>
      • Set VariableSet regionsPlayfield[15] = 16 <gen>
      • Set VariableSet regionsPlayfield[16] = 17 <gen>
      • Set VariableSet regionsPlayfield[17] = 18 <gen>
      • Set VariableSet regionsPlayfield[18] = 20 <gen>
      • Set VariableSet regionsPlayfield[19] = 21 <gen>
      • Set VariableSet regionsPlayfield[20] = 22 <gen>
      • Set VariableSet regionsPlayfield[21] = 23 <gen>
      • Set VariableSet regionsPlayfield[22] = 24 <gen>
      • Set VariableSet regionsPlayfield[23] = 25 <gen>
      • Set VariableSet regionsPlayfield[24] = 26 <gen>
      • Set VariableSet regionsPlayfield[25] = 27 <gen>
      • Set VariableSet regionsPlayfield[26] = 28 <gen>
      • Set VariableSet regionsPlayfield[27] = 30 <gen>
      • Set VariableSet regionsPlayfield[28] = 31 <gen>
      • Set VariableSet regionsPlayfield[29] = 32 <gen>
      • Set VariableSet regionsPlayfield[30] = 33 <gen>
      • Set VariableSet regionsPlayfield[31] = 34 <gen>
      • Set VariableSet regionsPlayfield[32] = 35 <gen>
      • Set VariableSet regionsPlayfield[33] = 36 <gen>
      • Set VariableSet regionsPlayfield[34] = 37 <gen>
      • Set VariableSet regionsPlayfield[35] = 38 <gen>
      • Set VariableSet regionsPlayfield[36] = 40 <gen>
      • Set VariableSet regionsPlayfield[37] = 41 <gen>
      • Set VariableSet regionsPlayfield[38] = 42 <gen>
      • Set VariableSet regionsPlayfield[39] = 43 <gen>
      • Set VariableSet regionsPlayfield[40] = 44 <gen>
      • Set VariableSet regionsPlayfield[41] = 45 <gen>
      • Set VariableSet regionsPlayfield[42] = 46 <gen>
      • Set VariableSet regionsPlayfield[43] = 47 <gen>
      • Set VariableSet regionsPlayfield[44] = 48 <gen>
2. Spawn "tile" units in each region and stores each unit to a unit array (0-44)
  • spawnTiles
    • Events
      • Map initialization
    • Conditions
    • Actions
      • For each (Integer A) from 0 to regionsPlayfieldAmount, do (Actions)
      • Loop - Actions
        • -------- SPAWN ONE TILE UNIT ON EACH 44 REGIONS --------
        • Unit - Create 1 tile for Neutral Passive at (Center of regionsPlayfield[(Integer A)]) facing 0.00 degrees
        • -------- STORE UNIT TO TILEUNIT ARRAY --------
        • Set VariableSet tileUnits[tileUnitsCount] = (Last created unit)
        • Set VariableSet tileUnitsCount = (tileUnitsCount + 1)
        • -------- SET DESIRED DEFAULT ANIMATION --------
        • Trigger - Run locust <gen> (checking conditions)
        • Animation - Change (Last created unit)'s vertex coloring to (100.00%, 100.00%, 100.00%) with 95.00% transparency
        • -------- MACADEMIA'S ADDITIONS --------
        • Trigger - Add to tileTriggers[(Integer A)] the event (Unit - A unit comes within (step / 2.00) of tileUnits[(Integer A)])
        • Custom script: call TriggerAddAction( udg_tileTriggers[GetForLoopIndexA()], function Trig_ChangeColor_Actions )
        • Trigger - Turn off tileTriggers[(Integer A)]
3. Here's the "ChangeColor" trigger (this trigger is not declared anywhere?)
  • Animation - Change tileUnits[(Integer A)]'s vertex coloring to (100.00%, 85.00%, 85.00%) with 85.00% transparency
 
Last edited:
Level 12
Joined
Jan 30, 2020
Messages
875
Edit: Try "gg_trg_Trig_ChangeColor_Actions"

No that does not work and this function does not exist.

I don't have the trigger i made earlier, but let's test it with a simple one :

  • test
    • Events
    • Conditions
    • Actions
      • Camera - Apply (Current camera) for Player 1 (Red) over 0.00 seconds
Once converted to custom text it becomes
JASS:
function Trig_test_Actions takes nothing returns nothing
    call CameraSetupApplyForPlayer( true, GetCurrentCameraSetup(), Player(0), 0 )
endfunction

//===========================================================================
function InitTrig_test takes nothing returns nothing
    set gg_trg_test = CreateTrigger(  )
    call TriggerAddAction( gg_trg_test, function Trig_test_Actions )
endfunction

What we'd want to access there is the function Trig_test_Actions.

And gg_trg_test_Actions does not exist.
 
Level 12
Joined
Jan 30, 2020
Messages
875
Check my updated msg :)
I don't see the other trigger just before the main one in your log.

Can you please put the trigger "ChangeColor" just before your trigger "SpawnTiles" and show me the error again ?

Reason is, just looking at the script in your error log shows me that it can not "not work" ^^
 
Level 3
Joined
Mar 21, 2020
Messages
35
No that does not work and this function does not exist.

I don't have the trigger i made earlier, but let's test it with a simple one :

  • test
    • Events
    • Conditions
    • Actions
      • Camera - Apply (Current camera) for Player 1 (Red) over 0.00 seconds
Once converted to custom text it becomes
JASS:
function Trig_test_Actions takes nothing returns nothing
    call CameraSetupApplyForPlayer( true, GetCurrentCameraSetup(), Player(0), 0 )
endfunction

//===========================================================================
function InitTrig_test takes nothing returns nothing
    set gg_trg_test = CreateTrigger(  )
    call TriggerAddAction( gg_trg_test, function Trig_test_Actions )
endfunction

What we'd want to access there is the function Trig_test_Actions.

And gg_trg_test_Actions does not exist.

Well I tried either mate :'(
 
Level 3
Joined
Mar 21, 2020
Messages
35
I don't see the other trigger just before the main one in your log.

Can you please put the trigger "ChangeColor" just before your trigger "SpawnTiles" and show me the error again ?

Reason is, just looking at the script in your error log shows me that it can not "not work" ^^

No more error, as you said! Animation doesn't change though :p
 
Level 12
Joined
Jan 30, 2020
Messages
875
Well this time it is MY fault :-D

In "Animation - Change MyUnit[(Integer A)]'s vertex coloring to (100.00%, 85.00%, 85.00%) with 85.00% transparency"

replace MyUnit[(Integer A)] with Triggering unit :D
 
Level 3
Joined
Mar 21, 2020
Messages
35
Well this time it is MY fault :-D

In "Animation - Change MyUnit[(Integer A)]'s vertex coloring to (100.00%, 85.00%, 85.00%) with 85.00% transparency"

replace MyUnit[(Integer A)] with Triggering unit :D

Loving the support so far, same result however. Want me to PM you the map for ease?
 
Level 3
Joined
Mar 21, 2020
Messages
35
I see that you're using 2 Map Initialization triggers, could it be that declareRegions is happening after spawnTiles? Try combining the two triggers or running spawnTiles using an Elapsed Time 0.00 Event.

I only have one ini trigger actually, I wrote that as an example :)

  • start
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Trigger - Run fog <gen> (checking conditions)
      • Trigger - Run declareCards <gen> (checking conditions)
      • Trigger - Run declareUnits <gen> (checking conditions)
      • Trigger - Run declareRegions <gen> (checking conditions)
      • Trigger - Run spawnBases <gen> (checking conditions)
      • Trigger - Run spawnUnits <gen> (checking conditions)
      • Trigger - Run spawnTiles <gen> (checking conditions)
      • Trigger - Run decideTurn <gen> (checking conditions)
      • Countdown Timer - Start turnTimer as a One-shot timer that will expire in turnTime seconds
      • Set VariableSet manaCurP1 = manaInitial
      • Set VariableSet manaCurP2 = manaInitial
      • Selection - Select baseP1 for Player 1 (Red)
      • Selection - Select baseP2 for Player 2 (Blue)
 
Level 12
Joined
Jan 30, 2020
Messages
875
Hello there !

Sorry I had to go to hospital for my daughter, and only just came back.

Will be able to have a look again at your map and track the reason the event is not triggering.


EDIT anyone else unable to test maps because of battle.net too busy ?
 
Last edited:
Level 12
Joined
Jan 30, 2020
Messages
875
Back

@lil apex : I found the problem.

The triggerArray elements simply were not initialized before adding events and actions.

No need to send you the map again, just add this action :

  • Custom script: set udg_tileTriggers[GetForLoopIndexA()]=CreateTrigger()
just before the action adding the event to tileTriggers[GetForLoopIndexA()]

and it will work !

By the way : really promising turn based game :)
 
Level 3
Joined
Mar 21, 2020
Messages
35
Thanks dude, hope your lil girl is alright!!

I'm out of town now too so I'll be AFK from lurking this website a bit, I'll let you know once home
 
Status
Not open for further replies.
Top