Any way to add glow effect to object via script?

Post » Mon Jun 18, 2012 12:59 am

Is there any way to add a visual effect (like glow or smoke) to an object (not a weapon or armor or lightsource) via a script?

What I'm trying to do is make a book object start glowing based on certain conditions, and stop glowing once its been read.
User avatar
Lucky Girl
 
Posts: 3486
Joined: Wed Jun 06, 2007 4:14 pm

Post » Sun Jun 17, 2012 7:05 pm

Here's the script that I came up with for my mod "Unread Books Glow". It's attached to each BOOK form that I want to have glow.

Scriptname UnreadBooksGlowScript extends ObjectReference{Gives a visible glow to books that have not been read by the Player yet.The list of books that the player has read is stored in theFormList ReadBooksList.When an object reference to a book not in that list is loaded, ashader is picked from ReadBooksEffectShaderList and applied tothe object reference.When an unread book is read, the book is added to theReadBooksList.Each unread book checks whether it has been read every 3 seconds.If so, it turns off its effect shader.This polling approach is unfortunate, however I have not found agood way to broadcast state changes.}; PropertiesFormList Property ReadBooksList AutoFormList Property ReadBooksEffectShaderList Auto; Script variablesEffectShader ourEffectShader = Noneint shaderIdx = -1int updateTime = 3 ; Seconds; FunctionsFunction TraceMe(string msg, ObjectReference ref)	Debug.Trace(msg + " " + (self as string) + " " + (self.GetCurrentLocation() as string) + " " + (self.getParentCell() as string) + " " + (self.GetWorldSpace() as string))EndFunctionFunction StartGlow()	;TraceMe("StartGlow", self)	if ourEffectShader == None		if shaderIdx == -1			; Pick random shader effect			shaderIdx = Utility.RandomInt(0, ReadBooksEffectShaderList.GetSize() - 1)		endIf		ourEffectShader = (ReadBooksEffectShaderList.GetAt(shaderIdx) as EffectShader)		ourEffectShader.Play(self)		RegisterForSingleUpdate(updateTime)	endIfEndFunctionFunction StopGlow()	;TraceMe("StopGlow", self)	if ourEffectShader != None		ourEffectShader.Stop(self)		ourEffectShader = None		UnregisterForUpdate()	endIfEndFunctionbool Function IsRead()	return ReadBooksList.HasForm(GetBaseObject())endFunctionbool Function IsUnread()	return !ReadBooksList.HasForm(GetBaseObject())endFunction; Event handlersEvent OnCellAttach()	;TraceMe("OnCellAttach", self)	if IsUnread()		StartGlow()	endIfEndEventEvent OnCellDetach()	;TraceMe("OnCellDetach", self)	StopGlow()EndEventEvent OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)	{Change to a different effect shader.  For debugging mostly}	;TraceMe("OnHit", self)	if IsUnread()		StopGlow()		shaderIdx = -1		StartGlow()		Debug.Trace("EffectShader #" + (shaderIdx as string) + " " + (ourEffectShader as string))		;Debug.Notification(shaderIdx as string)	endIfEndEventEvent OnRead()	;TraceMe("OnRead", self)	if IsUnread()		ReadBooksList.AddForm(GetBaseObject())		StopGlow()	endIfEndEventEvent OnUpdate()	;TraceMe("OnUpdate", self)	if IsUnread()		RegisterForSingleUpdate(updateTime)	else		StopGlow()	endIfEndEvent
User avatar
FLYBOYLEAK
 
Posts: 3440
Joined: Tue Oct 30, 2007 6:41 am

Post » Sun Jun 17, 2012 3:51 pm

SNIP--
Posted this in the wrong thread, my apologies.
User avatar
Amanda savory
 
Posts: 3332
Joined: Mon Nov 27, 2006 10:37 am


Return to V - Skyrim