HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Condtions not being evaluated and Actions not being called

02-08-2007, 05:19 AM#1
Pyrogasm
More of the GUI–>JASS rendition of the Nether Mage: part of the conditions for Planar Disruptance are not being evaluated, thus making the trigger fire when units use items. I'm checking if the current order of the unit is < 852008, or > 852013, in order to run the trigger. The trigger runs regardless.

Secondly, none of the actions past the declaration of locals runs in the Defabricate trigger (the commented-out debug message did run, however). The code compiles fine on my JASS Syntax checker, though.

Here they are:
Collapse Planar Disruptance Spell Cast JASS:
function Trig_Planar_Disruptance_Spell_Cast_JASS_Conditions takes nothing returns boolean
    return GetBooleanAnd( GetUnitTypeId(GetTriggerUnit()) != 'u00A', (GetBooleanOr(S2I(OrderId2String(GetUnitCurrentOrder(GetTriggerUnit()))) > 852013, S2I(OrderId2String(GetUnitCurrentOrder(GetTriggerUnit()))) < 852008)) )
endfunction


function Trig_Planar_Disruptance_Spell_Cast_JASS_Actions takes nothing returns nothing
    local unit U = GetTriggerUnit()
    local unit U2
    local real X = GetUnitX(U)
    local real Y = GetUnitY(U)
    local integer I = 0
    local effect SFX
    local integer array Buffs

    set Buffs[1] = 'B00B'
    set Buffs[2] = 'B00C'
    set Buffs[3] = 'B004'
    set Buffs[4] = 'B006'
    set Buffs[5] = 'B009'
    set Buffs[6] = 'B00A'

    loop
        exitwhen I > 3
        set I = I+1
        if UnitHasBuffBJ(U, Buffs[i]) == true then
            set SFX = AddSpecialEffectTarget( "Objects\\Spawnmodels\\Undead\\UDeathSmall\\UDeathSmall.mdl", U, "chest" )
            call SetWidgetLife( U, ( GetWidgetLife(U) + (20.00+(30.00*I)) ) )
            call DestroyEffect(SFX)
        endif
        if UnitHasBuffBJ(U, Buffs[I+3]) == true then
            set U2 = CreateUnit(GetOwningPlayer(U), 'u00A', X, Y, 0)
            call UnitApplyTimedLife(U2, 'BTLF', 1.00)
            call UnitAddAbility(U2, 'A000')
            call SetUnitAbilityLevel(U, 'A000', I)
            call IssueTargetOrder(U2, "banish", U)
        endif
    endloop

    set U = null
    set U2 = null
    set SFX = null
endfunction

//===========================================================================
function InitTrig_Planar_Disruptance_Spell_Cast_JASS takes nothing returns nothing
    set gg_trg_Planar_Disruptance_Spell_Cast_JASS = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Planar_Disruptance_Spell_Cast_JASS, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Planar_Disruptance_Spell_Cast_JASS, Condition( function Trig_Planar_Disruptance_Spell_Cast_JASS_Conditions ) )
    call TriggerAddAction( gg_trg_Planar_Disruptance_Spell_Cast_JASS, function Trig_Planar_Disruptance_Spell_Cast_JASS_Actions )
endfunction
Collapse Defabricate JASS:
function Trig_Defabricate_JASS_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A007'
endfunction

function Ethereal_Filter takes nothing returns boolean
    return IsUnitType(GetFilterUnit(), UNIT_TYPE_ETHEREAL)
endfunction


function Trig_Defabricate_JASS_Actions takes nothing returns nothing
    local unit U = GetTriggerUnit()
    local unit U2
    local unit U3
    local location P = GetSpellTargetLoc()
    local real X = GetLocationX(P)
    local real Y = GetLocationY(P)
    local integer Level = GetUnitAbilityLevel(U, 'A007')
    local group G = CreateGroup()
    local boolexpr B = Condition(function Ethereal_Filter)
    local integer I = 0
    local effect SFX

