Jump to content

Desperately Need Help Scripting!


elseagoat

Recommended Posts

Well, I looked at the ImageSpace Modifiers page, and at the ImageSpaceModifier Script page, but I still don't know a couple things.

 

So this is what I came up with, assuming that IMODs play in a loop, and that PopTo() is a combination of Remove() and Apply().

 

 

Scriptname ExampleScript extends ObjectReference  


Actor property Player auto
Float property EffectRadius auto
Float property SpellDuration auto
Float property IntroDuration auto
Float property LoopDuration auto
Float property OutroDuration auto
ImageSpaceModifier property Intro auto
ImageSpaceModifier property Loop auto
ImageSpaceModifier property Outro auto
GlobalVariable property IMODGlobal auto
{0 = none, 1 = Intro, 2 = Loop, 3 = Outro}
Float ElapsedTime = 0.0
Float Interval


Event OnLoad()

if (IMODGlobal.GetValueInt() != 0)
	ObjectReference OldActivator
	while (OldActivator == None)
		OldActivator = Game.FindRandomReferenceOfTypeFromRef(GetBaseObject(), Self, 4096.0)
		if (OldActivator == Self)
			OldActivator = None
		endif
	endwhile
	(OldActivator as ExampleScript).CleanUp(True)
endif
Interval = 0.5
RegisterForSingleUpdate(Interval)

EndEvent


Event OnUpdate()

ElapsedTime += Interval
if (ElapsedTime >= SpellDuration)
	CleanUp()
	Return
endif
int IMODstate = IMODGlobal.GetValueInt()
if (GetDistance(Player) <= EffectRadius)
	if (IMODstate == 0)
		Intro.Apply()
		IMODGlobal.SetValueInt(1)
		Interval = IntroDuration
	elseif (IMODstate == 1)
		Intro.PopTo(Loop)
		IMODGlobal.SetValueInt(2)
		Interval = LoopDuration
	elseif (IMODstate == 2)
		Interval = LoopDuration
	elseif (IMODstate == 3)
		Outro.PopTo(Intro)
		IMODGlobal.SetValueInt(1)
		Interval = IntroDuration
	endif
else
	if (IMODstate == 0)
		Outro.Apply()
	elseif (IMODstate == 1)
		Intro.PopTo(Outro)
	elseif (IMODstate == 2)
		Loop.PopTo(Outro)
	endif
	IMODGlobal.SetValueInt(3)
	Interval = OutroDuration
endif
RegisterForSingleUpdate(Interval)

EndEvent


Function CleanUp(Bool bNewExists = False)

if !bNewExists
	int IMODstate = IMODGlobal.GetValueInt()
	if (GetDistance(Player) <= EffectRadius)
		if (IMODstate == 1)
			Intro.PopTo(Outro)
		elseif (IMODstate == 2)
			Loop.PopTo(Outro)
		endif
		IMODGlobal.SetValueInt(3)
		Utility.Wait(OutroDuration)
		Outro.Remove()
	else
		if (IMODstate == 1)
			Intro.Remove()
		elseif (IMODstate == 2)
			Loop.Remove()
		elseif (IMODstate == 3)
			Outro.Remove()
		endif
	endif
	IMODGlobal.SetValueInt(0)
endif
Disable()
Delete()

EndFunction

 

 

I got it to compile, but no idea if it'll work. I'm also sure that it could be slimmed down too.

Edited by fg109
Link to comment
Share on other sites

Thanks! I'll give that a shot. I also wrote this real quick, The player should experience an IMOD while near the portal but upon leaving it will fade out, and will fade back in if the player returns. Also, it should remove the activator (which is not invisible, it is actually a black smokey object) if the player makes another one by casting the spell again.

 

Scriptname activatorDropFXSoulHarvest extends ObjectReference

float property MaxLife = 39.0 auto
{number of seconds to keep checking player distance}
float property MaxRadius = 1700.0 auto
{distance in units to apply IMOD to player}
float property fDelay = 0.9 auto
{time to wait before switching to constant Imod}
ImageSpaceModifier property IntroFX auto
{IsMod applied at the start of the spell effect}
ImageSpaceModifier property LoopFX auto
{main isMod for spell}
ImageSpaceModifier property OutroFX auto
{IsMod applied at the end of the spell effect}
Float Property fImodStrength = 1.0 auto
{IsMod Strength from 0.0 to 1.0}

