| 10-10-2006, 09:28 PM | #1 |
Its a varient of the standard area effect lightningstorm type spells. Im stuck at trying to add a 'expiration timer' to a lightning effect. I was considering have a local effect array and wiping them out. However I want to be creating X lightning bolts per second, so not sure how it would go together. JASS:function Trig_LightningStorm_Actions takes nothing returns nothing local unit caster = GetTriggerUnit() local unit dummy local group targets = CreateGroup() local location spellpoint = GetSpellTargetLoc() local real newx = GetLocationX(spellpoint) local real newy = GetLocationY(spellpoint) local player owner = GetOwningPlayer(caster) local integer number local integer level = GetUnitAbilityLevel(caster,'A068') local real damage = (LightningStorm_Damage(level)) call AddLightningEx("CLPB", false, newx, newy, 2000, newx, newy, 0) call DestroyGroup(targets) set caster = null set dummy = null endfunction Currently has some unneeded locals, but will use in next steps. |
| 10-10-2006, 09:41 PM | #2 |
Either use a timer to erase them(assuming you don't want all disappearing at the same time). Or you use a wait action, which requires execfunc so you don't pause the calling thread. Once you decide on a method I will post a wee bit more. |
| 10-10-2006, 09:56 PM | #3 |
Timer seems the best method then. |
| 10-11-2006, 06:23 AM | #4 |
This might not work with lightning, as don't they have some wierd handle index that is an order of magnitude higher? Not sure if reals could cope with that. JASS:function TimerAttach takes timer t, real dur, real value, code func returns nothing call TimerStart(t, value, false, null) call PauseTimer(t) call TimerStart(t, dur, false, func) endfunction function GetTimerInt takes timer t returns integer return R2I(TimerGetRemaining(t) + 0.5) endfunction function DestroyLightningTimedEx takes nothing returns nothing local lightning l = I2Lightning(GetTimerInt(GetExpiredTimer())) call DestroyLightning(l) call DestroyTimer(t) set l = null endfunction function DestroyLightningTimed takes lightning l, real dur returns nothing call TimerAttach(CreateTimer(), dur, H2I(l), function DestroyLightningTimedEx) endfunction |
| 10-11-2006, 01:27 PM | #5 |
Seems like a lot of work to do considering you can just use: JASS:function LightningStorm_DestroyLightning takes nothing returns nothing local timer t = GetExpiredTimer() local lightning l = GetTableLightning(GetAttachmentTable(t),"MrLightning") call DestroyLightning(l) call ClearTimer(t) set t = null set l = null endfunction function Trig_LightningStorm_Actions takes nothing returns nothing local unit caster = GetTriggerUnit() local unit dummy local group targets = CreateGroup() local location spellpoint = GetSpellTargetLoc() local real newx = GetLocationX(spellpoint) local real newy = GetLocationY(spellpoint) local player owner = GetOwningPlayer(caster) local integer number local integer level = GetUnitAbilityLevel(caster,'A068') local real damage = (LightningStorm_Damage(level)) local timer t = CreateTimer() local lightning l = AddLightningEx("CLPB", false, newx, newy, 2000, newx, newy, 0) call SetTableObject(GetAttachmentTable(t),"MrLightning",l) call TimerStart(t,TIMEOUT,false,function LightningStorm_DestroyLightning) call DestroyGroup(targets) set caster = null set dummy = null set t = null endfunction Just replace TIMEOUT with however long you have decided that wee little lightning should survive. |
| 10-11-2006, 04:05 PM | #6 |
Ok, ive hit another wall. For some reason this doesnt work properly anymore. Its meant to, create a rando lightning bolt from sky to ground within an area every X seconds. If an enemy unit happens to be close, it damages the unit and lightning spreads to other nearby enemy units. Without the secondary part, it worked fine, I got 20 random Lightning Bolts made, now I get about 2-3 and it stops. JASS://################################################################\\ // \\ // Configuration Section \\ // \\ //################################################################\\ constant function LightningStorm_AbilId takes nothing returns integer return 'A063' endfunction constant function LightningStorm_Duration takes integer level returns real return level * 2. + 6. endfunction constant function LightningStorm_SpellRadius takes integer level returns real return level * 25. + 125. endfunction constant function LightningStorm_EffectRadius takes integer level returns real return level * 25. + 25. endfunction constant function LightningStorm_Damage takes integer level returns real return level * 100. + 300. endfunction //################################################################\\ // \\ // Spell Section \\ // \\ //################################################################\\ function Trig_LightningStorm_Conditions takes nothing returns boolean return GetSpellAbilityId() == LightningStorm_AbilId() endfunction function LightningStorm_Group takes nothing returns boolean return (GetWidgetLife(GetFilterUnit()) > 0.405) and IsUnitEnemy(GetFilterUnit(), udg_tempplayer) endfunction function LightningStorm_DestroyLightning takes nothing returns nothing local timer t = GetExpiredTimer() local lightning l = GetTableLightning(GetAttachmentTable(t),"MrLightning") call DestroyLightning(l) call ClearTimer(t) set t = null set l = null endfunction function Trig_LightningStorm_Actions takes nothing returns nothing local unit caster = GetTriggerUnit() local unit dummy local unit target local group targets = CreateGroup() local location spellpoint = GetSpellTargetLoc() local location randpoint local real newx local real newy local player owner = GetOwningPlayer(caster) local real randang local real randdis local integer amount = 20 local integer number local integer level = GetUnitAbilityLevel(caster,'A063') local real damage = (LightningStorm_Damage(level)) local real dmg local timer t local lightning l loop exitwhen amount == 0 set t = CreateTimer() set randang = GetRandomReal(0, 360) set randdis = GetRandomReal(0,LightningStorm_SpellRadius(level)) set randpoint = PolarProjectionBJ(spellpoint, randdis, randang) set newx = GetLocationX(randpoint) set newy = GetLocationY(randpoint) set l = AddLightningEx("CLPB", false, newx, newy, 500, newx, newy, 0) call SetTableObject(GetAttachmentTable(t),"MrLightning",l) call TimerStart(t,0.5,false,function LightningStorm_DestroyLightning) set udg_tempplayer = owner call GroupEnumUnitsInRange(targets, newx, newy, LightningStorm_EffectRadius(level), Condition(function LightningStorm_Group)) set number = CountUnitsInGroup(targets) set target = GroupPickRandomUnit(targets) call GroupRemoveUnit(targets,target) set dmg = ( damage / I2R(number) ) loop set dummy = FirstOfGroup(targets) exitwhen (dummy==null) call UnitDamageTargetBJ( caster, dummy, dmg, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL ) call AddLightningBetweenUnitsTimed(target, dummy, 0.5, "CLPB") call GroupRemoveUnit(targets, dummy) endloop call TriggerSleepAction(0.1) set amount = amount - 1 endloop endfunction //=========================================================================== function InitTrig_LightningStorm takes nothing returns nothing set gg_trg_LightningStorm = CreateTrigger( ) call TriggerRegisterAnyUnitEventBJ( gg_trg_LightningStorm, EVENT_PLAYER_UNIT_SPELL_EFFECT ) call TriggerAddCondition( gg_trg_LightningStorm, Condition( function Trig_LightningStorm_Conditions ) ) call TriggerAddAction( gg_trg_LightningStorm, function Trig_LightningStorm_Actions ) endfunction |
| 10-11-2006, 04:21 PM | #7 |
Debug messages. |
| 10-11-2006, 04:59 PM | #8 |
I just tried several debug msges, but cant locate the problem. Anyone see the problem? :/ |
| 10-11-2006, 05:52 PM | #9 |
How about you tell us what those debug messages told you? Hmm? |
| 10-11-2006, 06:18 PM | #10 |
I checked amount each loop Should be going from 20 to 0 and stop at 0 It went 20/19/18 then spell just stops..? I checked amount picked in groups, as expected non clusters area = 0 units picked clustered area = X units picked. It seems the loop just stops, but I cant see a reason why |
| 10-11-2006, 06:51 PM | #11 |
Divide by zero. Crashes the thread. |
