Prolong 
		 | 
		
		
		
			
				
					| Category: | 
					Code | 
				 
				
				
					| Level: | 
					
					Intermediate   
					 | 
				 
				
				
					| Created: | 
					Wednesday May 20, 2009 - 15:46 | 
				 
				
					| Updated: | 
					Wednesday February 3, 2010 - 19:14 | 
				 
				
					| Views: | 
					4576 | 
				 
				
					| Summary: | 
					Make weather powers affect units built after the spell is cast | 
				 
			 
		 | 
		
		
		
			 Rating
			 
			
				
					| 
						 Staff says 
						
							4.0
						 
					 | 
					
					
						 Members say 
						
							4.0
						 
					 | 
				 
				
					| 
						 Average 
						4.0/5.0 
					 | 
				 
			 
			4 votes 
			
			
		 | 
	
	
And here are the actual caster objects, which fire ConstantWeather weapons again and again until killed.  Add them to system.ini:
         | Code | 
         ;------------------------------------------------------------------------------ ;;,;; added for 2.02e 
Object DarknessCaster 
 
    Draw = W3DScriptedModelDraw ModuleTag_Draw 
        DefaultModelConditionState 
            Model           = none 
        End 
    End 
     
    EvaEnemyObjectSightedEvent = None  ; Not a real unit 
   
    ; ***DESIGN parameters *** 
    EditorSorting   = SYSTEM 
    KindOf = BOAT ; NO_COLLIDE IMMOBILE INERT ; UNATTACKABLE 
     
 
    ; *** ENGINEERING Parameters *** 
    Body = ActiveBody ModuleTag_02 ; ImmortalBody ModuleTag_02 
        MaxHealth = 1     
        InitialHealth = 1 
    End 
 
    Behavior = DeletionUpdate ModuleTag_03 ; Not LifetimeUpdate, since I can't die.  This will DestroyObject me.  
        MinLifetime = SPELL_DARKNESS_DURATION 
        MaxLifetime = SPELL_DARKNESS_DURATION 
    End 
 
    Behavior = FireWeaponUpdate ModuleTag_WeaponFiringApplyAttributeModifier 
        FireWeaponNugget 
            WeaponName = ConstantDarkness 
            Offset = X:0 Y:0 Z:0 
            FireDelay = 0 
            OneShot = No 
        End 
    End 
 
End 
 
;------------------------------------------------------------------------------ ;;,;; added for 2.02e 
Object FreezingRainCaster 
 
    Draw = W3DScriptedModelDraw ModuleTag_Draw 
        DefaultModelConditionState 
            Model           = none 
        End 
    End 
     
    EvaEnemyObjectSightedEvent = None  ; Not a real unit 
   
    ; ***DESIGN parameters *** 
    EditorSorting   = SYSTEM 
    KindOf = BOAT ; NO_COLLIDE IMMOBILE INERT ; UNATTACKABLE 
     
 
    ; *** ENGINEERING Parameters *** 
    Body = ActiveBody ModuleTag_02 ; ImmortalBody ModuleTag_02 
        MaxHealth = 1     
        InitialHealth = 1 
    End 
 
    Behavior = DeletionUpdate ModuleTag_03 ; Not LifetimeUpdate, since I can't die.  This will DestroyObject me.  
        MinLifetime = SPELL_FREEZINGRAIN_DURATION 
        MaxLifetime = SPELL_FREEZINGRAIN_DURATION 
    End 
 
    Behavior = FireWeaponUpdate ModuleTag_WeaponFiringApplyAttributeModifier 
        FireWeaponNugget 
            WeaponName = ConstantFreezingRain 
            Offset = X:0 Y:0 Z:0 
            FireDelay = 0 
            OneShot = No 
        End 
    End 
 
End 
 | 
         
The constant weather weapons apply the attributemodifiers to all affected units:
         | Code | 
          
;------------------------------------------------------------------------------ 
;;,;; adding ConstantDarkness for 2.02e, using this to allow the Darkness attributemodifier to fire again and again, instead of only affecting the units on the field when it first takes effect 
Weapon ConstantDarkness ;;,;;  
    RadiusDamageAffects = ALLIES 
    LeechRangeWeapon      = Yes 
    AttackRange           = 999999 
    MeleeWeapon           = No 
    DelayBetweenShots     = 2000 
    PreAttackDelay        = 0 
    PreAttackType         = PER_SHOT  
    FiringDuration        = 0 
 
    AttributeModifierNugget 
        AttributeModifier        = SpellBookDarkness 
        Radius             = 999999 
        SpecialObjectFilter      = GENERIC_BUFF_RECIPIENT_OBJECT_FILTER 
        AffectHordeMembers      = Yes 
        DamageFXType             = SWORD_SLASH 
    End 
