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

Move heroes to regions... quite simple but not for me)))

Status
Not open for further replies.
Level 10
Joined
Mar 17, 2012
Messages
579
Hi everyone! Can somebody help me? I need to make a trigger that moves 4 heroes of 4 players from team 1 to Region#1 and 4 heroes of 4 players from team 2 to Region#2, but I have no idea how to make it.

P.S.
Team1: Blue, Orange, Yellow, Purple;
Team2: Pink, Gray, Dark Green, Brown.

Regions:
Region#1 - Arena Left;
Region#2 - Arena Right.

Thanks everyone who cares!^^,
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
· Create two Player Group Variables: Team1 and Team2
· Whenever a player picks a hero, add the unit to "Heroes" unit Group.

  • Actions
    • Set TUnit = (Picked Unit)
    • Unit Group - Pick every unit in Heroes and do (Actions)
      • Loop - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • ((Owner of TUnit) is in Team1) Equal to True
          • Then - Actions
            • Set TPoint = (Center of (Team1Region)
            • Unit - Move TUnit instantly to TPoint)
            • Custom script: call RemoveLocation(udg_TPoint)
          • Else - Actions
            • Set TPoint = (Center of (Team2Region)
            • Unit - Move TUnit instantly to TPoint)
            • Custom script: call RemoveLocation(udg_TPoint)
 
Level 9
Joined
Apr 23, 2011
Messages
460
JASS:
scope MoveUnits initializer init
    globals
        rect array Arena
    endglobals
    private function setupRects takes nothing returns nothing
        set Arena[0] = gg_rct_ArenaLeft
        set Arena[1] = gg_rct_ArenaRight
    endfunction
    
    private function HeroFilter takes nothing returns boolean
        if IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO) then
            return true
        endif
        return false
    endfunction
    private function GetTeam takes unit u returns integer
        local player p
        local integer i = 0
        loop
            set p = Player(i)
            if GetOwningPlayer(u) == p then
                set u = null
                set p = null
                return 0
            endif
            set i = i + 1
            exitwhen i > 5
        endloop
        set p = null
        set u = null
        return 1
    endfunction
            

    private function HeroMover takes unit u, integer team returns nothing
        local rect r = Arena[team]
        call SetUnitX(u, GetRectCenterX(r))
        call SetUnitY(u, GetRectCenterY(r))
        set u = null
        set r = null
    endfunction
    
    private function GetAllHeroes takes nothing returns nothing
        local group g = CreateGroup()
        local unit u
        local integer team
        call GroupEnumUnitsInRect(g, bj_mapInitialPlayableArea, Filter(function HeroFilter))
        loop
            set u = FirstOfGroup(g)
            call GroupRemoveUnit(g, u)
            exitwhen u == null
            set team = GetTeam(u)
            call HeroMover(u, team)
        endloop
        call DestroyGroup(g)
        set g = null
        set u = null
    endfunction
    
    private function init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterTimerEvent(t, 60., true)
        call TriggerAddAction(t, function GetAllHeroes)
        set t = null
    endfunction
endscope

Couldn't test it, but it should work. If you get errors you might need to change the rects to the appropriate names. In region editor take the names of the rects, (I used ArenaLeft for team 1 and ArenaRight for team 2 as you wished) and added "gg_rct_" to them as needed. Should work though.
 
Level 29
Joined
Mar 10, 2009
Messages
5,016
you need to call "setupRects" first or better use a global region in GUI variable editor since you're using gg_rct_ anyway...

JASS:
private function HeroFilter takes nothing returns boolean
   if IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO) then
      return true
    endif
    return false
endfunction

-->

JASS:
private function HeroFilter takes nothing returns boolean
   return IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO)
endfunction

and many more to be improved for better performance...
 
Level 10
Joined
Mar 17, 2012
Messages
579
· Create two Player Group Variables: Team1 and Team2
· Whenever a player picks a hero, add the unit to "Heroes" unit Group.

  • Actions
    • Set TUnit = (Picked Unit)
    • Unit Group - Pick every unit in Heroes and do (Actions)
      • Loop - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • ((Owner of TUnit) is in Team1) Equal to True
          • Then - Actions
            • Set TPoint = (Center of (Team1Region)
            • Unit - Move TUnit instantly to TPoint)
            • Custom script: call RemoveLocation(udg_TPoint)
          • Else - Actions
            • Set TPoint = (Center of (Team2Region)
            • Unit - Move TUnit instantly to TPoint)
            • Custom script: call RemoveLocation(udg_TPoint)

I forgot to notice that it have to be the Event: Time - Every 300 seconds of game time

How can I handle it? :eekani:
Spartipilo, can you tell me exactly what I have to enter in this variables? I can't completely catch this part of coding in WE))))
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
On Map Initialization Trigger add the Team1 players to a PlayerGroup variable called "Team1". Do the same thing for "Team2".

