• 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] Spell Prob ='[

Status
Not open for further replies.
Level 2
Joined
Mar 3, 2007
Messages
12
mmkay im trying to make a spell where you cast an ice bolt, then when the ice bolt hits the enemy it does the frost nova ability....
i know alot of people made this already, but im making it myself, ive done it before... but its not working now for some reason.....

JASS:
function Trig_Frost_Bolt_Conditions takes nothing returns boolean
    return ( GetSpellAbilityId() == 'A000' )
endfunction


function Trig_Frost_Bolt_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local unit enm = GetSpellTargetUnit()
    local location uloc = GetUnitLoc(u)
    local location enmloc = GetUnitLoc(enm)
    local real time = (DistanceBetweenPoints(uloc, enmloc) / 1000.0) 
    local player up = GetOwningPlayer(u)
    local unit spec
    
    call Preload("frostnova")
    call PolledWait(time)
    call SetUnitTimeScale(CreateUnitAtLoc( up, 'h001', uloc, 0.0 ), 2.0)
    set spec = GetLastCreatedUnit()
    call UnitAddAbilityBJ( 'A001', spec )
    set enmloc = GetUnitLoc(enm)
    call IssuePointOrderLocBJ( spec, "frostnova", enmloc )
     
    call PolledWait( 0.5 ) 
    set u = null
    set enm = null
    call RemoveLocation( uloc )
    set uloc = null
    call RemoveLocation( enmloc )
    set enmloc = null
    set spec = null
    set up = null
endfunction

//===========================================================================
function InitTrig_Frost_Bolt takes nothing returns nothing
    set gg_trg_Frost_Bolt = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Frost_Bolt, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Frost_Bolt, Condition( function Trig_Frost_Bolt_Conditions ) )
    call TriggerAddAction( gg_trg_Frost_Bolt, function Trig_Frost_Bolt_Actions )
endfunction

The 'h001' unit is the dummy caster, when my guy casts frost bolt, the trigger will make the dummy caster, but not give the dummy caster the ability or order him to cast it or even kill him in 2.0 sec.... please help =]
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
try removing the "preload" line, that should be in an init trigger, otherwise it's pointless.

By the way, you leak Enmloc at one point, and the code can really be improved (no locs, no bjs, etc)

And as for the spell not working --

CreateUnit/CreateUnitAtLoc don't return bj_lastCreatedUnit. you'll have to do something like this

local unit u = CreateUnit...
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
JASS:
function Trig_Frost_Bolt_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A000'
endfunction

function Trig_Frost_Bolt_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local unit enm = GetSpellTargetUnit()
    local location uloc = GetUnitLoc(u)
    local location enmloc = GetUnitLoc(enm)
    local unit spec
    call PolledWait(DistanceBetweenPoints(uloc, enmloc)/1000)
    set spec = CreateUnitAtLoc(GetOwningPlayer(u),'h001',uloc,0)
    call SetUnitTimeScale(spec,2)
    //Nasty BJ
    call UnitAddAbilityBJ('A001',spec)
    call RemoveLocation(uloc)
    call RemoveLocation(enmloc)
    set enmloc = GetUnitLoc(enm)
    // Uhh I do not think frostnova is a point order since it targets units (wrong function) and is a nasty BJ. . .
    call IssuePointOrderLocBJ( spec, "frostnova", enmloc )
    call RemoveLocation(enmloc)
    set u = null
    set enm = null
    set uloc = null
    set enmloc = null
    set spec = null
endfunction

function InitTrig_Frost_Bolt takes nothing returns nothing
    set gg_trg_Frost_Bolt = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Frost_Bolt, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Frost_Bolt, Condition( function Trig_Frost_Bolt_Conditions ) )
    call TriggerAddAction( gg_trg_Frost_Bolt, function Trig_Frost_Bolt_Actions )
    call Preload("frostnova")
endfunction
I removed a lot of unneeded variables and actions and overall improved efficency, I did not remove the BJs due to me being tired and I could make a mistake.

I fixed and highlighted most of the troubles. I am too tired to really work on it but if you still are having trouble tomorrow I will fully redo it for full efficency.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
JASS:
function Trig_Frost_Bolt_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A000'
endfunction

function Trig_Frost_Bolt_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local unit enm = GetSpellTargetUnit()
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    local real xt = GetUnitX(enm)
    local real yt = GetUnitY(enm)
    local unit spec
    call PolledWait(SquareRoot((x-xt)*(x-xt)+(y-yt)*(y-yt))/1000)
    set spec = CreateUnit(GetOwningPlayer(u),'h001',x,y,0)
    call SetUnitTimeScale(spec,2)
    call UnitAddAbility(spec,'A001')
    //Probably will want to change this to
    //call IssueTargetOrder( spec, "frostnova", enm )
    call IssuePointOrder( spec, "frostnova", xt, yt )
    set u = null
    set enm = null
    set spec = null
endfunction

function InitTrig_Frost_Bolt takes nothing returns nothing
    set gg_trg_Frost_Bolt = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Frost_Bolt, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Frost_Bolt, Condition( function Trig_Frost_Bolt_Conditions ) )
    call TriggerAddAction( gg_trg_Frost_Bolt, function Trig_Frost_Bolt_Actions )
    call Preload("frostnova")
endfunction
there's a full makeover, gets rid of the nasty locationhax and nasty bjhax as well. Just consider what super said about "frostnova".
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
PolledWait --

JASS:
function PolledWait takes real duration returns nothing
    local timer t
    local real  timeRemaining

    if (duration > 0) then
        set t = CreateTimer()
        call TimerStart(t, duration, false, null)
        loop
            set timeRemaining = TimerGetRemaining(t)
            exitwhen timeRemaining <= 0

            // If we have a bit of time left, skip past 10% of the remaining
            // duration instead of checking every interval, to minimize the
            // polling on long waits.
            if (timeRemaining > bj_POLLED_WAIT_SKIP_THRESHOLD) then
                call TriggerSleepAction(0.1 * timeRemaining)
            else
                call TriggerSleepAction(bj_POLLED_WAIT_INTERVAL)
            endif
        endloop
        call DestroyTimer(t)
    endif
endfunction

Worse for waits less than or equal to .1

Better for waits above .1, slightly
 
Status
Not open for further replies.
Top