End 
 
;------------------------------------------------------------------------------ 
;;,;; 2.02e fix for Freezing Rain, same deal as Darkness 
Weapon ConstantFreezingRain ;;,;;  
    RadiusDamageAffects = ENEMIES 
    LeechRangeWeapon      = Yes 
    AttackRange           = 999999 
    MeleeWeapon           = No 
    DelayBetweenShots     = 2000 
    PreAttackDelay        = 0 
    PreAttackType         = PER_SHOT  
    FiringDuration        = 0 
 
    AttributeModifierNugget 
        AttributeModifier        = GenericPassiveDebuff 
        AntiCategories        = LEADERSHIP 
        Radius             = 999999 
        SpecialObjectFilter      = GENERIC_BUFF_RECIPIENT_OBJECT_FILTER 
        AffectHordeMembers      = Yes 
        DamageFXType             = SWORD_SLASH 
    End 
 
    FireLogicNugget  
        LogicType        = DECREASE_BURN_RATE 
        Radius            = 999999 
        Damage            = 100 
    End 
End | 
         
The FireLogicNugget in ConstantFreezingRain is necessary because our OCLSpecialPower behavior for FreezingRain can no longer decrease burn rates on its own.
UPDATE:  Please be aware that you'll want to edit the SpecialObjectFilter line to suit your mod.  Neither of these powers used GENERIC_BUFF_RECIPIENT_OBJECT_FILTER originally; Darkness was able to affect many more units (like Trolls) and Freezing Rain was able to debuff more (in BFME II, where it had a debuff).  Also, you may desire a different anticategory line on Freezing Rain (BFME II's Freezing Rain is supposed to cancel Buffs and Spells) or to use a different modifier altogether.
Next, we have to make the game's two other weather powers, Cloud Break and Sunflare, cancel the attributemodifiers.  In object\goodfaction\goodfactionprops.ini, search for CloudBreakSunbeam and give it the appropriate FireWeaponUpdate:
         | Code | 
         Object CloudBreakSunbeam 
 
  ; *** ART Parameters *** 
  Draw = W3DScriptedModelDraw ModuleTag_Draw 
    DefaultModelConditionState 
      Model               = None 
      ParticleSysBone = None CloudBreakRays 
    End 
;    IdleAnimationState 
;      EnteringStateFX = FX_CloudBreakRays 
;    End  
         
    ; this is how you control birth fade 
;    BirthFadeTime = 1000  ; msec 
;    BirthFadeAdditive = Yes 
  
  End 
 
  ; *** AUDIO Parameters *** 
 
  ; ***DESIGN parameters *** 
  EditorSorting     = SYSTEM 
  ArmorSet 
    Armor = NoArmor 
  End 
  VisionRange = 0.0 
 
  ; *** ENGINEERING Parameters *** 
  KindOf = IMMOBILE UNATTACKABLE INERT SCARY 
 
  Body = ActiveBody ModuleTag_01 
    MaxHealth = 99999.0 
  End 
 
    ; the following two modules control death fade -- uses alpha for now 
    Behavior = LifetimeUpdate ModuleTag_02 
        MinLifetime = 5000   ; min lifetime in msec 
        MaxLifetime = 7000   ; max lifetime in msec 
    End 
 
    Behavior = FireWeaponUpdate ModuleTag_KillAllCurrentWeather ;;,;; added for 2.02e 
        FireWeaponNugget 
            WeaponName    = WeatherKiller 
            Offset = X:0 Y:0 Z:0 
            FireDelay    = 0 
            OneShot        = Yes 
        End 
    End 
 
    Behavior = AIUpdateInterface ModuleTag_03     
        AILuaEventsList                = SunbeamFunctions 
    End 
 
  Geometry = BOX 
  GeometryMajorRadius = 50.0 
  GeometryMinorRadius = 50.0 
  GeometryHeight = 100.0 
  GeometryIsSmall = No 
     
End | 
         
Do the same for SunflareSunbeam in system.ini:
         | Code | 
         ;//------------------------------------------------------------------------------ 
