Can't compare players using ==?

Evan1993

Ultra Cool Member
Reaction score
30
Why doesn't this work? You can compare players using == right?
Code:
function Trig_Retire_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'ANtm' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Retire_Actions takes nothing returns nothing
    local unit a
    local player p = GetOwningPlayer(GetSpellTargetUnit())
    set a = GetSpellTargetUnit()
    call UnitRemoveAbilityBJ( 'AInv', a )
    call UnitRemoveAbilityBJ( 'A00K', a )
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 12
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        if p == udg_Player[GetForLoopIndexA()] ) ) then
            set udg_Numb[1] = GetUnitUserData(GetSpellTargetUnit())
            call AdjustPlayerStateBJ( udg_Numb[1], udg_Player[GetForLoopIndexA()], PLAYER_STATE_RESOURCE_GOLD )
        else
        endif
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
    call PolledWait( 3.00 )
    call RemoveUnit( a )
endfunction


//===========================================================================
function InitTrig_Retire takes nothing returns nothing
    set gg_trg_Retire = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Retire, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Retire, EVENT_PLAYER_UNIT_SPELL_FINISH )
    call TriggerAddCondition( gg_trg_Retire, Condition( function Trig_Retire_Conditions ) )
    call TriggerAddAction( gg_trg_Retire, function Trig_Retire_Actions )
endfunction
 
N

no0by

Guest
Code:
        if p == udg_Player[GetForLoopIndexA()] [COLOR="Red"]) )[/COLOR] then

Theres you're error you have two brackets at the end but they dont enclose anything:
Code:
    if [COLOR="Blue"]([/COLOR] Player(0)==Player(1) [COLOR="blue"])[/COLOR] then
 

Doomhammer

Bob Kotick - Gamers' corporate spoilsport No. 1
Reaction score
67
Code:
function Trig_Retire_Conditions takes nothing returns boolean
    return (GetSpellAbilityId()=='ANtm') //more compact, faster to compile
endfunction

function Trig_Retire_Actions takes nothing returns nothing
    local unit a=GetSpellTargetUnit()
    local player p=GetOwningPlayer(a)
    local integer i=1  //use local integer instead of bj_forLoopAIndex
    call UnitRemoveAbility(a,'AInv') //use native instead of BJ "UnitRemoveAbilityBJ"
    call UnitRemoveAbility(a,'A00K') //same
    loop
        exitwhen (i>12)
        if (p==udg_Player[i]) then
            set udg_Numb[1]=GetUnitUserData(a) //make use of declared variables
            call SetPlayerState(udg_Player[i], PLAYER_STATE_RESOURCE_GOLD, udg_Numb[1]) //SetPlayerState is A LOT faster than what you had
        endif  //if no actions for "else", then it's not needed
        set i=i+1
    endloop
    call PolledWait(3.0)
    call RemoveUnit(a)
    set a=null //nullify to prevent leaks
    set p=null
endfunction

function InitTrig_Retire takes nothing returns nothing
    set gg_trg_Retire = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Retire, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Retire, EVENT_PLAYER_UNIT_SPELL_FINISH )
    call TriggerAddCondition( gg_trg_Retire, Condition( function Trig_Retire_Conditions ) )
    call TriggerAddAction( gg_trg_Retire, function Trig_Retire_Actions )
endfunction

looks like you have just started learning jass, so I thought I might help you along learn a bit more, i.e. how to write things more efficient; I haven't checked my version for flaws, but in overall it should be fine, at least to get an idea of where you can write things more efficiently. I'm sure you can optimize a lot more, once you really know exactly what you want. Check out my //comment; and get sth like Jass Shop Pro (download @ http://www.wc3sear.ch/files/downloads.php?ID=76&l=6) or other prog to help you write your lines.
 

Chocobo

White-Flower
Reaction score
409
Code:
function Trig_Retire_Conditions takes nothing returns boolean
    return (GetSpellAbilityId()=='ANtm')
endfunction

function Trig_Retire_Actions takes nothing returns nothing
    local unit a=GetSpellTargetUnit()
    local player p=GetOwningPlayer(a)
    local integer i
    call UnitRemoveAbility(a,'AInv')
    call UnitRemoveAbility(a,'A00K')
    loop
        exitwhen (i>12)
        if p==udg_Player[i] then
            set udg_Numb[1]=GetUnitUserData(a)
            call SetPlayerState(udg_Player[i], PLAYER_STATE_RESOURCE_GOLD, udg_Numb[1])
        endif
        set i=i+1
    endloop
    call PolledWait(3)
    call RemoveUnit(a)
    set a=null
    set p=null
endfunction

function InitTrig_Retire takes nothing returns nothing
    set gg_trg_Retire=CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Retire,ConvertPlayerUnitEvent(273))
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Retire,ConvertPlayerUnitEvent(275))
    call TriggerAddCondition(gg_trg_Retire,Condition(function Trig_Retire_Conditions))
    call TriggerAddAction(gg_trg_Retire,function Trig_Retire_Actions)
endfunction

Works fine, normally. A loop from 1 to 12.. wtf? Player 2 to 13.

Code:
function Trig_Retire_Conditions takes nothing returns boolean
    return (GetSpellAbilityId()=='ANtm')
endfunction

function Trig_Retire_Actions takes nothing returns nothing
    local unit a=GetSpellTargetUnit()
    local player p=GetOwningPlayer(a)
    local integer i=0
    call UnitRemoveAbility(a,'AInv')
    call UnitRemoveAbility(a,'A00K')
    loop
        exitwhen (i>11)
        if p==udg_Player[i] then
            set udg_Numb[1]=GetUnitUserData(a)
            call SetPlayerState(udg_Player[i], PLAYER_STATE_RESOURCE_GOLD, udg_Numb[1])
        endif
        set i=i+1
    endloop
    call PolledWait(3)
    call RemoveUnit(a)
    set a=null
    set p=null
endfunction

function InitTrig_Retire takes nothing returns nothing
    set gg_trg_Retire=CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Retire,ConvertPlayerUnitEvent(273))
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Retire,ConvertPlayerUnitEvent(275))
    call TriggerAddCondition(gg_trg_Retire,Condition(function Trig_Retire_Conditions))
    call TriggerAddAction(gg_trg_Retire,function Trig_Retire_Actions)
endfunction

This solves the problem of 1 error.
 

Doomhammer

Bob Kotick - Gamers' corporate spoilsport No. 1
Reaction score
67
yep, one of the few tiny things I forgot :rolleyes:
anywhoo, hope you got the idea of writing more efficient than GUI
btw, in your case there seems to be no need to have a udg_player[] global player array; that's what you have a native for:
Code:
constant native Player takes integer number returns player
e.g. Player(0) equals Player 1, red, Player(1) equals Player 2, blue, and so on.
that can come handy for triggers with multiple events, such as a chat message in my little example:

Code:
function InitTrig_BOnOff takes nothing returns nothing
    local integer i=0
    set gg_trg_BOnOff = CreateTrigger( )
    loop
        exitwhen (i>7)
        call TriggerRegisterPlayerChatEvent( gg_trg_BOnOff, Player(i), "-bounty", true )
        set i=i+1
    endloop
    call TriggerAddAction( gg_trg_BOnOff, function Trig_BOnOff_Actions )
endfunction

if you tell me a bit more about your thingy, especially what your numb-variable does, then we could optimize it even a bit further.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top