HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Help with JASS-ed spell

09-30-2006, 06:11 PM#1
zeroXD
I have a spell im experimenting with, it pulls the targeted unit towards the caster with a with a positively axelerating real, then, when it reaches a set location, it will slow down and axelerate negatively untill its somewhere in front of the caster. The problem is, nothing happens when the spell is cast.

Collapse JASS:
function Trig_spell_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A004' ) ) then
        return false
    endif
    return true
endfunction

function Trig_spell_End takes nothing returns nothing
local timer time=GetExpiredTimer()
local unit target=GetHandleUnit( time, "target" )
local unit caster=GetHandleUnit( time, "caster" )
local real angle=GetHandleReal( time, "angle" )
local real dist=GetHandleReal( time, "dist" )
    call SetUnitPosition( target, GetUnitX( target )+dist*Cos( angle ), GetUnitY( target )+dist*Sin( angle ) )
    if ( dist<=0 ) then
        call FlushHandleLocals( time )
        call DestroyTimer( time )
    endif
    call SetHandleReal( time, "dist", dist-0.20 )
set target=null
set caster=null
endfunction

function Trig_spell_Update takes nothing returns nothing
local timer t=GetExpiredTimer()
local timer time=CreateTimer()
local unit target=GetHandleUnit( t, "target" )
local unit caster=GetHandleUnit( t, "caster" )
local real angle=GetHandleReal( t, "angle" )
local real dist=GetHandleReal( t, "dist" )
local real differ=GetHandleReal( t, "differ" )
local location locB=GetUnitLoc( caster )
local location locA=GetUnitLoc( target )
local real diff=DistanceBetweenPoints( locA, locB )
    call SetUnitPosition( target, GetUnitX( target )+dist*Cos( angle ), GetUnitY( target )+dist*Sin( angle ) )
    if ( diff<=differ ) then
        call DestroyTimer( t )
        call FlushHandleLocals( t )
        call SetHandleReal( time, "dist", dist )
        call SetHandleHandle( time, "target", target )
        call SetHandleHandle( time, "caster", caster )
        call SetHandleReal( time, "angle", angle )
        call TimerStart( time, 0.033, true, function Trig_spell_End )
    endif
    call SetHandleReal( t, "dist", dist+0.20 )
    call RemoveLocation( locA )
    call RemoveLocation( locB )
set target=null
set caster=null
endfunction

function Trig_spell_Actions takes nothing returns nothing
local timer t=CreateTimer()
local unit target=GetSpellTargetUnit()
local unit caster=GetTriggerUnit()
local real dist=0
local location locA=GetUnitLoc( target )
local location locB=GetUnitLoc( caster )
local real angle=AngleBetweenPoints( locA, locB )
local real differ=DistanceBetweenPoints( locA, locB )/1.9
    call RemoveLocation( locB )
    call RemoveLocation( locA )
    call SetHandleReal( t, "dist", dist )
    call SetHandleHandle( t, "target", target )
    call SetHandleHandle( t, "caster", caster )
    call SetHandleReal( t, "angle", angle )
    call SetHandleReal( t, "differ", differ )
    call TimerStart( t, 0.033, true, function Trig_spell_Update )
endfunction

//===========================================================================

function InitTrig_spell takes nothing returns nothing
    set gg_trg_testing = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_spell, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_spell, Condition( function Trig_spell_Conditions ) )
    call TriggerAddAction( gg_trg_spell, function Trig_spell_Actions )
endfunction

Help, please.

Thanks
10-02-2006, 04:47 PM#2
Chuckle_Brother
Collapse JASS:
function InitTrig_spell takes nothing returns nothing
    set gg_trg_testing = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_spell, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_spell, Condition( function Trig_spell_Conditions ) )
    call TriggerAddAction( gg_trg_spell, function Trig_spell_Actions )
endfunction

That there is wrong, should be

Collapse JASS:
function InitTrig_spell takes nothing returns nothing
    set gg_trg_spell = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_spell, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_spell, Condition( function Trig_spell_Conditions ) )
    call TriggerAddAction( gg_trg_spell, function Trig_spell_Actions )
endfunction

May be other errors, but I am betting on that being your main issue.
10-02-2006, 05:19 PM#3
zeroXD
Oh, right, i had copied from another script

Hard to notice mistakes in the initiating func, always think its something else thats wrong.

Still its kinda bugged, the angle aint right for some reason, and the target newer stop moving ???
15 mins of working should fix that issue, but ill take that late...
10-02-2006, 06:10 PM#4
moyack
Other suggestions:

You can simplify this condition function changing it from this:
Collapse Ineficient condition:
function Trig_spell_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A004' ) ) then
        return false
    endif
    return true
endfunction

To this:
Collapse Better condition function:
function Trig_spell_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A004'
endfunction

