Skyrim Scripting - Making scripts reset

Post » Sun May 27, 2012 6:32 pm

A simple question:

Is their an easy way to get a script attached to a magic effect to reset itself and start again after it finishes processing everything within the script?

Note: It cant have anything to do with the RegisterForUpdate or OnUpdate commands because both commands do not work with menumode.

The reason I am trying to get this to work is so that for every hour while the player is asleep a global value is increased, here is the script:

Event OnInit()
RegisterForSleep()
endevent

Event OnSleepStart(float afSleepStartTime, float afDesiredSleepEndTime)
GlobalPCIsSleeping.setvalue(1)
game.getplayer().AddPerk(PerkSetValue)
endevent

Event OnSleepStop(bool abInterrupted)
game.getplayer().RemovePerk(PerkSetValue)
GlobalPCIsSleeping.setvalue(0)
endevent


The perk which is added mods the global value and adds 1 every game hour.

:ermm:
User avatar
djimi
 
Posts: 3519
Joined: Mon Oct 23, 2006 6:44 am

Post » Sun May 27, 2012 3:03 pm

Reset all the variables to their initial values in the OnEffectFinish() Event, maybe?
User avatar
ashleigh bryden
 
Posts: 3446
Joined: Thu Jun 29, 2006 5:43 am

Post » Mon May 28, 2012 2:20 am

Reset all the variables to their initial values in the OnEffectFinish() Event, maybe?

No it has to keep repeating the script, I thought maybe it would work if it was attached to a perk so it would always be constant but the script only processes once regardless.
User avatar
Kay O'Hara
 
Posts: 3366
Joined: Sun Jan 14, 2007 8:04 pm

Post » Sun May 27, 2012 4:09 pm

Then why not constantly repeat the functions in an OnUpdate() event?

Just use OnEffectStart() to set up the script and register for updates, then OnUpdate() does the stuff and will continue doing it until you tell it to stop.
User avatar
amhain
 
Posts: 3506
Joined: Sun Jan 07, 2007 12:31 pm

Post » Sun May 27, 2012 11:31 pm

Then why not constantly repeat the functions in an OnUpdate() event?

Just use OnEffectStart() to set up the script and register for updates, then OnUpdate() does the stuff and will continue doing it until you tell it to stop.

Thats what I would use but OnUpdate is an Event called periodically if the active magic effect/alias/form is registered for update events but the event will not be sent if the game is in menu mode and I need it to work in menu mode.

I am not sure if theirs a similar command to make it work in menu mode.

:dry:
User avatar
Adam Kriner
 
Posts: 3448
Joined: Mon Aug 06, 2007 2:30 am

Post » Sun May 27, 2012 4:43 pm

You could use States and a While loop but it depends how complicated your script is if it will work this way.

WHILE boKeepRunning == TRUE	  ;do code	  gotoState("CustomOnMagicEffectApply")	  ; etc.	  IF ; statement to stop running		 boKeepRunning = FALSE        ENDIFENDWHILE
We would probably have to see your script if its possible though. Sorry for the rough description but I'm still at work.
User avatar
Ana Torrecilla Cabeza
 
Posts: 3427
Joined: Wed Jun 28, 2006 6:15 pm

Post » Mon May 28, 2012 12:18 am

Is there some reason you can't just bind the spell to a property and re-apply it (call AddSpell or Cast) in the OnEffectFinish event?
User avatar
Peter P Canning
 
Posts: 3531
Joined: Tue May 22, 2007 2:44 am

Post » Mon May 28, 2012 1:19 am

Is there some reason you can't just bind the spell to a property and re-apply it (call AddSpell or Cast) in the OnEffectFinish event?

That does not seem to work.

:confused:
User avatar
Sammi Jones
 
Posts: 3407
Joined: Thu Nov 23, 2006 7:59 am

Post » Sun May 27, 2012 7:45 pm

