• 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.

[JASS] sells trigger not working

Status
Not open for further replies.
hello i have a problem w my sells trigger i think im missing something can anyone help me w y this isnt working the right way ? thx

JASS:
function Trig_Sell_Towers_Conditions takes nothing returns boolean
    if GetSpellAbilityId() == 'A003' then
        return true
    else
        return false
    endif
endfunction

function Trig_Sell_Towers_Actions takes nothing returns nothing
    local effect sfx
    local integer p = GetPlayerId( GetTriggerPlayer() )
    local unit u = GetTriggerUnit()
    local real x = GetUnitX( u )
    local real y = GetUnitY( u )
    local integer v = GetUnitPointValue( u )
    set sfx = AddSpecialEffect( "Units\\Demon\\Infernal\\InfernalBirth.mdl", x, y )
    call SetPlayerState( Player(p), PLAYER_STATE_RESOURCE_GOLD, (GetPlayerState( Player(p), PLAYER_STATE_RESOURCE_GOLD ) + v) )
    //set sfx = AddSpecialEffectTargetUnitBJ( "overhead", u, "Units\\Demon\\Infernal\\InfernalBirth.mdl" )
    call PolledWait( 1.50 )
    call RemoveUnit( u )
    call DestroyEffect( sfx )
    set sfx = null
    set u = null
endfunction

//===========================================================================
function InitTrig_Sell_Towers takes nothing returns nothing
    local trigger t
    local integer L = 0
    set t = CreateTrigger()
    loop
        exitwhen L > 11
        call TriggerRegisterPlayerUnitEvent( t, Player(L), EVENT_PLAYER_UNIT_SPELL_CAST, Condition( function Trig_Sell_Towers_Conditions ) )
        set L = L + 1
    endloop
    call TriggerAddAction( t, function Trig_Sell_Towers_Actions )
    set t = null
endfunction
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
For variable types that have a destroy function - like locations, groups and forces - you just need to use that function.

No, you still need to null them to prevent leaks.

The condition function can just return GetSpellAbilityId() == 'A003'

What does the trigger do, how does it bug? Use call BJDebugMsg("string") to debug it.
 
Level 16
Joined
Dec 15, 2011
Messages
1,423
Some optimizations for your code

JASS:
function Trig_Sell_Towers_Conditions takes nothing returns boolean
    if GetSpellAbilityId() == 'A003' then
        return true
    else
        return false
    endif
endfunction

function Trig_Sell_Towers_Actions takes nothing returns nothing
    local effect sfx
    local integer p = GetPlayerId( GetTriggerPlayer() )
    local unit u = GetTriggerUnit()
    local real x = GetUnitX( u )
    local real y = GetUnitY( u )
    local integer v = GetUnitPointValue( u )
    set sfx = AddSpecialEffect( "Units\\Demon\\Infernal\\InfernalBirth.mdl", x, y )
    call SetPlayerState( Player(p), PLAYER_STATE_RESOURCE_GOLD, (GetPlayerState( Player(p), PLAYER_STATE_RESOURCE_GOLD ) + v) )
    //set sfx = AddSpecialEffectTargetUnitBJ( "overhead", u, "Units\\Demon\\Infernal\\InfernalBirth.mdl" )
    call PolledWait( 1.50 )
    call RemoveUnit( u )
    call DestroyEffect( sfx )
    set sfx = null
    set u = null
endfunction

//===========================================================================
function InitTrig_Sell_Towers takes nothing returns nothing
    local trigger t
    local integer L = 0
    set t = CreateTrigger()
    loop
        exitwhen L > 11
        call TriggerRegisterPlayerUnitEvent( t, Player(L), EVENT_PLAYER_UNIT_SPELL_CAST, Condition( function Trig_Sell_Towers_Conditions ) )
        set L = L + 1
    endloop
    call TriggerAddAction( t, function Trig_Sell_Towers_Actions )
    set t = null
endfunction

->