Create another trigger:
Event: A unit enters (Playable map area)
Condition: Boolean - Triggering Unit is a Hero = true
Action: Unit Group - Add (Triggering Unit) to Heroes

Now, your trigger
Event: Time - Every 300 seconds of gametime
Conditions: None
  • Actions
    • Unit Group - Pick every unit in Heroes and do (Actions)
      • Loop - Actions
        • Set TUnit = (Picked Unit)
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
          • ((Owner of TUnit) is in Team1) Equal to True
        • Then - Actions
          • Set TPoint = (Center of (Team1Region)
          • Unit - Move TUnit instantly to TPoint)
          • Custom script: call RemoveLocation(udg_TPoint)
        • Else - Actions
          • Set TPoint = (Center of (Team2Region)
          • Unit - Move TUnit instantly to TPoint)
          • Custom script: call RemoveLocation(udg_TPoint)
The event doesn't matter, since the action is independent. It handles an already created PlayerGroup and Unit Group.
 
Level 10
Joined
Mar 17, 2012
Messages
579
Spartipilo, where did you get TUnit, TPoint, udg_TPoint?)) Is it empty variables?
as far as I understood Team2Region and Team1Region are my regions named "Arena Left" and "Arena Right"?
--------------
BINGO! I've found how to add player to playergroup! xD This is a real progress!!!))
 
Last edited:
Level 20
Joined
Jul 14, 2011
Messages
3,213
TUnit is a "Unit" variable.
TPoint is a "Point" variable
Team1 and Team2 are "Player Group" variables.
"udg_TPoint" is the name variable has on the script (The language behind the Graphic Interface)

Maker, there are 2 Point options. These must be created inside the loop, but you're right, it can be removed after.

  • Actions
    • Unit Group - Pick every unit in Heroes and do (Actions)
      • Loop - Actions
        • Set TUnit = (Picked Unit)
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
          • ((Owner of TUnit) is in Team1) Equal to True
        • Then - Actions
          • Set TPoint = (Center of (Team1Region)
          • Unit - Move TUnit instantly to TPoint)
        • Else - Actions
          • Set TPoint = (Center of (Team2Region)
          • Unit - Move TUnit instantly to TPoint)
    • Custom script: call RemoveLocation(udg_TPoint)
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Less script, less functions, more efficient. You avoid useless repetitive actions. I feel safer removing it inside the loop like in the first example, or seting both points before, and removing both later. I think it leaks the way I showed in the last post. Don't kill yourself with this. First example was good enough xD
 
Level 10
Joined
Mar 17, 2012
Messages
579
Spartipilo, Your trigger worked! But now I faced the problem... neutral heroes that respawns on my map in duel time moves to second region using:

Else - Actions
Set TPoint = (Center of (Team2Region)
Unit - Move TUnit instantly to TPoint)

I tried to make something like this:

Events:
Unit - A unit enters (Playable map area)
Conditions:
((Triggering Unit) is a hero) Equal to True
((Owner of (Triggering Unit)) is in Team1) Equal to True
((Owner of (Triggering Unit)) is in Team2) Equal to True
Actions:
Unit Group - Add (Triggering Unit) to Heroes

But it doesn't work((( I don't need neutral heroes to teleport(((

I also tried to remove this unit from Heroes:

Player Group - Add Neutral Hostile to NeutralHostile

Events:
Unit - A unit enters (Playable map area)
Conditions:
((Owner of (Triggering Unit)) is in NeutralHostile) Equal to True
Actions:
Unit Group - Remove (Triggering Unit) from Heroes

Doesn't work either((( Help me please
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Don't add Neutral Heroes to "Heroes" group. use "Heroes" for player heroes, and some other name like "NeutralHeroes" for Neutral Heroes.
 
Level 10
Joined
Mar 17, 2012
Messages
579
I didn't add them! They were added by using
Else - Actions
because they are not in Team1, so they in any another players group... including Neutral Hostile...

Anyway, I think I solved the problem... I just created another same trigger and pasted Team2 actions there and removed them from the first trigger)))
I'll check this 2 triggers with my friends tomorrow and tell you results ^^,
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
But you're only picking units inside "Heroes" unit group, so, it doesn't affect units outside that unit-group...

That's why I think you're adding them to the Heroes group.
 
Level 10
Joined
Mar 17, 2012
Messages
579
My neutral hostile unit-heroes have the trigger to respawn every 90 seconds so they enter playable map area and enter "Heroes"

and my "Else - Actions" say to move any other hero from "Heroes" to region2 that doesn't belong to Team1.

So it made me to make 2 triggers in stead of 1 ^_^
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Solution is easy... "DONT ADD THEM TO HEROES" Create a different unit group for those, or add in the condition "Owner of (Picked Unit) is controlled by a User". There's no need to create another trigger for team1, team2, and hostiles.
 
Status
Not open for further replies.
Top