Getting a script to run when the game loads

Post » Mon Jun 18, 2012 5:10 am

...unless akActor is specific to their mod or is obscure, there's a chance of overlap. The below iteration makes a chicken and checks it. If a plugin already has an ACHR, even better.
Actor rACHR = NoneEvent OnInit()	If !rActor		rACHR = Game.GetPlayer().PlaceAtMe(Game.GetForm(0x000A91A0), 1, True, True) As Actor		rACHR.SetScale(0)		rACHR.EnableAI(False)		rACHR.Enable()		RegisterForUpdate(5)	EndIfEndEventEvent OnUpdate()	If bGetGameLoaded(rACHR)		; Code that iterates once per save load		Else		; Code that reiterates normally		EndIfEndEventBool Function bGetGameLoaded(Actor akActor)	If akActor.GetActorValue("BrainCondition")		akActor.SetActorValue("BrainCondition", 0)		Return True	Else		Return False	EndIfEndFunction 
User avatar
Jessica Nash
 
Posts: 3424
Joined: Tue Dec 19, 2006 10:18 pm

Post » Mon Jun 18, 2012 2:33 am

I was messing around just now and figured out a way to sort of check GetGameRestarted().

Scriptname GameRestartedScript extends ActiveMagicEffect{Scripted ability attached to RefAlias filled with player.}GlobalVariable property GameSession autoSpell property OwningSpell autoEvent OnEffectStart(Actor akTarget, Actor akCaster)    GameSession.SetValue(GameSession.GetValue() + 1.0)    akTarget.RemoveSpell(OwningSpell)EndEvent

Every time that the game is restarted, the player has the spell added to him/her again. This is specific to each character.
User avatar
OJY
 
Posts: 3462
Joined: Wed May 30, 2007 3:11 pm

Post » Mon Jun 18, 2012 1:33 pm

Hi,

could someone explain the last comment for scripting noobs :wink:

It looks clean and short, but I don't see how this should work. You define a global variable to count the number of sessions and a random spell, which should be added to the players inventory. Right? Then you do something everytime an effect starts (which effect, by the way?). What you do is: Rise the variable (so that you can see, if a new game session starts) and remove the spell. So... why is the event "OnEffectStart" a reliable condition for a new game session? And why you remove the spell, if you want it added to the inventory every time you load a game?

And what confuses me even more: Could you use the AddForm(LeveledItem) with that method?
User avatar
Reven Lord
 
Posts: 3452
Joined: Mon May 21, 2007 9:56 pm

Post » Mon Jun 18, 2012 3:01 am

1. Create a magic effect (constant effect on self)
2. Attach script to magic effect
3. Create ability
4. Attach magic effect to ability (so the ability is the "OwningSpell")
5. Create a quest
6. Create a ref alias in the quest
7. Fill the ref alias with the player
8. Drag and drop the ability into the ref alias's spell list

As for how it works, whenever the game is loaded, the quest checks to make sure that the player has all the spells in the ref alias's spell list. If the player doesn't have the custom ability, it will be added to the player. When the ability gets added, the OnEffectStart of its magic effect runs.

For some reason, the quest only checks this once per game session. So this is not a reliable way to check for GetGameLoaded, only for GetGameRestarted.

This method has nothing to do with the AddForm method. There's nothing that conflicts with it.
User avatar
renee Duhamel
 
Posts: 3371
Joined: Thu Dec 14, 2006 9:12 am

Post » Mon Jun 18, 2012 9:37 am

Hi,

you've saved my day here! It's finally works! You can't imagine how long I try to figure out, how to check for the game been restarted!!! Thanks!

Just a question: What's the difference between "GetGameLoaded" and "GetGameRestarted" for you? For me the effect works fine, everytime I load a savegame (irrelevant if I load it out of an other active game or by restarting the whole game and load from the start menu).
User avatar
Nick Swan
 
Posts: 3511
Joined: Sat Dec 01, 2007 1:34 pm

Post » Mon Jun 18, 2012 12:29 pm

Just a question: What's the difference between "GetGameLoaded" and "GetGameRestarted"?
http://geck.gamesas.com/index.php/GetGameRestarted vs. http://geck.gamesas.com/index.php/GetGameLoaded

For maintaining stuff that's not saved, you'd want GetGameLoaded.
User avatar
Eilidh Brian
 
Posts: 3504
Joined: Mon Jun 19, 2006 10:45 am

Post » Mon Jun 18, 2012 10:30 am

GetGameRestarted = everytime you run Skyrim. Happens only one per session. The game you load will detect whether it is the first game you load in that game session.
GetGameLoaded = everytime you load a game. Happens everytime you load the game.

E.g. for my Auto-save and time mod's real-time alarm clock (used to wake you up from your game into the real world every 10 minutes by default), I need to reset its time counter on GetGameRestarted (). Time counted from the first time you load a game doesn't restart everytime you load a game.