//    call DisplayTimedTextToPlayer(GetOwningPlayer(U), 0, 0, 60, "("+R2S(X)+", "+R2S(Y)+")")
    call GroupEnumUnitsInRange( G, X, Y, 175.00, B )
    loop
        exitwhen U2 == null
        set U2 = FirstOfGroup(G)
        if IsUnitAlly(U2, GetOwningPlayer(U)) == true then
            set U3 = CreateUnit(GetOwningPlayer(U), 'u00A', X, Y, 0)
            call UnitApplyTimedLife(U3, 'BTLF', 1.00)
            call UnitAddAbility(U3, 'A00G')
            call SetUnitAbilityLevel(U3, 'A00G', Level)
            call IssueTargetOrder(U3, "rejuvination", U2)
        else
            set U3 = CreateUnit(GetOwningPlayer(U), 'u00A', X, Y, 0)
            call UnitApplyTimedLife(U, 'BTLF', 1.00)
            call UnitAddAbility(U3, 'A00H')
            call SetUnitAbilityLevel(U3, 'A00H', Level)
            call IssueTargetOrder(U3, "shadowstrike", U2)
        endif
        call GroupRemoveUnit(G, U2)
    endloop
    set U3 = CreateUnit(GetOwningPlayer(U), 'u00A', X, Y, 0)
    call UnitApplyTimedLife(U3, 'BTLF', 5.00)
    call UnitAddAbility(U3, 'A005')
    call IssuePointOrder(U3, "deathanddecay", X, Y)
    loop
        exitwhen I > 10
        set I = I+1
        set SFX = AddSpecialEffect( "Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl", (X+(GetRandomReal(-175.0, 175.0))), (Y+(GetRandomReal(-175.0, 175.0))) )
        call DestroyEffect(SFX)
        call TriggerSleepAction(0.00)
    endloop

    call DestroyGroup(G)
    call RemoveLocation(P)
    call DestroyBoolExpr(B)
    set G = null
    set U = null
    set U2 = null
    set U3 = null
    set P = null
    set B = null
endfunction


//===========================================================================
function InitTrig_Defabricate_JASS takes nothing returns nothing
    set gg_trg_Defabricate_JASS = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Defabricate_JASS, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Defabricate_JASS, Condition( function Trig_Defabricate_JASS_Conditions ) )
    call TriggerAddAction( gg_trg_Defabricate_JASS, function Trig_Defabricate_JASS_Actions )
endfunction
Another trigger related to Defabricate

You may or may not need this, but here's another trigger related to Defabricate. It runs a periodic check on all units on the map that are not ethereal, and removes the defabricate buffs from them.
Collapse Defabricate Periodic Remove JASS:
function Periodic_Ethereal_Filter takes nothing returns boolean
    return IsUnitType(GetFilterUnit(), UNIT_TYPE_ETHEREAL) == false
endfunction


function Trig_Defabricate_Periodic_Remove_JASS_Actions takes nothing returns nothing
    local boolexpr B = Condition(function Periodic_Ethereal_Filter)
    local group G = GetUnitsInRectMatching(GetWorldBounds(), B)
    local unit U

    loop
        set U = FirstOfGroup(G)
        exitwhen U == null
        call UnitRemoveBuffBJ('B005', U)
        call UnitRemoveBuffBJ('B007', U)
        call GroupRemoveUnit(G, U)
    endloop

    call DestroyGroup(G)
    call DestroyBoolExpr(B)
    set U = null
    set G = null
    set B = null
endfunction

//===========================================================================
function InitTrig_Defabricate_Periodic_Remove_JASS takes nothing returns nothing
    set gg_trg_Defabricate_Periodic_Remove_JASS = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Defabricate_Periodic_Remove_JASS, 0.30 )
    call TriggerAddAction( gg_trg_Defabricate_Periodic_Remove_JASS, function Trig_Defabricate_Periodic_Remove_JASS_Actions )
endfunction


02-08-2007, 11:45 AM#2
Rising_Dusk
Planar Disruptance used a couple BJs I worked out.
I also optimized your use of effects, since you didn't have to declare that local at all.
Also, your condition was failing; I rewrote it to work.
See the red.
Collapse JASS:
function Trig_Planar_Disruptance_Spell_Cast_JASS_Conditions takes nothing returns boolean
    return GetUnitTypeId(GetTriggerUnit()) != 'u00A' and (GetUnitCurrentOrder(GetTriggerUnit()) > 852013 or GetUnitCurrentOrder(GetTriggerUnit()) < 852008)
