HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Trigger crashes Warcraft

03-26-2008, 12:52 PM#1
Gwypaas
When I try to use this trigger my Warcraft crashes.
Collapse JASS:
function Trig_TestSlide_Actions takes nothing returns nothing
    local real X = GetUnitX(GetSpellAbilityUnit())
    local real Y = GetUnitY(GetSpellAbilityUnit())
    local real tX = X+500 * Cos(45*bj_DEGTORAD)
    local real tY = Y+500 * Sin(45*bj_DEGTORAD)
    call Slide(GetSpellAbilityUnit(), X, Y, tX, tY, 10)
endfunction

function TestCond takes nothing returns boolean
    return GetSpellAbilityId() == 'A001'
endfunction

//===========================================================================
function InitTrig_TestSlide takes nothing returns nothing
    local trigger Trig = CreateTrigger()
    local integer i = 0
    loop

        call TriggerRegisterPlayerUnitEvent(Trig, Player(i), EVENT_PLAYER_UNIT_SPELL_CAST, null)
        
        set i = i+1
        exitwhen i == 9
    endloop
    call TriggerAddCondition(Trig, Condition(function TestCond))
    call TriggerAddAction( Trig, function Trig_TestSlide_Actions )
endfunction


The slide function I call looks like this:
Collapse JASS:
private struct SlideData
    timer t
    unit whichUnit
    real totalDist
    real distDone = 0
    real startX
    real startY
    real targetX
    real targetY
    real cX
    real cY
    real angle
    real speed
endstruct

function SlideCallback takes nothing returns nothing
    local timer T = GetExpiredTimer()
    local SlideData SD = GetAttachedStructSlide(T)
    if SD.distDone >= SD.totalDist then
        call PauseTimer(SD.t)
        call DestroyTimer(SD.t)
        set SD.whichUnit = null
    else
        set SD.cX = SD.cX + SD.speed * Cos(SD.angle*bj_RADTODEG)
        set SD.cY = SD.cY + SD.speed * Sin(SD.angle*bj_RADTODEG)
        call SetUnitX(SD.whichUnit, SD.cX)
        call SetUnitX(SD.whichUnit, SD.cY)
        set SD.distDone = SD.distDone + SD.speed
    endif
    set T = null
endfunction

function Slide takes unit whichUnit, real startX, real startY, real targetX, real targetY, real speed returns nothing
    local SlideData SD = SlideData.create()
    
    set SD.startX = startX
    set SD.startY = startY
    set SD.targetX = targetX
    set SD.targetY = targetY
    set SD.cX = startX
    set SD.cY = startY
    
    set SD.whichUnit = whichUnit
    
    set SD.angle = bj_RADTODEG * Atan2((SD.targetY-SD.startY),(SD.targetX-SD.startX))
    set SD.speed = speed
    set SD.totalDist = SquareRoot(SD.targetX * SD.startX + SD.targetY * SD.startY)
    
    set SD.t = CreateTimer()
    call AttachStructSlide(SD.t, SD)
    call TimerStart(SD.t, 0.03, true, function SlideCallback)
endfunction

The slide trigger uses HSAS to attach the values btw.
03-26-2008, 03:05 PM#2
Captain Griffen
Is GetSpellAbilityUnit() null? I think it should be SPELL_EFFECT for the event.
03-26-2008, 03:51 PM#3
Gwypaas
Warcraft crashed because War3err was enabled. O.o

But now I have a another problem, the unit doesn't move 500 pixels away at 45 degrees, It moves to (0 , 0) instead.
03-26-2008, 04:09 PM#4
Alexander244
Second should be Y instead:
Collapse JASS:
call SetUnitX(SD.whichUnit, SD.cX)
call SetUnitX(SD.whichUnit, SD.cY)

Get rid of those, they're not needed & wrong:
Collapse JASS:
set SD.angle = bj_RADTODEG * Atan2((SD.targetY-SD.startY),(SD.targetX-SD.startX))
//...
set SD.cX = SD.cX + SD.speed * Cos(SD.angle*bj_RADTODEG)
set SD.cY = SD.cY + SD.speed * Sin(SD.angle*bj_RADTODEG)

This is wrong:
Collapse JASS:
set SD.totalDist = SquareRoot(SD.targetX * SD.startX + SD.targetY * SD.startY)

You need this to get war3err working.
03-26-2008, 07:15 PM#5
Gwypaas
I've changed that but it still doesn't work as it should, the triggers looks like this now:

Collapse JASS:
function SlideCallback takes nothing returns nothing
    local timer T = GetExpiredTimer()
    local SlideData SD = GetAttachedStructSlide(T)
    if SD.distDone >= SD.totalDist then
        call PauseTimer(SD.t)
        call DestroyTimer(SD.t)
        set SD.t = null
        set SD.whichUnit = null
        call SD.destroy()
    else
        set SD.cX = SD.cX + SD.speed * Cos(SD.angle)
        set SD.cY = SD.cY + SD.speed * Sin(SD.angle)
        call SetUnitX(SD.whichUnit, SD.cX)
        call SetUnitY(SD.whichUnit, SD.cY)
        set SD.distDone = SD.distDone + SD.speed
    endif
    set T = null
endfunction

function Slide takes unit whichUnit, real startX, real startY, real targetX, real targetY, real speed returns nothing
    local SlideData SD = SlideData.create()
    set SD.startX = startX
    set SD.startY = startY
    set SD.targetX = targetX
    set SD.targetY = targetY
    set SD.cX = startX
    set SD.cY = startY
    
    set SD.whichUnit = whichUnit
    
    set SD.angle = Atan2((SD.targetY-SD.startY),(SD.targetX-SD.startX))
    set SD.speed = speed
    set SD.totalDist = SquareRoot(SD.targetX * SD.startX + SD.targetY * SD.startY)
    
    set SD.t = CreateTimer()
    call AttachStructSlide(SD.t, SD)
    call TimerStart(SD.t, 0.03, true, function SlideCallback)
endfunction

Collapse JASS:
function Trig_TestSlide_Actions takes nothing returns nothing
    local unit u = GetSpellAbilityUnit()
    local real X = GetUnitX(u)
    local real Y = GetUnitY(u)
    local real tX = X+2500 * Cos(45*bj_DEGTORAD)
    local real tY = Y+2500 * Sin(45*bj_DEGTORAD)
    call BJDebugMsg("Test slide is casting")
    call Slide(u, X, Y, tX, tY, 30)
endfunction

function TestCond takes nothing returns boolean
    return GetSpellAbilityId() == 'A001'
endfunction

//===========================================================================
function InitTrig_TestSlide takes nothing returns nothing
    local trigger Trig = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(Trig, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(Trig, Condition(function TestCond))
    call TriggerAddAction( Trig, function Trig_TestSlide_Actions )
endfunction


But it still doesn't work because the unit sometimes doesn't move and it never moves 2500 pixels.
03-26-2008, 07:17 PM#6
Alexander244
Collapse JASS:
set SD.totalDist = SquareRoot(SD.targetX * SD.startX + SD.targetY * SD.startY)
should be:
SquareRoot((SD.targetX-SD.startX)^2 + (SD.targetY-SD.startY)^2)
03-26-2008, 08:33 PM#7
Gwypaas
Oh thanks, It was a while since I did this last time so I forgot how to do it :P

Atleast it works perfectly now thanks.

+rep!