User:Candlemaster/Absorb Frost

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search

Absorb Frost[edit | edit source]

These scripts require OBSE (I use v 18)

These scripts are complete, but not confirmed bug-free!

The purpose of this script is to allow a scripted spell or equipped item to cause any Frost Damage felt by the user to be healed by it, instead of damaged. With minor tweaks, this script can easily be modified to work with Fire Damage, Shock Damage, Damage Health, and even Sun Damage.

Known issues: When hit by a large-magnitude frost damage spell (Frost Damage 200 Points for 1 seconds), the user can still die. When I set the player's health to 1 and was hit by frost damage, I was killed. There is no way around this, as far as I know, unless there's a way to miraculously detect an effect's magnitude before it's applied to the user. If however, you survive the first frame of the damage, you will be healed by it as desired.

Final Script[edit | edit source]

scn HVHAbsorbFrostScriptOBSE

long TempMag  ;This variable stores the magnitude of the frost damage, and alterations are made upon it.
long EffectCode  ;Stores the effect code of the desired magic effect, since "GetNthActiveEffectCode" returns longs instead of chars
ref UserRef  ;The user (in most cases, the player - This exists instead of "player" to allow you to give it to npc's or companions)
long NumEffects
long CurrentEffect

Begin OnAdd
	set UserRef to GetContainer
End

Begin GameMode

	if ( UserRef.GetEquipped HVHIceRobeOBSE == 0 )
		return  ;Do nothing if the user doesn't have the item equipped
	endif

	set NumEffects to UserRef.GetActiveEffectCount
	set CurrentEffect to 0
	set EffectCode to GetMagicEffectCode FRDG ; Sets "Frost Damage" as the affected magic effect

	if ( NumEffects <= 0 )
		return  ;stops the loop from running at all if the player doesn't have any active effects
	endif

	Label  ;The loop begins here

	If ( UserRef.GetNthActiveEffectCode CurrentEffect == EffectCode )  ;Only apply the script to the effect you want
		set TempMag to UserRef.GetNthActiveEffectMagnitude CurrentEffect
		;PrintToConsole "Frost Damage Effect Found.  Magnitude == %.0f" TempMag
		if ( TempMag < 0 )  ;Only apply to magnitudes that we haven't already reversed
			set TempMag to ( TempMag * -1 )
			UserRef.SetNthActiveEffectMagnitude TempMag CurrentEffect
			;PrintToConsole "An effect has been reversed.  New Magnitude == %.0f" TempMag
		endif
	endif

	set CurrentEffect to ( CurrentEffect + 1 )
	if ( CurrentEffect < NumEffects )
		GoTo ;The loop ends here, but only if you have no more effects to go through.
	endif

End

This script is based off Attempt #3, using the magnitude reversal approach. When applied (worn), the player still experiences Frost Damage, and in the Active Effects page, it is displayed as a positive magnitude. However, the player's health will increase, instead of decrease, as desired.

See User:Candlemaster/Absorb_Frost/Progress to see how this script was developed.