HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Why does this not work/crashes

03-01-2007, 10:28 PM#1
Joker
Collapse JASS:
//************************************************************************//
//           Constant Function (acts like global variables)               //
//************************************************************************//

constant function Trig_Needle_Bomb_AbilityId takes nothing returns integer
    return 'A00E'
endfunction

constant function Trig_Needle_Bomb_DummyId takes nothing returns integer
    return 'o001'
endfunction

constant function Trig_Needle_Bomb_ArrowId takes nothing returns integer
    return 'o003'
endfunction

//************************************************************************//
//                        Spell Functions                                 //
//************************************************************************//

function Trig_Needle_Bomb_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == Trig_Needle_Bomb_AbilityId()
endfunction

function Trig_Needle_Bomb_Effect_Condition takes nothing returns boolean
    return IsUnitType( GetFilterUnit(), UNIT_TYPE_STRUCTURE) == false
endfunction        

function Trig_Needle_Bomb_Effect_Core takes timer t returns nothing
    local unit a = GetHandleUnit( t, "caster" )
    local integer lvl = GetUnitAbilityLevel( a, Trig_Needle_Bomb_AbilityId() )
    local real tx = GetLocationX( GetHandleLoc( t, "targetloc" ) )
    local real ty = GetLocationY( GetHandleLoc( t, "targetloc" ) )
    local real tt
    local real f
    local unit d = GetHandleUnit( t, "bomb" )
    local unit b
    local unit ff
    local real bx
    local real by
    local group g = CreateGroup()
    local boolexpr bb = Condition( function Trig_Needle_Bomb_Effect_Condition )
        
    set GetHandleReal( t, "facing" ) = GetHandleReal( t, "facing" ) + 10
    set GetHandleReal( t, "Timer" ) = GetHandleReal( t, "Timer" ) + 0.1
    set tt = GetHandleReal( t, "Timer" )
    set f = GetHandleReal( t, "facing" )
    set b = CreateUnit( GetOwningPlayer(a), Trig_Needle_Bomb_ArrowId(), tx, ty, f )
    set bx = GetUnitX(bx)
    set by = GetUnitY(by)
    
    if tt < 2 then
        call SetUnitPosition( b, tx + 25 * Cos(f * bj_DEGTORAD), ty + 25 * Sin(f * bj_DEGTORAD) )
        call GroupEnumUnitsInRange( g, bx, by, 60, bb )
                
        if IsUnitEnemy( ff, GetOwningPlayer(a) ) == true then
            loop
                set ff = FirstOfGroup(g) 
                exitwhen ff == null
                call DestroyEffect( AddSpecialEffect( "Objects\Spawnmodels\Other\BeastmasterBlood\BeastmasterBlood.mdl", bx, by )
                call UnitDamageTarget( b, ff, lvl * 25,  false, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_MAGIC, WEAPON_TYPE_WHOKNOWS )
                call GroupRemoveUnit( g, ff )
            endloop
        endif            
             
    else
        call RemoveUnit(d)
        call RemoveUnit(b)
        call PauseTimer(t)
        call DestroyTimer(t)
        call FlushHandleLocals(t)
    endif
    
    call DestroyGroup(g)
    call DestroyBoolExpr(bb)
    set a = null
    set d = null
    set b = null
    set ff = null
    set g = null
    set bb = null
endfunction    

function Trig_Needle_Bomb_Effect takes nothing returns nothing
    call Trig_Needle_Bomb_Effect_Core( GetExpiredTimer() )
endfunction

function Trig_Needle_Bomb_Actions_Core takes timer t returns nothing
    local location l = GetSpellTargetLoc()
    local real lx = GetLocationX(l)
    local real ly = GetLocationY(l)
    
    call SetHandleHandle( t, "caster", GetSpellAbilityUnit() )
    call SetHandleHandle( t, "bomb", CreateUnit( GetOwningPlayer(GetSpellAbilityUnit()), Trig_Needle_Bomb_DummyId(), lx, ly, 0 ) )
    call SetHandleHandle( t, "targetloc", l )
    call SetHandleReal( t, "Timer", 1 )
    call SetHandleReal( t, "facing", 0 )

    call TimerStart( t, 3 - GetHandleReal( t, "Timer" ), true, function Trig_Needle_Bomb_Effect )
    
    //call RemoveLocation(l)
    set l = null
endfunction


function Trig_Needle_Bomb_Actions takes nothing returns nothing
    call TriggerSleepAction( 4.4 )
    call Trig_Needle_Bomb_Actions_Core( CreateTimer() )
endfunction

//===========================================================================
function InitTrig_Needle_Bomb takes nothing returns nothing
    set gg_trg_Needle_Bomb = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Needle_Bomb, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Needle_Bomb, Condition( function Trig_Needle_Bomb_Conditions ) )
    call TriggerAddAction( gg_trg_Needle_Bomb, function Trig_Needle_Bomb_Actions )
    call Preload( "Objects\Spawnmodels\Other\BeastmasterBlood\BeastmasterBlood.mdl" )
