HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Spell trouble... Unit won't move.

03-19-2007, 12:09 PM#1
zeroXD
I just made a spell that is supposed to move the caster to the target point over a half second period, and eventually stop if it collides in a tree or cliff or whatever...

However, I'm having a problem: the caster simply don't want to move his lazy ass...
Ability rawcode is right.
Collapse JASS:
function Trig_Wind_Walk_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A011'
endfunction

function IsWWTargetable takes unit u, group g, player owner returns boolean
    return IsUnitInGroup(u, g)==false and IsUnitLiving(u)==true and IsUnitMagicImmune(u)==false and IsUnitFlying(u)==false and IsUnitEnemy(u, owner)==true
set owner = null
endfunction

function Wind_Walk_Move takes nothing returns nothing
local timer t = GetExpiredTimer()
local unit caster = GetHandleUnit( t, "caster" )
local real angle = GetHandleReal( t, "angle" )
local real speed = GetHandleReal( t, "speed" )
local real damage = GetHandleReal( t, "damage" )
local real maxDist = GetHandleReal( t, "maxDist" )
local real dist = GetHandleReal( t, "dist" )
local group hitUnits = GetHandleGroup( t, "hitUnits" )
local real x = GetUnitX( caster )
local real y = GetUnitY( caster )
local real targX = x+speed*Cos( angle*3.14159/180.0 )
local real targY = y+speed*Sin( angle*3.14159/180.0 )
local group targets
local unit u
local effect fx
    if IsTerrainPathable( targX, targY, PATHING_TYPE_WALKABILITY )==true and dist < maxDist then // I think this is the problem...
        call SetUnitPosition( caster, targX, targY )
        call SetHandleReal( t, "dist", dist+speed )
        set targets = CreateGroup()
        call GroupEnumUnitsInRange( targets, targX, targY, 100, null )
        loop
            set u = FirstOfGroup( targets )
            exitwhen u == null
            if IsWWTargetable(u, hitUnits, GetOwningPlayer(caster))==true then
                call UnitSpellDamageTarget( caster, u, damage ) // Home made function for spelldamage.
                call GroupAddUnit( hitUnits, u )
                set x = GetUnitX( u )
                set y = GetUnitY( u )
                set angle = 180.0/3.14159*Atan2( y-targY, x-targX )
                call KnockBack2( u, 15, 0.5, angle ) // For knocking back without interrupting channelling spells.
            endif
            call GroupRemoveUnit( targets, u )
            set u = null
        endloop
        call DestroyGroup( targets )
        set targets = null
    else
        set fx = GetHandleEffect( t, "fx" )
        call DestroyEffect( fx )
        set fx = null
        call FlushHandleLocals( t )
        call PauseTimer( t )
        call DestroyTimer( t )
        set t = null
    endif
set caster = null
set hitUnits = null
endfunction

function Trig_Wind_Walk_Actions takes nothing returns nothing
local timer t = CreateTimer()
local unit caster = GetTriggerUnit()
local location targLoc = GetSpellTargetLoc()
local real targX = GetLocationX( targLoc )
local real targY = GetLocationY( targLoc )
local real x = GetUnitX( caster )
local real y = GetUnitY( caster )
local real angle = 180.0/3.14159*Atan2( targY-y, targX-x )
local integer level = GetUnitAbilityLevel( caster, 'A011' )
local integer agi = GetHeroAgi( caster, true )
local real damage = (10+(level*10))+(agi*(0.5*level)) // Damage dealt when dashing past units, based on agility.
local real dist = SquareRoot( (targX-x)*(targX-x)+(targY-y)*(targY-y) ) // The distance between cast point and target point.
local real speed = dist/25 // This is the speed.
local group hitUnits = CreateGroup()
local effect fx = AddSpecialEffectTarget( "war3mapImported\\DustAndRocks.mdx", caster, "origin" )
    call RemoveLocation( targLoc )
    set targLoc = null
    call SetUnitPathing( caster, false )
    call SetHandleHandle( t, "caster", caster )
    call SetHandleReal( t, "angle", angle )
    call SetHandleReal( t, "damage", damage )
    call SetHandleReal( t, "maxDist", dist )
    call SetHandleReal( t, "dist", 0 )
    call SetHandleReal( t, "speed", speed )
    call SetHandleHandle( t, "hitUnits", hitUnits )
    call SetHandleHandle( t, "fx", fx )
    call TimerStart( t, 0.02, true, function Wind_Walk_Move )
set caster = null
set fx = null
set hitUnits = null
endfunction

//===========================================================================
function InitTrig_Wind_Walk takes nothing returns nothing
    set gg_trg_Wind_Walk = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Wind_Walk, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Wind_Walk, Condition( function Trig_Wind_Walk_Conditions ) )
    call TriggerAddAction( gg_trg_Wind_Walk, function Trig_Wind_Walk_Actions )
endfunction

Help would be apreciated.
03-19-2007, 12:40 PM#2
Toadcop
maybe your unit have movespeed == 0 ? then unit will be not visualy moved !
03-19-2007, 02:01 PM#3
zeroXD
My unit is a hero with 320 movement speed.
03-19-2007, 02:32 PM#4
WNxCryptic
IsTerrainPathable has an inverted return, so as its written up there ^, it will return false whenever you're intending it to return true.

put a "not" inbetween the if and IsTerrainPathable
03-19-2007, 02:39 PM#5
grim001
oh man that spell looks supremely lagtastic