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

[JASS] Spell Problem

Status
Not open for further replies.
Level 7
Joined
Jul 9, 2008
Messages
253
Hello everybody, I got another problem with a spell I tried to make. Basicly it should do a triggered Entangling Roots, but it gets an error when I try to save or test the map. Although turning the trigger on, doesn't.

Please tell me what I did wrong, and what I need to improve.

Trigger:

JASS:
// Spell ID //

constant function Entangling_ID takes nothing returns integer
    return 'A00D'
endfunction

// Constant Damage //

constant function Entangling_Constant_Factor takes nothing returns real
    return 0.8
endfunction

// Level Damage //

constant function Entangling_Level_Factor takes nothing returns real
    return 0.2
endfunction 

// Duration //

constant function Entangling_Duration takes nothing returns integer
    return 5
endfunction

// Dummy ID //

constant function Dummy_ID takes nothing returns integer
    return 'h004'
endfunction

// Dummy Model //

constant function Dummy_Model takes nothing returns string
    return "Abilities\\Spells\\NightElf\\EntanglingRoots\\EntanglingRootsTarget.mdl"
endfunction

// Dummy Size //

constant function Dummy_Size takes nothing returns real
    return 1.6
endfunction

// Spell Condition //

function Trig_Entangling_Vines_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == Entangling_ID()
endfunction

function Trig_Entangling_Vines_Actions takes nothing returns nothing
    local unit caster = GetTriggerUnit()
    local unit target = GetSpellTargetUnit()
    local player p = GetOwningPlayer( caster )
    local integer level = GetUnitAbilityLevelSwapped( Entangling_ID() , caster )
    local real x = GetUnitX( target )
    local real y = GetUnitY( target )
    local real facing = GetUnitFacing( caster )
    local integer i = 0
    local unit u
    local integer int = GetHeroInt( caster , true )
    local effect model
    //
    set u = CreateUnit( p , Dummy_ID() , x , y , facing )
    call SetUnitScale( u , Dummy_Size() , Dummy_Size() , Dummy_Size() )
    set model = AddSpecialEffectTarget( Dummy_Model() , u , "origin" )
    //
    loop
        if i == Entangling_Duration() then
            call RemoveUnit( u )
            call DestroyEffect( model )
        endif
        exitwhen i == Entangling_Duration()
        if GetUnitState( target , UNIT_STATE_LIFE ) > 0 then
            call UnitDamageTarget( caster , u , ( int * ( Entangling_Constant_Factor() + ( Entangling_Level_Factor() * I2R( level ) ) ) ) , true , false , ATTACK_TYPE_CHAOS , DAMAGE_TYPE_NORMAL , WEAPON_TYPE_WHOKNOWS ) 
        else
            call RemoveUnit( u )
            call DestroyEffect( model )
        endif
        call PolledWait( 1. )
        set i = i + 1
    endloop
    //Actions//
    set caster = null
    set target = null
    set p = null
    set u = null
    set model = null
endfunction
        
function AntiLeaker takes nothing returns boolean
    return true
endfunction

//===========================================================================
function InitTrig_Entangling_Vines takes nothing returns nothing
    local trigger t = CreateTrigger( )
    local filterfunc f = Filter( function AntiLeaker )
    local integer i = 0
    loop
        call TriggerRegisterPlayerUnitEvent( t, Player( i ) , EVENT_PLAYER_UNIT_SPELL_EFFECT , f )
        set i = i + 1
        exitwhen i == 16
    endloop
    call TriggerAddCondition( t , Condition( function Trig_Entangling_Vines_Conditions ) )
    call TriggerAddAction( t , function Trig_Entangling_Vines_Actions )
    call DestroyFilter( f )
    set f = null
    set t = null
endfunction

Thanks in advance, Quetzalcotl
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
JASS:
    local trigger t = CreateTrigger( )
    local filterfunc f = Filter( function AntiLeaker )
    local integer i = 0
    loop
        call TriggerRegisterPlayerUnitEvent( t, Player( i ) , EVENT_PLAYER_UNIT_SPELL_EFFECT , f )
        set i = i + 1
        exitwhen i == 16
    endloop
    call TriggerAddCondition( t , Condition( function Trig_Entangling_Vines_Conditions ) )
    call TriggerAddAction( t , function Trig_Entangling_Vines_Actions )
    call DestroyFilter( f )
    set f = null
    set t = null

This is probably going to give you an error or two.

JASS:
    local trigger t=CreateTrigger()
    local integer i=0
        loop
            exitwhen (i==16)
            call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
            set i =i+1
        endloop
        call TriggerAddCondition(t, Filter(function ...))
        call TriggerAddAction(t, function ...)

There is no real need (or benefit) of nulling your handles in the initializer function. These variables are only all0cated once so the memory leak is ignorable. The "Anti Leak" function is also useless, since blizzard fixed these kinds of memory leaks (I believe). I don't think that 'null' boolexprs leak anymore.

YourNameHere said:
What error on which line do you get?

Yes, this would help.
 
Level 7
Joined
Jul 9, 2008
Messages
253
Okey so I tried to save it again and it worked, so I tried to test it, but the map didn't load and just started warcraft 3.

Edit: That's odd, when I did what Berbanog said it worked, which is weird because I have the same event for one of my spells.

Well thank you all for helping

P.S. Is there a different way to check if a unit has a specific buff other than UnitHasBuffBJ?
 
Last edited:
Status
Not open for further replies.
Top