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

[General] How to detect the region left?

Status
Not open for further replies.
Level 9
Joined
Jun 4, 2007
Messages
205
EDIT: Problem solved!!

A little backstory first: my map is a basic RPG wich uses a worldmap-like travel system, where you enter Travel Mode, select the area you want to go and the hero is teleported there - no biggie.
The system itself is very easy, I wanted to spawn different creep types upon arrival, depending on the area the hero teleported to, for that I used the CNum variable to detect everything about that area, in a separated trigger:


  • Creep setups
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- AREA 1 --------
      • Set Cnum = 1
      • Set CREEP_region[Cnum] = 011sewers <gen>
      • Set CREEP_max[Cnum] = 20
      • Set CREEP_typeA[Cnum] = Rat
      • Set CREEP_typeB[Cnum] = Giant Rat
      • Set CREEP_typeC[Cnum] = Bat
      • Set CREEP_typeD[Cnum] = Giant Bat
      • Set CREEP_typeE[Cnum] = Wurm
      • -------- AREA 2 --------
      • Set Cnum = (Cnum + 1)
      • Set CREEP_region[Cnum] = 012murlocs <gen>
      • Set CREEP_max[Cnum] = 30
      • Set CREEP_typeA[Cnum] = Murloc
      • Set CREEP_typeB[Cnum] = Mur'gul
      • Set CREEP_typeC[Cnum] = Water Elemental
      • Set CREEP_typeD[Cnum] = Murloc Warrior
      • Set CREEP_typeE[Cnum] = Mur'gul Sorcerer
And so on... for the upcoming areas, I'll basically use "Cnum" to control the event "hero enters the region".
When the hero fast travels, he is teleported in the selected area, and a number of enemies spawn in random points there, up to the maximum amount allowed for that region (CREEP_max).

  • Enter areas
    • Events
      • Unit - A unit enters 011sewers <gen>
      • Unit - A unit enters 012murlocs <gen>
      • Unit - A unit enters 013gnolls <gen>
      • Unit - A unit enters 014graveyard <gen>
      • Unit - A unit enters 015mine <gen>
      • Unit - A unit enters 016foresttroll <gen>
      • Unit - A unit enters 017lighthouse <gen>
      • Unit - A unit enters 018magitower <gen>
      • Unit - A unit enters 019sacredgrove <gen>
      • Unit - A unit enters 020elventemple <gen>
      • Unit - A unit enters 021kings <gen>
      • Unit - A unit enters 022greendragon <gen>
      • Unit - A unit enters 023pirates <gen>
    • Conditions
      • ((Triggering unit) is A Hero) Equal to True
    • Actions
      • Wait 0.03 seconds
      • If ((011sewers <gen> contains (Triggering unit)) Equal to True) then do (Set Cnum = 1) else do (Do nothing)
      • If ((012murlocs <gen> contains (Triggering unit)) Equal to True) then do (Set Cnum = 2) else do (Do nothing)
      • If ((013gnolls <gen> contains (Triggering unit)) Equal to True) then do (Set Cnum = 3) else do (Do nothing)
      • If ((014graveyard <gen> contains (Triggering unit)) Equal to True) then do (Set Cnum = 4) else do (Do nothing)
      • If ((015mine <gen> contains (Triggering unit)) Equal to True) then do (Set Cnum = 5) else do (Do nothing)
      • If ((016foresttroll <gen> contains (Triggering unit)) Equal to True) then do (Set Cnum = 6) else do (Do nothing)
      • If ((017lighthouse <gen> contains (Triggering unit)) Equal to True) then do (Set Cnum = 7) else do (Do nothing)
      • If ((018magitower <gen> contains (Triggering unit)) Equal to True) then do (Set Cnum = 8) else do (Do nothing)
      • If ((019sacredgrove <gen> contains (Triggering unit)) Equal to True) then do (Set Cnum = 9) else do (Do nothing)
      • If ((020elventemple <gen> contains (Triggering unit)) Equal to True) then do (Set Cnum = 10) else do (Do nothing)
      • If ((021kings <gen> contains (Triggering unit)) Equal to True) then do (Set Cnum = 11) else do (Do nothing)
      • If ((022greendragon <gen> contains (Triggering unit)) Equal to True) then do (Set Cnum = 12) else do (Do nothing)
      • If ((023pirates <gen> contains (Triggering unit)) Equal to True) then do (Set Cnum = 13) else do (Do nothing)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in (Units in CREEP_region[Cnum] matching (((Matching unit) is A Hero) Equal to True))) Equal to 1
        • Then - Actions
          • For each (Integer A) from 1 to CREEP_max[Cnum], do (Actions)
            • Loop - Actions
              • Set ROLL = (Random integer number between 0 and 10)
              • Set Ctemp_point = (Random point in CREEP_region[Cnum])
              • If (ROLL Less than or equal to 3) then do (Unit - Create 1 CREEP_typeA[Cnum] for Neutral Hostile at Ctemp_point facing (Random real number between 1.00 and 359.00) degrees) else do (Do nothing)
              • If ((ROLL Greater than or equal to 4) and (ROLL Less than or equal to 6)) then do (Unit - Create 1 CREEP_typeB[Cnum] for Neutral Hostile at Ctemp_point facing (Random real number between 1.00 and 359.00) degrees) else do (Do nothing)
              • If ((ROLL Equal to 7) or (ROLL Equal to 8)) then do (Unit - Create 1 CREEP_typeC[Cnum] for Neutral Hostile at Ctemp_point facing (Random real number between 1.00 and 359.00) degrees) else do (Do nothing)
              • If (ROLL Equal to 9) then do (Unit - Create 1 CREEP_typeD[Cnum] for Neutral Hostile at Ctemp_point facing (Random real number between 1.00 and 359.00) degrees) else do (Do nothing)
              • If (ROLL Equal to 10) then do (Unit - Create 1 CREEP_typeE[Cnum] for Neutral Hostile at Ctemp_point facing (Random real number between 1.00 and 359.00) degrees) else do (Do nothing)
              • Custom script: call RemoveLocation(udg_Ctemp_point)
        • Else - Actions
