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

[JASS] waypoint trigger bugs globally

Status
Not open for further replies.
Level 5
Joined
Aug 19, 2015
Messages
68
Alright i have this trigger to move a unit to all waypoints in an array.
The waypoints in the array are filled from 0 to 33.
The code seems to work but:
Since I implemented this, units are getting stuck and cant be moved until you deselect them and use a spell or some kind of messy debug...
Or for example I was about to build something and when my teammate entered the command, the building location selection got canceled.

Help please

JASS:
function Trig_orderwaypoints_Func009C takes nothing returns boolean
    if ( not ( GetEventPlayerChatString() == "-wp -" ) ) then
        return false
    endif
    return true
endfunction

function Trig_orderwaypoints_Actions takes nothing returns nothing
    local unit u
    local integer loopstart
    local integer loopend
    local group ggg = GetUnitsSelectedAll(GetTriggerPlayer())
    set u = GroupPickRandomUnit(ggg)
    call DestroyGroup(ggg)


    if ( Trig_orderwaypoints_Func009C() ) then
        set loopstart = 33
        set loopend = 0
        loop
            exitwhen loopstart < loopend
            call IssuePointOrderLocBJ( u, "move", udg_baseloc[loopstart] )
            loop
                exitwhen ( (GetUnitCurrentOrder(u) == 0) or (GetUnitCurrentOrder(u) == 851971))
                call TriggerSleepAction(RMaxBJ(bj_WAIT_FOR_COND_MIN_INTERVAL, 2))
            endloop
            if GetUnitCurrentOrder(u) == 851971 then
                 set loopstart = 0
            endif
            set loopstart = loopstart - 1
        endloop
    else
        set loopstart = 0
        set loopend = 33
        loop
            exitwhen loopstart > loopend
            call IssuePointOrderLocBJ( u, "move", udg_baseloc[loopstart] )
            loop
                exitwhen ( (GetUnitCurrentOrder(u) == 0) or (GetUnitCurrentOrder(u) == 851971))
                call TriggerSleepAction(RMaxBJ(bj_WAIT_FOR_COND_MIN_INTERVAL, 2))
            endloop
            if GetUnitCurrentOrder(u) == 851971 then
                 set loopstart = 33
            endif
            set loopstart = loopstart + 1
        endloop
    endif
 
    set ggg = null
    set u = null

endfunction

//===========================================================================
function InitTrig_orderwaypoints takes nothing returns nothing
    set gg_trg_orderwaypoints = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_orderwaypoints, Player(10), "-wp", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_orderwaypoints, Player(10), "-wp -", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_orderwaypoints, Player(11), "-wp", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_orderwaypoints, Player(11), "-wp -", true )
    call TriggerAddAction( gg_trg_orderwaypoints, function Trig_orderwaypoints_Actions )
endfunction
map: https://www.dropbox.com/s/8nkfbm5cb38nnpw/Vamp Zero SDK turbo 1.49.w3x?raw=1
 
