MasterMuhaha Posted June 17, 2012 Share Posted June 17, 2012 hey guys. i need a little help with a mod. i need a script for an npc, that disables the npc at 0 o´clock and enables it at 6 o´clock. thank you in advance. :) Link to comment Share on other sites More sharing options...
steve40 Posted June 18, 2012 Share Posted June 18, 2012 (edited) Attach the script below to the npc, then click the Properties button in the CK and "auto-fill" it. You can manually enter different times for the EnableTime and DisableTime properies, but I have already assigned the default values 6 and 24. I've designed this script to be very idiot proof. EnableTime and DisableTime should be a number between 0 and 24, it doesn't matter which order they are in. Reveal hidden contents Scriptname TimedSpawnControl extends ObjectReference {Script to enable the Actor between two different hours of the day} ;*************************************************** GlobalVariable Property GameHour Auto {You need to autofill this property from the CK} float Property EnableTime = 6.0 auto {Enable me at about 6am by default} float Property DisableTime = 24.0 auto {Disable me at about midnight by default} float interval ; The time interval for the next update ;*************************************************** Event OnInit() ; make sure sensible values have been set If EnableTime < 0.0 || EnableTime > 24.0 EnableTime = 6.0 EndIf ; make sure sensible values have been set If DisableTime < 0.0 || DisableTime > 24.0 DisableTime = 24.0 EndIf CheckTime() ; check the time and enable/disable me when I'm first initialized EndEvent ;*************************************************** Event OnUpdateGameTime() CheckTime() ; check the time and enable/disable me at calculated intervals EndEvent ;*************************************************** Function CheckTime() ; Debug.MessageBox("[TimedSpawnControl] CheckTime was called.") If IsActiveTime() Enable() Else Disable() EndIf GetInterval() RegisterForSingleUpdateGameTime(interval) EndFunction ;*************************************************** Event OnDeath() UnregisterForUpdateGameTime() EndEvent ;*************************************************** bool Function IsActiveTime() {Returns TRUE if current time is within the active time range} bool bTimeRange = false If (DisableTime >= EnableTime) bTimeRange = (GameHour.GetValue() >= EnableTime) && (GameHour.GetValue() < DisableTime) Else bTimeRange = (GameHour.GetValue() >= EnableTime) || (GameHour.GetValue() < DisableTime) EndIf ; Debug.MessageBox("[TimedSpawnControl] IsActiveTime returned: " + bTimeRange) Return bTimeRange EndFunction ;*************************************************** Function GetInterval() {Calculate the time interval for the next update call} float int1 float int2 If EnableTime >= GameHour.GetValue() Int1 = EnableTime - GameHour.GetValue() Else Int1 = EnableTime - GameHour.GetValue() +24 EndIf If DisableTime >= GameHour.GetValue() Int2 = DisableTime - GameHour.GetValue() Else Int2 = DisableTime - GameHour.GetValue() +24 EndIf If Int1 <= Int2 ; choose the smallest time interval interval = Int1 Else interval = int2 EndIf If Interval < 0.167 interval = 0.167 ; set the minimum update interval to about 10 game minutes EndIf ; Debug.MessageBox("[TimedSpawnControl] The next update will be in " + interval + " hours.") EndFunction ;*************************************************** Edit: I fixed a few typos. The script compiles. Edited June 19, 2012 by steve40 Link to comment Share on other sites More sharing options...
gasti89 Posted June 18, 2012 Share Posted June 18, 2012 (edited) The script below is a modified version of a script i've found on the CKwiki to turn on/off lights depending on the game time. I don't have the opportunity to test it too, sorry. Reveal hidden contents ScriptName TimedNPCSwitch extends ObjectReference {Switches the enable/disable state of a NPC depending on the game hour of the day} float Property NPCOffTime = 24.0 auto {The time at which NPC should be turned off} float Property NPCOnTime = 6.0 auto {The time at which NPC should be turned on} float Function GetCurrentHourOfDay() global {Returns the current time of day in hours since midnight} float Time = Utility.GetCurrentGameTime() Time -= Math.Floor(Time) ; Remove "previous in-game days passed" bit Time *= 24 ; Convert from fraction of a day to number of hours Return Time EndFunction Function RegisterForSingleUpdateGameTimeAt(float GameTime) {Registers for a single UpdateGameTime event at the next occurrence of the specified GameTime (in hours since midnight)} float CurrentTime = GetCurrentHourOfDay() If (GameTime < CurrentTime) GameTime += 24 EndIf RegisterForSingleUpdateGameTime(GameTime - CurrentTime) EndFunction Event OnInit() If (GetCurrentHourOfDay() > NPCOffTime) GoToState("NPCOff") Else GoToState("NPCOn") EndIf EndEvent State NPCOff Event OnBeginState() Disable() RegisterForSingleUpdateGameTimeAt(NPCOnTime) EndEvent Event OnUpdateGameTime() GoToState("NPCOn") EndEvent EndState State NPCOn Event OnBeginState() Enable() RegisterForSingleUpdateGameTimeAt(NPCOffTime) EndEvent Event OnUpdateGameTime() GoToState("NPCOff") EndEvent EndState You can put this script on the NPC it self, or put it on a marker and set it as the "Enable Parent" of the NPC. So switching the marker will switch the NPC too. Source: http://www.creationkit.com/Light_Switch Edited June 18, 2012 by gasti89 Link to comment Share on other sites More sharing options...
steve40 Posted June 18, 2012 Share Posted June 18, 2012 (edited) That script would get confused if, say, the npc "on" time was 22:00 and the "off" time was 06:00. Say it was currently 21:00, the OnInit in the Wiki's script would incorrectly enable the npc. Also it would be weird if the actor died and his corpse kept enabling and disabling at 6:00 and 24:00. My script won't make those errors 8) Edited June 18, 2012 by steve40 Link to comment Share on other sites More sharing options...
MasterMuhaha Posted June 18, 2012 Author Share Posted June 18, 2012 On 6/18/2012 at 8:08 AM, steve40 said: That script would get confused if, say, the npc "on" time was 22:00 and the "off" time was 06:00. Say it was currently 21:00, the OnInit in Bethesda's script would incorrectly enable the npc. Also it would be weird if the actor died and his corpse kept enabling and disabling at 6:00 and 24:00. Mine wouldn't make those errors 8) man, why can´t this be as simple as in the previous script language used for morrowind, oblivion and fallout. why did they change it anyway? the other one was pretty simple and completely sufficient. but thanks :) Link to comment Share on other sites More sharing options...
gasti89 Posted June 18, 2012 Share Posted June 18, 2012 Aww Steve, i can't tell you that you're right cause i understand around 50% of the script i posted ahahah! Anyway, can you have a look at this thread? It's something that bugs me since two weeks. Thanks ;) Link to comment Share on other sites More sharing options...
steve40 Posted June 18, 2012 Share Posted June 18, 2012 (edited) Oh, and you probably should be aware of this little problem which I was careful to avoid in my script. From the Creation Kit wiki: "Using this function (RegisterForSingleUpdateGameTime) could cause your game to freeze under any of the following conditions:afInterval is less than some number between 0.0244 and 0.0238." Random freezes anyone? :devil: Edited June 18, 2012 by steve40 Link to comment Share on other sites More sharing options...
MasterMuhaha Posted June 18, 2012 Author Share Posted June 18, 2012 guys, an other problem. i need the npc to be disabled at 24 o'clock and to be enabled and COMPLETELY RESET at 6 o´clock. the purpose of all this is that i have a randomized-character-npc which should generate/output an npc from the leveled list it is based on. but it appears to be, that once an npc from the leveled list has been generated, it stays there. what i mean is, i want to have an other npc from the leveled list to spawn after an enable-disable-sequence, but there is always the same npc from the list spawning. i thought, that it might work, if i simply do not ENABLE the leveled-list-npc at 6 o´clock, but make it spawn an other one of its kind with a placeatme-command and delete the original with markfordelete. now, since i have problems with programming in papyrus, i ask for your help. :) Link to comment Share on other sites More sharing options...
steve40 Posted June 19, 2012 Share Posted June 19, 2012 (edited) On 6/17/2012 at 10:53 PM, MasterMuhaha said: hey guys. i need a little help with a mod. i need a script for an npc, that disables the npc at 0 o´clock and enables it at 6 o´clock. thank you in advance. :) You got what you asked for. We're shooting at moving targets here. Sorry >:( . Edited June 19, 2012 by steve40 Link to comment Share on other sites More sharing options...
Recommended Posts