Scriptname SHESON_DynDOLOD_Minion extends ObjectReference
;this script took 2 and a half months to figure out

ObjectReference MyMaster = None
String MyWorld = "None"
String MyImportFileName = "None"
String MyModName = "DynDOLOD.esp"
Bool MyObjectEnable = FALSE

Event OnCellAttach()
	StorageUtil.SetIntValue(self, "CellState", 1)
	if (Game.GetPlayer().GetActorValue("SpeedMult") <= 500)
		MyWorld = StringUtil.Substring(self.GetWorldspace() as string, 13, StringUtil.Find(self.GetWorldspace() as string, "(") - 14)
		MyImportFileName = "DynDOLOD_" + JsonUtil.GetStringValue("DynDOLOD_Worlds", MyWorld, MyWorld)
		MyMaster = Game.GetFormFromFile(JsonUtil.IntListGet(MyImportFileName, "master", 0), MyModName) As ObjectReference
		if (MyMaster != None)
			if (StorageUtil.GetIntValue(MyMaster, "DynDOLOD_Active", 1) == 1)
				Activate(self)
				MyObjectEnable = TRUE
			endIf
		endIf
	endIf
endEvent

Event OnCellDetach()
	StorageUtil.SetIntValue(self, "CellState", 0)
	if (MyObjectEnable)
		Activate(self)
		MyObjectEnable = FALSE
	endIf
endEvent
