Jump to content

Need help with INI/Text-files-handling.


didisaan

Recommended Posts

Hi

 

I'm the author of the Item Distribution Framework mod. I have been trying to get INI/Text-file-handling to work, so that the users of the mod can exclude mods that they don't want processed by my mod, but have hade no luck.

Anyone who is a master at this and willing to help?

Link to comment
Share on other sites

Nice.

 

Well, the master script as it is now, goes through all the loaded mods. Then it reads all weapons/armors and distributes them through subscripts.

What I want to do is:

 

Whenever it loads in a new modfile, before it does anything else, it should first check the ini/txt-file if that mod is excluded and if it is, it should "restart" the loop and check the next modfile.

 

If have messed around with GetINISectionNames, but can't get it working.

Link to comment
Share on other sites

Could I see your script? Do you know where it's failing?

 

Also, I've found that sometimes, when you do stuff like this, though most of the time people use a GameMode block with GetGameRestarted and this seems to have proliferated the practise, it doesn't always work. I've found that in such rare circumstances, MenuMode 4 works (I assume you're using JIP LN).

 

My idea for this was to use this:

https://geckwiki.com/index.php/ReadArrayFromFile

 

Users would have to make a text file for it, but maybe we can get that other function working. I think seeing your whole script would be the best way for that, though.

Link to comment
Share on other sites

ScriptName aaaWeaponDistributionMainScript

<lots of variables>

Begin GameMode

If (GetGameLoaded || GetGameRestarted)

let iCount := 00
let iNumOfLoadedMods := GetNumLoadedMods 

while iCount < (iNumOfLoadedMods + 1)
let sModName := GetNthModName iCount
; Checks for excluded mods
if eval sModName == "FalloutNV.esm"
let iCount += 1
Continue
<lots of excluded mods>
else
;Gets all weapons from the current modindex and adds them to the correct formid/leveled lists
foreach AllWeapons <- (GetLoadedTypeArray 40 iCount)
let rWeaponId := *AllWeapons
let rRepairList := GetRepairList rWeaponId ; Gets the Repair List from the current weapon
let sIconPath := GetIconPath rWeaponId ; Gets the icon path from the current weapon
; If a Repair List is found, call the corresponding script.
if rRepairList == "Repair10mmPistol"
call aaaRepair10mmPistolScript rWeaponId
<lots more repair list checking action>
endif
loop
Break
endif
loop
let iCount += 1
endif

StopQuest aaaWeaponDistributionMain

End

This is the script, with repeating code shortened down.

Edited by didisaan
Link to comment
Share on other sites

Great. So, where is this script failing and where are you trying to use the function that isn't working? I'd rather you just post the entire script as it appears in your mod file, especially with the indentations, as this is a little hard to read (not impossible or anything, but not as smooth as it could be). If you're concerned about length, just put the spoiler tag code round the code block code. As in, put the word spoiler in [brackets] before the code block starts, and then put the word spoiler in [brackets] after it as well, but with a stroke before spoiler, like so:

 

[sp0iler] [c0de]

This is some spoilery code, this is.

[/c0de] [/sp0iler]

 

This is not spoilery code.

Edited by EPDGaffney
Link to comment
Share on other sites

Haha, managed to post the wrong version of the code... Sorry.

Here's the correct code.

 

ScriptName aaaWeaponDistributionMainScript
 
array_var AllWeapons
ref rWeaponId
ref rRepairList
int iNumOfLoadedMods
int iCount
string_var sModName
string_var sIconPath
 
Array_Var tempArrOuter
String_var iniSection
 
Begin GameMode
 
If (GetGameLoaded || GetGameRestarted)
 
let iCount := 00
let iNumOfLoadedMods := GetNumLoadedMods 
 
while iCount < (iNumOfLoadedMods + 1)
let sModName := GetNthModName iCount
ForEach tempArrOuter <- GetINISectionNames
let iniSection := $tempArrOuter["value"]
if eval sModName == iniSection
print "not used " + iniSection
Break
else
;Gets all weapons from the current modindex and puts them in the correct formid/leveled lists
print "used " + iniSection
foreach AllWeapons <- (GetLoadedTypeArray 40 iCount)
let rWeaponId := *AllWeapons
let rRepairList := GetRepairList rWeaponId ; Gets the Repair List from the current weapon
let sIconPath := GetIconPath rWeaponId ; Gets the icon path from the current weapon
; If a Repair List is found, call the corresponding script.
  Reveal hidden contents

endif
loop
Break
endif
loop
let iCount += 1
loop
endif
 
StopQuest aaaWeaponDistributionMain
 
End

 

It seems to work at first, but then it stops checking the file.

Link to comment
Share on other sites

Ah that makes sense.

 

So, as I've said, I'm no expert, but I've done things similar to this before and currently find success with them the most rewarding things to script, probably because the results are so far-reaching and because they take a lot of logic to put together. What I'm saying is, this is my first thought, but it's possible I've missed something simple:

 

Are you not using break where you'd want to use continue ?

 

Also, I have to think it was unnecessary to look at every single repair list individually. I'd need to have a think on how to do it properly, but I'm sceptical on that one.

Link to comment
Share on other sites

If there's another way of distinguishing the different weapons than repair lists, eg by icon or mesh path, you could skip all those elseifs by parking all the UDFs in a stringmap, with the paths as key, and simply call them straight through the stringmap:

call MyStringmap[$svPath] rWeaponID

That's one line instead of dozens of elseif checks, which in a loop really makes a difference.

 

On second thought, you might do the same based off a repair list, if you convert it to a string using RefToString.

if IsFormValid rRepairList
  let svKey := RefToString rRepairList
else
  let svKey := GetIconPath rWeaponID
endif
call MyStringMap[$svKey] rWeaponID
Edited by DoctaSax
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...