HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Making a line of units

03-21-2007, 09:27 PM#1
Joker
well im trying to create a spell that creates a wall, but the units arent creating the line in the direction i want it to.

I want this:

xxxxxxxxxxxxxxxxx <-- Wall

Caster---->o

But sometimes, it goes in some odd direction

Code: (I know their handles, still trying to learn structs)
Collapse JASS:
function Trig_Serpent_Wall_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A00F'
endfunction

function Trig_Serpent_Wall_Effect_Core takes timer t returns nothing
    local player p = GetHandlePlayer( t, "player" )
    local location l = GetHandleLocation( t, "loc" )
    local real r = GetHandleReal( t, "real" )
    local real f = GetHandleReal( t, "face" )
    local unit s = GetHandleUnit( t, "unit" )
    local integer i = GetUnitAbilityLevel( s, 'A00F' )
    local real lx = GetLocationX(l)
    local real ly = GetLocationY(l)
    local unit a = CreateUnit( p, 'osp4', lx + r * Cos(f*bj_DEGTORAD), ly - r * Sin(f*bj_DEGTORAD), f )
    local unit b = CreateUnit( p, 'osp4', lx - r * Cos(f*bj_DEGTORAD), ly + r * Sin(f*bj_DEGTORAD), f )
    call UnitApplyTimedLife( a, 'BTLF', 15 )
    call UnitApplyTimedLife( b, 'BTLF', 15 )
    
    if r < 100 * i then
        call SetHandleReal( t, "real" , GetHandleReal( t, "real" ) + 100 )
    else
        call RemoveLocation(l)
        call PauseTimer(t)
        call DestroyTimer(t)
        call FlushHandleLocals(t)
    endif
    
    set l = null
    set s = null
    set a = null
    set b = null
endfunction 

function Trig_Serpent_Wall_Effect takes nothing returns nothing
    call Trig_Serpent_Wall_Effect_Core( GetExpiredTimer() )
endfunction

function Trig_Serpent_Wall_Actions_Core takes timer t, player p, location l, real f, unit s returns nothing
    call SetHandleReal( t, "real", 100 )
    call SetHandleReal( t, "face", f )
    call SetHandleHandle( t, "player", p )
    call SetHandleHandle( t, "loc", l )
    call SetHandleHandle( t, "unit", s )
    call TimerStart( t, 0.25, true, function Trig_Serpent_Wall_Effect )
endfunction

function Trig_Serpent_Wall_Actions takes nothing returns nothing
    local location l = GetSpellTargetLoc()
    local unit s = GetSpellAbilityUnit()
    local player p = GetOwningPlayer(s)
    local real f = GetUnitFacing( s ) - 90
    local unit a = CreateUnit( p, 'osp4', GetLocationX(l), GetLocationY(l), f )
    
    call UnitApplyTimedLife( a, 'BTLF', 15 )
    call Trig_Serpent_Wall_Actions_Core( CreateTimer(), p, l, f, s )
    
    set a = null
    set l = null 
    set s = null 
endfunction

//===========================================================================
function InitTrig_Serpent_Wall takes nothing returns nothing
    set gg_trg_Serpent_Wall = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Serpent_Wall, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Serpent_Wall, Condition( function Trig_Serpent_Wall_Conditions ) )
    call TriggerAddAction( gg_trg_Serpent_Wall, function Trig_Serpent_Wall_Actions )
endfunction
03-21-2007, 10:04 PM#2
Anopob
I believe player variables leak...and if they don't you're still leaking "unit s" in the last function. About the spell, I'm not sure...just because I don't do walls and stuff.
03-21-2007, 10:39 PM#3
Joker
i thought player vars didnt need to be null. Thx for finding the unit one though.
03-21-2007, 11:00 PM#4
Earth-Fury
Quote:
Whenever something is never going to be destroyed, you do not need to worry about this bug. For example, in an AoS map, the heroes will likely never be removed, so setting to null will not fix any leak. Similarly, multiboards aren't likely to be and players can't be destroyed.
http://wc3campaigns.net/showthread.php?t=81872

I seem to end up linking to this tutorial every day i post here...
03-21-2007, 11:07 PM#5
Joker
anyone find what im doing wrong with the acutal effect and not leaks?
03-22-2007, 02:25 AM#6
wantok
My first guess would be that this line is causing your strange behavior:
Collapse JASS:
local real f = GetUnitFacing( s ) - 90
If your unit's facing is less than 90 it will give you a negative facing degree. I'm not positive but I think this may cause problems. Check if the number will be negative and if so add 360 to it.
03-22-2007, 04:42 PM#7
Thunder_Eye
Collapse JASS:
local real UnitAngle = GetUnitFacing(s) - 90
local real TrueAngle = UnitAngle+360 - I2R(R2I((UnitAngle+360)/360) * 360
if you prefer math before an if
03-22-2007, 07:57 PM#8
Joker
whats the I2R(R2I for?
03-22-2007, 09:18 PM#9
Ammorth
and your order of operations is mixed up.

UnitAngle+360 - I2R(R2I(UnitAngle+360/360) * 360
really means

UnitAngle+360 - I2R(R2I(UnitAngle+1)) * 360
Negative angles are fine (-90 == 270).


Why not just get the angle between caster and point of cast and then add 90degrees for 1 side of the wall and subtract 90degrees for the other side of the wall? That will make it in front of the caster.