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

Trying to use a string to teleport units from one region A to region B

Status
Not open for further replies.
Level 1
Joined
Feb 19, 2020
Messages
2
Disclaimer;
I've looked through some tutorials and I've googled a fair bit but I'm coming up short.
I'm not here to have someone write my triggers and variables for me, I'm just looking for some help in understanding how to use the tools correctly.
If anyone could link a tutorial regarding variables that has some practice examples in it that would be much appreciated!

Also I'm VERY new to WC3 WE so Arrays, Variables and Integers are probably a bit out of my depth right now, but I'm trying to learn how to use them.




Goal: Teleport unit(s) inside of Region A to Region B using a String.

I've created a region called (Dungeon entreance outside).
When a Hero unit steps inside the region and the player who owns the unit writes "-enter" in the chat I want all the units inside (Dungeon entreance outside) to teleport to another region (Dungeon entreance inside).

My first attempt:
  • Enter dungeon unit group Copy
    • Events
      • Unit - A unit enters Dungeon entreance outside <gen>
    • Conditions
      • ((Entered chat string) Equal to -enter) and (((Triggering unit) is A Hero) Equal to True)
    • Actions
      • Unit Group - Pick every unit in (Units in Dungeon entreance outside <gen>) and do (Unit - Move (Triggering unit) instantly to (Center of Dungeon entreance inside <gen>))
How is the "Triggering unit" decided?
My guess is that the Trigger hasn't been declared or that I (player red) is the "Triggering unit" since I'm the one entering the string?
Or do I have to enter the String before the unit enters the region?



Anyways, after that I tried creating a Unit Group array variable to store the Hero as a variable.

The problem I'm running into is that I have no idéa if the Variable works, I don't know how to "debug".

  • Enter dungeon unit group
    • Events
      • Unit - A unit enters Dungeon entreance outside <gen>
    • Conditions
      • ((Triggering unit) is A Hero) Equal to True
    • Actions
      • Unit Group - Add (Triggering unit) to hero_enter_group[0]
  • Enter outside
    • Events
      • Player - Player 1 (Red) types a chat message containing -enter as An exact match
    • Conditions
      • ((Triggering unit) is in hero_enter_group[0]) Equal to True
    • Actions
      • Unit - Move (Triggering unit) instantly to (Center of Dungeon entreance inside <gen>)
I'm just thinking out loud here but;
Is it possible to see the Variable live while I'm testing the map? So that I can see whether the Hero gets stored in the Variable or not.
Maybe a timer that loops and shows a text saying "variable empty" every 2 seconds as long as the variable is empty?
Something along the lines of "If variable empty (show to (player red (string_empty))) else (show to (player red (string_not_empty)))".


Again, any pointers towards beginner friendly tutorials with practice examples or explanations of different triggers would be much appreciated!
 
Level 20
Joined
Aug 13, 2013
Messages
1,696
The mechanics you're intending to do so; requires 3 triggers;

1)detection of the unit entering the region
2)detection of the unit leaving the region
3)detection of the player entered chat string. (initially disabled)

the algorithm for the first trigger is to check if the unit is not dead and is a hero. If the conditions are met then check if the unit is being contained in the group (unit group global variable)... if it's not then add the unit to that group. Check if the number of units in the group is greater than 0 then turn on the third trigger. Before jumping on the third trigger, the purpose of the second trigger is to know if the unit already contained in the group leaves the region without entering to the other side so that we can remove it easily if it's true (this avoids the player to abuse your wanted mechanics or produce a bug). The third trigger is initially off. It turns on when the unit group is containing atleast 1 unit. This is where you put the player chat string events, pick every unit in the unit group then check if the picked unit belongs to the triggering player then pick every unit in the region that is not dead and owned by the triggering player then transfer them to the other location of region if it's true... finally remove the unit to the unit group then check if the unit group is now empty then turn off this third trigger.

I know it seems very complicated. This also involves learning triggering, variables, leaks. I suggest you to learn at these tutorials first;

