Jump to content

[LE] OnSleepSTart - how to use?


Recommended Posts

I'm trying to get this script to compile:

 

Scriptname SleepCounterScript extends ActiveMagicEffect

Float WellRestedOver
Spell Property pAbilityToRemove Auto
Float fSleepStartTime
Float fWellRestedTime
Float fWellRestedStartTime
Float fSleepStopTime

EVENT OnEffectStart()
RegisterForSleep()
ENDEVENT

EVENT OnUpdateGameTime()
Game.GetPlayer().RemoveSpell(pAbilityToRemove)
WellRestedOver = 1
ENDEVENT

EVENT OnSleepStart()
fSleepStartTime = Utility.GetCurrentGameTime()
ENDEVENT

EVENT OnSleepStop()
if (WellRestedOver == 1)
fWellRestedTime = ((fSleepStopTime-fSleepStartTime)*24)
RegisterForSingleUpdateGameTime(fWellRestedTime)
WellRestedOver = 0
fWellRestedStartTime = fSleepStopTime
else
fWellRestedTime = ((fSleepStopTime-fSleepStartTime)*24+fWellRestedTime-(fSleepStartTime-fWellRestedStartTime)*24)
RegisterForSingleUpdateGameTime(fWellRestedTime)
fWellRestedStartTime = fSleepStopTime
endif
ENDEVENT

 

but all I get is this error message:

 


E:\SteamLibrary\steamapps\common\Skyrim\Data\scripts\Source\SleepCounterScript.psc(10,0): the parameter types of function oneffectstart in the empty state on script sleepcounterscript do not match the parent script activemagiceffect
E:\SteamLibrary\steamapps\common\Skyrim\Data\scripts\Source\SleepCounterScript.psc(19,0): the parameter types of function onsleepstart in the empty state on script sleepcounterscript do not match the parent script activemagiceffect
E:\SteamLibrary\steamapps\common\Skyrim\Data\scripts\Source\SleepCounterScript.psc(23,0): the parameter types of function onsleepstop in the empty state on script sleepcounterscript do not match the parent script activemagiceffect
No output generated for E:\SteamLibrary\steamapps\common\Skyrim\Data\scripts\Source\SleepCounterScript.psc, compilation failed.

 

So I guess I'm using the commands wrong... but why?

 

EDIT: This compiles - will test it now.

 

Scriptname SleepCounterScript extends ActiveMagicEffect

Float WellRestedOver
Spell Property pAbilityToRemove Auto
Float fSleepStartTime
Float fWellRestedTime
Float fWellRestedStartTime
Float fSleepStopTime

FUNCTION OnInit()
RegisterForSleep()
WellRestedOver = 1
ENDFUNCTION

EVENT OnUpdateGameTime()
Game.GetPlayer().RemoveSpell(pAbilityToRemove)
WellRestedOver = 1
ENDEVENT

EVENT OnSleepStart(float afSleepStartTime, float afDesiredSleepEndTime)
fSleepStartTime = Utility.GetCurrentGameTime()
ENDEVENT

EVENT OnSleepStop(bool abInterrupted)
if (WellRestedOver == 1)
fWellRestedTime = ((fSleepStopTime-fSleepStartTime)*24)
RegisterForSingleUpdateGameTime(fWellRestedTime)
WellRestedOver = 0
fWellRestedStartTime = fSleepStopTime
else
fWellRestedTime = ((fSleepStopTime-fSleepStartTime)*24+fWellRestedTime-(fSleepStartTime-fWellRestedStartTime)*24)
RegisterForSingleUpdateGameTime(fWellRestedTime)
fWellRestedStartTime = fSleepStopTime
endif
ENDEVENT

 

Edited by TangerineDog
Link to comment
Share on other sites

I'm trying to follow the logic of the script to figure out what you're trying to do. From a glance it looks like you're trying to detect sleep and determine if the player slept long enough to get well rested? If so I think you have your logic wrong.

Link to comment
Share on other sites

I think you should have a look in the vanilla script "ActiveMagicEffect.psc" to see what is a valid event.

Scriptname SleepCounterScript extends ActiveMagicEffect

; Event received when this effect is first started (OnInit may not have been run yet!)
Event OnEffectStart(Actor akTarget, Actor akCaster)
EndEvent

; Event received when this effect is finished (effect may already be deleted, calling functions on this effect will fail)
Event OnEffectFinish(Actor akTarget, Actor akCaster)
EndEvent
Link to comment
Share on other sites

That script has problems because it's in the OnSleepStop that you need to get the current time. The OnSleepStart gives you the current time as a parameter. Here's my rewrite which also eliminates your status variable and moves another that doesn't have to be global. I really like this idea.

Scriptname SleepCounterScript extends ActiveMagicEffect

Spell Property pAbilityToRemove Auto
Float fSleepStartTime
Float fWellRestedStartTime
Float fWellRestedTime

FUNCTION OnInit()
    RegisterForSleep()
ENDFUNCTION

EVENT OnUpdateGameTime()
    Game.GetPlayer().RemoveSpell(pAbilityToRemove)
    fWellRestedTime = 0.0
ENDEVENT

EVENT OnSleepStart(float afSleepStartTime, float afDesiredSleepEndTime)
    fSleepStartTime = afSleepStartTime
ENDEVENT

EVENT OnSleepStop(bool abInterrupted)
    Float fSleepStopTime = Utility.GetCurrentGameTime()
    if fWellRestedTime > 0.0
        fWellRestedTime = ((fSleepStopTime-fSleepStartTime)*24.0) + (fWellRestedTime-(fSleepStartTime-fWellRestedStartTime)*24.0)
    else
        fWellRestedTime = ((fSleepStopTime-fSleepStartTime)*24.0)
    endif
    RegisterForSingleUpdateGameTime(fWellRestedTime)
    fWellRestedStartTime = fSleepStopTime
ENDEVENT
Link to comment
Share on other sites

  • Recently Browsing   0 members

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