Jump to content

Scripting: Spawn actors without using PlaceAtMe


Recommended Posts

Hello again Nexus forums! Today I'm trying to make traps that summon creatures. In Morrowind's daedric shrines there were altar items that summoned daedra when disturbed. I want exactly the same behavior but with ghosts.

 

I have the following script for when the player disturbs a sacred resting place:

ScriptName LohithaHauntedDoorScript
;Summons a ghost to the parent ref.

short doOnce
ref targetMarker

Begin OnReset
	set doOnce to 0
End

Begin OnActivate
	if GetOpenState != 3
		SetOpenState 0
		return
	else
		SetOpenState 1
		if doOnce != 0
			return
		else
			set doOnce to 1
			set targetMarker to GetParentRef
			targetMarker.PlaceAtMe CreatureGhost
			PlaySound AMBBreath
		endif

	endif		
End

The code above performs exactly as I desire. The problem is that, apparently, the PlaceAtMe function causes the player's save file to grow every time it's used. Having suffered massive save files myself, I want to avoid using the PlaceAtMe function.

 

The construction set wiki recommends to use an existing creature and moving them. I can't seem to get this working. My current attempt uses the following code:

Begin OnActivate
	if GetOpenState != 3
		SetOpenState 0
		return
	else
		SetOpenState 1
		if doOnce != 0
			return
		else
			set doOnce to 1
			set targetMarker to GetParentRef
			PlaySound AMBBreath
			set summonedGhost to CreatureGhost.CreateFullActorCopy
			summonedGhost.Disable
			summonedGhost.MoveToMarker targetMarker
			summonedGhost.Enable
		endif

	endif		
End

Do any of you super knowledgeable folk understand why this wouldn't work? Is it because I'm disabling, moving, and enabling in the same frame? How can I delay these steps to different frames?(if necessary)

Link to comment
Share on other sites

The problem with PlaceAtMe started at the beginning of time when authors used it indiscriminately on objects (non-Actors) and there was no way to solve it at the time

 

Later on, the OBSE devs added the DeleteReference and all was good (for responsible authors that knew how to clean up their own mess)

 

For Actors, that is not really a problem as the game engine has ways to remove them (otherwise the savegame would be bloated just with the vanilla creatures spawning from leveled lists). The CellReset article details part of this cleanup process.

 

 

On the other hand, CreateFullActorCopy creates a copy of a BaseObject and there is no way to remove it. Better not use it.

Link to comment
Share on other sites

Thanks QQuix! I think I understand how savegames interact with actors now.

 

Please correct me if this line of thinking is wrong.

 

In my use case, PlaceAtMe creates a dynamic(generated at runtime) reference to the ghost. The spawned ghost is non-persistent by default. As a dynamic, non-persistent reference, it will be cleaned from the save file after 72 in-game hours(according to the iHoursToRespawnCell variable). Regardless of the number of ghosts this script spawns, whether the player leaves them dead or alive, they will be deleted from the save file as expected.

 

Since I can safely use PlaceAtMe, the final script for my trapped door(yet another trapped door, haha!) is:

ScriptName LohithaHauntedDoorScript
;Summons a ghost to the parent ref.

short doOnce
ref targetMarker

Begin OnReset
	set doOnce to 0
End

Begin OnActivate
	if GetOpenState != 3
		SetOpenState 0
		return
	else
		if GetLocked == 1
			 return
		else
			SetOpenState 1
			if doOnce != 0
				return
			else
				set doOnce to 1
				set targetMarker to GetParentRef
				targetMarker.PlaceAtMe CreatureGhost
				PlaySound AMBBreath
			endif
		endif
	endif		
End
Link to comment
Share on other sites

  • Recently Browsing   0 members

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