niston Posted June 10, 2024 Share Posted June 10, 2024 Use this function: ; uses functions from SUP Import SUP_F4SE ; Assign this in CK or use Game.GetForm() or whatever Keyword Property WorkshopItemKeyword Auto Const Mandatory ; Safely delete a powered reference from script with SUP F4SE ; Parameters ; refElement: Powered ObjectReference to delete ; Return Value ; True = success, False = failure Bool Function SafeDeletePoweredRef(ObjectReference refElement) ; parameters supplied? If (refElement == none) Debug.Trace(Self + ": ERROR - SafeDeletePoweredRef() failed: Missing or invalid parameter.") Return False EndIf ; sup scrap crash fix active? If (IsSUPPatchActive(1) == false) Debug.Trace(Self + ": ERROR - SafeDeletePoweredRef() failed: SUP F4SE Scrap Crash Fix disabled; Unable to safely delete reference.") Return False EndIf ; get refElement workshop ObjectReference refWorkshop = refElement.GetLinkedRef(WorkshopItemKeyword) as ObjectReference If (refWorkshop == none) Debug.Trace(Self + ": ERROR - SafeDeletePoweredRef() failed: Object does not have valid WorkshopItemKeyword reflink.") Return False EndIf ; get objects connected to refElement ObjectReference[] connectedObjects = refElement.GetConnectedObjects() ; delete refElement.Delete() ; notify formerly connected objects Int i = 0 While (i < connectedObjects.Length) WorkshopGenerateFakeReferenceEvent(refWorkshop, connectedObjects[i]) i += 1 EndWhile ; success Return True EndFunction That's all - No need to open Workshop or some suchlike; It won't CTD. 1 Link to comment Share on other sites More sharing options...
niston Posted June 11, 2024 Author Share Posted June 11, 2024 Code previously used a function from PowerGridTools. Reworked for pure SUP F4SE now. Thanks msalaba for pointing it out. Link to comment Share on other sites More sharing options...
Recommended Posts