ReDragon2013 Posted December 21, 2021 Share Posted December 21, 2021 (edited) Unfortuantely papyrus script language is not always very easy to understand. Very often is an 'improvement' of vanilla scripts, a step forward to get runtime errors with improved version.That is most likely by using new script versions on savegames. defaultPrisonerDoorSCRIPT (vanilla code) Scriptname defaultPrisonerDoorSCRIPT extends ObjectReference {Default script on a door, that is linked to a prisoner, to handle his factions.} import game import utility import debug Faction Property dunPrisonerFaction Auto ObjectReference Property Prisoner01 Auto ObjectReference Property Prisoner02 Auto ObjectReference Property Prisoner03 Auto ObjectReference Property Prisoner04 Auto ObjectReference Property Prisoner05 Auto ObjectReference Property Prisoner06 Auto ObjectReference Property PrisonerLink Auto Hidden bool Property AlreadyLoaded Auto Hidden EVENT OnLoad() if AlreadyLoaded == FALSE if Prisoner01 (Prisoner01 as Actor).AddToFaction(dunPrisonerFaction) endif if Prisoner02 (Prisoner02 as Actor).AddToFaction(dunPrisonerFaction) endif if Prisoner03 (Prisoner03 as Actor).AddToFaction(dunPrisonerFaction) endif if Prisoner04 (Prisoner04 as Actor).AddToFaction(dunPrisonerFaction) endif if Prisoner05 (Prisoner05 as Actor).AddToFaction(dunPrisonerFaction) endif if Prisoner06 (Prisoner06 as Actor).AddToFaction(dunPrisonerFaction) endif PrisonerLink = GetLinkedRef() if PrisonerLink (PrisonerLink as Actor).AddToFaction(dunPrisonerFaction) endif endif AlreadyLoaded = TRUE EndEVENT Auto STATE WaitingToBeOpened EVENT OnOpen (ObjectReference triggerRef) if Prisoner01 (Prisoner01 as Actor).RemoveFromFaction(dunPrisonerFaction) Utility.Wait(0.1) (Prisoner01 as Actor).EvaluatePackage() endif if Prisoner02 (Prisoner02 as Actor).RemoveFromFaction(dunPrisonerFaction) Utility.Wait(0.1) (Prisoner02 as Actor).EvaluatePackage() endif if Prisoner03 (Prisoner03 as Actor).RemoveFromFaction(dunPrisonerFaction) Utility.Wait(0.1) (Prisoner03 as Actor).EvaluatePackage() endif if Prisoner04 (Prisoner04 as Actor).RemoveFromFaction(dunPrisonerFaction) Utility.Wait(0.1) (Prisoner04 as Actor).EvaluatePackage() endif if Prisoner05 (Prisoner05 as Actor).RemoveFromFaction(dunPrisonerFaction) Utility.Wait(0.1) (Prisoner05 as Actor).EvaluatePackage() endif if Prisoner06 (Prisoner06 as Actor).RemoveFromFaction(dunPrisonerFaction) Utility.Wait(0.1) (Prisoner06 as Actor).EvaluatePackage() endif if PrisonerLink (PrisonerLink as Actor).RemoveFromFaction(dunPrisonerFaction) Utility.Wait(0.1) (PrisonerLink as Actor).EvaluatePackage() endif GoToState("AlreadyOpened") EndEVENT endSTATE STATE AlreadyOpened ;do nothing EndSTATE defaultPrisonerDoorSCRIPT (subhuman VSmO 1.1) Scriptname defaultPrisonerDoorSCRIPT extends ObjectReference {Default script on a door, that is linked to a prisoner, to handle his factions.} ;import game ;import utility ;import debug Faction Property dunPrisonerFaction Auto ObjectReference Property Prisoner01 Auto ObjectReference Property Prisoner02 Auto ObjectReference Property Prisoner03 Auto ObjectReference Property Prisoner04 Auto ObjectReference Property Prisoner05 Auto ObjectReference Property Prisoner06 Auto ObjectReference Property PrisonerLink Auto Hidden bool Property AlreadyLoaded Auto Hidden ; subhuman - VSmO 1.1 Actor[] thePrisoners EVENT OnLoad() if AlreadyLoaded == FALSE ; subhuman VSmO 1.1 thePrisoners = new Actor[7] thePrisoners[0] = Prisoner01 as Actor thePrisoners[1] = Prisoner02 as Actor thePrisoners[2] = Prisoner03 as Actor thePrisoners[3] = Prisoner04 as Actor thePrisoners[4] = Prisoner05 as Actor thePrisoners[5] = Prisoner06 as Actor thePrisoners[6] = GetLinkedRef() as Actor int index = 0 while (index < 7) if thePrisoners[index] != none thePrisoners[index].AddToFaction(dunPrisonerFaction) endIf index += 1 endWhile ; if Prisoner01 ; (Prisoner01 as Actor).AddToFaction(dunPrisonerFaction) ; endif ; if Prisoner02 ; (Prisoner02 as Actor).AddToFaction(dunPrisonerFaction) ; endif ; if Prisoner03 ; (Prisoner03 as Actor).AddToFaction(dunPrisonerFaction) ; endif ; if Prisoner04 ; (Prisoner04 as Actor).AddToFaction(dunPrisonerFaction) ; endif ; if Prisoner05 ; (Prisoner05 as Actor).AddToFaction(dunPrisonerFaction) ; endif ; if Prisoner06 ; (Prisoner06 as Actor).AddToFaction(dunPrisonerFaction) ; endif ; ; PrisonerLink = GetLinkedRef() ; if PrisonerLink ; (PrisonerLink as Actor).AddToFaction(dunPrisonerFaction) ; endif AlreadyLoaded = TRUE endif EndEVENT Auto STATE WaitingToBeOpened EVENT OnOpen (ObjectReference triggerRef) ; subhuman - VSmO 1.1 int index = 0 while (index < 7) if thePrisoners[index] != none thePrisoners[index].RemoveFromFaction(dunPrisonerFaction) ; *** error line here *** endIf index += 1 endWhile index = 0 while (index < 7) if thePrisoners[index] != none thePrisoners[index].EvaluatePackage() endIf index += 1 endWhile thePrisoners = new Actor[1] ; *** ??? ; if Prisoner01 ; (Prisoner01 as Actor).RemoveFromFaction(dunPrisonerFaction) ; Utility.Wait(0.1) ; (Prisoner01 as Actor).EvaluatePackage() ; endif ; if Prisoner02 ; (Prisoner02 as Actor).RemoveFromFaction(dunPrisonerFaction) ; Utility.Wait(0.1) ; (Prisoner02 as Actor).EvaluatePackage() ; endif ; if Prisoner03 ; (Prisoner03 as Actor).RemoveFromFaction(dunPrisonerFaction) ; Utility.Wait(0.1) ; (Prisoner03 as Actor).EvaluatePackage() ; endif ; if Prisoner04 ; (Prisoner04 as Actor).RemoveFromFaction(dunPrisonerFaction) ; Utility.Wait(0.1) ; (Prisoner04 as Actor).EvaluatePackage() ; endif ; if Prisoner05 ; (Prisoner05 as Actor).RemoveFromFaction(dunPrisonerFaction) ; Utility.Wait(0.1) ; (Prisoner05 as Actor).EvaluatePackage() ; endif ; if Prisoner06 ; (Prisoner06 as Actor).RemoveFromFaction(dunPrisonerFaction) ; Utility.Wait(0.1) ; (Prisoner06 as Actor).EvaluatePackage() ; endif ; ; if PrisonerLink ; (PrisonerLink as Actor).RemoveFromFaction(dunPrisonerFaction) ; Utility.Wait(0.1) ; (PrisonerLink as Actor).EvaluatePackage() ; endif GoToState("AlreadyOpened") EndEVENT endSTATE STATE AlreadyOpened ;do nothing EndSTATE A user posted here: https://www.nexusmods.com/skyrimspecialedition/mods/54061?tab=posts next error code [ (0005E811)].defaultPrisonerDoorSCRIPT.OnOpen() - "<savegame>" Line ? [12/15/2021 - 04:15:23AM] Error: Cannot access an element of a None array stack: [ (0005E811)].defaultPrisonerDoorSCRIPT.OnOpen() - "<savegame>" Line ? [12/15/2021 - 04:15:23AM] Error: Cannot call RemoveFromFaction() on a None object, aborting function call stack: [ (0005E811)].defaultPrisonerDoorSCRIPT.OnOpen() - "<savegame>" Line ? [12/15/2021 - 04:15:23AM] VM is freezing... [12/15/2021 - 04:15:23AM] VM is frozen [12/15/2021 - 04:15:23AM] Saving game... [12/15/2021 - 04:16:09AM] VM is thawing... [12/15/2021 - 04:16:09AM] Error: Cannot access an element of a None array stack: [ (0005E811)].defaultPrisonerDoorSCRIPT.OnOpen() - "<savegame>" Line ? [12/15/2021 - 04:16:09AM] Error: Cannot access an element of a None array stack: [ (0005E811)].defaultPrisonerDoorSCRIPT.OnOpen() - "<savegame>" Line ? [12/15/2021 - 04:16:09AM] Error: Cannot call RemoveFromFaction() on a None object, aborting function callWhat can be done to make it right? defaultPrisonerDoorSCRIPT (subhuman VSmO 1.1 bugfixed) Scriptname defaultPrisonerDoorSCRIPT extends ObjectReference {Default script on a door, that is linked to a prisoner, to handle his factions.} Faction Property dunPrisonerFaction Auto ObjectReference Property Prisoner01 Auto ObjectReference Property Prisoner02 Auto ObjectReference Property Prisoner03 Auto ObjectReference Property Prisoner04 Auto ObjectReference Property Prisoner05 Auto ObjectReference Property Prisoner06 Auto ObjectReference Property PrisonerLink Auto Hidden Bool Property AlreadyLoaded auto Hidden ; subhuman - VSmO 1.1 Actor[] thePrisoners ; -- EVENTs -- EVENT OnLoad() IF ( AlreadyLoaded ) RETURN ; - STOP - ENDIF ;--------------------- AlreadyLoaded = TRUE myF_Action(TRUE) ; object has 3D loaded, make sure every valid prisoner got the right faction ENDEVENT ;============================================= auto State WaitingToBeOpened ;=========================== EVENT OnOpen(ObjectReference akActionRef) ; "Event called when the object has finished opening. (Like a door that has finished animating open)" gotoState("AlreadyOpened") ; ### STATE ### myF_Action(False) ENDEVENT ;======= endState ;============================================= State AlreadyOpened ;================== EVENT OnLoad() ; do not trigger action inside OnLoad() event after cell reset ENDEVENT EVENT OnOpen(ObjectReference akActionRef) myF_Action(False) ENDEVENT ;======= endState ; -- FUNCTIONs -- 2 ;---------------------- FUNCTION DestroyArray() ;---------------------- actor[] b thePrisoners = b ; unassign the array (like never used before) Debug.Notification("defaultPrisonerDoor: Bugfix applied!") Debug.Trace(self+" - Bugfix for VSmO 1.1 applied!") ENDFUNCTION ;-------------------------- FUNCTION myF_Action(Bool b) ;-------------------------- actor aRef ; "You can easily get the length of any array by calling the length property on it. If you assign None to an array, the length will be 0." IF thePrisoners.Length ; check for array which was added by subhuman - VSmO 1.1 DestroyArray() ENDIF int i = 0 WHILE (i < 7) aRef = myF_GetRef(i) as Actor IF ( aRef ) IF ( b ) ; b == TRUE OnLoad() aRef.AddToFaction(dunPrisonerFaction) ELSE ; b == False OnOpen() aRef.RemoveFromFaction(dunPrisonerFaction) ENDIF ENDIF i = i + 1 ENDWHILE IF ( b ) RETURN ; - STOP - action within OnLoad() event finished here ENDIF ;--------------------- Utility.Wait(0.1) i = 0 WHILE (i < 7) aRef = myF_GetRef(i) as Actor IF ( aRef ) aRef.EvaluatePackage() ; evaluate the package of each available actor, after faction remove ENDIF i = i + 1 ENDWHILE ENDFUNCTION ;----------------------------------------- ObjectReference FUNCTION myF_GetRef(Int i) ; internal helper ;----------------------------------------- IF ( i ) IF (i == 1) RETURN Prisoner01 ENDIF ; ---------- IF (i == 2) RETURN Prisoner02 ENDIF ; ---------- IF (i == 3) RETURN Prisoner03 ENDIF ; ---------- IF (i == 4) RETURN Prisoner04 ENDIF ; ---------- IF (i == 5) RETURN Prisoner05 ENDIF ; ---------- IF (i == 6) RETURN Prisoner06 ENDIF ; ---------- ENDIF RETURN self.GetLinkedRef() ENDFUNCTION Edited December 21, 2021 by ReDragon2013 Link to comment Share on other sites More sharing options...
ReDragon2013 Posted December 21, 2021 Author Share Posted December 21, 2021 (edited) If your savegame does not have seen the script changes made by subhuman I would suggest next papyrus code. defaultPrisonerDoorSCRIPT ;/ Scriptname defaultPrisonerDoorSCRIPT extends ObjectReference {Default script on a door, that is linked to a prisoner, to handle his factions.} import game import utility import debug Faction Property dunPrisonerFaction Auto ObjectReference Property Prisoner01 Auto ObjectReference Property Prisoner02 Auto ObjectReference Property Prisoner03 Auto ObjectReference Property Prisoner04 Auto ObjectReference Property Prisoner05 Auto ObjectReference Property Prisoner06 Auto ObjectReference Property PrisonerLink Auto Hidden bool Property AlreadyLoaded Auto Hidden EVENT OnLoad() if AlreadyLoaded == FALSE if Prisoner01 (Prisoner01 as Actor).AddToFaction(dunPrisonerFaction) endif if Prisoner02 (Prisoner02 as Actor).AddToFaction(dunPrisonerFaction) endif if Prisoner03 (Prisoner03 as Actor).AddToFaction(dunPrisonerFaction) endif if Prisoner04 (Prisoner04 as Actor).AddToFaction(dunPrisonerFaction) endif if Prisoner05 (Prisoner05 as Actor).AddToFaction(dunPrisonerFaction) endif if Prisoner06 (Prisoner06 as Actor).AddToFaction(dunPrisonerFaction) endif PrisonerLink = GetLinkedRef() if PrisonerLink (PrisonerLink as Actor).AddToFaction(dunPrisonerFaction) endif endif AlreadyLoaded = TRUE EndEVENT Auto STATE WaitingToBeOpened EVENT OnOpen (ObjectReference triggerRef) if Prisoner01 (Prisoner01 as Actor).RemoveFromFaction(dunPrisonerFaction) Utility.Wait(0.1) (Prisoner01 as Actor).EvaluatePackage() endif if Prisoner02 (Prisoner02 as Actor).RemoveFromFaction(dunPrisonerFaction) Utility.Wait(0.1) (Prisoner02 as Actor).EvaluatePackage() endif if Prisoner03 (Prisoner03 as Actor).RemoveFromFaction(dunPrisonerFaction) Utility.Wait(0.1) (Prisoner03 as Actor).EvaluatePackage() endif if Prisoner04 (Prisoner04 as Actor).RemoveFromFaction(dunPrisonerFaction) Utility.Wait(0.1) (Prisoner04 as Actor).EvaluatePackage() endif if Prisoner05 (Prisoner05 as Actor).RemoveFromFaction(dunPrisonerFaction) Utility.Wait(0.1) (Prisoner05 as Actor).EvaluatePackage() endif if Prisoner06 (Prisoner06 as Actor).RemoveFromFaction(dunPrisonerFaction) Utility.Wait(0.1) (Prisoner06 as Actor).EvaluatePackage() endif if PrisonerLink (PrisonerLink as Actor).RemoveFromFaction(dunPrisonerFaction) Utility.Wait(0.1) (PrisonerLink as Actor).EvaluatePackage() endif GoToState("AlreadyOpened") EndEVENT endSTATE STATE AlreadyOpened ;do nothing EndSTATE ### original script inside ### /; ; ######################################################################## ; ######################################################################## Scriptname defaultPrisonerDoorSCRIPT extends ObjectReference {v1.5 ReDragon 2021} ; default script on a door which is also linked to a prisoner (to handle the prisoner faction). Faction PROPERTY dunPrisonerFaction auto ObjectReference PROPERTY Prisoner01 auto ObjectReference PROPERTY Prisoner02 auto ObjectReference PROPERTY Prisoner03 auto ObjectReference PROPERTY Prisoner04 auto ObjectReference PROPERTY Prisoner05 auto ObjectReference PROPERTY Prisoner06 auto ;ObjectReference PROPERTY PrisonerLink auto Hidden ; UnUSED by now Bool PROPERTY AlreadyLoaded auto Hidden ; [default=False], if cell gets reset this will be switch to default value! ; -- EVENTs -- 1 + "WaitingToBeOpened" + "AlreadyOpened" EVENT OnReset() ; after cell reset the property "AlreadyLoaded" will be set back to default value, which is False ENDEVENT EVENT OnLoad() IF ( AlreadyLoaded ) RETURN ; - STOP - ENDIF ;--------------------- AlreadyLoaded = TRUE myF_Action(TRUE) ; object has 3D loaded, make sure every valid prisoner got the right faction ENDEVENT ;=========================================== auto State WaitingToBeOpened ;=========================== EVENT OnOpen(ObjectReference akActionRef) ; prisons door has been opened by someone gotoState("AlreadyOpened") ; ### STATE ### myF_Action(False) ENDEVENT ;======= endSTATE ;=========================================== State AlreadyOpened ;================== EVENT OnLoad() ; do not trigger action inside OnLoad() event after cell reset ENDEVENT ;======= endState ; -- FUNCTIONs -- 2 ;-------------------------- FUNCTION myF_Action(Bool b) ;-------------------------- actor aRef int i = 0 WHILE (i < 7) aRef = myF_GetRef(i) as Actor IF ( aRef ) IF ( b ) ; OnLoad() aRef.AddToFaction(dunPrisonerFaction) ELSE ; OnOpen() aRef.RemoveFromFaction(dunPrisonerFaction) ENDIF ENDIF i = i + 1 ENDWHILE IF ( b ) RETURN ; - STOP - ENDIF ;--------------------- Utility.Wait(0.1) i = 0 WHILE (i < 7) aRef = myF_GetRef(i) as Actor IF ( aRef ) aRef.EvaluatePackage() ; evaluate the package of each available actor, after faction remove ENDIF i = i + 1 ENDWHILE ENDFUNCTION ;----------------------------------------- ObjectReference FUNCTION myF_GetRef(Int i) ; internal helper ;----------------------------------------- IF ( i ) IF (i == 1) RETURN Prisoner01 ENDIF ; ---------- IF (i == 2) RETURN Prisoner02 ENDIF ; ---------- IF (i == 3) RETURN Prisoner03 ENDIF ; ---------- IF (i == 4) RETURN Prisoner04 ENDIF ; ---------- IF (i == 5) RETURN Prisoner05 ENDIF ; ---------- IF (i == 6) RETURN Prisoner06 ENDIF ; ---------- ENDIF RETURN self.GetLinkedRef() ENDFUNCTION Edited December 21, 2021 by ReDragon2013 Link to comment Share on other sites More sharing options...
Recommended Posts