Wahnfried1883 Posted November 16, 2021 Share Posted November 16, 2021 Hi, I need help with a script that only should work once per day. The idea behind that is book, that increases your skills by one point once per day. This is the script: Scriptname aaMTGF_BookWissenScript extends ObjectReferenceimport utilityimport gameBool Usable = trueEvent OnRead()If Usable == TrueUsable = FalseGame.IncrementSkillBy("Smithing", 1)Game.IncrementSkillBy("HeavyArmor", 1)Game.IncrementSkillBy("Block", 1)Game.IncrementSkillBy("TwoHanded", 1)Game.IncrementSkillBy("OneHanded", 1)Game.IncrementSkillBy("Marksman", 1)Game.IncrementSkillBy("LightArmor", 1)Game.IncrementSkillBy("Sneak", 1)Game.IncrementSkillBy("Lockpicking", 1)Game.IncrementSkillBy("Pickpocket", 1)Game.IncrementSkillBy("Speechcraft", 1)Game.IncrementSkillBy("Alchemy", 1)Game.IncrementSkillBy("Illusion", 1)Game.IncrementSkillBy("Conjuration", 1)Game.IncrementSkillBy("Destruction", 1)Game.IncrementSkillBy("Restoration", 1)Game.IncrementSkillBy("Alteration", 1)Game.IncrementSkillBy("Enchanting", 1)RegisterForSingleUpdateGameTime(24.0) ;updates in 24 hoursElseDebug.MessageBox("The knowledge in this book can only be used once per day.")EndifEndEventEvent OnUpdateGameTime()Usable = trueEndEvent Unfortunately, the script will only work one or two times after reading the book. After that, no matter how long I wait, I get always the debug messagebox: "The knowledge in this book can only be used once per day." I tried to read the book in the player's inventory if that matters. What's wrong? Any help is appreciated. Link to comment Share on other sites More sharing options...
IsharaMeradin Posted November 16, 2021 Share Posted November 16, 2021 The timer for the update event pauses when in menus. Thus it is possible that 24 hours passes and yet the update event has not taken place. You might be better served storing the current time on the first read and on subsequent reads check to see if the then current time is 24 hours greater than the stored time. If it is not, display the message. If it is, do the skill increases and store the new current time. See: GetCurrentGameTime Link to comment Share on other sites More sharing options...
Wahnfried1883 Posted November 16, 2021 Author Share Posted November 16, 2021 Thank you very much for your reponse. Can you be more specific? I have no idea how to do that. Scripting isn't exactly my forte. Link to comment Share on other sites More sharing options...
IsharaMeradin Posted November 17, 2021 Share Posted November 17, 2021 For easier example, shifted the skill advancement into a separate function. Option 1 uses the global variable GameDaysPassed Scriptname aaMTGF_BookWissenScript extends ObjectReference GlobalVariable Property GameDaysPassed Auto Float EndTime = 0.0 Event OnRead() Float CurrentTime = GameDaysPassed.GetValue() If (CurrentTime >= EndTime) EndTime = (CurrentTime + 1.0) ;advance end time to minimum value needed AdvanceMultipleSkills() ;apply skill advancement Else Debug.MessageBox("The knowledge in this book can only be used once per day.") EndIf EndEvent ;local function to handle all the actual work -- could be called from other scripts if needed Function AdvanceMultipleSkills() Game.IncrementSkillBy("Smithing", 1) Game.IncrementSkillBy("HeavyArmor", 1) Game.IncrementSkillBy("Block", 1) Game.IncrementSkillBy("TwoHanded", 1) Game.IncrementSkillBy("OneHanded", 1) Game.IncrementSkillBy("Marksman", 1) Game.IncrementSkillBy("LightArmor", 1) Game.IncrementSkillBy("Sneak", 1) Game.IncrementSkillBy("Lockpicking", 1) Game.IncrementSkillBy("Pickpocket", 1) Game.IncrementSkillBy("Speechcraft", 1) Game.IncrementSkillBy("Alchemy", 1) Game.IncrementSkillBy("Illusion", 1) Game.IncrementSkillBy("Conjuration", 1) Game.IncrementSkillBy("Destruction", 1) Game.IncrementSkillBy("Restoration", 1) Game.IncrementSkillBy("Alteration", 1) Game.IncrementSkillBy("Enchanting", 1) EndFunction Option 2 use GetCurrentGameTime Scriptname aaMTGF_BookWissenScript extends ObjectReference Float EndTime = 0.0 Event OnRead() Float CurrentTime = Utility.GetCurrentGameTime() If (CurrentTime >= EndTime) EndTime = (CurrentTime + 1.0) ;advance end time to minimum value needed AdvanceMultipleSkills() ;apply skill advancement Else Debug.MessageBox("The knowledge in this book can only be used once per day.") EndIf EndEvent ;local function to handle all the actual work -- could be called from other scripts if needed Function AdvanceMultipleSkills() Game.IncrementSkillBy("Smithing", 1) Game.IncrementSkillBy("HeavyArmor", 1) Game.IncrementSkillBy("Block", 1) Game.IncrementSkillBy("TwoHanded", 1) Game.IncrementSkillBy("OneHanded", 1) Game.IncrementSkillBy("Marksman", 1) Game.IncrementSkillBy("LightArmor", 1) Game.IncrementSkillBy("Sneak", 1) Game.IncrementSkillBy("Lockpicking", 1) Game.IncrementSkillBy("Pickpocket", 1) Game.IncrementSkillBy("Speechcraft", 1) Game.IncrementSkillBy("Alchemy", 1) Game.IncrementSkillBy("Illusion", 1) Game.IncrementSkillBy("Conjuration", 1) Game.IncrementSkillBy("Destruction", 1) Game.IncrementSkillBy("Restoration", 1) Game.IncrementSkillBy("Alteration", 1) Game.IncrementSkillBy("Enchanting", 1) EndFunction Neither example were tested for compilation or function. They are intended as example rather than plug and play. Some adjustments may be needed for specific use cases. Link to comment Share on other sites More sharing options...
Wahnfried1883 Posted November 17, 2021 Author Share Posted November 17, 2021 You are awesome! Thanks! I prefer the second option without the property just in case I have to change something later mid-game. I'll memorialize you in my mod in Maiq's book, I promise. :happy: Link to comment Share on other sites More sharing options...
Recommended Posts