Because i'm sure you want to do spells that complies with JESP standard, you should use contant functions that will work as configurable values in your spell. Your code should look in this way:

Collapse JASS:
constant function AccelerationSpell_SpellID takes nothing returns integer
    return 'A004'
endfunction

function AccelerationSpell_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == AccelerationSpell_SpellID()
endfunction

Obviosly you can change "AccelerationSpell" by your spell name, JESP says that ALL the functions (except inittrig_spellname) must have this pattern:

SpellName_FunctionName


So all your functions should be in this way:

Collapse JASS:
// Constant functions section

constant function AccelerationSpell_SpellID takes nothing returns integer
    return 'A004'
endfunction


// Custom funtions section
function AccelerationSpell_End takes nothing returns nothing
local timer time=GetExpiredTimer()
local unit target=GetHandleUnit( time, "target" )
local unit caster=GetHandleUnit( time, "caster" )
local real angle=GetHandleReal( time, "angle" )
local real dist=GetHandleReal( time, "dist" )
    call SetUnitPosition( target, GetUnitX( target )+dist*Cos( angle ), GetUnitY( target )+dist*Sin( angle ) )
    if ( dist<=0 ) then
        call FlushHandleLocals( time )
        call DestroyTimer( time )
    endif
    call SetHandleReal( time, "dist", dist-0.20 )
set target=null
set caster=null
endfunction

function AccelerationSpell_Update takes nothing returns nothing
local timer t=GetExpiredTimer()
local timer time=CreateTimer()
local unit target=GetHandleUnit( t, "target" )
local unit caster=GetHandleUnit( t, "caster" )
local real angle=GetHandleReal( t, "angle" )
local real dist=GetHandleReal( t, "dist" )
local real differ=GetHandleReal( t, "differ" )
local location locB=GetUnitLoc( caster )
local location locA=GetUnitLoc( target )
local real diff=DistanceBetweenPoints( locA, locB )
    call SetUnitPosition( target, GetUnitX( target )+dist*Cos( angle ), GetUnitY( target )+dist*Sin( angle ) )
    if ( diff<=differ ) then
        call DestroyTimer( t )
        call FlushHandleLocals( t )
        call SetHandleReal( time, "dist", dist )
        call SetHandleHandle( time, "target", target )
        call SetHandleHandle( time, "caster", caster )
        call SetHandleReal( time, "angle", angle )
        call TimerStart( time, 0.033, true, function AccelerationSpell__End )
    endif
    call SetHandleReal( t, "dist", dist+0.20 )
    call RemoveLocation( locA )
    call RemoveLocation( locB )
set target=null
set caster=null
endfunction


// Trigger functions sections
function AccelerationSpell_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == AccelerationSpell_SpellID()
endfunction

function AccelerationSpell_Actions takes nothing returns nothing
local timer t=CreateTimer()
local unit target=GetSpellTargetUnit()
local unit caster=GetTriggerUnit()
local real dist=0
local location locA=GetUnitLoc( target )
local location locB=GetUnitLoc( caster )
local real angle=AngleBetweenPoints( locA, locB )
local real differ=DistanceBetweenPoints( locA, locB )/1.9
    call RemoveLocation( locB )
    call RemoveLocation( locA )
    call SetHandleReal( t, "dist", dist )
    call SetHandleHandle( t, "target", target )
    call SetHandleHandle( t, "caster", caster )
    call SetHandleReal( t, "angle", angle )
    call SetHandleReal( t, "differ", differ )
    call TimerStart( t, 0.033, true, function AccelerationSpell_Update )
endfunction

//===========================================================================

function InitTrig_AccelerationSpell takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( t, Condition( function AccelerationSpell_Conditions ) )
    call TriggerAddAction( t, function AccelerationSpell_Actions )
    set t = null
endfunction

As you can see, I've rearranged your functions, so your code will look more organized and now it will easy for checking missing things and it will become easily configurable by only changing the values in the constant section. Check the inittrig function, it's now more effective and it doesn't uses globals :D

All this knowledge has been given to me by Master Rising_Dusk, Master Blu_da_Noob and all the tutorials made about JASS.

PS: Ahhh... I forgot one thing, in the "AccelerationSpell_Actions" you need to destroy the timer and then set to null all the handle variables (units, timer and locations), so they don't leak.
10-02-2006, 11:15 PM#5
Chuckle_Brother
As nice as that is, it doesn't fix his angle/movement issue.

I don't see anything glaringly wrong with the code, though your angle will be bugged because you need to multiple the angle by bj_DEGTORAD(check the function PolarProjectionBJ).

Put some debug msges here and there, see what values are used, and if it ever actual starts off the slowdown timer.
10-03-2006, 08:23 AM#6
zeroXD
Will try that, and btw moyack, im not making any JESP-spells right now, im only experimenting with some stuff, and about half of my big codes seems to crash pretty much...