Jump to content

Need help with a simple script


Recommended Posts

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.

Link to comment
Share on other sites

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

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

  • Recently Browsing   0 members

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