MathiewMay Posted March 31, 2021 Share Posted March 31, 2021 Hi, i have some experience modding other games, and i still can't understand why can't i just make a script run on start and do its thing as long as the game is running. i have searched on the forum and the only thing i found is a post from 2012 that says to create a quest, that only runs when you load a save game, also it does not continue running after the quest was givent to the player, and it does not run when the player re start his game from a save that was already given the quest. i wanted to know how can i do just that, make a script that run on start and do its thing as long as the game is running, its a basic scripting implementation that all other games have, all the other games i have modded allow for something as basic as this, yet i still can't find how to do this correctly. i have been searching everywhere for the past 2 days for something like this and everytime i either get a nexus mods post from some random guy asking a question about a mod or i get a guide that shows how to add things to the game like items and npcs obviously something im not interested in. i really can't find just a simple explenation on how to do this. without having to jump thry 3 different forums that says different things and end up never working. Note that i have already seen this post https://forums.nexusmods.com/index.php?/topic/558795-script-tutorial-script-initialization-on-game-load/Its outdated and does not do what i want either. Maybe some one knows the answer and would be kind enough to inform me and others. Link to comment Share on other sites More sharing options...
IsharaMeradin Posted March 31, 2021 Share Posted March 31, 2021 Papyrus scripts do not constantly "run". If the object holding the script is loaded then it will be able to receive events and run code from those events. If the object is not loaded and not persistent then it will not be able to receive any events until it is loaded. To get around this, one does need to use a start game enabled quest to hold their script. If you have specific stuff that needs to happen one each load of the game (not just when the game starts), then you'll need to create a player alias on the start game enabled quest and put the script on the alias. You can then set up a local custom function to handle the workload. Use the OnInit event to register for a short single update (quests can trigger OnInit twice, registering for an update will cause the local function to run only once instead of twice). Use the OnPlayerLoadGame event to run your function each time the game is loaded. It will trigger for new sessions as well as re-loads due to death. Simple example: ScriptName SomePlayerAliasScript Extends ReferenceAlias Event OnInit() RegisterForSingleUpdate(1.0) ;a one second wait EndEvent Event OnPlayerLoadGame() DoMyStuff() EndEvent Event OnUpdate() DoMyStuff() EndEvent Function DoMyStuff() ;do all the work here EndFunction If this does not help, perhaps then if you went into more detail about what you want to achieve, more direct assistance could be given. Link to comment Share on other sites More sharing options...
MathiewMay Posted March 31, 2021 Author Share Posted March 31, 2021 Hi, th Papyrus scripts do not constantly "run". If the object holding the script is loaded then it will be able to receive events and run code from those events. If the object is not loaded and not persistent then it will not be able to receive any events until it is loaded. To get around this, one does need to use a start game enabled quest to hold their script. If you have specific stuff that needs to happen one each load of the game (not just when the game starts), then you'll need to create a player alias on the start game enabled quest and put the script on the alias. You can then set up a local custom function to handle the workload. Use the OnInit event to register for a short single update (quests can trigger OnInit twice, registering for an update will cause the local function to run only once instead of twice). Use the OnPlayerLoadGame event to run your function each time the game is loaded. It will trigger for new sessions as well as re-loads due to death. Simple example: ScriptName SomePlayerAliasScript Extends ReferenceAlias Event OnInit() RegisterForSingleUpdate(1.0) ;a one second wait EndEvent Event OnPlayerLoadGame() DoMyStuff() EndEvent Event OnUpdate() DoMyStuff() EndEvent Function DoMyStuff() ;do all the work here EndFunction If this does not help, perhaps then if you went into more detail about what you want to achieve, more direct assistance could be given.Hi, thanks for taking the to reply to my post, with the method you sugested the script is ran as expected, is there any explenation on why it works that way? or is it just limited to objects being the only thing that can run scripts? Link to comment Share on other sites More sharing options...
IsharaMeradin Posted April 1, 2021 Share Posted April 1, 2021 I am not very good with all the ins and outs. If you want a detailed explanation as to why it works the way it works perhaps reading over the Papyrus Primer on the Creation Kit wiki will give you some insight. Link to comment Share on other sites More sharing options...
Recommended Posts