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

[Trigger] help me with trigger code

Status
Not open for further replies.
Level 3
Joined
Nov 3, 2017
Messages
34
Friends of such a question, I want to make a duel in the map 3 to 3, but I can not implement the code, I did 1 for 1 and 3 for 3 does not work. Is there a sentence with the algorithm?
 
Level 3
Joined
Nov 3, 2017
Messages
34
I dont get it o_O
Explain your problem a bit more.
Maybe post triggers?

I do not know how this will help, it's just that I can call it a solid text, I probably have enough errors)))

JASS:
scope DuelMode

    globals
        private constant integer PERIOD = 200
    endglobals
   
    function InitRectDuel takes nothing returns nothing
        set udg_arectt1[1] = GetRectCenter(gg_rct_pArena1)
        set udg_arectt1[2] = GetRectCenter(gg_rct_pArena2)
        set udg_arectt1[3] = GetRectCenter(gg_rct_pArena3)
        set udg_arectt1[4] = GetRectCenter(gg_rct_pArena4)
        set udg_arectt1[5] = GetRectCenter(gg_rct_KingTeam1)
        set udg_arectt2[1] = GetRectCenter(gg_rct_pArena5)
        set udg_arectt2[2] = GetRectCenter(gg_rct_pArena6)
        set udg_arectt2[3] = GetRectCenter(gg_rct_pArena7)
        set udg_arectt2[4] = GetRectCenter(gg_rct_pArena8)
        set udg_arectt2[5] = GetRectCenter(gg_rct_KingTeam2)
    endfunction
   
    function SetHeal takes nothing returns nothing
        call SetUnitState(GetEnumUnit(), UNIT_STATE_LIFE, GetUnitState(GetEnumUnit(), UNIT_STATE_MAX_LIFE))
        call SetUnitState(GetEnumUnit(), UNIT_STATE_MANA, GetUnitState(GetEnumUnit(), UNIT_STATE_MAX_MANA))
    endfunction
   
    function UnpauseArena takes nothing returns nothing
        call PauseUnit(GetEnumUnit(), false)
        call SetUnitInvulnerable(GetEnumUnit(), false)
        if GetPlayerController(GetOwningPlayer(GetEnumUnit())) == MAP_CONTROL_COMPUTER then
            call IssuePointOrderLoc(GetEnumUnit(), "attack", GetRectCenter(gg_rct_DuelArena))
        endif
    endfunction
   
    function ConArena takes nothing returns boolean
        return udg_bDuel == true and (GetDyingUnit() == udg_Team1LeaderHero[1] or GetDyingUnit() == udg_Team1LeaderHero[2] or GetDyingUnit() == udg_Team1LeaderHero[3] or GetDyingUnit() == udg_Team2LeaderHero[1] or GetDyingUnit() == udg_Team2LeaderHero[2] or GetDyingUnit() == udg_Team2LeaderHero[3])
    endfunction
   
    function LeaderMove takes nothing returns nothing
        local unit e = GetEnumUnit()
        local player pe = GetOwningPlayer(e)
        if IsPlayerInForce(pe, udg_Team1) then
            call SetUnitPositionLoc(e, GetRectCenter(gg_rct_Revive_Hero_Team_1))
            call PanCameraToTimedLocForPlayer(pe, GetRectCenter(gg_rct_Revive_Hero_Team_1), 0)
        elseif IsPlayerInForce(pe, udg_Team2) then
            call SetUnitPositionLoc(e, GetRectCenter(gg_rct_Revive_Hero_Team_2))
            call PanCameraToTimedLocForPlayer(pe, GetRectCenter(gg_rct_Revive_Hero_Team_2), 0)
        endif
        set e = null
        set pe = null
    endfunction
   
    function FightArena takes nothing returns nothing
        local trigger t = GetTriggeringTrigger()
        local unit d = GetDyingUnit()
        local integer team1
        local integer team2
        local integer temp
        local integer i
        local player p
        local unit u
        if IsUnitInGroup(d, udg_t1) then
            call GroupRemoveUnit(udg_t1, d)
            if CountUnitsInGroup(udg_t1)<=0 then
                call PauseAllUnitsBJ(true)
            endif
        elseif IsUnitInGroup(d, udg_t2) then
            call GroupRemoveUnit(udg_t2, d)
            if CountUnitsInGroup(udg_t2)<=0 then
                call PauseAllUnitsBJ(true)
            endif
        endif
        if CountUnitsInGroup(udg_t1)<=0 or CountUnitsInGroup(udg_t2)<=0 then
            call StopMusic(true)
            set team1 = CountUnitsInGroup(udg_t1)
            set team2 = CountUnitsInGroup(udg_t2)
            if team1<=0 then
                call EchoText(10, "Team 2 has victory Duel!")
                call PolledWait(3)
                call ForGroup(udg_t2, function LeaderMove)
            endif
            if team2<=0 then
                call EchoText(10, "Team 1 has victory Duel!")
                call PolledWait(3)
                call ForGroup(udg_t1, function LeaderMove)
            endif
            set temp = CountPlayersInForceBJ(udg_Team1)
            set i = 1
            loop
                exitwhen i>temp
                set p = udg_AlliancePlayers[i]
                set u = udg_Hero[GetPlayerId(p)]
                if u != udg_Team1LeaderHero[1] and u != udg_Team1LeaderHero[2] and u != udg_Team1LeaderHero[3] then
                    call SetUnitPositionLoc(u, udg_HeroSavePoints1[i])
                    call PanCameraToTimedForPlayer(p, GetLocationX(udg_HeroSavePoints1[i]), GetLocationY(udg_HeroSavePoints1[i]), 0)
                    call SetUnitInvulnerable(u, false)
                    call RemoveLocation(udg_HeroSavePoints1[i])
                    set udg_HeroSavePoints1[i] = null
                endif
                set u = null
                set p = null
                set i = i + 1
            endloop
            set temp = CountPlayersInForceBJ(udg_Team2)
            set i = 1
            loop
                exitwhen i>temp
                set p = udg_UndeadPlayers[i]
                set u = udg_Hero[GetPlayerId(p)]
                if u != udg_Team2LeaderHero[1] and u != udg_Team2LeaderHero[2] and u != udg_Team2LeaderHero[3] then
                    call SetUnitPositionLoc(u, udg_HeroSavePoints2[i])
                    call PanCameraToTimedForPlayer(p, GetLocationX(udg_HeroSavePoints2[i]), GetLocationY(udg_HeroSavePoints2[i]), 0)
                    call SetUnitInvulnerable(u, false)
                    call RemoveLocation(udg_HeroSavePoints2[i])
                    set udg_HeroSavePoints2[i] = null
                endif
                set u = null
                set p = null
                set i = i + 1
            endloop
            call PauseAllUnitsBJ(false)
            call DestroyGroup(udg_t1)
            call DestroyGroup(udg_t2)
            set udg_t1 = null
            set udg_t2 = null
            set udg_Team1LeaderHero[1] = null
            set udg_Team1LeaderHero[2] = null
            set udg_Team1LeaderHero[3] = null
            set udg_Team2LeaderHero[1] = null
            set udg_Team2LeaderHero[2] = null
            set udg_Team2LeaderHero[3] = null
            set udg_bDuel = false
            set udg_bPause = false
            call TimerStart(udg_duel_timer, PERIOD, false, null)
            call TimerDialogDisplay(udg_timer_window, true)
            call DestroyTrigger(t)
            set t = null
        endif
        set d = null
        set team1 = 0
        set team2 = 0
        set temp = 0
        set i = 0
        set p = null
        set u = null
    endfunction
   
    function StartDuel takes nothing returns nothing
        local trigger t
        local boolean x1 = false
        local boolean x3 = false
        local boolean x2 = false
        local integer rnd
        local integer team
        local integer i
        local player p
        local unit u
        local integer x
        set udg_bDuel = true
        set udg_bPause = true
        call TimerDialogDisplay(udg_timer_window, false)
        call EchoText(10, "Duel Time!")
        call PlaySoundBJ(gg_snd_start_duel)
        call PauseAllUnitsBJ(true)
        call PolledWait(5.5)
        set team = CountPlayersInForceBJ(udg_Team1)
        set i = 1
        loop
            exitwhen i>team
                set p = udg_AlliancePlayers[i]
                set u = udg_Hero[GetPlayerId(p)]
                set udg_HeroSavePoints1[i] = GetUnitLoc(u)
                call SetUnitPositionLoc(u, udg_arectt1[i])
                call PanCameraToTimedForPlayer(p, GetLocationX(udg_arectt1[i]), GetLocationY(udg_arectt1[i]), 0)
                call SetUnitInvulnerable(u, true)
                set u = null
                set p = null
            set i = i + 1
        endloop
        set team = CountPlayersInForceBJ(udg_Team2)
        set i = 1
        loop
            exitwhen i>team
                set p = udg_UndeadPlayers[i]
                set u = udg_Hero[GetPlayerId(p)]
                set udg_HeroSavePoints2[i] = GetUnitLoc(u)
                call SetUnitPositionLoc(u, udg_arectt2[i])
                call PanCameraToTimedForPlayer(p, GetLocationX(udg_arectt2[i]), GetLocationY(udg_arectt2[i]), 0)
                call SetUnitInvulnerable(u, true)
                set u = null
                set p = null
            set i = i + 1
        endloop
        if udg_arena3x3 == true then
            set rnd = GetRandomInt(1, 2)
            if rnd == 1 then
                set x1 = true
            elseif rnd == 2 then
                set x3 = true
            endif
        else
            set x1 = true
        endif
        if x1 == true then
            set team = CountPlayersInForceBJ(udg_Team1)
            loop
                exitwhen x2 == true
                    set rnd = GetRandomInt(1, team)
                    set p = udg_AlliancePlayers[rnd]
                    set u = udg_Hero[GetPlayerId(p)]
                    if GetUnitTypeId(u)!=0 and not IsUnitType(u, UNIT_TYPE_DEAD) then
                        set udg_Team1LeaderHero[1] = u
                        set x2 = true
                    endif
                    set rnd = 0
                    set p = null
                    set u = null
            endloop
            set team = CountPlayersInForceBJ(udg_Team2)
            set x2 = false
            loop
                exitwhen x2 == true
                    set rnd = GetRandomInt(1, team)
                    set p = udg_UndeadPlayers[rnd]
                    set u = udg_Hero[GetPlayerId(p)]
                    if GetUnitTypeId(u)!=0 and not IsUnitType(u, UNIT_TYPE_DEAD) then
                        set udg_Team2LeaderHero[1] = u
                        set x2 = true
                    endif
                    set rnd = 0
                    set p = null
                    set u = null
            endloop
        endif
        if x3 == true then
            set team = CountPlayersInForceBJ(udg_Team1)
            set i = 1
            loop
                exitwhen i==4
                set rnd = GetRandomInt(1, team)
                set p = udg_AlliancePlayers[rnd]
                set u = udg_Hero[GetPlayerId(p)]
                if GetUnitTypeId(u)!=0 and not IsUnitType(u, UNIT_TYPE_DEAD) then
                    if udg_Team1LeaderHero[i] == null and udg_Team1LeaderHero[i] != udg_Team1LeaderHero[i-1] then
                        set udg_Team1LeaderHero[i] = u
                        set i = i + 1
                    endif
                endif
                set rnd = 0
                set p = null
                set u = null
            endloop
            set team = CountPlayersInForceBJ(udg_Team2)
            set i = 1
            loop
                exitwhen i==4
                set rnd = GetRandomInt(1, team)
                set p = udg_UndeadPlayers[rnd]
                set u = udg_Hero[GetPlayerId(p)]
                if GetUnitTypeId(u)!=0 and not IsUnitType(u, UNIT_TYPE_DEAD) then
                    if udg_Team2LeaderHero[i] == null and udg_Team2LeaderHero[i] != udg_Team2LeaderHero[i-1] then
                        set udg_Team2LeaderHero[i] = u
                        set i = i + 1
                    endif
                endif
                set rnd = 0
                set p = null
                set u = null
            endloop
        endif
        if x1 == true then
            set udg_t1 = CreateGroup()
            set udg_t2 = CreateGroup()
            call SetUnitPositionLoc(udg_Team1LeaderHero[1], GetRectCenter(gg_rct_Arena2))
            call PanCameraToTimedLocForPlayer(GetOwningPlayer(udg_Team1LeaderHero[1]), GetRectCenter(gg_rct_Arena2), 0)
            call GroupAddUnit(udg_t1, udg_Team1LeaderHero[1])
            call SetUnitPositionLoc(udg_Team2LeaderHero[1], GetRectCenter(gg_rct_Arena6))
            call PanCameraToTimedLocForPlayer(GetOwningPlayer(udg_Team2LeaderHero[1]), GetRectCenter(gg_rct_Arena6), 0)
            call GroupAddUnit(udg_t2, udg_Team2LeaderHero[1])
        endif
        if x3 == true then
            set udg_t1 = CreateGroup()
            set udg_t2 = CreateGroup()
            if udg_Team1LeaderHero[1] != null then
                call SetUnitPositionLoc(udg_Team1LeaderHero[1], GetRectCenter(gg_rct_Arena2))
                call PanCameraToTimedLocForPlayer(GetOwningPlayer(udg_Team1LeaderHero[1]), GetRectCenter(gg_rct_Arena2), 0)
                call GroupAddUnit(udg_t1, udg_Team1LeaderHero[1])
            endif
            if udg_Team1LeaderHero[2] != null then
                call SetUnitPositionLoc(udg_Team1LeaderHero[2], GetRectCenter(gg_rct_Arena1))
                call PanCameraToTimedLocForPlayer(GetOwningPlayer(udg_Team1LeaderHero[2]), GetRectCenter(gg_rct_Arena1), 0)
                call GroupAddUnit(udg_t1, udg_Team1LeaderHero[2])
            endif
            if udg_Team1LeaderHero[3] != null then
                call SetUnitPositionLoc(udg_Team1LeaderHero[3], GetRectCenter(gg_rct_Arena3))
                call PanCameraToTimedLocForPlayer(GetOwningPlayer(udg_Team1LeaderHero[3]), GetRectCenter(gg_rct_Arena3), 0)
                call GroupAddUnit(udg_t1, udg_Team1LeaderHero[3])
            endif
            if udg_Team2LeaderHero[1] != null then
                call SetUnitPositionLoc(udg_Team2LeaderHero[1], GetRectCenter(gg_rct_Arena6))
                call PanCameraToTimedLocForPlayer(GetOwningPlayer(udg_Team2LeaderHero[1]), GetRectCenter(gg_rct_Arena6), 0)
                call GroupAddUnit(udg_t2, udg_Team2LeaderHero[1])
            endif
            if udg_Team2LeaderHero[2] != null then
                call SetUnitPositionLoc(udg_Team2LeaderHero[2], GetRectCenter(gg_rct_Arena4))
                call PanCameraToTimedLocForPlayer(GetOwningPlayer(udg_Team2LeaderHero[2]), GetRectCenter(gg_rct_Arena4), 0)
                call GroupAddUnit(udg_t2, udg_Team2LeaderHero[2])
            endif
            if udg_Team2LeaderHero[3] != null then
                call SetUnitPositionLoc(udg_Team2LeaderHero[3], GetRectCenter(gg_rct_Arena5))
                call PanCameraToTimedLocForPlayer(GetOwningPlayer(udg_Team2LeaderHero[3]), GetRectCenter(gg_rct_Arena5), 0)
                call GroupAddUnit(udg_t2, udg_Team2LeaderHero[3])
            endif
        endif
        if CountUnitsInGroup(udg_t1)>0 and CountUnitsInGroup(udg_t2)>0 then
            call ForGroup(udg_t1, function SetHeal)
            call ForGroup(udg_t2, function SetHeal)
        endif
        call PlayMusic(gg_snd_mkarena)
        call EchoText(3, "3")
        call PolledWait(4)
        call EchoText(3, "2")
        call PolledWait(1.52)
        call EchoText(3, "1")
        call PolledWait(1)
        call EchoText(3, "Fight!")
        call ForGroup(GetUnitsInRectAll(gg_rct_DuelArena), function UnpauseArena)
        set t = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DEATH)
        call TriggerAddCondition(t, Condition(function ConArena))
        call TriggerAddAction(t, function FightArena)
        set t = null
        set x1 = false
        set x2 = false
        set x3 = false
        set rnd = 0
        set team = 0
        set i = 0
        set p = null
        set u = null
    endfunction
   
    function StartTrig_Duel_Mode takes nothing returns nothing
        local integer team1 = CountPlayersInForceBJ(udg_Team1)
        local integer team2 = CountPlayersInForceBJ(udg_Team2)
        if team1 >= 3 and team2 >= 3 and udg_arena3x3 == false then
            set udg_arena3x3 = true
        endif
        set udg_Team1LeaderHero[0] = gg_unit_h003_0076
        set udg_Team2LeaderHero[0] = gg_unit_u009_0078
        set gg_trg_Duel_Mode = CreateTrigger()
        call TriggerRegisterTimerExpireEvent(gg_trg_Duel_Mode, udg_duel_timer)
        call TriggerAddAction(gg_trg_Duel_Mode, function StartDuel)
        call TimerStart(udg_duel_timer, PERIOD, false, null)
        set udg_timer_window = CreateTimerDialog(udg_duel_timer)
        call TimerDialogSetTitle(udg_timer_window, "Next Duel")
        call TimerDialogDisplay(udg_timer_window, true)
        call InitRectDuel()
    endfunction
   
endscope
 
Level 3
Joined
Nov 3, 2017
Messages
34
If i understand it correctly, you have a duel time in your map, where 3 heroes fight against 3 heroes?
If that is the case, your code seems way too long. What exactly is not working?

Look, there is a time allotted, through which the duel will begin. The essence is that if both 1 and 2 teams have more than 3 players, then mode 3 on 3 is activated. Assume that the condition is true and we both have more than 3 players in both teams, then when the timer ends the random duel or 3 on 3 or 1 to 1. What does not work for me - 1-to-1 mode works fine, but when 3 to 3, either 2 or 2 heroes appear or 3 at all against 1, that is not 3 on 3
 
Status
Not open for further replies.
Top