Everything here is working ok, the hero enters the region and gets swarmed by the correct creeps, in the correct amount (notice that he won't create new creeps if someone else was already in the region - there is a separate respawn system to keep the creeps going as long as someone is in the region).

The problem is when the hero leaves, I cannot detect the "region left" in a single trigger, in order to track it and - if there are no heros left there - clean it up (remove all creeps present)

Here's my trigger, I want to define Cnum to the region left(ignore the =1 for now), but HOW?

Thanks in advance.

  • Leave areas
    • Events
      • Unit - A unit leaves 011sewers <gen>
      • Unit - A unit leaves 012murlocs <gen>
      • Unit - A unit leaves 013gnolls <gen>
      • Unit - A unit leaves 014graveyard <gen>
      • Unit - A unit leaves 015mine <gen>
      • Unit - A unit leaves 016foresttroll <gen>
      • Unit - A unit leaves 017lighthouse <gen>
      • Unit - A unit leaves 018magitower <gen>
      • Unit - A unit leaves 019sacredgrove <gen>
      • Unit - A unit leaves 020elventemple <gen>
      • Unit - A unit leaves 021kings <gen>
      • Unit - A unit leaves 022greendragon <gen>
      • Unit - A unit leaves 023pirates <gen>
    • Conditions
      • ((Triggering unit) is A Hero) Equal to True
    • Actions
      • Set Cnum = 1
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in (Units in CREEP_region[Cnum] matching (((Matching unit) is A Hero) Equal to True))) Equal to 0
        • Then - Actions
          • Custom script: set bj_wantDestroyGroup = true
          • Unit Group - Pick every unit in (Units in CREEP_region[Cnum] owned by Neutral Hostile) and do (Actions)
            • Loop - Actions
              • If (((Picked unit) is An Ancient) Equal to False) then do (Unit - Remove (Picked unit) from the game) else do (Do nothing)
        • Else - Actions
 
Last edited:
Level 12
Joined
Jan 2, 2016
Messages
973
Well. I am not sure how exactly you made the hero leave the region, but I'd do something like:
If he leaves, using a skill, I'd detect in which region he was when he used the skill.
If he's using teleporters to do so, I'd detect which teleporter he has used (or in which region was the teleporter, if there are few of them per region)
Stuff like that...

Edit: For general use, you could also add this in the begining of your transportation trigger:
  • Set Temp_Real = 0
  • Set Temp_Real = 1
  • Set Temp_Location = Location of unit (~The unit being moved~)
And make another trigger with event "A real (Temp_Real) reaches value = 0"
And there you can detect the region the Hero is in, using the Temp_Location :p
 
Last edited:
Level 25
Joined
May 11, 2007
Messages
4,651
Does something like this work? With creepRegionInt being how many regions you have.
  • Hero leaves
    • Events
      • Unit - A unit leaves Ogre Dancing Club <gen>
      • Unit - A unit leaves Ninjas in Pyjamans Hideout <gen>
      • Unit - A unit leaves Empires mod suggestion forum <gen>
    • Conditions
      • ((Triggering unit) is A Hero) Equal to True
    • Actions
      • Set tempPoint1 = (Position of (Triggering unit))
      • For each (Integer tempInt) from 1 to creepRegionInt, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Region centered at tempPoint1 with size (200.00, 200.00)) contains (Center of creepRegion[creepRegionInt])) Equal to True
            • Then - Actions
              • -------- You've found your region! --------
              • Set tempGroup1 = (Units in creepRegion[tempInt] matching ((((Matching unit) is A Hero) Equal to True) and (((Matching unit) is alive) Equal to True)))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Number of units in tempGroup1) Equal to 0
                • Then - Actions
                  • -------- Remove zeh creeps! --------
                  • Set tempGroup2 = (Units in creepRegion[tempInt] matching ((Owner of (Matching unit)) Equal to Neutral Hostile))
                  • Unit Group - Pick every unit in tempGroup2 and do (Actions)
                    • Loop - Actions
                      • Unit - Remove (Picked unit) from the game
                  • Custom script: call DestroyGroup(udg_tempGroup2)
                • Else - Actions
              • Custom script: call DestroyGroup(udg_tempGroup1)
            • Else - Actions
      • Custom script: call RemoveLocation(udg_tempPoint1)
 
