| 03-26-2008, 12:52 PM | #1 |
When I try to use this trigger my Warcraft crashes. 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: 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 |
Is GetSpellAbilityUnit() null? I think it should be SPELL_EFFECT for the event. |
| 03-26-2008, 03:51 PM | #3 |
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 |
Second should be Y instead: JASS:call SetUnitX(SD.whichUnit, SD.cX) call SetUnitX(SD.whichUnit, SD.cY) Get rid of those, they're not needed & wrong: 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: 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 |
I've changed that but it still doesn't work as it should, the triggers looks like this now: 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 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 |
JASS:set SD.totalDist = SquareRoot(SD.targetX * SD.startX + SD.targetY * SD.startY) SquareRoot((SD.targetX-SD.startX)^2 + (SD.targetY-SD.startY)^2) |
| 03-26-2008, 08:33 PM | #7 |
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! |
