Making an item usable 1 per day

Post » Tue Jun 19, 2012 7:07 pm

Im trying to make the dragon priest wooden mask that i modded to be able to warp to the dragon priest sanctuary and then back to original location be usable only once per day but it seems that the variables that i use to keep track of time keep resetting back to initialized values. Here's my script if someone could help.

Scriptname DunLabyrinthianWoodenMaskModSCRIPT extends ActiveMagicEffect {Script that handles the use of the wooden Bromjunaar mask as a key to the sanctuary}objectReference property SanctuaryMarker auto{Where to put the player when the mask is used as a key}location property DragonPriestSanctuaryLocation auto{The sanctuary Cell}imageSpaceModifier property AzuraFadeToBlack auto{Use a basic fade-to-black for the transition}imageSpaceModifier property FadeToBlackBackImod autoSound Property TransitionSFX  AutoobjectReference property maskActual auto{Point explicity to the unique, placed reference of the mask in the world}ObjectReference selfRefObjectReference warpMarkerbool property firstRun = True Autofloat property lastUseTime Autofloat property hoursSinceLastUse AutoEVENT OnEffectStart(Actor Target, Actor Caster)selfRef = casterdebug.trace("OnEffectStart lastUseTime = " + lastUseTime)debug.trace("OnEffectStart Firstrun = " + firstRun)if caster == game.GetPlayer() && !firstRun  hoursSinceLastUse = 24 * (Utility.GetCurrentGameTime() -  lastUseTime)  debug.trace("Firstrun = " + firstRun)endifdebug.trace("hoursSinceLastUse = " + hoursSinceLastUse)if caster == game.getPlayer() && !game.getPlayer().IsInCombat() && ((hoursSinceLastUse > 24.0) || firstRun)  firstRun = False  debug.trace("Warping Firstrun = " + firstRun)  warpMarker = game.getPlayer().PlaceAtMe(Game.GetForm(00000032))  AzuraFadeToBlack.apply()  TransitionSFX.play(caster)  utility.wait(2.5)  caster.moveTo(SanctuaryMarker)  FadeToBlackBackImod.apply()  AzuraFadeToBlack.remove()   endif  endEVENTEVENT onEffectFinish(Actor Target, Actor Caster)if Caster == game.getPlayer() && game.getPlayer() .isInLocation(DragonPriestSanctuaryLocation) == TRUE  ;when player removes the mask in sanctuary, return to Skyrim  AzuraFadeToBlack.apply()  TransitionSFX.play(caster)  utility.wait(2.5)  game.getPlayer().MoveTo(warpMarker)  FadeToBlackBackImod.apply()  AzuraFadeToBlack.remove()  if caster.getItemCount(maskActual) < 1   ; safety catch - if the player dropped the mask in the sanctuary, add it to inventory so it doesn't get lost.   caster.addItem(maskActual)  endif  hoursSinceLastUse = 0.0  debug.trace("OnEffectFinish hoursSinceLastUse = " + hoursSinceLastUse)  lastUseTime = Utility.GetCurrentGameTime()  debug.trace("OnEffectFinish lastUseTime = " + lastUseTime) endifwarpMarker.Delete()endEVENT
User avatar
lucy chadwick
 
Posts: 3412
Joined: Mon Jul 10, 2006 2:43 am

Post » Wed Jun 20, 2012 1:49 am

mmh, Lastusetime is not stored in a global way, but only during the instance of your spell, and it's recreated any time you cast the spell.
you should use a globalvariable to keep the value
User avatar
Batricia Alele
 
Posts: 3360
Joined: Mon Jan 22, 2007 8:12 am

Post » Tue Jun 19, 2012 2:41 pm

How do i create a global variable.
User avatar
Laura Hicks
 
Posts: 3395
Joined: Wed Jun 06, 2007 9:21 am

Post » Tue Jun 19, 2012 11:22 pm

How do i create a global variable.
in ck Miscellaneous -> global there you can create a Gvariable that can store integer or float value.

http://www.creationkit.com/GlobalVariable_Script

note that the game is using a globalvariable for to store the gametime. it's gameHour, you can have a direct access to it, instead of calling a utility.function
User avatar
kiss my weasel
 
Posts: 3221
Joined: Tue Feb 20, 2007 9:08 am

Post » Wed Jun 20, 2012 2:27 am

Thank you very much McGuffin finally got it working. Here's my final script and if there is anything in here thats not right even though the script works could somebody let me know cause this is my first scripting ive done and dont know if im doing things efficiently or properly.

Scriptname dunWoodenMaskMod extends activemagiceffect ObjectReference Property SanctuaryMarker  Auto Location Property DragonPriestSanctuaryLocation  Auto ImageSpaceModifier Property AzuraFadeToBlack  Auto ImageSpaceModifier Property FadeToBlackBackImod  Auto Sound Property TransitionSFX  Auto ObjectReference Property maskActual  Auto GlobalVariable Property lastUseTime  Auto GlobalVariable Property hoursSinceLastUse  AutoGlobalVariable Property GameDaysPassed AutoObjectReference selfRefObjectReference warpMarkerfloat lastUTfloat hoursSLUfloat gDPEVENT OnEffectStart(Actor Target, Actor Caster)selfRef = casterlastUT = lastUseTime.GetValue()hoursSLU = hoursSinceLastUse.GetValue()gDP = GameDaysPassed.GetValue()Debug.Trace("Variables = " + lastUT + ", " + hoursSLU + ", " + gDP)if caster == game.GetPlayer() && lastUT != 0.0  hoursSLU = 24.0 * (gDP - lastUT)  ;hoursSinceLastUse.SetValue(24.0 * (GameDaysPassed - lastUseTime))endifif caster == game.getPlayer() && !game.getPlayer().IsInCombat() && ((hoursSLU > 24.0) || (lastUT == 0.0))  warpMarker = game.getPlayer().PlaceAtMe(Game.GetForm(00000032))  AzuraFadeToBlack.apply()  TransitionSFX.play(caster)  utility.wait(2.5)  caster.moveTo(SanctuaryMarker)  FadeToBlackBackImod.apply()  AzuraFadeToBlack.remove()   endif  endEVENTEVENT onEffectFinish(Actor Target, Actor Caster)if Caster == game.getPlayer() && game.getPlayer() .isInLocation(DragonPriestSanctuaryLocation) == TRUE  ;when player removes the mask in sanctuary, return to Skyrim  AzuraFadeToBlack.apply()  TransitionSFX.play(caster)  utility.wait(2.5)  game.getPlayer().MoveTo(warpMarker)  FadeToBlackBackImod.apply()  AzuraFadeToBlack.remove()  if caster.getItemCount(maskActual) < 1   ; safety catch - if the player dropped the mask in the sanctuary, add it to inventory so it doesn't get lost.   caster.addItem(maskActual)  endif  hoursSLU = 0.0  hoursSinceLastUse.SetValue(hoursSLU)  lastUseTime.SetValue(GameDaysPassed.GetValue())  endifwarpMarker.Delete()endEVENT
User avatar
Rhiannon Jones
 
Posts: 3423
Joined: Thu Sep 21, 2006 3:18 pm


Return to V - Skyrim