Why won't my script work?

Post » Sat May 18, 2013 12:35 am

I'm trying to make a script that deletes an npc when the player leaves the area and then replaces it with a new one. Basically a quick respawn script.

Here is the script:

Scriptname AAAKillAndDisableWhenFarFromPlayer extends ObjectReference
{Script that will kill and delete this alias/actor once it has gotten a certain distance from the player.}

ActorBase Property ZZZActorSpawnWinterhold auto
{This should point to your leveled list}

Event OnUnload()

PlaceAtMe(ZZZActorSpawnWinterhold) ; spawn an Actor from the leveled list
delete()

EndEvent

User avatar
Amy Melissa
 
Posts: 3390
Joined: Fri Jun 23, 2006 2:35 pm

Post » Sat May 18, 2013 9:53 am

Always read the notes:

http://www.creationkit.com/OnUnload_-_ObjectReference

This event is only sent when an object's 3d is unloaded. This may or may not have anything to do with its parent cell and/or the player's location in the world. Don't rely on it happening every time a player leaves the parent cell, even an interior.

In addition to that, you're far better off doing it the other way around. Rather than making the "respawn" happen when the player leaves the cell, make it happen when the player re-visits the cell. So use OnCellAttach instead.

User avatar
Isabel Ruiz
 
Posts: 3447
Joined: Sat Nov 04, 2006 4:39 am

Post » Sat May 18, 2013 12:14 am

First of all, use http://www.creationkit.com/OnCellDetach_-_ObjectReference instead of OnUnload().

Does your script fail to compile? Or does it just not work?

If it doesn't compile, I think you need to do "Self.PlaceAtMe" and "Self.Delete()".

edit: Better reply above... my scripting skill is only 21 :spotted owl:

User avatar
Dominic Vaughan
 
Posts: 3531
Joined: Mon May 14, 2007 1:47 pm

Post » Sat May 18, 2013 10:40 am

http://www.creationkit.com/PlaceActorAtMe_-_ObjectReference for an ActorBase or http://www.creationkit.com/ObjectReference.PlaceAtMe_(Papyrus) for a LeveledActor I'd imagine.

Also, http://www.creationkit.com/Delete_-_ObjectReference will only work on dynamically created references. If this script is attached to a REFR defined in the plugin, Delete won't work.

User avatar
Dezzeh
 
Posts: 3414
Joined: Sat Jun 16, 2007 2:49 am

Post » Fri May 17, 2013 8:14 pm

Thanks guys, I was able to get it to work.

User avatar
Jinx Sykes
 
Posts: 3501
Joined: Sat Jan 20, 2007 11:12 pm


Return to V - Skyrim