ScriptName aeQuestAdventurerScript Extends Quest ReferenceAlias[] Property Adventurers Auto ObjectReference Property WIDeadBodyCleanupCellMarker Auto ObjectReference Property aeAdventurerMarker Auto FormList Property aeLocationList Auto FormList Property aeInnEntranceList Auto FormList Property aeLandingPointList Auto FormList Property aeDungeonStartList Auto FormList Property aeDungeonRouteList Auto FormList Property aeDungeonGoalList Auto FormList Property aeSleepPointList Auto Faction Property aeFactionAdvDiscovering Auto Faction Property aeFactionAdvGoal Auto Faction Property aeFactionAdvSleeping Auto Actor Property PlayerRef Auto Int CurrentLocation = -1 Int NextLocation = -1 ; 冒険者にFactionを追加する Function AddToFaction(Faction akFaction) Int i = Adventurers.Length while i > 0 i -= 1 Actor kActor = Adventurers[i].GetActorReference() if kActor kActor.AddToFaction(akFaction) kActor.EvaluatePackage() endif endwhile EndFunction ; 現在時刻を取得する Float Function GetCurrentHourOfDay() Float fTime = Utility.GetCurrentGameTime() fTime -= Math.Floor(fTime) fTime *= 24.0 return fTime EndFunction ; 目標の時刻までの時間を求める Float Function GetNextHourInterval(Float afHour, Bool abAddRandom = false) Float fInterval = 24.0 + afHour - GetCurrentHourOfDay() ; 25時間以上先になっていたら調整 ; ただし1時間以上先にする ; https://www.creationkit.com/index.php?title=RegisterForSingleUpdateGameTime_-_Form if 25.0 0 i -= 1 Actor kActor = Adventurers[i].GetActorReference() if kActor kActor.RemoveFromFaction(akFaction) kActor.EvaluatePackage() endif endwhile EndFunction ; 冒険者を出現させる Function SpawnAdventurer() Faction kEEFactionForceEquipArmor if Game.GetModByName("EnemyEquipment.esp") 0 i -= 1 Actor kActor = Adventurers[i].GetActorReference() if kActor kActor.Delete() Adventurers[i].Clear() endif kActor = WIDeadBodyCleanupCellMarker.PlaceActorAtMe(kActorForm as ActorBase) Adventurers[i].ForceRefTo(kActor) if kEEFactionForceEquipArmor kActor.AddToFaction(kEEFactionForceEquipArmor) endif kActor.MoveTo(aeAdventurerMarker) endwhile EndFunction ; 現在地域を更新する Function UpdateLocation() Location kLoc = PlayerRef.GetCurrentLocation() if kLoc Int i = aeLocationList.Find(kLoc) if i != -1 NextLocation = i Debug.Trace("AE: new location = " + kLoc) endif endif EndFunction Event OnInit() UpdateLocation() GoToState("WAITING") EndEvent State WAITING Event OnBeginState() Float fInterval = GetNextHourInterval(8.0, abAddRandom = true) RegisterForSingleUpdateGameTime(fInterval) Debug.Trace("AE: [WAITING] OnBeginState: interval = " + fInterval) EndEvent Event OnUpdateGameTime() Debug.Trace("AE: [WAITING] OnUpdateGameTime: next location = " + NextLocation) if NextLocation == -1 RegisterForSingleUpdateGameTime( GetNextHourInterval(8.0, abAddRandom = true) ) return endif CurrentLocation = NextLocation aeAdventurerMarker.MoveTo(aeInnEntranceList.GetAt(CurrentLocation) as ObjectReference) SpawnAdventurer() GoToState("READY") EndEvent EndState State READY Event OnBeginState() Debug.Trace("AE: [READY] OnBeginState") RegisterForSingleUpdate(30.0) EndEvent Event OnUpdate() Float fHour = GetCurrentHourOfDay() if 10.0 < fHour || PlayerRef.GetDistance(aeAdventurerMarker) < 1000.0 GoToState("LANDING") return endif if 12.0 < fHour GoToState("WAITING") else RegisterForSingleUpdate(30.0) endif EndEvent EndState State LANDING Event OnBeginState() Debug.Trace("AE: [LANDING] OnBeginState") aeAdventurerMarker.MoveTo(aeLandingPointList.GetAt(CurrentLocation) as ObjectReference) RegisterForSingleUpdate(30.0) EndEvent Event OnUpdate() if PlayerRef.GetDistance(aeAdventurerMarker) < 1000.0 GoToState("ENTERING") return endif if 15.0 < GetCurrentHourOfDay() GoToState("RESTING") else RegisterForSingleUpdate(30.0) endif EndEvent EndState State ENTERING Event OnBeginState() Debug.Trace("AE: [ENTERING] OnBeginState") aeAdventurerMarker.MoveTo(aeDungeonStartList.GetAt(CurrentLocation) as ObjectReference) AddToFaction(aeFactionAdvDiscovering) RegisterForSingleUpdate(30.0) EndEvent Event OnUpdate() if PlayerRef.GetDistance(aeAdventurerMarker) < 1000.0 GoToState("DISCOVERING1") return endif if 17.0 < GetCurrentHourOfDay() GoToState("RESTING") else RegisterForSingleUpdate(30.0) endif EndEvent EndState State DISCOVERING1 Event OnBeginState() Debug.Trace("AE: [DISCOVERING1] OnBeginState") aeAdventurerMarker.MoveTo(aeDungeonRouteList.GetAt(CurrentLocation) as ObjectReference) RegisterForSingleUpdate(30.0) EndEvent Event OnUpdate() if PlayerRef.GetDistance(aeAdventurerMarker) < 1000.0 GoToState("DISCOVERING2") return endif if 19.0 < GetCurrentHourOfDay() GoToState("RESTING") else RegisterForSingleUpdate(30.0) endif EndEvent EndState State DISCOVERING2 Event OnBeginState() Debug.Trace("AE: [DISCOVERING2] OnBeginState") aeAdventurerMarker.MoveTo(aeDungeonGoalList.GetAt(CurrentLocation) as ObjectReference) RegisterForSingleUpdate(30.0) EndEvent Event OnUpdate() if PlayerRef.GetDistance(aeAdventurerMarker) < 1000.0 GoToState("GOAL") return endif if 19.0 < GetCurrentHourOfDay() GoToState("RESTING") else RegisterForSingleUpdate(30.0) endif EndEvent EndState State GOAL Event OnBeginState() Debug.Trace("AE: [GOAL] OnBeginState") RemoveFromFaction(aeFactionAdvDiscovering) AddToFaction(aeFactionAdvGoal) RegisterForSingleUpdate(30.0) EndEvent Event OnUpdate() if 19.0 < GetCurrentHourOfDay() GoToState("RESTING") else RegisterForSingleUpdate(30.0) endif EndEvent EndState State RESTING Event OnBeginState() Debug.Trace("AE: [RESTING] OnBeginState") aeAdventurerMarker.MoveTo(aeSleepPointList.GetAt(CurrentLocation) as ObjectReference) RemoveFromFaction(aeFactionAdvGoal) RemoveFromFaction(aeFactionAdvDiscovering) RegisterForSingleUpdate(30.0) EndEvent Event OnUpdate() Float fTime = GetCurrentHourOfDay() if 23.0 < fTime || fTime < 4.0 GoToState("SLEEPING") elseif 4.0 < fTime && fTime < 15.0 GoToState("WAITING") else RegisterForSingleUpdate(30.0) endif EndEvent EndState State SLEEPING Event OnBeginState() Debug.Trace("AE: [SLEEPING] OnBeginState") AddToFaction(aeFactionAdvSleeping) RegisterForSingleUpdate(5.0) EndEvent Event OnUpdate() Float fTime = GetCurrentHourOfDay() if 5.0 < fTime && fTime < 23.0 GoToState("WAITING") else RegisterForSingleUpdate(5.0) endif EndEvent EndState