• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Why does both these triggers run?

Status
Not open for further replies.
Level 15
Joined
Nov 30, 2007
Messages
1,202
JASS:
library Selection initializer init

globals
    unit array CurrentSelection
endglobals 

private function Selection takes nothing returns boolean
    local boolean CityWasSelected = false
    local unit u = GetTriggerUnit()
    local player owner = GetOwningPlayer(u) 
    local player clicker = GetTriggerPlayer()
    local integer pID = GetPlayerId(clicker) 
    local integer i = 0 
    local real x
    local real y
    local integer array b_count
    
    loop
        exitwhen CityType[i] == null
        if (GetUnitTypeId(u) == CityType[i]) then
            set CityWasSelected = true
        endif
        set i = i + 1
    endloop

    if (CityWasSelected == true) then
        if (owner == clicker) then
            set x = GetUnitX(u)
            set y = GetUnitY(u) 
            set CurrentSelection[pID] = u
            call BJDebugMsg(GetUnitName(CurrentSelection[pID]))
            call DisableTrigger(deselect)
            call SetUnitPosition(CityController[pID],x,y)
            call ShowUnit(CityController[pID], true) 
            if (GetLocalPlayer() == clicker) then 
                call ClearSelection()
                call SelectUnit(CityController[pID], true) 
            endif
            call SetUnitPosition(CityController[pID],x,y)
            call EnableTrigger(deselect)
            call ShowUnit(CityController[pID], true)
            set i = 0
            //call BJDebugMsg("----------------------")
            call BJDebugMsg(I2S(GetUnitUserData(u)))
            loop
                exitwhen Building_order[i] == null 
                set b_count[i] = CountBuildings(GetUnitUserData(u), i)
                //call BJDebugMsg("BUILDING_" + I2S(i) + " = " + I2S(b_count[i])) 
                set i = i + 1
            endloop
            
        endif
    endif 
    return false 
endfunction

//===========================================================================
private function init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterPlayerSelectionEventBJ( t, Player(0), true )
    call TriggerRegisterPlayerSelectionEventBJ( t, Player(1), true )
    call TriggerRegisterPlayerSelectionEventBJ( t, Player(2), true )
    call TriggerRegisterPlayerSelectionEventBJ( t, Player(3), true )
    call TriggerRegisterPlayerSelectionEventBJ( t, Player(4), true )
    call TriggerRegisterPlayerSelectionEventBJ( t, Player(5), true )
    call TriggerRegisterPlayerSelectionEventBJ( t, Player(6), true )
    call TriggerRegisterPlayerSelectionEventBJ( t, Player(7), true )
    call TriggerRegisterPlayerSelectionEventBJ( t, Player(8), true )
    call TriggerRegisterPlayerSelectionEventBJ( t, Player(9), true )
    call TriggerRegisterPlayerSelectionEventBJ( t, Player(10), true )
    call TriggerRegisterPlayerSelectionEventBJ( t, Player(11), true )
    call TriggerAddCondition( t, Condition( function Selection) )
    set t = null
endfunction

endlibrary
JASS:
library Deselection initializer init

globals
    trigger deselect
endglobals

function Deselection takes nothing returns boolean
    local unit u = GetTriggerUnit()
    local integer pID = GetPlayerId(GetTriggerPlayer())
    
    call BJDebugMsg("DESELECTION RUN") 
    
    if (u == CityController[pID]) then
        call ShowUnit(u, false) 
        set CurrentSelection[pID] = null
        call BJDebugMsg("DESELECTED CityController")
    elseif (u == CurrentSelection[pID]) then
        set CurrentSelection[pID] = null
        call BJDebugMsg("DESELECTED Town (probably)")
    endif
    
    set u = null
    
    return false
endfunction

//===========================================================================
private function init takes nothing returns nothing
    local trigger t = CreateTrigger()
    set  deselect = t
    call TriggerRegisterPlayerSelectionEventBJ( t, Player(0), false )
    call TriggerRegisterPlayerSelectionEventBJ( t, Player(1), false )
    call TriggerRegisterPlayerSelectionEventBJ( t, Player(2), false )
    call TriggerRegisterPlayerSelectionEventBJ( t, Player(3), false )
    call TriggerRegisterPlayerSelectionEventBJ( t, Player(4), false )
    call TriggerRegisterPlayerSelectionEventBJ( t, Player(5), false )
    call TriggerRegisterPlayerSelectionEventBJ( t, Player(6), false )
    call TriggerRegisterPlayerSelectionEventBJ( t, Player(7), false )
    call TriggerRegisterPlayerSelectionEventBJ( t, Player(8), false )
    call TriggerRegisterPlayerSelectionEventBJ( t, Player(9), false )
    call TriggerRegisterPlayerSelectionEventBJ( t, Player(10), false )
    call TriggerRegisterPlayerSelectionEventBJ( t, Player(11), false )
    call TriggerAddCondition( t, Condition( function Deselection) ) 
    set t = null
endfunction

endlibrary

I tried to make so the deselection trigger not run while the player is selecting a City, but sadly to no avail. It still prints "DESELECTION RUN". I though I disabled the trigger? :>
 
Last edited:
Level 12
Joined
Feb 22, 2010
Messages
1,115
Because when you use SetUnitPosition, it gives an order to moved unit.(This order is the reason why units moved via SetUnitPosition is get stunned/paused/interrupted)
 
Level 15
Joined
Aug 7, 2013
Messages
1,338
Because when you use SetUnitPosition, it gives an order to moved unit.(This order is the reason why units moved via SetUnitPosition is get stunned/paused/interrupted)

How to stun/pause/interrupt a unit without a spell? Is there a native? I've tried doing Issue Immediate Order - Stop, but that doesn't work.
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
How to stun/pause/interrupt a unit without a spell? Is there a native? I've tried doing Issue Immediate Order - Stop, but that doesn't work.

What kind of interruption you need, what is the problem exactly, issue Immediate stop order should work.
 
Level 15
Joined
Nov 30, 2007
Messages
1,202
Changed problem in topic. :ogre_rage:

Nvm. Added this code to check for Cities deselected (don't want that) instead of enable/disable trigger.

JASS:
    loop
        exitwhen CityType[i] == null 
        if (GetUnitTypeId(u) == CityType[i]) then
            set TownNotDeselected = false
        endif
        set i = i + 1
    endloop
    
    if (TownNotDeselected == true) then

    // rest...
 
Last edited:
How to stun/pause/interrupt a unit without a spell? Is there a native? I've tried doing Issue Immediate Order - Stop, but that doesn't work.
Have you tried:
JASS:
call PauseUnit (u,true)
call IssueImmediateOrder(u, "stop")
call PauseUnit (u,false)

@Pinzu, hm thats odd. What happens if you start a 0-timeout timer that Enables the trigger again instead of doing so directly in same thread.
 
Status
Not open for further replies.
Top