AddItemToLeveledList and Start Game Enabled quests

Post » Thu May 26, 2011 7:44 pm

Executive Summary (;tldr)

I've made a new weapon, and want to distribute it to the NPCs populating the wider Mojave wasteland. To prevent compatibility issues with other mods that may edit existing leveled lists, I'm going to try to use the AddItemToLeveledList function to accomplish this. I'm worried that using this function on a script attached to a Start Game Enabled quest will cause it to keep adding the new weapon to the levelled list every time the game is saved and subsequently loaded.

http://www.glowfoto.com/static_image/05-085801L/7786/jpg/11/2010/img4/glowfoto

http://www.glowfoto.com/static_image/05-070845L/2678/jpg/11/2010/img6/glowfoto

Detail

The http://geck.gamesas.com/index.php/AddItemToLeveledList for AddItemToLeveledList states that the script function:

(...)is for those special cases where you want to alter the contents of a list at runtime or want to change it without putting it in your ESP/ESM file. Once altered using this function, it will persist in the save game data.


(Bolded emphasis mine)

I've already set up a weapon condition list, CondLaserCarbineNPC and a WithAmmo list that incorporates the weapon condition list. I've created a quest with the "Start Game Enabled" checkbox ticked, which runs the following script:

scriptName SRNewWeaponLLDistributionshort finishedbegin gameModeif finished == 0AddItemToLeveledList Fiend1WeaponGunNV WithAmmoLaserCarbineLoot 0 1 1  ;; 0 = level; 1 = count; 1 = condition at 100%stopquest   SRNewWeaponLLDistributionQuestset finished to 1player.additem f 1 ;; adds a bottle cap to player inventory if script ran successfullyendifif finished == 1stopquest  SRNewWeaponLLDistributionQuest;;Praise Jaysus!endifend


My problem is this:

As this quest script runs every time the game starts, adding the new withAmmo weapon list, and the altered levelled list persists in the save game data, will this mean that the Fiend levelled list will keep getting appended with the withAmmo weapon list every time a progressed quickload occurs?

e.g.

Mod gets enabled in launcher.
Player loads a save game - quest script runs, adding new withAmmo weapon list to the fiend levelled list.
Player plays a bit, quicksaving now and then.
Player dies, reloads game. As game is starting again, quest script runs, adding new weapon cond list to the fiend levelled list again. The first addition is already present as it persists in the save data.
Player plays a bit, quicksaving. Now these quicksaves have the fiend levelled list with two identical new weapon cond lists added. The next time a quickload occurs, this will increase to three.
ad infiinitum, progressively lowering the chance of seeing fiends armed with anything but the new weapon.

Am I misunderstanding how this function will interact as a quest script on quests that run via Start Game Enabled quests?
User avatar
Trista Jim
 
Posts: 3308
Joined: Sat Aug 25, 2007 10:39 pm

Post » Fri May 27, 2011 5:44 am

I'm 99% certain that Start Game Enabled only means that the quest is started when you begin a NEW game, not when you load a save. The character creation quest for instance, is an example of a vanilla quest marked Start Game Enabled. In fact, FOSE specifically had functions GetGameLoaded and GetGameRestarted in order to manage things that reset between sessions, so it's pretty safe to say the feature isn't available through the GECK ;)

Edit: That is not to say you need to start a new game for such a quest to start. What the variable means is that the quest does not have a start trigger, it's simply "always enabled".
User avatar
Katie Louise Ingram
 
Posts: 3437
Joined: Sat Nov 18, 2006 2:10 am

Post » Thu May 26, 2011 11:10 pm

Notes:

- A start quest script (where you give it a priority of 35-65 and check off the box) will run on any load where the quest did not exist yet. So, take a save from before you added the ESP to the load order, and the quest will run when you load that save. Not just when you begin a new game. A good way to test this is to create debug MESG items that you can call with "ShowMessage MyPrefixDebugMessage".

There are two ways to control "run-once" style scripts.

- For quest scripts, a StopQuest line is best, and you don't need any "DoOnce" or "Finished" or "OnlyOnce" type variables. Once the quest runs, it gets stopped and in all subsequent saves, it will be completely inactive. The major downside to this is that it makes debugging difficult - you need to get everything right the first time, or maintain a library of save files from before you added the ESP to the load order.

Begin GameMode    ; Do stuff    ; Do some more stuff    StopQuest MyPrefixNameQuestEnd


- For scripts attached to objects, you don't have StopQuest available so you'll have to use the DoOnce variables. The downside is that the condition check still occurs on every frame, but since it's just a comparison to zero, it should have very minor impact.

short DoOnceBegin GameMode    If (DoOnce == 0)        ; Do stuff        ; Do more stuff        Set DoOnce To 1    EndIfEnd


- You *can* combine the two methods, they won't cancel each other out. But it's a bit of a waste to do both methods as they both do basically the same thing.

Now for the mind-bending bit...

Let's say that you're going to create a mod where you do things once at startup, but then you want to add additional items down the road that also do things at startup. You can't use StopQuest, because it would either make you add additional quests for every additional item that you added, or the users would have to type in "StartQuest questid" in the console to get things working again.

That's a good case for using the "DoOnce" method in a quest-related script. Your start-up quest script will then end up looking like:

short DoOnce1stReleaseBegin GameMode    If (DoOnce1stRelease==0)        ; Do stuff related to the initial release        Set DoOnce1stRelease To 1    EndIfEnd


Then, when you add more stuff...

short DoOnce1stReleaseshort DoOnce2ndReleaseBegin GameMode    If (DoOnce1stRelease==0)        ; Do stuff related to the initial release        Set DoOnce1stRelease To 1    EndIf    If (DoOnce2ndRelease==0)        ; Do stuff related to the second release of the mod        Set DoOnce1stRelease To 1    EndIfEnd


That way, if they download your mod and have never used it before, both blocks of code will fire. But if they had originally downloaded the first version, DoOnce1stRelease would have already been set to one. So when they download the new version of the mod, only the second block of code will execute. Doing it this way lets you slowly extend a mod, without breaking previous functionality or accidentally spawning 2nd copies of things.
User avatar
N3T4
 
Posts: 3428
Joined: Wed Aug 08, 2007 8:36 pm

Post » Fri May 27, 2011 2:35 am

That's awesome, thanks for the elaboration, Snabbik.
User avatar
Big Homie
 
Posts: 3479
Joined: Sun Sep 16, 2007 3:31 pm

Post » Fri May 27, 2011 12:54 am

I'm curious how well it's working out for you? In my preliminary testing, if you can find the right leveled list, it works rather well.

http://geck.gamesas.com/index.php/AddItemToLeveledList

The only downside to adding to an existing leveled list is that you need to think of the leveled list as one big "pick one of these randomly" list. Which is fine if you want raiders to use a new weapon, but not so good if you want to add ammo to vendors in addition to what they already have, and have it respawn.
User avatar
Matt Fletcher
 
Posts: 3355
Joined: Mon Sep 24, 2007 3:48 am

Post » Fri May 27, 2011 4:00 am

In quest tab, Start Game Enabled starts only once, if this is a new game, the quest starts the moment you start the game.

If you load a save file that never had this mod, then it starts the moment you load that save file.
User avatar
OJY
 
Posts: 3462
Joined: Wed May 30, 2007 3:11 pm


Return to Fallout: New Vegas