• 🏆 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] Easy Peasy Spell Question

Status
Not open for further replies.
Level 12
Joined
May 30, 2009
Messages
829
I was practicing a really basic spell, and simply put, why does it not work?
JASS:
library Shadowstep initializer Init

globals
    private constant integer SPELL_ID = 'A000'
    private constant integer DUMMY_ID = 'h000'
endglobals
//================================
//End of Configurables
//================================
private function Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == SPELL_ID ) ) then
        return false
    endif
    return true
endfunction

private function Actions takes nothing returns nothing
    local unit u = GetSpellAbilityUnit()
    local unit t = GetSpellTargetUnit()
    local real x
    local real y
    local real x2
    local real y2
    local location ul = GetUnitLoc(u)
    local location ut = GetUnitLoc(t)
    local real facing = GetUnitFacing(t)
    local real angle = Atan2(y-y2,x-x2) * bj_RADTODEG
    set x = GetUnitX(t)
    set y = GetUnitY(t)
    set x2 = (x + 200)
    set y2 = (y + 200)
    call SetUnitPosition(u, x2, y2)
    call SetUnitFacing(u, facing)
    call BJDebugMsg("Function actions has run!")
endfunction
//===========================================================================
private function Init takes nothing returns nothing
    set gg_trg_Shadowstep = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Shadowstep, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Shadowstep, Condition( function Conditions ) )
    call TriggerAddAction( gg_trg_Shadowstep, function Actions )

    set bj_lastCreatedUnit = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), DUMMY_ID, 0, 0, 0)
    call UnitAddAbility(bj_lastCreatedUnit, SPELL_ID)
    call KillUnit(bj_lastCreatedUnit)

endfunction

endlibrary

Thanks in advance.
 
This should work.

JASS:
library Shadowstep initializer Init

    globals
        private constant integer SPELL_ID = 'A000'
        private constant integer DUMMY_ID = 'h000'
    endglobals
    //================================
    //End of Configurables
    //================================
    private function Conditions takes nothing returns boolean
        return GetSpellAbilityId() == SPELL_ID
    endfunction

    private function Actions takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local unit t = GetSpellTargetUnit()
        local real x
        local real y
        local real x2
        local real y2
        local real facing = GetUnitFacing(t)
        local real angle
        set x = GetUnitX(t)
        set y = GetUnitY(t)
        set x2 = (x + 200)
        set y2 = (y + 200)
        set angle = Atan2(y-y2,x-x2) * bj_RADTODEG
        call SetUnitPosition(u, x2, y2)
        call SetUnitFacing(u, facing)
        call BJDebugMsg("Function actions has run!")
    endfunction

    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddCondition(t, Condition(function Conditions))
        call TriggerAddAction(t, function Actions)

        set bj_lastCreatedUnit = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), DUMMY_ID, 0, 0, 0)
        call UnitAddAbility(bj_lastCreatedUnit, SPELL_ID)
        call KillUnit(bj_lastCreatedUnit)

    endfunction

endlibrary
 
Level 9
Joined
Nov 28, 2008
Messages
704
You were using the variables before you had set them.

You were doing y-y2 or wahtever. y2 was still null.

By the way, I advise putting this in a scope. Not a library.
 
Status
Not open for further replies.
Top