Jump to content

Recommended Posts

Posted

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 ObjectReference

import utility
import game

Bool Usable = true

Event OnRead()

If Usable == True
Usable = False
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)

RegisterForSingleUpdateGameTime(24.0) ;updates in 24 hours
Else
Debug.MessageBox("The knowledge in this book can only be used once per day.")
Endif
EndEvent

Event OnUpdateGameTime()
Usable = true
EndEvent


 

 

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.

Posted

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

Posted

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.

Posted

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.

Posted

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:

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...