Basics of Triggers
Variables
Memory Leaks

After you're finish reading those patiently just reply to this thread so that we can help you out.
 
Level 10
Joined
Dec 11, 2009
Messages
234
  • Events
    • Player - Player 1 (Red) types a chat message containing -enter as An exact match
  • Conditions
    • ((Triggering unit) is in hero_enter_group[0]) Equal to True
"(Triggering unit)" doesn't make sense here, because this event fires when Player 1 types a chat message.
"(Triggering unit)" can be used ONLY in events like "Unit dies", "Unit owned by Player casts ability", etc.
Same logic applied to other things: "(Entered chat string)" can be used ONLY in event "Player - Chat message"

You can usually see some hints about this in Trigger Editor:
tips.jpg


When a Hero unit steps inside the region and the player who owns the unit writes "-enter" in the chat I want all the units inside (Dungeon entreance outside) to teleport to another region (Dungeon entreance inside).
If you only have 1 hero, you don't need arrays here at all. You probably won't even need the unit group.
You need 3 triggers and 1 variable of type "Boolean" (for example, named as "IsHeroInEntranceArea"):
  • Trigger 1 executes when unit enters the region. Checks if it's a hero, then sets "IsHeroInEntranceArea = True"
  • Trigger 2 executes when unit leaves the region. Checks if it's a hero, then sets "IsHeroInEntranceArea = False"
  • Trigger 3 executes when player types "-enter", checks if "IsHeroInEntranceArea is True" (and some other conditions, like is he dead, etc.) and then does "Pick all units in the area" and moves them where you want:
  • -------- THIS IS WRONG --------
  • Unit Group - Pick every unit in (Units in Dungeon entreance outside <gen>) and do (Unit - Move (Triggering unit) instantly to (Center of Dungeon entreance inside <gen>))
  • -------- THIS IS CORRECT --------
  • Unit Group - Pick every unit in (Units in Dungeon entreance outside <gen>) and do (Unit - Move (Picked unit) instantly to (Center of Dungeon entreance inside <gen>))
If you have more than 1 heroes, then it's a bit trickier.

Is it possible to see the Variable live while I'm testing the map?
With boolean variable it's easy:
  • DebugCheck
    • Events
      • Time - Every 2.00 seconds of game time
      • Player - Player 1 (Red) skips a cinematic sequence // <-- this one fires on ESC press, which may be useful
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • IsHeroInEntranceArea Equal to True
        • Then - Actions
          • Game - Display to (All players) the text: Hero is inside entrance region!
        • Else - Actions
          • Game - Display to (All players) the text: No hero is inside entrance region
 
Level 20
Joined
Aug 13, 2013
Messages
1,696
  • -------- THIS IS WRONG --------
  • Unit Group - Pick every unit in (Units in Dungeon entreance outside <gen>) and do (Unit - Move (Triggering unit) instantly to (Center of Dungeon entreance inside <gen>))
  • -------- THIS IS CORRECT --------
  • Unit Group - Pick every unit in (Units in Dungeon entreance outside <gen>) and do (Unit - Move (Picked unit) instantly to (Center of Dungeon entreance inside <gen>))
The second works although;
Both of them use a GUI function that are not convenient in this case you should use multiple actions for unit filtering.
Both leaks a unit group and location.
 
Level 1
Joined
Feb 19, 2020
Messages
2
Thank you @jakeZinc and @BizzaroFukuro for the tutorials and responses, I feel like I understand the Variables and Triggers at least a little bit better now.

I am however having some trouble finding some of the Events/Actions that are referred to in this thread and in the "Variables" tutorial, more specifically the "Game - Display to" action:
base.gif
Untitled Trigger 002
  • joinminus.gif
    events.gif
    Events
    • line.gif
      joinbottom.gif
      timer.gif
      Time - Elapsed game time is 5.00 seconds
  • join.gif
    cond.gif
    Conditions
  • joinbottomminus.gif
    actions.gif
    Actions
    • empty.gif
      joinbottom.gif
      game.gif
      Game - Display to (All players) the text: (Fruits[1] + :) + (String(FruitsAmount[1]))))
