I'm trying to make a ghost who only appears during a few hours at night, patrols between some markers, and disappears in the morning.
Is there an "easy" way to activate/deactivate NPC on a schedule ?
Thanks!
Scriptname GhostScript extends QuestProperty Actor Ghost Autoint i = 0auto State Initialization Event OnInit() Registerforupdate(300) EndEvent Event OnUpdate() ; Here we've got to figure out the current hour that will be checked every 5 minutes. ; Unfortunately I'm not sure how to do this. ; Although there is a GameTimeToString function that sort of fits our task. ; If the time is right, i.e. it is night and the ghost should be enabled... ; the script goes like this (it should be inside if/endif). UnregisterForUpdate() GoToState("Schedule") EndEventEndStateState Schedule Event OnInit() while i >= 0 Ghost.enable() WaitGameTime(5) ; The script now pauses for 5 in-game hours. Ghost.disable() WaitGameTime(19) i = i + 1 ; After pausing for 19 hours the script will go from the beggining, ; enabling the ghost, then waiting, disabling him and so on. endwhile EndEventEndStateGlobalVariable property GameHour auto{ Make this point to the GameHour global }float property fStartSpawnTime = 6.0 auto{ The Time after which this spawner can be active}float property fEndSpawnTime = 11.0 auto{ The Time before which this spawner can be active}bool Function IsActiveTime() bool binTimeRange = false if (fEndSpawnTime >= fStartSpawnTime) binTimeRange = (GameHour.GetValue() >= fStartSpawnTime) && (GameHour.GetValue() < fEndSpawnTime) else binTimeRange = (GameHour.GetValue() >= fStartSpawnTime) || (GameHour.GetValue() < fEndSpawnTime) endIf ; this script also takes into account weather conditions - Ashs return binTimeRange && ((Weather.GetCurrentWeather() == none) || (Weather.GetCurrentWeather().GetClassification() < 2) || (bSpawnInPrecipitation == TRUE))endFunction
Scriptname GhostScript extends QuestActor Property Ghost Autoint i = 0GlobalVariable Property GameHour Autoauto State Initialization Event OnInit() Registerforupdate(300) EndEvent Event OnUpdate() if GameHour.GetValue() >= 24.0 ; It's possible that it should be value 0.0. You could also just say 23 and be safe. UnregisterForUpdate() GoToState("Schedule") endif EndEventEndStateState Schedule Event OnInit() while i >= 0 Ghost.enable() WaitGameTime(5) ; The script now pauses for 5 in-game hours. Ghost.disable() WaitGameTime(19) i = i + 1 ; After pausing for 19 hours the script will go from the beggining, ; enabling the ghost, then waiting, disabling him and so on. endwhile EndEventEndState
I added Universal's script to my quest scripts tab, and the compilation returns the following errors :(8,4): function oninit cannot be defined in state initialization without also being defined in the empty state(24,12): WaitGameTime is not a function or does not exist(27,12): WaitGameTime is not a function or does not exist(21,4): function oninit cannot be defined in state schedule without also being defined in the empty state
Scriptname GhostScript extends QuestActor Property Ghost Autoint i = 0GlobalVariable Property GameHour Auto Event OnInit() Registerforupdate(300) EndEvent Event OnUpdate() if GameHour.GetValue() >= 24.0 ; It's possible that it should be value 0.0. You could also just say 23 and be safe. UnregisterForUpdate() GoToState("Schedule") endif EndEventState Schedule Event OnBeginState() while i >= 0 Ghost.enable() Utility.WaitGameTime(5) ; The script now pauses for 5 in-game hours. Ghost.disable() Utility.WaitGameTime(19) i = i + 1 ; After pausing for 19 hours the script will go from the beggining, ; enabling the ghost, then waiting, disabling him and so on. endwhile EndEventEndStateState GhostOn Event OnBeginState() Ghost.enable() Utility.WaitGameTime(5) GoToState("GhostOff"); EndEventEndStateState GhostOff Event OnBeginState() Ghost.disable() Utility.WaitGameTime(19) GoToState("GhostOn"); EndEventEndState
Then it should work the same way.
Then it should work the same way.
Anyway, thanks to you all, i still learned useful things, and i will keep trying.