Object SunflareSunbeam 
     
    ;// *** ART Parameters *** 
    Draw = W3DScriptedModelDraw ModuleTag_Draw 
        DefaultModelConditionState 
            Model               = NONE 
            ParticleSysBone        = None SunRays 
            ParticleSysBone        = None SunFlareGlow 
            ParticleSysBone        = None SunFlareProxy 
        End 
    End 
 
    ;// *** AUDIO Parameters *** 
 
    ;// ***DESIGN parameters *** 
    EditorSorting     = SYSTEM 
     
    ArmorSet 
        Armor = NoArmor 
    End 
     
    VisionRange = 0.0 
 
    ;// *** ENGINEERING Parameters *** 
    KindOf = IMMOBILE UNATTACKABLE INERT SCARY 
 
    Body = ActiveBody ModuleTag_01 
        MaxHealth = 99999.0 
    End 
 
    ;// the following two modules control death fade -- uses alpha for now 
    Behavior = LifetimeUpdate ModuleTag_02 
        MinLifetime = SPELL_SUNFLARE_DURATION   ;// min lifetime in msec 
        MaxLifetime = SPELL_SUNFLARE_DURATION   ;// max lifetime in msec 
    End 
 
    Behavior = FireWeaponUpdate ModuleTag_KillAllCurrentWeather ;;,;; added for 2.02e 
        FireWeaponNugget 
            WeaponName    = WeatherKiller 
            Offset = X:0 Y:0 Z:0 
            FireDelay    = 0 
            OneShot        = Yes 
        End 
    End 
 
    Behavior = FireWeaponUpdate ModuleTag_DamageHandler 
        FireWeaponNugget 
            WeaponName    = SunflareWeapon 
            FireDelay    = 0 
            OneShot        = Yes    ;// Alternative is to fire as often as the reload time of this weapon allows 
        End 
    End 
 
    Behavior = AIUpdateInterface ModuleTag_03     
        AILuaEventsList                = SunbeamFunctions 
    End 
 
      Geometry            = CYLINDER 
    GeometryMajorRadius = 50.0 
    GeometryMinorRadius = 50.0 
    GeometryHeight        = 100.0 
    GeometryIsSmall        = No 
     
End | 
         
Finally, we have to edit the attributemodifiers themselves.  Be careful here, since 1.06's, 2.01's, and 2.02's stacking systems all work differently, and you'll need to edit these to meet the needs of your own mod.  
Originally, the Duration on the attributemodifiers had to be 0 - or forever - as it was controlled by the weather system.  Now that the attributemodifiers are not controlled by the weather, they need to be set to a normal value; in 2.02e, 3000.  This means that three seconds after the CasterObject dies, units will no longer be affected by the attributemodifier.  2.02e can use its generic debuff attributemodifier to accomplish this with Freezing Rain, but needs a special attributemodifier for Darkness since Darkness needs to carry a special Spell FX:
         | Code | 
         ModifierList SpellBookDarkness 
    Category = SPELL 
    Modifier = DAMAGE_MULT 150%     
    Modifier = ARMOR 33% ;;,;; 50% 
    Duration = 3000 ;;,;; 0 ; changed for 2.02e because this is no longer applied by the weather - see note in system.ini 
    FX         = FX_DarknessFlares  ;;,;; FX_InfiniteGenericLeadershipLvl1 
End | 
         
For the purposes of your own mod, you'll probably want to keep the original FX, unless you plan on adding a new one.  You may also wish to use RainDebuff instead of GenericPassiveDebuff on Freezing Rain; to do this, just edit the AttributeModifier line in the ConstantFreezingRain weapon; be sure to remember to change the Duration line on RainDebuff from 0.  Note that if you mod is based on RotWK 2.01, you don't have RainDebuff at all and will have to add it yourself.
Though that was fairly complicated, the results are definitely worth it.  Weather powers are much more fun to use when they actually work properly!
Prolong - Tuesday July 14, 2009 - 21:11
Does that happen all the time?  Sometimes the rain doesn't seem to appear, but I don't think that's related to this fix as I'm sure that happened before and it usually/often doesn't now; certainly I've seen the rain appear multiple times on the current version of 2.02.
Also, I'm going to update the tutorial to indicate that this is issue is probably with the FX not affecting units that actually are affected, given that the BT2DC patch has fixed Freezing Rain in a different way by tweaking the FX.
--------
Also updated a bit on the second page regarding the objectfilters of the attributemodifiers, as 2.02's are different from what they were originally and I had forgotten to mention that I'd changed that in the posted code.
--------
And now I've added a third page showing an alternative way to fix Freezing Rain, which MaDDoX and Rainmaker developed BT2DC.  It's a lot easier than my method, that's for sure.  Doesn't work for Darkness for whatever reason (not sure why) so my tricks are still good for something though. :D