Jump to content

Adding Race-based NPCs to an array?


Hitman69

Recommended Posts

Disclaimer: I'm not sure this is the right sub-forum, so if any Mod decides it isn't, please move this to the right one...

 

 

Well, I've been screwing around with the CS (OBSE-enabled, of course). And I've built a little proof-of concept mod. However, I can't get it to work properly. Everything works, except the one thing I need to have working.

 

What I need to do, is to first build an array out of the races required, via .ini, and then, the game should scan each cell periodically for NPC's of those races, and add all females to an array. In my case, I've only gotten one race, but I want this to be easily expandable to mod-added races.

 

Here's what I build as my .ini-file:

let NPCDetectionQuest.TimeBeforeNextRun := 10
ar_Resize NPCDetectionQuest.RaceArray 0
let NPCDetectionQuest.RacetoAdd := GetFormFromMod "Beautiful People 2ch-Ed.esm" 00391E
ar_append NPCDetectionQuest.RaceArray NPCDetectionQuest.RacetoAdd

 

The reason that I put in the ar_Resize is so that the races won't be listed multiple times after each restart of Oblivion, as the .ini runs once per load.

 

 

As for the detection-script, here it is:

scn NPCDetectionSCRIPT

;references
ref me
ref Race
ref RacetoAdd
ref MeforDebug

;arrays
array_var RaceArray

;integers
short Timer
short TimeBeforeNextRun
short DoOnce
short RaceIndex
short FoundRace
short RaceArrayLength
short NPCIndex
short ListCheck

Begin GameMode
if DoOnce != 1
	Let  RaceArray := ar_Construct Array
	Let DoOnce := 1
endif
If GetGameLoaded
	RunBatchScript "ini\AllowedRaces.ini"
endif

if Timer == 0 || GetCellChanged
	set me to GetFirstRef 35 1
	while (me)

;Checks for race, gender, and existance in array are here.
;If both check out, adds the NPC to the array.

		if me.GetIsSex Female
			Let RaceIndex := 0
			Let RaceArrayLength := ar_Size RaceArray
			Let FoundRace := 0
			while RaceIndex < RaceArrayLength && FoundRace == 0
				Let Race := RaceArray[RaceIndex]
				if me.GetIsRace Race
					let FoundRace := 1
					if NPChandlingquest.DebugVar
						MessageBoxEX "NPC (%n) was detected of allowed race (%n)" me Race
					endif
				endif
				Let RaceIndex := RaceIndex + 1
			loop
			if FoundRace
				Let NPCIndex := ar_Find me NPChandlingquest.listofNPCs
				if ar_HasKey NPChandlingquest.listofNPCs NPCIndex
				else
					ar_Append NPChandlingquest.listofNPCs me
					if NPChandlingquest.DebugVar
						Let ListCheck := (ar_Size NPChandlingquest.listofNPCs) - 1
						Let MeforDebug := NPChandlingquest.listofNPCs[ListCheck]
						MessageBoxEX "NPC (%n, %i) was added to the array" MeforDebug MeforDebug
					endif
				endif
			endif
		endif
		set me to GetNextRef
	loop

	Let Timer := TimeBeforeNextRun
else
	Let Timer := Timer - 1
endif
End

 

I was wondering what I'm doing wrong, because when I set NPChandlingquest.debugvar to the right value, and then move to cell with a NPC of the specific race (I should add, I never entered that specific cell, or any near it before), the script doesn't detect said NPC. It never gives me a single messagebox, and any functions of the mods depending on the NPC being in the array won't fire.

 

I'd appreciate any suggestions. I am willing to switch to Pluggy-arrays, however, I'd rather not, as pluggy tends to chrash the game.

 

Thanks,

 

Hitman69

Link to comment
Share on other sites

RunBatchScript would run all the lines in the ini file as though they were typed into the console. I don't think the console accepts "let", ":=", array functions, etc.

 

Is there any reason why you need an ini file? I don't see how it would be any more user friendly if you still have to open up the CS to get the FormID of the races.

Link to comment
Share on other sites

Well, to get the formID's you can also use Tes4View/-Edit or Wrye. However, the main reason I'm doing this is so that when updates to the mod are applied, the user doesn't need to re-apply any changes he originally made in the CS, leading to better update-ability. Anyhow, opening the CS is mandatory, as the mod also requires dialog, which I can't possibly make for every race. I leave that up to the user. However, this way, at least they don't have to edit the scripts, and have a lot smaller chance to screw things up. Dialog is a hell of a lot easier than scripting (even more so, considering they can just copy-pasta my original dialog).

 

Your post did make things more clear to me. I think I'm going to implement the same kind of system BreakUndies uses (Variables from ini -> Queststage setting -> Quest runs script with OBSE). Would that work?

 

Thanks for your help,

 

Hitman69

 

EDIT: I figured it out. Turns out that the problem wasn't inside the ini, but the location of the ini. :facepalm:

While I made the game look for "ini\AllowedRaces.ini", I should have made the game look for "Data\ini\AllowedRaces.ini"

 

I also turned out to have put a +1 where I should have put a -1 :whistling: (for debugging purposes only, shouldn't have effect on the thing itself)

Edited by Hitman69
Link to comment
Share on other sites

  • Recently Browsing   0 members

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