endfunction


This is supposed to create a ball at the target, then arrows starts shooting out. Something like this:


but instead, this crashes (most likely from the loop), what am i doing wrong?
03-01-2007, 11:53 PM#2
WNxCryptic
Collapse JASS:
            loop
                set ff = FirstOfGroup(g) 
                exitwhen ff == null
                call DestroyEffect( AddSpecialEffect( "Objects\Spawnmodels\Other\BeastmasterBlood\BeastmasterBlood.mdl", bx, by )
                call UnitDamageTarget( b, ff, lvl * 25,  false, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_MAGIC, WEAPON_TYPE_WHOKNOWS )
            endloop

Executes an infinite loop, that's probably part of the issue in question.
03-02-2007, 12:06 AM#3
Joker
Ok, i added a GroupRemoveUnit to fix that. Now, all that happens is that the
Collapse JASS:
call SetHandleHandle( t, "bomb", CreateUnit( GetOwningPlayer(GetSpellAbilityUnit()), Trig_Needle_Bomb_DummyId(), lx, ly, 0 ) )
gets created at the center of the map instead of the GetSpellTargetLoc() and the arrows do not move after being created.
03-02-2007, 12:58 AM#4
wantok
One thing I noticed:
Collapse JASS:
local location l = GetSpellTargetLoc()
This is not going to return the correct location since there is no spell cast event that triggers the function it is in.

It will return a location of (0,0) which is probably why your units are spawning in the middle.

There are major problems with the Trig_Needle_Bomb_Effect_Core function. Your arrows don't move because you only move them one time when you create them. Even if you did move them a period of 2 secondsis going to make for some really slow choppy movement. You use the ff variable before you set it.

I changed the first function to pass the location of the spell target and I started to do stuff to the Trig_Needle_Bomb_Effect_Core function but it needs to be completely reworked.
Collapse JASS:
function Trig_Needle_Bomb_Actions_Core takes nothing returns nothing
    local trigger t = GetExpiredTimer()
    local location l = GetHandleLoc(t, "targetloc")
    local real lx = GetLocationX(l)
    local real ly = GetLocationY(l)
    local unit u = GetHandleUnit(t, "caster")
    
    call SetHandleHandle( t, "bomb", CreateUnit( GetOwningPlayer(u), Trig_Needle_Bomb_DummyId(), lx, ly, 0 ) )
    call SetHandleHandle( t, "targetloc", l )
    call SetHandleReal( t, "Timer", 1 )
    call SetHandleReal( t, "facing", 0 )

    call TimerStart( t, 3 - GetHandleReal( t, "Timer" ), true, function Trig_Needle_Bomb_Effect_Core )
    
    //call RemoveLocation(l)
    set l = null
    set u = null
endfunction


function Trig_Needle_Bomb_Actions takes nothing returns nothing
    local timer t = CreateTimer()
    call SetHandleHandle(t, "targetloc", GetSpellTargetLoc())
    call SetHandleHandle( t, "caster", GetSpellAbilityUnit() )

    call TimerStart(t, 4.4, FALSE, function Trig_Needle_Bomb_Actions_Core)
    
endfunction

You need another function to move the arrows and deal damage. When you create an arrow unit in the Trig_Needle_Bomb_Effect_Core function, create another repeating timer and attach all the info needed to move the arrow. Start that timer and make your new function the timer callback function.
03-02-2007, 01:19 AM#5
ixmike88
You can't have "Objects\Spawnmodels\Other\BeastmasterBlood\BeastmasterBlood.mdl" as a string, you must use "\\" instead of '\' in strings.

fix:

Objects\\Spawnmodels\\Other\\BeastmasterBlood\\BeastmasterBlood.mdl