Last edited:
What exactly are you trying to accomplish with the trigger? In general, these sorts of loops are best done through timers. Waiting until a condition happens is not the best idea (if you don't have some sort of emergency break condition)--what if the unit is issued a different order? What if he is killed?

To avoid those situations, try a systematic approach. Create a system that accepts a unit, a set of waypoints, and orders the unit to move through the way points. It'll be much more modular, and if you use timers, you can have better checks and break conditions. It is a bit difficult to tackle though.
 
Level 5
Joined
Aug 19, 2015
Messages
68
well the manual exit point is when the unit is moved manually for 2 seconds (order 851971)
that i didnt check if the unit is killed is right but that shouldnt cause this kind of bugs ... well until now the scout unit was never or very rarely killed i guess and the bug occurs very often...
i would most appreciate a way to do it this way, because the time can be different if one path is blocked and i dont have to do distance checks all the time... (which also wont return a 'true' if the path is blocked i guess... )

p.s. im almost sure its the GetUnitsSelectedAll(GetTriggerPlayer())
i tried a script without this function and there seemed to be no bugs
 
Last edited:
Level 5
Joined
Aug 19, 2015
Messages
68
if someone finds this and wants my sloppy solution (with 1 trigger per unit), here he goes:
JASS:
function Trig_orderwaypoints_zero takes nothing returns nothing

    local unit u = udg_shade[0]
    local integer loopstart
    local integer loopend

    call DisplayTextToForce( GetPlayersAll(), "alter" )
        set udg_wp_active[0] = true
        set loopstart = 0
        set loopend = 34
        loop
            exitwhen loopstart > loopend
            call IssuePointOrderLocBJ( u, "move", udg_baseloc[loopstart] )
            loop
                exitwhen ( (GetUnitCurrentOrder(u) == 0) or (GetUnitCurrentOrder(u) == 851971)) or (GetUnitState(u, UNIT_STATE_LIFE) == 0)
                call TriggerSleepAction(RMaxBJ(bj_WAIT_FOR_COND_MIN_INTERVAL, 2))
            endloop
            if (GetUnitCurrentOrder(u) == 851971) or (GetUnitState(u, UNIT_STATE_LIFE) == 0) then
                 set loopstart = 33
            endif
            set loopstart = loopstart + 1
        endloop
        set u = null
        set udg_wp_active[0] = false

endfunction


function Trig_order_Func001A takes nothing returns nothing

    if (udg_wp_active[udg_shadeloop] == false) then
        set udg_shade[udg_shadeloop] = GetEnumUnit()
    else
        if (udg_wp_active[udg_shadeloop+1] == false) then
            set udg_shade[udg_shadeloop+1] = GetEnumUnit()
        endif
    endif
    set udg_shadeloop=udg_shadeloop+1
endfunction


function Trig_orderwaypoints_a_Actions takes nothing returns nothing

    local group ggg = GetUnitsOfPlayerAndTypeId(GetTriggerPlayer(),'ushd')
    set udg_shadeloop = 0
    call ForGroupBJ( ggg, function Trig_order_Func001A )
    call DestroyGroup(ggg)
    set ggg = null
    if (udg_wp_active[0] == false) then
            call Trig_orderwaypoints_zero()
    endif

endfunction

//===========================================================================
function InitTrig_orderwaypoints_zero takes nothing returns nothing

    set gg_trg_orderwaypoints_zero = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_orderwaypoints_zero, Player(10), "-wp", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_orderwaypoints_zero, Player(10), "-waypoints", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_orderwaypoints_zero, Player(11), "-wp", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_orderwaypoints_zero, Player(11), "-waypoints", true )
    call TriggerAddAction( gg_trg_orderwaypoints_zero, function Trig_orderwaypoints_a_Actions )

endfunction

JASS:
function Trig_orderwaypoints_one takes nothing returns nothing

    local unit u = udg_shade[1]
    local integer loopstart
    local integer loopend


        set udg_wp_active[1] = true
        set loopstart = 34
        set loopend = 0
        loop
            exitwhen loopstart < loopend
            call IssuePointOrderLocBJ( u, "move", udg_baseloc[loopstart] )
            loop
                exitwhen ( (GetUnitCurrentOrder(u) == 0) or (GetUnitCurrentOrder(u) == 851971)) or (GetUnitState(u, UNIT_STATE_LIFE) == 0)
                call TriggerSleepAction(RMaxBJ(bj_WAIT_FOR_COND_MIN_INTERVAL, 2))
            endloop
            if (GetUnitCurrentOrder(u) == 851971) or (GetUnitState(u, UNIT_STATE_LIFE) == 0) then
                 set loopstart = 0
            endif
            set loopstart = loopstart - 1
        endloop
        set u = null
        set udg_wp_active[1] = false

endfunction


function Trig_orderwaypoints_b_Actions takes nothing returns nothing
    call TriggerSleepAction(0.10)
    if (udg_wp_active[1] == false) then
            call Trig_orderwaypoints_one()
    endif

endfunction

//===========================================================================
function InitTrig_orderwaypoints_one takes nothing returns nothing

    set gg_trg_orderwaypoints_one = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_orderwaypoints_one, Player(10), "-wp", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_orderwaypoints_one, Player(10), "-waypoints", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_orderwaypoints_one, Player(11), "-wp", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_orderwaypoints_one, Player(11), "-waypoints", true )
    call TriggerAddAction( gg_trg_orderwaypoints_one, function Trig_orderwaypoints_b_Actions )

endfunction
 
Status
Not open for further replies.
Top