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

Select reviving hero only if...

Status
Not open for further replies.
Level 23
Joined
Jun 26, 2020
Messages
1,838
I have these 3 triggers to select a reviving hero (and another things) only if the player doesn't have selected a controllable unit, but they doesn't work fine because it happens even without complying with this rule, what's wrong?

When you select a unit:
vJASS:
function Trig_Para_no_deseleccionar_Actions takes nothing returns nothing
    if GetOwningPlayer(GetTriggerUnit())==GetTriggerPlayer() or GetPlayerAlliance(GetOwningPlayer(GetTriggerUnit()),GetTriggerPlayer(),ALLIANCE_SHARED_CONTROL) then
        set udg_Tengo_a_alguien_seleccionado[GetConvertedPlayerId(GetTriggerPlayer())]=true
    else
        set udg_Tengo_a_alguien_seleccionado[GetConvertedPlayerId(GetTriggerPlayer())]=false
    endif
endfunction

//===========================================================================
function InitTrig_Para_no_deseleccionar takes nothing returns nothing
    local integer i=1
    set gg_trg_Para_no_deseleccionar=CreateTrigger()
    loop
        exitwhen i>11
        if i!=6 then
            call TriggerRegisterPlayerSelectionEventBJ(gg_trg_Para_no_deseleccionar,Player(i),true)
        endif
        set i=i+1
    endloop
    call TriggerAddAction(gg_trg_Para_no_deseleccionar,function Trig_Para_no_deseleccionar_Actions)
endfunction
When you deselect and don't have selected a unit
vJASS:
function Trig_Ya_no_Conditions takes nothing returns boolean
    return IsUnitSelected(null,GetTriggerPlayer())
endfunction

function Trig_Ya_no_Actions takes nothing returns nothing
    set udg_Tengo_a_alguien_seleccionado[GetConvertedPlayerId(GetTriggerPlayer())]=false
endfunction

//===========================================================================
function InitTrig_Ya_no takes nothing returns nothing
    local integer i=1
    set gg_trg_Ya_no=CreateTrigger()
    loop
        exitwhen i>11
        if i!=6 then
            call TriggerRegisterPlayerSelectionEventBJ(gg_trg_Ya_no,Player(i),false)
        endif
        set i=i+1
    endloop
    call TriggerAddCondition(gg_trg_Ya_no,Condition(function Trig_Ya_no_Conditions))
    call TriggerAddAction(gg_trg_Ya_no,function Trig_Ya_no_Actions)
endfunction
The trigger to select the reviving hero:
vJASS:
function Trig_Seleccion_Actions takes nothing returns nothing
    local location l
    local unit h=GetRevivingUnit()
    local player p=GetOwningPlayer(h)
    if not udg_Tengo_a_alguien_seleccionado[GetConvertedPlayerId(p)] then
        if LocalPlayer==p then
            call ClearSelection()
            call SelectUnit(h,true)
        endif
        set l=GetUnitLoc(h)
        call PanCameraToTimedLocForPlayer(p,l,0)
        call RemoveLocation(l)
    else
        call DisplayTextToPlayer(p,0,0,"|cff61dbffYour hero has resurrected|r")
    endif
    set l=null
endfunction

//===========================================================================
function InitTrig_Seleccion takes nothing returns nothing
    set gg_trg_Seleccion=CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Seleccion,EVENT_PLAYER_HERO_REVIVE_FINISH)
    call TriggerAddAction(gg_trg_Seleccion,function Trig_Seleccion_Actions)
endfunction
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,178
In multiplayer selection events require network synchronisation as such there exists a period of time where by the player has a unit locally selected but your selection detection triggers have not yet registered that it is selected. If the hero revives during this time then the player will have their current selection overridden with the revived hero despite having other units locally selected at the time. A similar problem can happen with deselection not yet being synchronised and as such the revived hero not being selected when it should be.

Also make sure that your deselection event is correctly firing when you expect it to. For example, does it fire when the player loses selection of a dead unit?
 
Level 23
Joined
Jun 26, 2020
Messages
1,838
In multiplayer selection events require network synchronisation as such there exists a period of time where by the player has a unit locally selected but your selection detection triggers have not yet registered that it is selected. If the hero revives during this time then the player will have their current selection overridden with the revived hero despite having other units locally selected at the time. A similar problem can happen with deselection not yet being synchronised and as such the revived hero not being selected when it should be.

Also make sure that your deselection event is correctly firing when you expect it to. For example, does it fire when the player loses selection of a dead unit?
Ay, nothing is easy when is about programming in W3, and yes, the problem was the trigger is not fired when the selected unit dies, so I fix that and now works fine, thank you.
 
Status
Not open for further replies.
Top