Expect GetGameRestarted () and GetGameLoaded () is both True in that first game of the session.
User avatar
Alessandra Botham
 
Posts: 3440
Joined: Mon Nov 13, 2006 6:27 pm

Post » Mon Jun 18, 2012 8:15 am

Alright.

Short question: Is it possible, to put a delay into your script, so that the changes don't set in immediately but a few seconds later? I tried this, but it doesn't work:

Spoiler

Scriptname GameRestartedScript extends activemagiceffect{Scripted ability attached to RefAlias filled with player.}GlobalVariable property GameSession autoSpell property OwningSpell automiscobject Property Gold Autoleveleditem Property VendorList AutoGlobalVariable Property FarengarInvestCapitalGV AutoEvent OnEffectStart(Actor akTarget, Actor akCaster)GameSession.SetValue(GameSession.GetValue() + 1.0)akTarget.RemoveSpell(OwningSpell)RegisterForSingleUpdate(5)EndEventEvent OnSingleUpdate()VendorList.AddForm(Gold, 1, FarengarInvestCapitalGV.GetValueInt())Debug.MessageBox("Gold added")EndEvent
User avatar
danni Marchant
 
Posts: 3420
Joined: Sat Oct 07, 2006 2:32 am

Post » Sun Jun 17, 2012 11:32 pm

The event should be OnUpdate, not OnSingleUpdate. RegisterForSingleUpdate just means that OnUpdate will only fire once (unless you call RegisterForSingleUpdate again).
User avatar
Thomas LEON
 
Posts: 3420
Joined: Mon Nov 26, 2007 8:01 am

Post » Mon Jun 18, 2012 2:21 pm

Jubeldibub: If, per that other thread, you're looking to maintain a LeveledItem change via AddForm(), you'd want GetGameLoaded() rather than GetGameRestarted() as the form(s) added to the LVLI will be lost each time a save is loaded and that's when you'd want to reiterate, not just when a new character is created or when the game is closed/opened.

Spoiler
Actor rACHR = NoneGlobalVariable Property FarengarInvestCapitalGV AutoLeveledItem Property VendorList AutoMiscObject Property Gold AutoEvent OnInit()	If !rACHR		rACHR = Game.GetPlayer().PlaceAtMe(Game.GetForm(0x000A91A0), 1, True, True) As Actor		rACHR.SetScale(0)		rACHR.EnableAI(False)		rACHR.Enable()		RegisterForUpdate(5)	EndIfEndEventEvent OnUpdate()	If bGetGameLoaded()		VendorList.AddForm(Gold, 1, FarengarInvestCapitalGV.GetValueInt())	Else		;Normal code	EndIfEndEventBool Function bGetGameLoaded()	If rACHR.GetActorValue("BrainCondition")		rACHR.SetActorValue("BrainCondition", 0)		Return True	Else		Return False	EndIfEndFunction
User avatar
Benji
 
Posts: 3447
Joined: Tue May 15, 2007 11:58 pm

Post » Mon Jun 18, 2012 4:29 am

Hi Justin,

strange to say, but the "quest-method" loads my script every time I load a game. Here is it without my delay tries:

Spoiler

Scriptname GameRestartedScript extends activemagiceffect{Scripted ability attached to RefAlias filled with player.}GlobalVariable property GameSession autoSpell property OwningSpell automiscobject Property Gold Autoleveleditem Property VendorList AutoGlobalVariable Property FarengarInvestCapitalGV AutoEvent OnEffectStart(Actor akTarget, Actor akCaster)GameSession.SetValue(GameSession.GetValue() + 1.0)akTarget.RemoveSpell(OwningSpell)VendorList.AddForm(Gold, 1, FarengarInvestCapitalGV.GetValueInt())Debug.MessageBox("Gold hinzugefügt")EndEvent

However the game crashes, if I load a savegame and then load another savegame out of the current. Don't know if the script is responsible for this.
Apart from that it works, so far I see, reliable. I checked it with the DebugMessageBox (see above), which will triggered every time I load a game, not just the first time I load a specific savegame.

Is there a way to delay the lines, which are triggered through the OnEffectStart-Event? I tried it with OnUpdate and OnSingleUpdate, both didn't work (my messagebox don't appear anymore, if I load a game).

And to your script: Where I have to attach this? Also on an magiceffect linked to a spell and a quest? I tried it like that, but got the compiling error: "(19,3): too many arguments passed to function"
User avatar
Marcin Tomkow
 
Posts: 3399
Joined: Sun Aug 05, 2007 12:31 pm

Post » Mon Jun 18, 2012 3:29 pm

It'd be attached to a quest, I'd imagine.

Compiling: Fixed it.
User avatar
Channing
 
Posts: 3393
Joined: Thu Nov 30, 2006 4:05 pm

