evanbgood Posted February 23, 2011 Share Posted February 23, 2011 (edited) Sorry to be posting two questions so close to each other, but after being helped through my mod-editing troubles, I discovered some script editing troubles. So here's what I'm trying to do. My mod, EMP Ammo Expansion, adds 8 new kinds of ammo to the game. Originally, I did this by simply adding my ammo to the appropriate form lists, saving, and calling it a day. A few people disliked this because it overwrote 8 form lists, meaning no other mods that touched those 8 kinds of ammo would play nice with mine. I originally made the mod before NVSE was available and planned to make a script work-around to this problem as soon as it came out... Obviously, I procrastinated a little. So, now I'm trying to take care of it. What I have so far is a simple script activation quest that starts on gamemode and, using NVSE's ListAddForm command, I made a script to add each ammo to the end of their respective lists (I couldn't do this earlier with the non-NVSE add command because it made the ammo the first in the list instead of the last, meaning it would be the default ammo for all guns). I'm super bad at scripting, so you can imagine how happy I was when it seemed to work and the ammo loaded properly!... Kinda. That's when I noticed my problem. For some reason, using this method, guns refuse to swap away from my EMP ammo. Normally, if you hit your ammo swap key, you cycle through all the types of ammo available in your inventory. When you get to the end of the list, it goes back to the first one, in a 1, 2, 3, 1, 2, 3... pattern. However, whenever I load a gun with EMP ammo now, the swap refuses to cycle, going 1, 2, 3, 4, stop. Strangely, the game still allows me to go into the ammo menu, manually select an ammo, and continue as normal until EMP ammo is loaded again. The ammo itself works fine, and every gun seems to recognize it properly. In fact, everything is just perfect, until you try to use an ammo swap key to go back to standard ammo from EMP. Color me stumped! I have no clue how to even start to address this one! My only guess is there's some conflict between how the ammo swap quick key looks at an ammo list and how NVSE adds them. Here's my script, if that'll help scriptname empammoexpansionenablescript begin gamemode ListAddForm AmmoList556mm Ammo556mmEMP ListAddForm AmmoList50MG Ammo50MGEMP ListAddForm AmmoList308 Ammo308EMP ListAddForm AmmoListMissile AmmoEMPMissile ListAddForm AmmoList25mmGrenade Ammo25mmGrenadeEMP ListAddForm AmmoList40mmGrenade Ammo40mmGrenadeEMP ListAddForm AmmoList12Ga Ammo12GaEMPSlug ListAddForm AmmoList20Ga Ammo20GaEMPSlug ShowMessage EMPAmmoEnabled stopquest empammoexpansionenabler end Any ideas would be greatly appreciated! Edit: Okay, so there's a 50/50 chance that this may be a fluke. It looks like I get this problem with one of my save files, but not with a newer one I have available. On the save it does work on, however, I found a new problem. Though the script works fine the first time the quest is loaded, the game seems to "reset" the ammo lists upon exiting. Is there some other command I should use than "gamemode" to make sure my form lists are updated every time the game starts? I suppose I could just remove the stopquest, but that seems rather inefficient to have a script like this running over and over again non-stop. Again, any ideas would be great! I want to get this published already! Edited February 23, 2011 by evanbgood Link to comment Share on other sites More sharing options...
davidlallen Posted February 23, 2011 Share Posted February 23, 2011 This thread may have a solution. At any rate, it avoids using NVSE which adds many complications. http://www.thenexusforums.com/index.php?/topic/298096-a-more-mod-friendly-way-to-add-to-perk-formlists/ Link to comment Share on other sites More sharing options...
evanbgood Posted February 23, 2011 Author Share Posted February 23, 2011 This thread may have a solution. At any rate, it avoids using NVSE which adds many complications. http://www.thenexusforums.com/index.php?/topic/298096-a-more-mod-friendly-way-to-add-to-perk-formlists/ Unfortunately, that's the AddFormtoFormList command that I was trying to avoid. It's possible that that might work, but addformtoformlist always adds items to the 0th index. In my case, that means that all guns use my special ammo by default if its in the player's inventory instead of the most standard ammo that normally takes the 0 index. What I really need is a way to run a quest or script once, whenever a game loads, or a similar effect through other means. Link to comment Share on other sites More sharing options...
davidlallen Posted February 23, 2011 Share Posted February 23, 2011 (edited) Cayou find out what is the 0th item before you start; remove it; add yours; and then add the 0th one back? I have not seen the problem that information added by a quest at time 0 should be lost, which is what you seem to be describing. However, I usually use an "onload" for the object. This may trigger multiple times so you may need a variable like bDoneOnce. But you could try checking to see if your item is on the formlist, and if not, then add it. Edited February 23, 2011 by davidlallen Link to comment Share on other sites More sharing options...
Pelinor Posted February 23, 2011 Share Posted February 23, 2011 (edited) You could do something like the code below to add the ammo to the bottom of the list while using AddFormToFormList, if you wanted. (Spoiler because it takes up the page.) It may be better to add your ammo to the FormList entries, then instruct the users to use FNVEdit to merge the lists. ScriptName empammoexpansionenablescript short iListIndex short iListNum reference rAmmo reference rList reference rNewAmmo begin GameMode Label 1 if iListNum == 0 set rList to AmmoList556mm set rNewAmmo to Ammo556mmEMP elseif iListNum == 1 set rList to AmmoList50MG set rNewAmmo to Ammo50MGEMP elseif iListNum == 2 set rList to AmmoList308 set rNewAmmo to Ammo308EMP elseif iListNum == 3 set rList to AmmoListMissile set rNewAmmo to AmmoEMPMissile elseif iListNum == 4 set rList to AmmoList25mmGrenade set rNewAmmo to Ammo25mmGrenadeEMP elseif iListNum == 5 set rList to AmmoList40mmGrenade set rNewAmmo to Ammo40mmGrenadeEMP elseif iListNum == 6 set rList to AmmoList12Ga set rNewAmmo to Ammo12GaEMPSlug elseif iListNum == 7 set rList to AmmoList20Ga set rNewAmmo to Ammo20GaEMPSlug else ShowMessage EMPAmmoEnabled StopQuest empammoexpansionenabler endif if rList if ListGetFormIndex rList rNewAmmo < 0 set iListIndex to ListGetCount rList AddFormToFormList rList rNewAmmo else set rAmmo to ListGetNthForm rList iListIndex if rAmmo != rNewAmmo ListRemoveForm rList rAmmo AddFormToFormList rList rAmmo else set iListNum to iListNum + 1 endif endif Goto 1 endif end (Edit: I forgot to reply to the other issue. To get a script to run once per game session you can use NVSE's GetGameRestarted, or once per load with GetGameLoaded.) Edited February 23, 2011 by Pelinor Link to comment Share on other sites More sharing options...
davidlallen Posted February 23, 2011 Share Posted February 23, 2011 Parallel discussion on this thread:http://www.thenexusforums.com/index.php?/topic/305266-convert-a-base-form-to-a-persistent-reference-temporarily Link to comment Share on other sites More sharing options...
evanbgood Posted February 24, 2011 Author Share Posted February 24, 2011 Cayou find out what is the 0th item before you start; remove it; add yours; and then add the 0th one back? I have not seen the problem that information added by a quest at time 0 should be lost, which is what you seem to be describing. However, I usually use an "onload" for the object. This may trigger multiple times so you may need a variable like bDoneOnce. But you could try checking to see if your item is on the formlist, and if not, then add it. I think you misunderstood. AddFormToFormList doesn't remove or replace index 0, of course. What it does do, however, is it makes the new entry index 0 and adds 1 to all other entries. I think that 99.9% of the time, this isn't an issue, but because guns always check for index 0 first from their ammo list, it makes the gun load the wrong ammo first. Also, I haven't checked it, but I get the feeling that there isn't a difference between AddFormToFormList and ListAddForm when it comes to changes lasting after a game restart. Also, a little update on the original problem (ammo not cycling), I think that it was simply caused by an infinite script loop, where indexes 4 thru infinity were being filled with form entries, meaning the ammo would try to swap to the same one over and over again and, thus, do nothing... That's the theory, at least. You could do something like the code below to add the ammo to the bottom of the list while using AddFormToFormList, if you wanted. (Spoiler because it takes up the page.) It may be better to add your ammo to the FormList entries, then instruct the users to use FNVEdit to merge the lists. (Edit: I forgot to reply to the other issue. To get a script to run once per game session you can use NVSE's GetGameRestarted, or once per load with GetGameLoaded.) Wow, that's THREE good answers! Thank you! I suppose the FNVEdit route is probably the safest for everyone, but I try to keep things as user-friendly as possible when I can. Actually, my experience is so low with FNVEdit that I wouldn't even know how to go about merging the two, but it's something I'm sure I'll learn in time. I could see that being very useful though for my other major mod project. Out of curiosity, does an FNVEdit merge allow two adjustments to the same item? For example, if I had a mod that changed stimpaks to +50 health and another mod that renamed them to "AID: Stimpak", would it result in a form entry that contained both changes? The code answer is... impressive. And a wee bit over my head, I think! I've been staring at it, and I think I kind of get how it works, but yikes... Seems like the long road to home. But thank you, thank you, thank you for coming back to add that edit! It looks like GetGameReloaded is exactly what I was looking for! I can't see too much of a difference between GetGameReloaded and GetGameLoaded, but I think Reloaded is what I'm looking for. It sounds like all I'd need is an "if getgamereloaded == 1" line and I'd be in business. However, this does beg one important question. If this script is running on gamemode and the quest never ends, I assume the script will go "Did the game just reload? No. Did the game just reload? No." every frame of the game in the background. How "bad" is this, performance wise? I don't want to add an unnecessary process to every frame if it causes the game to hiccup at all. The solution that comes to mind is to add a long process delay on the quest. I'm assuming 1 every 30 seconds is pretty negligible, but (in case this wasn't painfully obvious) I don't know too much about scripting and its effect on processing speed and memory. If it's no big deal to have a script running in the background and an extra little trigger quest, though, I may have found my solution! Thanks guys, I think I'm almost there! Link to comment Share on other sites More sharing options...
Recommended Posts