Help with timed respawn script

Post » Sat Nov 17, 2012 3:07 pm

I'm attempting to script a custom npc to spawn and despawn at certain times each day. The npc is a ghost who only appears at night and will reappear at 8pm even if the player has defeated her previously. This is the script attached to the npc:

Spoiler
Scriptname WoodcuttersWifeRespawnScript extends ActorGlobalVariable Property GameHour  AutoFunction Enable (bool abFadeIn = false) nativeFunction Disable (bool abFadeOut = false) nativeFunction Resurrect() nativebool function isdead() nativebool function SpawnTime()	if GameHour.GetValue() == 20.0			Self.Enable()			Debug.Trace("Wakey wakey")	 	endif	if GameHour.GetValue() == 7.0			Self.Disable()			Debug.Trace("Goodnight")	endifendFunctionbool function ResurrectTime()	if GameHour.getValue() >= 20.0 && self.isdead()		self.resurrect()		Debug.Trace("It's alive!")	endif		endfunction


Unfortunately nothing happens in game. The npc dosen't enable (and resurrect if need be) at 8pm, nor does she disable at 7am.
I added some debug.trace messages, tested, and checked the log. I found this:

[07/29/2012 - 02:06:22AM] warning: Variable ::gametime_var on script WoodcuttersWifeRespawnScript loaded from save not found within the actual object. This variable will be skipped.


I have no idea what this means nor how to alleviate it. Any help would be greatly appreciated.
User avatar
OTTO
 
Posts: 3367
Joined: Thu May 17, 2007 6:22 pm

Post » Sat Nov 17, 2012 1:49 pm

Spoiler
ScriptName WoodcuttersWifeRespawnScript Extends ActorGlobalVariable Property GameHour AutoEvent OnInit()	RegisterForSingleUpdate(5)EndEventEvent OnUpdate()	RegisterForSingleUpdate(5)	Float fTime = GameHour.GetValue()	If IsEnabled() != (fTime > 20.0 || fTime < 7.0)		If IsEnabled()			Disable()			Debug.Trace("Goodnight")		Else			Enable()			Debug.Trace("Wakey wakey")			If IsDead()				Resurrect()				Debug.Trace("It's alive!")			EndIf		EndIf	EndIfEndEvent
Be sure to fill the property in the CK from the actor's scripts window. All instances of 'Self' were unnecessary as functions can be called implicitly. The native game functions needn't be in your script. As the script was, neither of the functions will happen while an OnUpdate event will.
User avatar
xxLindsAffec
 
Posts: 3604
Joined: Sun Jan 14, 2007 10:39 pm

Post » Sat Nov 17, 2012 11:10 pm

Thank you! That worked perfectly. I did however, encounter a small problem upon the actors resurrection. She was stark naked. So I added a couple of equipItem functions which sorted it.
User avatar
Neliel Kudoh
 
Posts: 3348
Joined: Thu Oct 26, 2006 2:39 am


Return to V - Skyrim

cron