Post » Mon Jun 18, 2012 9:33 am

Okay, tested your script and it works well (and with delay). Thank you for that!

But something still goes wrong: Irrelevant which script I use (yours or RandomNoobs), the game crashes to desktop (without any error message), when I try to load a savegame out of a running game (not the start menu). Has it something to do with the global variable I use? Perhaps I do something wrong here. I rise the variable "FarengarInvestCapitalGV" (in fact I rise the "Global" with which it is defined) in another script (attached to a other quest) and use the rised amount here, in your script. Can this cause errors or crashes?
User avatar
lucy chadwick
 
Posts: 3412
Joined: Mon Jul 10, 2006 2:43 am

Post » Sun Jun 17, 2012 11:32 pm

It the "Use All" flag ticked in your LVLI? I've read of a few instances it not being checked coincided w/ crashes.
User avatar
Nancy RIP
 
Posts: 3519
Joined: Mon Jan 29, 2007 5:42 am

Post » Mon Jun 18, 2012 3:03 pm

The "Use All" Flag was active. But in the LeveledItem, which I change with the script, already was a "Gold001" object (count = 1). After deleting this, the crashes disappeared. Perhaps the game can't handle multiple items of the same type (if one of them is forced in with a script).

Once again to the delay: I thought, if I implement a delay, that the respawning chest of a merchant doesn't have the added item in it immediately, but after the next respawn time. Unfortunately it's not like this. Is there a easy way to delay the adding of the item (after a load), so that it not appears until the chest is respawned again?
User avatar
noa zarfati
 
Posts: 3410
Joined: Sun Apr 15, 2007 5:54 am

Post » Sun Jun 17, 2012 10:59 pm

Perhaps add the gold to an empty LVLI and add that LVLI to the vanilla one. Leveled Items can have other leveled items. Not sure about waiting 'til respawn, but you could probably fill alias slots with vanilla vendor containers and add the gold OnReset style.
User avatar
Harry Hearing
 
Posts: 3366
Joined: Sun Jul 22, 2007 6:19 am

Post » Mon Jun 18, 2012 4:44 am

The LeveledItem, in which I add the gold, is indeed in another LeveledItem (if I don't do that, the game for whatever reason chrashes). But I can't put it into a vanilla one. For my invest mod, every merchant of the game got an own LeveledItem "shell" and an own LeveledItem, in which the gold is stored.

you could probably fill alias slots with vanilla vendor containers and add the gold OnReset style
Sorry, but what!? Alias slots? OnReset Style? I don't get this one :geek:
User avatar
Sophie Morrell
 
Posts: 3364
Joined: Sat Aug 12, 2006 11:13 am

Post » Mon Jun 18, 2012 9:22 am

I was messing around just now and figured out a way to sort of check GetGameRestarted().

Scriptname GameRestartedScript extends ActiveMagicEffect{Scripted ability attached to RefAlias filled with player.}GlobalVariable property GameSession autoSpell property OwningSpell autoEvent OnEffectStart(Actor akTarget, Actor akCaster)	GameSession.SetValue(GameSession.GetValue() + 1.0)	akTarget.RemoveSpell(OwningSpell)EndEvent

Every time that the game is restarted, the player has the spell added to him/her again. This is specific to each character.
Please forgive my lack of knowledge...
What is the purpose of the global "GameSession" and why is it incremented?

Also, in your "setup" instructions, I'm not 100% sure, but the magic effect archtype is suppose to be script. Correct?
User avatar
Emma louise Wendelk
 
Posts: 3385
Joined: Sat Dec 09, 2006 9:31 pm

Post » Mon Jun 18, 2012 8:07 am

...unless akActor is specific to their mod or is obscure, there's a chance of overlap. The below iteration makes a chicken and checks it. If a plugin already has an ACHR, even better.
Actor rACHR = NoneEvent OnInit()	If !rActor		rACHR = Game.GetPlayer().PlaceAtMe(Game.GetForm(0x000A91A0), 1, True, True) As Actor		rACHR.SetScale(0)		rACHR.EnableAI(False)		rACHR.Enable()		RegisterForUpdate(5)	EndIfEndEventEvent OnUpdate()	If bGetGameLoaded(rACHR)		; Code that iterates once per save load		Else		; Code that reiterates normally		EndIfEndEventBool Function bGetGameLoaded(Actor akActor)	If akActor.GetActorValue("BrainCondition")		akActor.SetActorValue("BrainCondition", 0)		Return True	Else		Return False	EndIfEndFunction 

Thank you for this. You should consider adding this to the Wiki's Example Scripts.
Same for RandomNoob's GetGameRestarted snippet.

True, these may become obsolete when SKSE has the functions, but there will always be people who prefer not to use SKSE.
User avatar
helen buchan
 
Posts: 3464
Joined: Wed Sep 13, 2006 7:17 am

Previous

Return to V - Skyrim