JASS:
function Trig_Sell_Towers_Conditions takes nothing returns boolean
    local integer p
    local unit u

    if GetSpellAbilityId() == 'A003' then
        set p = GetPlayerId( GetTriggerPlayer() )
        set u = GetTriggerUnit()
        call SetPlayerState( Player(p), PLAYER_STATE_RESOURCE_GOLD, (GetPlayerState( Player(p), PLAYER_STATE_RESOURCE_GOLD ) + GetUnitPointValue( u )) )
        //set sfx = AddSpecialEffectTargetUnitBJ( "overhead", u, "Units\\Demon\\Infernal\\InfernalBirth.mdl" )
        call DestroyEffect( AddSpecialEffect( "Units\\Demon\\Infernal\\InfernalBirth.mdl", GetUnitX(u), GetUnitY(u) ) )
        call PolledWait( 1.50 )
        call RemoveUnit( u )

        set u = null
    endif
    return false
endfunction

//===========================================================================
function InitTrig_Sell_Towers takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t, Condition( function Trig_Sell_Towers_Conditions ) )
    set t = null
endfunction

TriggerRegisterAnyUnitEventBJ isn't a bad BJ anymore. Give it a second chance :p

Another side note: EVENT_PLAYER_UNIT_SPELL_EFFECT is more common because it is only fired when the spell actually goes into effect, rather than begins casting (which in some case is needed and we have to use EVENT_PLAYER_UNIT_SPELL_CAST)

@rulerofiron99: some local types aren't cleared after removal :p
 
Last edited:
Level 23
Joined
Apr 16, 2012
Messages
4,041
Doomlord sorry, that would never remove and null the unit
if you call Wait or PolledWait in TriggerCondition block, it will crash the running thread immedietally so your code leaks like a truck basically

to be correct, you must null all variables that are of type agent when you are done with them(almost everything except TextTag, UberSplat, Lightning) because there is shitty reference counter, which wont allow the HandleId to be recyclied
only time you dont need to null them is if they dont have any value assigned to them
 
i got it to work by doing this
i also know its not mui yet i just need it to work ill make it mui soon i hope lol
JASS:
function InitTrig_Sell_Towers takes nothing returns nothing
    local trigger t
    local integer L = 0
    set t = CreateTrigger()
    loop
        exitwhen L > 11
        call TriggerRegisterPlayerUnitEvent( t, Player(L), EVENT_PLAYER_UNIT_SPELL_CAST, Condition( function Trig_Sell_Towers_Conditions ) )
        set L = L + 1
    endloop
    call TriggerAddAction( t, function Trig_Sell_Towers_Actions )
    set t = null
endfunction

to this
JASS:
function InitTrig_Sell_Towers takes nothing returns nothing
    local trigger t
    local integer L = 0
    set t = CreateTrigger()
    call TriggerAddCondition( t, Condition( function Trig_Sell_Towers_Conditions ) )
    loop
        exitwhen L > 11
        call TriggerRegisterPlayerUnitEvent( t, Player(L), EVENT_PLAYER_UNIT_SPELL_CAST, null )
        set L = L + 1
    endloop
    call TriggerAddAction( t, function Trig_Sell_Towers_Actions )
    set t = null
endfunction

any reason y i cant use the boolexpr on this one ?
JASS:
call TriggerRegisterPlayerUnitEvent( t, Player(L), EVENT_PLAYER_UNIT_SPELL_CAST, null )

thx for ur help
 
Last edited:
Level 23
Joined
Apr 16, 2012
Messages
4,041
No caching = no nulling. This doesn't relate to your wait in any way. In addition, unless you use an artificial wait, your spell won't be MUI.

Im saying your trigger shortened the code by 5 lines and using wait in triggercondition will crash the thread so anything after the wait will not run anymore
Why wouldnt it work, as long as you have local variables it will work with any kind of wait in triggeraction block, it will be inaccurate

and the nulling has nothing to do with what I said with wait
why isnt this mui? Its mui, it would not be mui if you used wait and global variables, its just inefficient
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
actually, using local and wait is MUI, its only a little bit inaccurate because Wait is never exactly as long as you want it but a very little bit longer.
Better way would be using hashtable and a timer, but if you never worked with such stuff you should read about them. But this is not so advanced spell or w/e to go to this concept
 
Status
Not open for further replies.
Top