Lightning Help

Level 12
Joined
Mar 24, 2013
Messages
1,105
Hio, I'm trying to make a spell that makes a unit at a location and this unit has a lighting effect between it and the caster up to 600 range upon which it "breaks" upon reentering the lightning should be recreated.

I have this so far, but it crashes because I'm moving a destroyed lightning but I'm not understanding precisely why its destroyed, I'm probably making some wrong presumptions with the scripts, but I don't claim to have a clue xD.

  • Battery
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to [ES] Battery
    • Actions
      • Set Battery_Caster = (Triggering unit)
      • Set Battery_CasterLoc = (Position of (Triggering unit))
      • Set TempPoint = (Target point of ability being cast)
      • Unit - Create 1 [Dummy] Battery for (Triggering player) at TempPoint facing Default building facing degrees
      • Set Battery = (Last created unit)
      • Set Battery_Loc = (Position of Battery)
      • Custom script: call RemoveLocation(udg_TempPoint)
      • Lightning - Create a Mana Flare lightning effect from source Battery_Loc to target Battery_CasterLoc
      • Set Battery_Lightning = (Last created lightning effect)
      • Trigger - Turn on Battery Lightning <gen>
      • Countdown Timer - Start Battery_Timer as a One-shot timer that will expire in 15.00 seconds

  • Battery Lightning
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • Set Battery_CasterLoc = (Position of Battery_Caster)
      • Set Battery_Loc = (Position of Battery)
      • Custom script: if udg_Battery_Lightning == null then
      • Game - Display to (All players) the text: Lighting null/makin...
      • Lightning - Create a Mana Flare lightning effect from source Battery_Loc to target Battery_CasterLoc
      • Set Battery_Lightning = (Last created lightning effect)
      • Custom script: endif
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Distance between Battery_CasterLoc and Battery_Loc) Less than or equal to 600.00
        • Then - Actions
          • Custom script: if udg_Battery_Lightning != null then
          • Lightning - Move Battery_Lightning to source Battery_Loc and target Battery_CasterLoc
          • Custom script: endif
        • Else - Actions
          • Game - Display to (All players) the text: Killing Lightning
          • Lightning - Destroy Battery_Lightning
      • Custom script: call RemoveLocation(udg_Battery_Loc)
      • Custom script: call RemoveLocation(udg_Battery_CasterLoc)
  • Battery End
    • Events
      • Time - Battery_Timer expires
    • Conditions
    • Actions
      • Trigger - Turn off Battery Lightning <gen>
      • Lightning - Destroy Battery_Lightning
      • Unit - Kill Battery
 
Level 14
Joined
Aug 30, 2004
Messages
909
Have you considered using a dummy unit with a re-worked life drain ability that drains 0 life or something?

I've used these lightning effects and had it crash my campaign before when i tried saving... I wonder if I was moving a destroyed lightninging effect? This is the first I've heard of it. In any case, thank you for the tip and I hope my suggestion helps.

EDIT:

Another possibility: I think you might leak your points once between the start and periodic trigger. You set Battery_CasterLoc, for example, and then in the periodic trigger you immediately set it again without clearing it. That probably isn't your problem, but I used to get crashes in my Star Wars map from pointers being cleared or not cleared... they confuse me.

I also think you might be spamming lightning effects every .05 seconds and deleting them. When your unit moves far away, the periodic trigger first destroys their lightning. Then it fires again .05 seconds later, detects that there is no lightning so it makes a new one, then sees that the unit is too far and destroys it again. That seems inefficient and could cause problems.
 
Top