TangerineDog Posted September 30, 2017 Share Posted September 30, 2017 I've got a script that's based on doing something and setting a new timer every time said timer runs out. Unfortunately, the command I'm using doesn't register the time you wait or sleep. Is there a similar command that takes the time you wait and sleep into account? Link to comment Share on other sites More sharing options...
IsharaMeradin Posted September 30, 2017 Share Posted September 30, 2017 Store the previous game time (when you registered for the update)Compare the new game time with the previous when the update triggersIf more than the expected count, do a bit of math to get a multiplier.Use the multiplier to change values of whatever you are doing every so often Brief example: Float OldTime Float NewTime Float Property DesiredTime Auto Int MyMultiplier ;some function or event OldTime = Utility.GetCurrentGameTime() RegisterForGameTime(DesiredTime) ;end some function or event Event OnUpdateGameTime() NewTime = Utility.GetCurrentGameTime() MyMultiplier = Floor( (NewTime - OldTime) / DesiredTime) ;multiply increasing values by MyMultiplier as in HungerCount = MyMultiplier * 1 ;other stuff EndEvent Disclaimer: I've not actually tested this idea. I feel the theory is sound however. I suggest testing with a simple counter that merely displays the number of game hours that passed in order to determine if it works correctly before applying to a real project. Link to comment Share on other sites More sharing options...
cdcooley Posted September 30, 2017 Share Posted September 30, 2017 OnUpdateGameTime can't trigger while the game is in any MenuMode state even if game time is passing. Sleep, Wait, and Fast Travel all block it, so you need to check how much time actually passed like IsharaMeradin shows. It's also possible for a mod to directly change the current time or day so you might want to double-check how big that multiplier is before applying it. In rare cases the value might be negative if a mod does something strange! Link to comment Share on other sites More sharing options...
foamyesque Posted October 1, 2017 Share Posted October 1, 2017 OnUpdateGameTime can't trigger while the game is in any MenuMode state even if game time is passing. Sleep, Wait, and Fast Travel all block it, so you need to check how much time actually passed like IsharaMeradin shows. It's also possible for a mod to directly change the current time or day so you might want to double-check how big that multiplier is before applying it. In rare cases the value might be negative if a mod does something strange! It will however trigger after you exit those menus, in my experience, so if you're after just at least X time passing you're okay. Link to comment Share on other sites More sharing options...
cdcooley Posted October 1, 2017 Share Posted October 1, 2017 It will however trigger after you exit those menus, in my experience, so if you're after just at least X time passing you're okay. Yes, the fact that the update triggers as soon as the Sleep/Wait menu or loading screen completes was implied but I should probably have stated that. Thanks. Link to comment Share on other sites More sharing options...
TangerineDog Posted October 1, 2017 Author Share Posted October 1, 2017 (edited) After looking up what floor does, I, too, see the logic behind that approach. I've worked it into my script like this: Scriptname TimeTestScript extends activemagiceffectGlobalVariable Property TimeCount AutoFloat Property TimeFloatThing AutoFloat OldTimeFloat NewTimeInt MyMultiplierEvent OnEffectStart(Actor akTarget, Actor akCaster) ; start timer RegisterForSingleUpdateGameTime(TimeFloatThing) OldTime = Utility.GetCurrentGameTime() EndEventEvent OnUpdateGameTime(); debug.trace(self + "OnUpdateGameTime") NewTime = Utility.GetCurrentGameTime() MyMultiplier = math.floor((NewTime-OldTime)/TimeFloatThing) TimeCount.GetValue() TimeCount.Mod(MyMultiplier) Debug.Notification("Time increased") RegisterForSingleUpdateGameTime(TimeFloatThing) OldTime = Utility.GetCurrentGameTime() EndEvent but unfortunately it doesn't change the TimeCount at all. Also tried it with my other script - doesn't change the global there either. Edited October 1, 2017 by TangerineDog Link to comment Share on other sites More sharing options...
IsharaMeradin Posted October 1, 2017 Share Posted October 1, 2017 Make sure you test new changes on a new game or a save that hasn't seen the file(s) in question. There are instances where scripts and other things will not update mid-game giving you unexpected results. If it still does not work after that, I don't know. Link to comment Share on other sites More sharing options...
TangerineDog Posted October 1, 2017 Author Share Posted October 1, 2017 (edited) Make sure you test new changes on a new game or a save that hasn't seen the file(s) in question. There are instances where scripts and other things will not update mid-game giving you unexpected results. If it still does not work after that, I don't know. I did. I have a clean save I test all the scripts on, the mods are 100% new every time.Could it have something to do with the value the global should be set to being a variable, not a fixed integer? Edit: Nope, just tried setting MyMultiplier to 7 instead of using math.floor((NewTime-OldTime)/TimeFloatThing) and it worked fine.Something is wrong with this line: math.floor((NewTime-OldTime)/TimeFloatThing) Edit 2: waiting a day does something. I think I'll need to figure out what values NewTime and OldTime give, maybe their floor ends up being 0 if I wait less than half a day... I'm using pHourstoWait in my main script and have set it to 0.4, so that HungerCount increases by 1 point every 0.4 hours for a total of 45 points over 24 hours, so (NewTime-OldTime) gets divided by 0.4.If it happens to be less than 0.4, the floor would be 0.I'll write something up that shows me the exact value... And Edit 3: yep, that's it! I just waited for 3 hours and it got me 0.29something.Now I'll try to come up with some workaround... Last Edit: math.floor((NewTime*24-OldTime*24)/TimeFloatThing)That way, it's completely based around hours and one hours passed - the smallest possible time to wait - nets 2,5. So far, so good.Unfortunately, hat means that a lot of time is still gonna go unnoticed. Edited October 1, 2017 by TangerineDog Link to comment Share on other sites More sharing options...
TangerineDog Posted October 1, 2017 Author Share Posted October 1, 2017 (edited) I think this is it. This script - I'm yet to test it - should always raise HungerCount by at least 1. Also, it will, if the last update happened before a full multiple of the set timer had been reached, set the next timer for the amount of time that still was on the timer. It will do that by updating the time waited that's been determined by the floor-command. If the floor, however, had to knock a part of the set timer down, then the timer will be set for that fraction. If the knocked down fraction was 0 - which is the case if teh timer was not interrupted - then the timer is set as usual. Here it is: ScriptName HungerCounterScript extends activemagiceffectFloat Property pHoursToWait AutoGlobalVariable Property HungerCount AutoGlobalVariable Property HungerCount01 AutoGlobalVariable Property HungerCount02 AutoGlobalVariable Property HungerCount03 AutoSpell Property HungerSpell01 AutoSpell Property HungerSpell02 AutoSpell Property HungerSpell03 AutoFloat OldTimeFloat NewTimeInt ChangeMultiplierEvent OnUpdateGameTime(); debug.trace(self + "OnUpdateGameTime")NewTime = Utility.GetCurrentGameTime()ChangeMultiplier = math.floor((NewTime*24-OldTime*24)/pHoursToWait)if ChangeMultiplier < 1ChangeMultiplier = 1endifHungerCount.GetValue()HungerCount.Mod(ChangeMultiplier)Debug.Notification("Hunger increased")if HungerCount.GetValue() == HungerCount03.GetValue()Debug.Notification("You are starving.")Game.GetPlayer().RemoveSpell(HungerSpell02)Game.GetPlayer().AddSpell(HungerSpell03, false)endifif HungerCount.GetValue() == HungerCount02.GetValue()Debug.Notification("You are hungry.")Game.GetPlayer().RemoveSpell(HungerSpell01)Game.GetPlayer().AddSpell(HungerSpell02, false)endifif HungerCount.GetValue() == HungerCount01.GetValue()Debug.Notification("You have an appetite.")Game.GetPlayer().AddSpell(HungerSpell01, false)endifif (((NewTime*24-OldTime*24)/pHoursToWait)-math.floor((NewTime*24-OldTime*24)/pHoursToWait)) > 0RegisterForSingleUpdateGameTime((((NewTime*24-OldTime*24)/pHoursToWait)-math.floor((NewTime*24-OldTime*24)/pHoursToWait))*pHoursToWait)elseRegisterForSingleUpdateGameTime(pHoursToWait)endifOldTime = Utility.GetCurrentGameTime()EndEventEvent OnEffectStart(Actor akTarget, Actor akCaster); start timerRegisterForSingleUpdateGameTime(pHoursToWait)OldTime = Utility.GetCurrentGameTime()EndEvent Edit: Just tested it - success! Edited October 1, 2017 by TangerineDog Link to comment Share on other sites More sharing options...
Recommended Posts