| 01-12-2011, 08:19 AM | #1 |
Let say i have a "slide" lib JASS:library CodSlide initializer init requires TerrainPathability //Setup=============================================== globals private constant real DEFAULT_SPEED = 20. endglobals //EndSetup============================================ private interface eventHandler method onFinish takes nothing returns nothing defaults nothing method onLoop takes nothing returns nothing defaults nothing endinterface struct Slide extends eventHandler unit u real angle real dis real speed = DEFAULT_SPEED real discount = 0. private method periodic takes nothing returns nothing local timer t local real mX = PolarProjectionX(GetUnitX(.u),.speed,angle) local real mY = PolarProjectionY(GetUnitY(.u),.speed,angle) //check if col if .discount >= .dis then if(this.onFinish.exists) then call .onFinish() endif call .stopPeriodic() call .destroy() return endif //move if IsTerrainWalkable(mX,mY) then call SetUnitPosition(.u,mX,mY) endif set .discount = .discount + speed if(.onLoop.exists) then call .onLoop() endif endmethod implement T32x static method start takes unit u,real dis,real angle returns nothing local thistype s = thistype.create() set s.u = u set s.dis = dis set s.angle = angle call s.startPeriodic() endmethod endstruct private function init takes nothing returns nothing endfunction endlibrary and a spell make with this: JASS://=========================================================================// //Spell: //Author: //MUI: //MPI: //Credit: //Require: //=========================================================================// scope FlashMove initializer init //=========================================================================// //Setup // //=========================================================================// globals private constant integer SPELL_ID = 'A00R' private constant integer WAIT_4_EFF = 2 private constant real SPEED = 25. private constant real EFF_TIME_LIFE = 0.6 private constant string MODEL_PATH = "Codart\\Model\\Cloud2\\accloud by raphthegreat.mdl" private constant integer A = 150 private constant integer R = 100 private constant integer G = 200 private constant integer B = 255 private constant real GROUP_RADIUS = 200 private constant integer ARM_CRK_TIME = T32_FPS * 2 endglobals private function filt takes nothing returns boolean return IsUnitEnemy(GetSpellTargetUnit(),GetOwningPlayer(GetTriggerUnit())) and IsUnitAliveBJ(GetSpellTargetUnit()) endfunction //=========================================================================// //End Setup // //=========================================================================// //Misc======================================================================= globals endglobals private struct SlideX extends Slide integer timecount = 0 private static method removeModel takes nothing returns nothing local timer t = GetExpiredTimer() local xefx fx = xefx(GetTimerData(t)) call fx.hiddenDestroy() call ReleaseTimer(t) endmethod method onLoop takes nothing returns nothing local xefx fx local timer t call BJDebugMsg("xit") //eff set timecount = timecount + 1 if timecount >= WAIT_4_EFF then set fx = xefx.create(GetUnitX(u),GetUnitY(u),Deg2Rad(angle)) set fx.fxpath = MODEL_PATH call fx.recolor(R,G,B,A) set t = NewTimer() call SetTimerData(t,fx) call TimerStart(t,EFF_TIME_LIFE,false,function thistype.removeModel) set timecount = 0 endif endmethod method onFinish takes nothing returns nothing local real x = GetUnitX(.u) local real y = GetUnitY(.u) local ArmCrack a local unit enum call GroupUnitsInArea(ENUM_GROUP, x, y, GROUP_RADIUS) loop set enum = FirstOfGroup(ENUM_GROUP) exitwhen enum == null if IsUnitEnemy(enum,GetOwningPlayer(.u)) and IsUnitAliveBJ(enum) then set a = ArmCrack.create(enum) call a.setup(ARM_CRK_TIME) endif call GroupRemoveUnit(ENUM_GROUP,enum) endloop call ReleaseGroup(ENUM_GROUP) set enum = null endmethod endstruct //Condition================================================================== private function Con takes nothing returns boolean return GetSpellAbilityId() == SPELL_ID endfunction //Action===================================================================== private function Actions takes nothing returns nothing local real tX = GetSpellTarX() local real tY = GetSpellTarY() local unit c = GetTriggerUnit() local real cX = GetUnitX(c) local real cY = GetUnitY(c) local real dis = DistanceBetweenCords(cX,cY,tX,tY) call SlideX.start(c,dis,AngleBetweenCord(cX,cY,tX,tY)) //call SetUnitAnimation( c, "spell two") //call AddSpecialEffectTarget("Abilities\\Spells\\Undead\\Cripple\\CrippleTarget.mdl",c,"weapon") //call AddSpecialEffectTarget("Abilities\\Weapons\\IllidanMissile\\IllidanMissile.mdl",c,"weapon") //call AddSpecialEffectTarget("Abilities\\Weapons\\PhoenixMissile\\Phoenix_Missile_mini.mdl",c,"weapon") set c = null endfunction //Init======================================================================= private function init takes nothing returns nothing local trigger t = CreateTrigger( ) call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT ) call TriggerAddAction( t, function Actions ) call TriggerAddCondition(t, Condition( function Con)) endfunction endscope The 2 method "onFinish" and "onLoop" that i implement in the spell won't be call. show me my wrong :( |
| 01-12-2011, 01:56 PM | #2 |
Try adding some debug messages to the periodic function to see if it runs (although, if the unit is moving then it probably does). Other than that, I don't know what the problem could be, I use the same method of calling an onLoop method in xemissile and it works just fine. I guess you could try skipping the .exists checks, however the example I gave works with such a check as well. By the way, if you use SetUnitPosition instead of SetUnitX/Y, then the IsTerrainWalkable check is not really needed since SetUnitPosition does take unit pathing into account. |