Maybe I don't quite understand the question but the following native function is in the base form, can you not manipulate that in anyway to get what you are trying:-

; Register for a single OnUpdateGameTime event, in afInterval hours of game time. All scripts attached to this form will get the update eventsFunction RegisterForSingleUpdateGameTime(float afInterval) native
User avatar
Prohibited
 
Posts: 3293
Joined: Tue Jun 12, 2007 6:13 am

Post » Sun May 27, 2012 7:11 pm

I haven't tested this but would something like this work for you?


Spoiler

import GameEvent OnInit()	RegisterForSleep()endeventEvent OnSleepStart(float afSleepStartTime, float afDesiredSleepEndTime)	GlobalPCIsSleeping.setvalue(1)	getplayer().AddPerk(PerkSetValue)	RegisterForSingleUpdateGameTime(1)endeventEvent OnSleepStop(bool abInterrupted)	getplayer().RemovePerk(PerkSetValue)	GlobalPCIsSleeping.setvalue(0)	UnregisterForUpdateGameTime()endeventEvent OnUpdate()	getplayer().AddPerk(PerkSetValue)endevent
User avatar
Benito Martinez
 
Posts: 3470
Joined: Thu Aug 30, 2007 6:33 am

Post » Sun May 27, 2012 9:52 pm

I haven't tested this but would something like this work for you?


Spoiler

import GameEvent OnInit()	RegisterForSleep()endeventEvent OnSleepStart(float afSleepStartTime, float afDesiredSleepEndTime)	GlobalPCIsSleeping.setvalue(1)	getplayer().AddPerk(PerkSetValue)	RegisterForSingleUpdateGameTime(1)endeventEvent OnSleepStop(bool abInterrupted)	getplayer().RemovePerk(PerkSetValue)	GlobalPCIsSleeping.setvalue(0)	UnregisterForUpdateGameTime()endeventEvent OnUpdate()	getplayer().AddPerk(PerkSetValue)endevent

Thats what I thought would work but apparantly OnUpdate and any similar command all fail to work while in menu mode.
User avatar
Tanya
 
Posts: 3358
Joined: Fri Feb 16, 2007 6:01 am

Post » Sun May 27, 2012 11:17 pm

A simple question:

Is their an easy way to get a script attached to a magic effect to reset itself and start again after it finishes processing everything within the script?

Note: It cant have anything to do with the RegisterForUpdate or OnUpdate commands because both commands do not work with menumode.

The reason I am trying to get this to work is so that for every hour while the player is asleep a global value is increased, here is the script:

Event OnInit()
RegisterForSleep()
endevent

Event OnSleepStart(float afSleepStartTime, float afDesiredSleepEndTime)
GlobalPCIsSleeping.setvalue(1)
game.getplayer().AddPerk(PerkSetValue)
endevent

Event OnSleepStop(bool abInterrupted)
game.getplayer().RemovePerk(PerkSetValue)
GlobalPCIsSleeping.setvalue(0)
endevent


The perk which is added mods the global value and adds 1 every game hour.

:ermm:

If I am reading correctly, you seem to be making this more complicated than it needs to be (guilty as charged, believe me, it's easy). So all you want to do is increase a Global to keep track of how many hours the player slept? You want to keep adding to this Global and not reset it, correct?

GlobalVariable property MyIncrementVar AutoFloat SleepStartFloat SleepTimeEvent OnEffectStart(Actor akTarget, Actor akCaster)	RegisterForSleep()endeventEvent OnSleepStart(float afSleepStartTime, float afDesiredSleepEndTime)	   SleepStart = gameHour.GetValue()endeventEvent OnSleepStop(bool abInterrupted)	    SleepTime = GameHour.GetValue() - SleepStart	   If SleepTime > 0		    MyIncrementVar.setValue((MyIncrementVar.GetValue() + (SleepTime + 24))    Else		    MyIncrementVar.setValue(MyIncrementVar.getValue() + SleepTime)    EndIfendeventEvent OnEffectFinish(Actor akTarget, Actor akCaster)	  UnregisterForSleep()EndEvent

In Fact, even that's overcomplicating things. I think you might actually just want to use this:

GlobalVariable property MyIncrementVar AutoEvent OnEffectStart(Actor akTarget, Actor akCaster)	   RegisterForSleep()EndEventEvent OnSleepStop(bool abInterrupted)	  MyIncrementVar.SetValue(QueryStat("Hours Slept") as Float)EndEventEvent OnEffectFinish(Actor akTarget, Actor akCaster)	 UnregisterForSleep()EndEvent
User avatar
Emily abigail Villarreal
 
Posts: 3433
Joined: Mon Aug 27, 2007 9:38 am

Post » Sun May 27, 2012 1:59 pm


GlobalVariable property MyIncrementVar Auto

Event OnEffectStart(Actor akTarget, Actor akCaster)
RegisterForSleep()
EndEvent

Event OnSleepStop(bool abInterrupted)
MyIncrementVar.SetValue(QueryStat("Hours Slept") as Float)
EndEvent

Event OnEffectFinish(Actor akTarget, Actor akCaster)
UnregisterForSleep()
EndEvent[/code]

Good example but it doesn't get the job done.

That would just set the global value to 1-24 depending on hours slept which is not what I need.

What I need it to do is MOD the value (add to or subtract from the global value) not set it to some other value.

For example if you slept for 3 hours it would add 30 to the value and if you slept for 10 hours it would add 100.
User avatar
Georgine Lee
 
Posts: 3353
Joined: Wed Oct 04, 2006 11:50 am

Post » Sun May 27, 2012 9:13 pm

Good example but it doesn't get the job done.

That would just set the global value to 1-24 depending on hours slept which is not what I need.

What I need it to do is MOD the value (add to or subtract from the global value) not set it to some other value.

For example if you slept for 3 hours it would add 30 to the value and if you slept for 10 hours it would add 100.

Then just use TK's first example. You just need to change it a little bit:

GlobalVariable property GameDaysPassed AutoGlobalVariable property CustomGlobal AutoFloat SleepStartFloat SleepTimeEvent OnEffectStart(Actor akTarget, Actor akCaster)    RegisterForSleep()endeventEvent OnSleepStart(float afSleepStartTime, float afDesiredSleepEndTime)    SleepStart = GameDaysPassed.ValueendeventEvent OnSleepStop(bool abInterrupted)    SleepTime = GameDaysPassed.Value - SleepStart    CustomGlobal.SetValue(CustomGlobal.Value + (SleepTime * 24 * 10))endeventEvent OnEffectFinish(Actor akTarget, Actor akCaster)    UnregisterForSleep()EndEvent
User avatar
Lil Miss
 
Posts: 3373
Joined: Thu Nov 23, 2006 12:57 pm

Post » Sun May 27, 2012 5:37 pm

GlobalVariable property GameDaysPassed Auto
GlobalVariable property CustomGlobal Auto

Float SleepStart
Float SleepTime

Event OnEffectStart(Actor akTarget, Actor akCaster)
RegisterForSleep()
endevent

Event OnSleepStart(float afSleepStartTime, float afDesiredSleepEndTime)
SleepStart = GameDaysPassed.Value
endevent

Event OnSleepStop(bool abInterrupted)
SleepTime = GameDaysPassed.Value - SleepStart
CustomGlobal.SetValue(CustomGlobal.Value + (SleepTime * 24 * 10))
endevent

Event OnEffectFinish(Actor akTarget, Actor akCaster)
UnregisterForSleep()
EndEvent

With some editing this works very nicely, thanks for the help, you will be given credit when my mod goes live on the Nexus.

:biggrin:
User avatar
phillip crookes
 
Posts: 3420
Joined: Wed Jun 27, 2007 1:39 pm


Return to V - Skyrim