Level 9
Joined
Jun 4, 2007
Messages
205
The travel works like this: hero, anywhere, in any area, casts the Fast Travel Spell, becomes paused/hidden and invulnerable - the player loses control of him.
Then a flying Wisp unit is spawned and selected for the player in the world map, it has the "Travel There" spell, wich targets a structure.
Upon successfully using Travel There, the wisp is hidden and the player gains control of the hero back again, being teleported to the area.

w1HTPwI.jpg


I wanted to clean the area he's leaving with a single trigger if possible, like when I did with the entering, otherwise I can just create 1 trigger per area and it also works.

EDIT: i'll try that LordDz brb
 
Last edited:
Level 25
Joined
May 11, 2007
Messages
4,651
So ya don't miss my post as you just posted that:
Does something like this work? With creepRegionInt being how many regions you have.
  • Hero leaves
    • Events
      • Unit - A unit leaves Ogre Dancing Club <gen>
      • Unit - A unit leaves Ninjas in Pyjamans Hideout <gen>
      • Unit - A unit leaves Empires mod suggestion forum <gen>
    • Conditions
      • ((Triggering unit) is A Hero) Equal to True
    • Actions
      • Set tempPoint1 = (Position of (Triggering unit))
      • For each (Integer tempInt) from 1 to creepRegionInt, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Region centered at tempPoint1 with size (200.00, 200.00)) contains (Center of creepRegion[creepRegionInt])) Equal to True
            • Then - Actions
              • -------- You've found your region! --------
              • Set tempGroup1 = (Units in creepRegion[tempInt] matching ((((Matching unit) is A Hero) Equal to True) and (((Matching unit) is alive) Equal to True)))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Number of units in tempGroup1) Equal to 0
                • Then - Actions
                  • -------- Remove zeh creeps! --------
                  • Set tempGroup2 = (Units in creepRegion[tempInt] matching ((Owner of (Matching unit)) Equal to Neutral Hostile))
                  • Unit Group - Pick every unit in tempGroup2 and do (Actions)
                    • Loop - Actions
                      • Unit - Remove (Picked unit) from the game
                  • Custom script: call DestroyGroup(udg_tempGroup2)
                • Else - Actions
              • Custom script: call DestroyGroup(udg_tempGroup1)
            • Else - Actions
      • Custom script: call RemoveLocation(udg_tempPoint1)
 
Level 9
Joined
Jun 4, 2007
Messages
205
After trying a few things here and there, a Integer A loop worked perfectly!

Running through all regions and checking for heros everytime someone leaves a region:

  • Leave areas
    • Events
      • Unit - A unit leaves 011sewers <gen>
      • Unit - A unit leaves 012murlocs <gen>
      • Unit - A unit leaves 013gnolls <gen>
      • Unit - A unit leaves 014graveyard <gen>
      • Unit - A unit leaves 015mine <gen>
      • Unit - A unit leaves 016foresttroll <gen>
      • Unit - A unit leaves 017lighthouse <gen>
      • Unit - A unit leaves 018magitower <gen>
      • Unit - A unit leaves 019sacredgrove <gen>
      • Unit - A unit leaves 020elventemple <gen>
      • Unit - A unit leaves 021kings <gen>
      • Unit - A unit leaves 022greendragon <gen>
      • Unit - A unit leaves 023pirates <gen>
    • Conditions
      • ((Triggering unit) is A Hero) Equal to True
    • Actions
      • For each (Integer A) from 1 to CREEPareas_TOTAL, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in (Units in CREEP_region[(Integer A)] matching (((Matching unit) is A Hero) Equal to True))) Equal to 0
            • Then - Actions
              • Custom script: set bj_wantDestroyGroup = true
              • Unit Group - Pick every unit in (Units in CREEP_region[(Integer A)] owned by Neutral Hostile) and do (Actions)
                • Loop - Actions
                  • If (((Picked unit) is An Ancient) Equal to False) then do (Unit - Remove (Picked unit) from the game) else do (Do nothing)
            • Else - Actions
Thank you for the help!
 
Status
Not open for further replies.
Top