Jump to content

[LE] Actor Deletion Question


Recommended Posts

I'm working on a mod that adds new generic NPCs to towns and cities. The way I go about this is I have several Markers in cities, that detect when the player has entered or exited the area. When the player leaves the area, a new person is placed using PlaceAtMe. When the player enters the area, and a sufficient amount of time has passed, the person is marked for deletion.

 

Here's the source code:

GlobalVariable Property MinLiving Auto
GlobalVariable Property MaxLiving Auto
GlobalVariable Property RespawnWait Auto
GlobalVariable Property GameDaysPassed Auto
ObjectReference Property PlaceMarker Auto
LeveledActor Property ToPlace Auto

string Property MarkerName Auto

float LastUpdate = -100.0
Actor Person = None

Event OnCellDetach()
	Debug.Trace("People: " + MarkerName + " Detached from Cell")
	if((!Person || Person.IsDead() || Person.IsDeleted()) && (GameDaysPassed.GetValue() - LastUpdate) > RespawnWait.GetValue())
		Debug.Trace("People: " + MarkerName + " Placing New Person")
		Person = PlaceMarker.PlaceAtMe(ToPlace) as Actor
		LastUpdate = GameDaysPassed.GetValue()
		Debug.Trace("People: " + MarkerName + " New Person Placed: " + Person.GetFormID())
	endIf
endEvent

Event OnCellAttach()
	Debug.Trace("People: " + MarkerName + " Attached to Cell")
	float RandLiving = Utility.RandomFloat(MinLiving.GetValue(), MaxLiving.GetValue())
	if(Person && (GameDaysPassed.GetValue() - LastUpdate) > RandLiving)
		Debug.Trace("People: " + MarkerName + " Deleting Person: " + Person.GetFormID())
		Person.DeleteWhenAble()
		Debug.Trace("People: " + MarkerName + " Person Deleted")
		Person = None
	endIf
endEvent

My question is, how safe is this? Would this constant deletion potentially cause save-game bloat? Or if one of the radiant npcs was used in an alias, then deleted, would that cause issues?

Link to comment
Share on other sites

  • 1 month later...
Off the top of my head and at first glance it appears you forgot to use actorbase property while using placeatme. I was under the influence thats the only way placeatme works. Also id try disabling the npcs then deletion. I think that helps prevent the bloat save. Edited by Gamer921
Link to comment
Share on other sites

From what I've seen from Beth's scripts, they like to disable the object first and then delete.

 

self.disable()

self.delete()

 

I haven't done it any other way than this. Obviously you don't disable an object that isn't visible to begin with.

Disable hides it from immediate view but the reference remains in case you EVER enable it again: http://www.creationkit.com/index.php?title=Disable_-_ObjectReference

Disables this reference, fading it out if necessary. This function is latent and will wait for the fade out and/or disable to happen.

Delete is really more like delete when conditions are met: http://www.creationkit.com/index.php?title=Delete_-_ObjectReference

Flags this object reference as wanting to be deleted. A reference that is flagged for delete will be deleted as soon as:

  • It is no longer in a script property
  • It is no longer registered for updates
  • It is no longer being watched for Anim Events
  • It is no longer held in a quest Alias

Both are used so that the object disappears immediately and is then marked to be removed when the conditions are met.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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