ObjectReference OldActivator
int whilecount = 0
int updatecount = 0
bool PinRadLastCheck = true

Event OnLoad()
IntroFX.Remove()
LoopFX.Remove()
OutroFX.Remove()
     while (whilecount < 25)
     		OldActivator = Game.FindRandomReferenceOfTypeFromRef(GetBaseObject(), Self, 4096.0)
           if (OldActivator != Self)
		whilecount = 25
	endif
	whilecount += 1
       endwhile
       if (OldActivator != Self)
	(OldActivator as activatorDropFXSoulHarvest).ClearAll()
       endif
	introFX.apply(fImodStrength)                                  
	Utility.Wait(fDelay)                           
	introFX.PopTo(LoopFX,fImodStrength)
	RegisterForSingleUpdate(1.0)
EndEvent

Event OnUpdate()
If (UpdateCount == MaxLife)
	ClearAll()
EndIf
If (UpdateCount < MaxLife)
	If (Game.GetPlayer().GetDistance(Self) > MaxRadius)
		If (PInRadLastCheck == true)
			PInRadLastCheck = false
			IntroFX.Remove()
			LoopFX.PopTo(OutroFX,fImodStrength)
		EndIf
	EndIf
	If (Game.GetPlayer().GetDistance(Self) < MaxRadius)
		If (PInRadLastCheck == false)
			PInRadLastCheck = true
			LoopFX.Remove()
			OutroFX.remove()
			introFX.apply(fImodStrength)                                  
			Utility.Wait(fDelay)                           
			introFX.PopTo(LoopFX,fImodStrength)
		EndIf
	EndIf
updatecount += 1
RegisterForSingleUpdate(1.0)
EndIf
EndEvent

Function ClearAll()
IntroFX.Remove()
LoopFX.Remove()
OutroFX.Remove()
DisableNoWait()
Delete()

Edited by elseagoat
Link to comment
Share on other sites

Ok so the script I posted above, sometimes works, but sometimes doesn't.

 

It appears to remove activators successfully on successive casts.

 

So basically, I cast it once, cast it again, and sometimes it will detect the other activator and remove it. But, sometimes it doesn't. Also, it doesn't seem to stop the script ion the old activator from running at all because the script on the old activator will in fact still remove the imods when its duration runs up. I am going to try a new script, slightly different with a while loop in another place.

Link to comment
Share on other sites

Ok, thanks to the script you posted, I got an idea to circumvent the need for a while loop (which I found caused issues, because it took a second or two to run sometimes if it took more tries to find the object, and it wasnt 100% foolproof, even with only a small chance, there was still a chance that the oldactivator would not be found.)

 

 

Now that I know about globalvariables, I can easily keep track of whether there is an older activator. So basically, I have two scripts, one script is responsible for checking the globalvariable, then deciding which of two identical activators with different names should be placed, and then doing a check to see if the OTHER activator is in the radius and removing it, and then "flip flopping" the global variable next time so it reverses which activator is deleted and which is placed.

 

When it deletes it, it does so through casting (again, thanks for making me aware of this) so that it can easily set a boolean variable within the activator script that is trying to run in order to stop it from looping. Which is important so that the old activator, upon deleting itself when time runs out, does not remove IMODs caused by any newer casts of the spell.

 

Will report back if it works. I am so so so close to having a VERY polished looking spell here.

Edited by elseagoat
Link to comment
Share on other sites

Looks great. I love it

 

edit: when are you gonna upload!

 

 

I can upload right now!

 

Now I am not sure how this works, but if you install it with other mods I don't know what it will do. The spell is completely self contained with its own scripts and forms, so it doesn't modify anything vanilla, its all new stuff. Other than that, a few references to some existing visual FX.

 

Anyways, on my game, its the only mod im running, and to get the spell do:

 

help harvest

 

and look for the "spel" Soul Harvest. For me, it is player.addspell 02000d66

 

 

Eventually, though, I plan to incorperate this into a conjuration overhaul as a final perk in the necromancy branch. It is pretty powerful, though I don't think too overpowered.

Edited by elseagoat
Link to comment
Share on other sites

Wow, I did not know you kept the name 'MyActivatorScript'. Since scripts are not embedded in your mod file now, you have to be careful of some other mod having the same script names as yours. Otherwise, one mod's scripts will overwrite the other's, and one of the mods will no longer work correctly. I suggest prefixing all your scripts with your username. Edited by fg109
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...