| 10-16-2007, 02:29 PM | #1 |
I made a very simple wave spell, infact I simply copy pasted an old one and updated it. For some bizzare reason it is causing immense lag, whenever its cast. Ive studied/examined/went over it many times but cant see anything wrong with it. So here it is, a MUI wave spell, can anyone see the problem with it? thx (Note I removed the register unit in range part, as trying to determine the lag cause). JASS:globals rangerdata array RangerArray integer RangerTotal=0 endglobals struct rangerdata unit missile=null real angle=0 endstruct function DeathWave_Cons takes nothing returns boolean return GetSpellAbilityId()=='ACbc' endfunction function DeathWave_Move takes nothing returns nothing local rangerdata dat local integer i=0 loop exitwhen i==RangerTotal set dat=RangerArray[i] if GetWidgetLife(dat.missile)>.405 then call MoveUnitToPolarProjection(dat.missile,30,dat.angle) call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Undead\\DeathCoil\\DeathCoilSpecialArt.mdl",GetUnitX(dat.missile),GetUnitY(dat.missile))) else set RangerTotal=RangerTotal-1 set RangerArray[i]=RangerArray[RangerTotal] call dat.destroy() endif set i=i+1 endloop if RangerTotal==0 then call ClearTrigger(GetTriggeringTrigger(),null,null) endif endfunction function DeathWave_Acts takes nothing returns nothing local rangerdata dat=rangerdata.create() local unit u=GetTriggerUnit() local location l=null local real x1=GetUnitX(u) local real y1=GetUnitY(u) local real x2=0 local real y2=0 if GetSpellTargetUnit()==null then set l=GetSpellTargetLoc() set x2=GetLocationX(l) set y2=GetLocationY(l) call RemoveLocation(l) set l=null else set x2=GetUnitX(GetSpellTargetUnit()) set y2=GetUnitY(GetSpellTargetUnit()) endif set dat.angle=57.29582*Atan2(y2-y1,x2-x1) set dat.missile=CreateUnit(GetOwningPlayer(u),'otbk',x1,y1,dat.angle) call UnitApplyTimedLife(dat.missile,'BTLF',1.5) if RangerTotal==0 then call StartTimer(CreateTrigger(),.03,true,function DeathWave_Move) endif set RangerTotal=RangerTotal+1 set RangerArray[RangerTotal-1]=dat set u=null endfunction //=========================================================================== function InitTrig_Death_Wave takes nothing returns nothing set gg_trg_Death_Wave=CreateTrigger() call TriggerRegisterAnyUnitEventBJ(gg_trg_Death_Wave,EVENT_PLAYER_UNIT_SPELL_EFFECT) call TriggerAddCondition(gg_trg_Death_Wave,Condition(function DeathWave_Cons)) call TriggerAddAction(gg_trg_Death_Wave,function DeathWave_Acts) endfunction |
| 10-16-2007, 05:59 PM | #2 |
on an unrelated note, as I am not sure of the lag issue I do not think you are using the 1 timer/spell method correctly you should update the current data to the last before ou decrease the total by 1, and you should also be subtracting 1 from i, so you run that instance again, and do not skip over it not sure of the lag though the only thing i could think of is your goofy trigger method you are using |
| 10-16-2007, 06:37 PM | #3 |
Maybe I'm missing something, but it seems that you should have exitwhen i >= RangerTotal in your DeathWave_Move. First iteration, there will be one Ranger, so currently Code:
exitwhen i == 1 (RangerTotal) when it completes, you set RangerTotal = RangerTotal -1 and increment i, which will be Code:
exitwhen 1 == 0. Maybe loops don't work how I think - seems like the whole WE would crash (endless loop). But that could be the problem. |
| 10-16-2007, 09:49 PM | #4 |
Aha I got it, after dat.destroy I didnt set i=i-1 thx for help. |
| 10-16-2007, 10:08 PM | #5 |
heh, you could always put your set i = i + 1 inside your top if block...if you want to sacrifice clarity for efficiency :) |
