Paladin555 Posted November 9, 2021 Share Posted November 9, 2021 Hi, I want to change this event so when an NPC dies there's a 10 second delay before Self.Reset(None) brings the NPC back. I want to make it act like a respawn timer if possible. Here's the code: Event OnDeath(Actor akKiller) Self.Reset(None)EndEvent Link to comment Share on other sites More sharing options...
SKKmods Posted November 9, 2021 Share Posted November 9, 2021 The challenge you have is not with code, but the game design. When a actor dies it is marked as a corpse. If the actor/corpse is non persistent and the number of corpses exceeds the corpse cleanup counters like iRemoveExcessDeadCount (there are several) the game will delete the corpse. If that corpse has an active script timer attached you will end up generating hanging scripts which can stack up to crash games. To avoid this you should make the actor/corpse persistent though a quest alias and run the script on that. Link to comment Share on other sites More sharing options...
Paladin555 Posted November 9, 2021 Author Share Posted November 9, 2021 Not too worried about stability as this script is for alternate save npc battles. Just trying to find a way to delay Self.Reset(None) for a few seconds. They respawn too quickly. Link to comment Share on other sites More sharing options...
LarannKiar Posted November 9, 2021 Share Posted November 9, 2021 (edited) Not too worried about stability as this script is for alternate save npc battles. Just trying to find a way to delay Self.Reset(None) for a few seconds. They respawn too quickly. You could try it with two scripts: a quest script and an actor script. The actor script would call the functions of the quest script which resets your actors with timers. Attach this quest script (Scriptname: HandlerScript) to a quest (EditorID should be: HandlerQuest). Scriptname HandlerScript extends Quest Actor[] myActors Event OnQuestInit() myActors = new Actor[0] EndEvent Function InitializeMe(Actor ActorToInitialize) If myActors.Find(ActorToInitialize) < 0 myActor.Add(ActorToInitialize) EndIf EndFunction Function ResetMe(Actor ActorToReset) If myActors.Find(ActorToReset) >= 0 StartTimer(10, myActors.Find(ActorToReset)) Else Debug.Trace("Error, ResetMe: " + ActorToReset + " hasn't been initialized and couldn't be found in myActors.") EndIf EndFunction Event OnTimer(int aiTimerID) If myActors[aiTimerID] != none If myActors[aiTimerID].IsDead() == 1 myActors[aiTimerID].Reset() ;fixed "variable myActor is undefined" Else Debug.Trace("Error, OnTimer: " + myActors[aiTimerID] + " is not dead.") ;fixed "variable ActorToReset is undefined" EndIf Else Debug.Trace("Error, OnTimer: myActors with index: " + aiTimerID + " is none.") EndIf EndEvent Function Shutdown() ;should be called when the HandlerQuest stops Int Index = 0 While myActors.Length >= Index If myActors[Index] != none CancelTimer(Index) ;fixed "type mismatch on parameter 1 - cannot pass a actor to a int" EndIf Index = Index + 1 EndWhile myActors.Clear() EndFunction Attach the actor script to your actor: Scriptname YOURSCRIPTNAME extends Actor Const Quest Property HandlerQuest Auto Const Event OnInit() Utility.Wait(0.2) (HandlerQuest as HandlerScript).InitializeMe(Self) EndEvent Event OnDying(Actor akKiller) (HandlerQuest as HandlerScript).ResetMe(Self) EndEvent I haven't tested them but hopefully they'll work.. EDIT: I fixed the errors you posted below.. I should've tried to compile them.. sorry. Anyway, glad you get it working. Edited November 9, 2021 by LarannKiar Link to comment Share on other sites More sharing options...
Paladin555 Posted November 9, 2021 Author Share Posted November 9, 2021 (edited) I tried saving the HandlerScriptNPC, but I get this: Compiling "HandlerScriptNPC"...C:\Users\...\AppData\Local\Temp\PapyrusTemp\HandlerScriptNPC.psc(12,2): variable myActor is undefinedC:\Users\...\AppData\Local\Temp\PapyrusTemp\HandlerScriptNPC.psc(12,10): none is not a known user-defined script typeC:\Users\...\AppData\Local\Temp\PapyrusTemp\HandlerScriptNPC.psc(27,10): variable myActor is undefinedC:\Users\...\AppData\Local\Temp\PapyrusTemp\HandlerScriptNPC.psc(27,18): none is not a known user-defined script typeC:\Users\...\AppData\Local\Temp\PapyrusTemp\HandlerScriptNPC.psc(29,57): variable ActorToReset is undefinedC:\Users\...\AppData\Local\Temp\PapyrusTemp\HandlerScriptNPC.psc(39,14): type mismatch on parameter 1 - cannot pass a actor to a intNo output generated for HandlerScriptNPC, compilation failed. Failed compilation - Are you sure you want to save? I created a new quest named HandlerQuest, added a new script titled: HandlerScriptNPC, and then pasted the Script code using edit source. Had to rename the script title because it was already in use. Edited November 9, 2021 by Paladin555 Link to comment Share on other sites More sharing options...
Paladin555 Posted November 9, 2021 Author Share Posted November 9, 2021 (edited) I just created a smaller actor script using that utlility.wait line from your post. Scriptname RespawnNPCScript extends Actor Const Event OnDeath(Actor akKiller) Utility.Wait(5.0)Self.Reset(None)EndEvent That seemed to have did the job. Thanks LarannKiar! Edited November 9, 2021 by Paladin555 Link to comment Share on other sites More sharing options...
Recommended Posts