Victory trigger doesn't work for computer player, why ?

chango

New Member
Reaction score
1
Hi, sorry for my bad english but i m from chile :D

well, this is the problem:

my map is a very simple hero arena, and i have a trigger to check the kills of every player but computer doesn't win only the user players do :s.

I m new in world editor and jass so maybe there is a stupid mistake.

here is the trigger:

JASS:
function Trig_CheckeandoMuertes_Conditions takes nothing returns boolean
    return GetOwningPlayer(GetTriggerUnit()) != GetOwningPlayer(GetKillingUnitBJ())
    return IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO)
    return true
endfunction

function Trig_CheckeandoMuertes_Func004Func001Func004A takes nothing returns nothing
    if ( GetEnumPlayer() != udg_ganador ) then
        call CustomDefeatBJ( GetEnumPlayer(), "TRIGSTR_039" )
    endif
endfunction

function Trig_CheckeandoMuertes_Actions takes nothing returns nothing
    local force jugadores = GetPlayersAll()
    set udg_kills[GetConvertedPlayerId(GetOwningPlayer(GetKillingUnitBJ()))] = ( udg_kills[GetConvertedPlayerId(GetOwningPlayer(GetKillingUnitBJ()))] + 1 )
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 12
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        if ( udg_kills[GetForLoopIndexA()] >= 2 ) then
            set udg_ganador = ConvertedPlayer(GetForLoopIndexA())
            call CustomVictoryBJ( udg_ganador, true, true )
            call ForForce( jugadores, function Trig_CheckeandoMuertes_Func004Func001Func004A )
        endif
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
    call DestroyForce(jugadores)
endfunction

//===========================================================================
function InitTrig_CheckeandoMuertes takes nothing returns nothing
    set gg_trg_CheckeandoMuertes = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_CheckeandoMuertes, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_CheckeandoMuertes, Condition( function Trig_CheckeandoMuertes_Conditions ) )
    call TriggerAddAction( gg_trg_CheckeandoMuertes, function Trig_CheckeandoMuertes_Actions )
endfunction


Thanks.
 

chango

New Member
Reaction score
1
Maybe is the CustomDefeatBJ the problem ??

It's posibly that the problem is in the Defeat function?. So the computer player actually won, but since i am not Defeated i don't realize that?

Also i found a stupid mistake in the condition :eek: the correct function is this:

JASS:
function Trig_CheckeandoMuertes_Conditions takes nothing returns boolean
    return ( GetOwningPlayer(GetTriggerUnit()) != GetOwningPlayer(GetKillingUnitBJ()) and IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) )
endfunction


becouse with the old function I was wining killing neutral creeps :D

Thanks.
 

chango

New Member
Reaction score
1
Yes is the defeat function the problem

I instaled de W3 in a second comp and i tested and even when some player won the others players are not defeated so there is a problem with the ForForce or the custom defeat, but i don't know why is not working :(

Any sugestions ?

Please :banghead:
 

Builder Bob

Live free or don't
Reaction score
249
First of all, I don't really understand how the trigger is supposed to work. It really looks strange to me. If a player gets two or more hero kills he will win, and everyone else will lose. Why even bother with the loop if that is the intended function.

Are you trying to let everyone have two lives instead? If you describe what is supposed to happen I can try to help you.


There is one thing I can help you with right away though.

replace this
JASS:
    local force jugadores = GetPlayersAll()
    (...)
            call ForForce( jugadores, function Trig_CheckeandoMuertes_Func004Func001Func004A )
    (...)
    call DestroyForce(jugadores)
with this
JASS:
    (...)
            call ForForce( bj_FORCE_ALL_PLAYERS, function Trig_CheckeandoMuertes_Func004Func001Func004A )
    (...)


This is because GetPlayersAll() returns bj_FORCE_ALL_PLAYERS, which is a global force created at map start. By destroying the force, GetPlayersAll() will return null the next times you call it.
 

chango

New Member
Reaction score
1
Thanks, but that was not the problem.

I thought that every call to the function GetPlayersAll() create a new force so I destroyed to prevent memory leaks.

Anyway i replace the ForForce call with a loop for 1 to 12 and now it works properly.

The map is a hero arena, so when someone get X kills win the game, I use just 2 to test the trigger faster but it will be a variable so it can be configured by the host at the beginning.

Here is the trigger finished maybe can be useful to someone:

JASS:
function Trig_CheckeandoMuertes_Conditions takes nothing returns boolean
    return ( GetOwningPlayer(GetTriggerUnit()) != GetOwningPlayer(GetKillingUnitBJ()) and IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) )
endfunction

function Trig_CheckeandoMuertes_Actions takes nothing returns nothing
    local integer indexJugadores = 1
    local integer indexJugadoresFinal = 12
    set udg_kills[GetConvertedPlayerId(GetOwningPlayer(GetKillingUnitBJ()))] = ( udg_kills[GetConvertedPlayerId(GetOwningPlayer(GetKillingUnitBJ()))] + 1 )
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 12
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        if ( udg_kills[GetForLoopIndexA()] >= 2 ) then
            set udg_ganador = ConvertedPlayer(GetForLoopIndexA())
            call CustomVictoryBJ( udg_ganador, true, true )
            loop
                exitwhen indexJugadores > indexJugadoresFinal
                if ( GetForLoopIndexA() != indexJugadores ) then
                    call CustomDefeatBJ( ConvertedPlayer(indexJugadores), "TRIGSTR_039" )
                endif
                set indexJugadores = indexJugadores + 1
            endloop
        endif
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
endfunction

//===========================================================================
function InitTrig_CheckeandoMuertes takes nothing returns nothing
    set gg_trg_CheckeandoMuertes = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_CheckeandoMuertes, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_CheckeandoMuertes, Condition( function Trig_CheckeandoMuertes_Conditions ) )
    call TriggerAddAction( gg_trg_CheckeandoMuertes, function Trig_CheckeandoMuertes_Actions )
endfunction


Sorry again for my bad english :S

Thanks.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top