endfunction


function Trig_Planar_Disruptance_Spell_Cast_JASS_Actions takes nothing returns nothing
    local unit U = GetTriggerUnit()
    local unit U2
    local real X = GetUnitX(U)
    local real Y = GetUnitY(U)
    local integer I = 0
    local effect SFX //Doesnt need to be declared now
    local integer array Buffs

    set Buffs[1] = 'B00B'
    set Buffs[2] = 'B00C'
    set Buffs[3] = 'B004'
    set Buffs[4] = 'B006'
    set Buffs[5] = 'B009'
    set Buffs[6] = 'B00A'

    loop
        exitwhen I > 3
        set I = I + 1
        if GetUnitAbilityLevel(U, Buffs[i]) > 0 then
            call DestroyEffect(AddSpecialEffectTarget( "Objects\\Spawnmodels\\Undead\\UDeathSmall\\UDeathSmall.mdl", U, "chest" ))
            call SetWidgetLife( U, ( GetWidgetLife(U) + (20.00+(30.00*I)) ) )
        endif
        if GetUnitAbilityLevel(U, Buffs[I+3]) > 0 then
            set U2 = CreateUnit(GetOwningPlayer(U), 'u00A', X, Y, 0)
            call UnitApplyTimedLife(U2, 'BTLF', 1.00)
            call UnitAddAbility(U2, 'A000')
            call SetUnitAbilityLevel(U, 'A000', I)
            call IssueTargetOrder(U2, "banish", U)
        endif
    endloop


    set U = null
    set U2 = null
    set SFX = null //This is also unnecessary now
endfunction

//===========================================================================
function InitTrig_Planar_Disruptance_Spell_Cast_JASS takes nothing returns nothing
    set gg_trg_Planar_Disruptance_Spell_Cast_JASS = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Planar_Disruptance_Spell_Cast_JASS, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Planar_Disruptance_Spell_Cast_JASS, Condition( function Trig_Planar_Disruptance_Spell_Cast_JASS_Conditions ) )
    call TriggerAddAction( gg_trg_Planar_Disruptance_Spell_Cast_JASS, function Trig_Planar_Disruptance_Spell_Cast_JASS_Actions )
endfunction

For defab, the issue is kinda funny. :P
Note this --
Collapse JASS:
    loop
        exitwhen U2 == null
        set U2 = FirstOfGroup(G)
        //...
And then this --
Collapse JASS:
local unit U2 //Uninitialized
That means as soon as the loop runs it exits because U2 == null.

Try this to make it work --
Collapse JASS:
    loop
        set U2 = FirstOfGroup(G)
        exitwhen U2 == null
        //...
02-09-2007, 01:21 AM#3
Pyrogasm
Allrighty... Defabricate is fixed, but for some reason the conditions for Planar Disruptance are still not being evaluated correctly. A bug, perhaps? I may add that if I set up equivalent conditions in GUI, they are evaluated without a hitch.
02-09-2007, 03:39 AM#4
Pyrogasm
Pardon my double posting, but I've figured out what the problem was: the item I was testing (a tome of knowlege) has an orderid of 0 when used (even if it's used from the inventory as a permanent item, like mine was).

Can anyone explain why this is?
02-09-2007, 12:21 PM#5
Rising_Dusk
An orderid of 0? >_>

It is possible that power up items work differently...
However I doubt it had an order id of 0, that seems very unlikely.

Make sure to display it to the screen you use the following call --
Collapse JASS:
call BJDebugMsg(I2S(GetIssuedOrderId()))
Or in your case...
Collapse JASS:
call BJDebugMsg(I2S(GetUnitCurrentOrder()))
02-10-2007, 12:19 AM#6
Pyrogasm
I meant "Tome of Power", the one that increases your level.

And yes, I'm positive it had an orderid of 0. I put in a debug message; it showed values between 852008 and 852013 for all the item slots except when I used my Tome of Power (I had made it into a permanent item that could be held in the invenotry). When I used it, the string "0" showed up.