(that smiley isn't supposed to be there but I don't know how to turn smileys off)

and "Event Response - Entered/Matched Chat Message" (highlighted with the green box)


I've both used the "Search for text -->" function and looked in the "Event Response" category but couldn't find them using either method.
View media item 129011View media item 129010


@BizzaroFukuro My goal as of right now is to create a rudimentary ORPG map for me and a couple of friends to play, that's why I want several units to be able to enter the dungeon at the same time.
 
Level 10
Joined
Dec 11, 2009
Messages
234
I am however having some trouble finding some of the Events/Actions that are referred to in this thread and in the "Variables" tutorial, more specifically the "Game - Display to" action:
Game - Text Message.jpg


I've both used the "Search for text -->" function and looked in the "Event Response" category but couldn't find them using either method.
Because those are not actions/conditions.

Here are few examples:
EventResponse.jpg
 
Level 20
Joined
Aug 13, 2013
Messages
1,696
@SkyCrawler
What version do you have? If we're compatible (1.30.4 below)
I can easily send a sample demo map for you to either study or copy.
Or post the code here instead;

entering

activation string

leaving

  • entering
    • Events
      • Unit - A unit enters outside region <gen>
    • Conditions
      • ((Triggering unit) is dead) Equal to False
      • ((Triggering unit) is A Hero) Equal to True
    • Actions
      • Set the_hero = (Triggering unit)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (the_hero is in the_hero_group) Equal to False
        • Then - Actions
          • Unit Group - Add the_hero to the_hero_group
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in the_hero_group) Greater than 0
            • Then - Actions
              • Game - Display to (All players) the text: ((String((Number of units in the_hero_group))) + entered)
              • Trigger - Turn on activation string <gen>
            • Else - Actions
        • Else - Actions
  • activation string
    • Events
      • Player - Player 1 (Red) types a chat message containing -enter as A substring
    • Conditions
    • Actions
      • Unit Group - Pick every unit in the_hero_group and do (Actions)
        • Loop - Actions
          • Set the_hero = (Picked unit)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Owner of the_hero) Equal to (Triggering player)
            • Then - Actions
              • Custom script: set bj_wantDestroyGroup = true
              • Unit Group - Pick every unit in (Units in outside region <gen>) and do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • ((Picked unit) is dead) Equal to False
                      • (Owner of (Picked unit)) Equal to (Triggering player)
                    • Then - Actions
                      • Set location = (Center of inside region <gen>)
                      • Unit - Move (Picked unit) instantly to location
                      • Custom script: call RemoveLocation( udg_location )
                    • Else - Actions
              • Game - Display to (All players) the text: ((String((Number of units in the_hero_group))) + moved)
              • Unit Group - Remove the_hero from the_hero_group
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Number of units in the_hero_group) Equal to 0
                • Then - Actions
                  • Trigger - Turn off (This trigger)
                • Else - Actions
            • Else - Actions
  • leaving
    • Events
      • Unit - A unit leaves outside region <gen>
    • Conditions
      • ((Triggering unit) is dead) Equal to False
      • ((Triggering unit) is A Hero) Equal to True
      • ((Triggering unit) is in the_hero_group) Equal to True
    • Actions
      • Unit Group - Remove (Triggering unit) from the_hero_group
      • Game - Display to (All players) the text: ((String((Number of units in the_hero_group))) + left)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in the_hero_group) Equal to 0
        • Then - Actions
          • Trigger - Turn off activation string <gen>
        • Else - Actions
EDIT:

Note that you can make or specify more players that can use -enter on the activation string's event. In this case, only player (1) red can use it. Also the code provided above is just multi-player instance.

bandicam-2020-02-24-22-08-55-921-gif.347957
 
Last edited:
Status
Not open for further replies.
Top