OnModuleLoad and OnModuleStart events

What’s the difference beetwen those two events? I can’t find the answer anywhere. Am I correct that the OnModuleLoad event is fired every time the module is loaded, unlike the OnModuleStart event that is fired only once when starting this module for the first time?

I’m trying to teach AI from Tony_K’s mod to use custom classes, spells and feats from Kaedrin’s PrC Pack.

Modifications and additions to the AI for spells, classes, and racial information can be done by calling functions from the hench_i0_custom script on module startup. In order to make this easier, functions that initialize all of the spells, classes, and racial sub types supported by the AI are provided in HenchSpellDef.nss, HenchClassDef.nss, and HenchRacialDef.nss which are provided as separate files in the hak and erf releases.

What is best suited for the definition of “on module startup” in this context? Can I use the OnPCLoaded event for this purpose?

I can’t comment about Tony_K’s stuff.

OnModuleStart provides a brand new copy of the module (the file stored in the modules subfolder), all previous in game modifications are zeroed. Anything set in the module by the builder will load though. So a script attached to OnPCLoaded should fire.

OnModuleLoad loads a copy of the module then applies the in game modifications stored in the save folder, if the player restarts the game from a save. It does it from the current cache (…\AppData\Local\Temp\NWN2\CURRENTCAMPAIGN or CURRENTGAME) during a play session.

OnModuleLoad acts as OnModuleStart the first time the module is loaded.

1 Like

it’s possible that custom definitions in Tony’s might be stored on the module object … so loading them might be needed only once per module (perhaps)

I think that’d be OnModuleStart …

either way, the way to query/trace those scripts during runtime is to enable logging* and use PrintString() instead of SendMessageToPC()

*but don’t enable LogRunScript - just use PrintString(“filename”) instead (else the logfile gets swamped).

and … the log gets wiped each time the game loads from desktop. So, uh, have it open in notepad++, do something IG, then refresh the file in notepad++ (warning: nwn2 might fail to load from desktop if the logfile is already open - suggest: get to the nwn2 start screen, then load the logfile in notepad++, etc)

1 Like

Yes, they are stored on the module object. This is how it looks like:

void HenchSetSpellEntry(int nSpellID, int iSpellInfo, int iTargetInfo, int nDamageInfo, int nSaveDC,
	int nEffectTypes, int nSaveType, float fEffectWeight)
	iSpellInfo += HenchGetSpellVersion();

	string sSpellInfoStr = HENCH_SPELL_ID_INFO + IntToString(nSpellID);

	SetLocalInt(GetModule(), sSpellInfoStr, iSpellInfo);
	SetLocalInt(GetModule(), sSpellInfoStr + HENCH_SPELL_TARGET_COLUMN_NAME, iTargetInfo);
	SetLocalFloat(GetModule(), sSpellInfoStr + HENCH_SPELL_EFFECT_WEIGHT_COLUMN_NAME, fEffectWeight);
	SetLocalInt(GetModule(), sSpellInfoStr + HENCH_SPELL_EFFECT_TYPES_COLUMN_NAME, nEffectTypes);
	SetLocalInt(GetModule(), sSpellInfoStr + HENCH_SPELL_DAMAGE_INFO_COLUMN_NAME, nDamageInfo);
	SetLocalInt(GetModule(), sSpellInfoStr + HENCH_SPELL_SAVE_TYPE_COLUMN_NAME, nSaveType);
	SetLocalInt(GetModule(), sSpellInfoStr + HENCH_SPELL_SAVE_DC_TYPE_COLUMN_NAME, nSaveDC);

I’ll try to tinker around with what you said, thanks for the advice. Tony_K already provided some entries for Kaedrin’s spells (although they’re for the old version, but anyway), so I don’t think it will be that hard to add the rest. There’s also a wonderful tool made by Pain that much simplifies the process (set first all the entries in GUI and then move them to the script). I could add these entries directly to the corresponding 2da, using that tool, but it cannot format henchclasses.2da and henchracial.2da, and I prefer to keep all these custom entries in one place.

Hmm, I just looked at the amount of data I’d have to add manually via the script… and I changed my mind :slight_smile: I’ll use Pain’s tool for the spells, and Tony_K’s custom functions for the rest (classes, races).

I’m wondering how to tell AI about custom active feats… Is there any internal mechanism for this?

i was going to point out that HenchSpells.2da is (should be) an alternate way of storing such spelldata as HenchSetSpellEntry() etc. [The function call likely overwrites any corresponding entry in the .2da - but i guess you should check that … if you have any SpellId conflicts between the two ]

There’s also things deeper in the core-ai that should be noticed, at least: there are checks to verify efficacy here and there. Examples:

DispatchSpell() in ‘hench_i0_itemsp’ (note that this #include isn’t just for items)
HenchSpellAttack() in ‘hench_i0_attack’
HenchCheckTurnUndead() in ‘hench_i0_attack’ (example of extreme specialization)

i’m thinking that such functions might need to be tweaked (or additional functions written and inserted) here and there, to deal with extra/unexpected spells – hopefully not tho

1 Like

probably, I haven’t look at feats as much as spells (if at all…)

i’d say its really a matter of learning as much as you can about the core AI – trial & error, giving yourself feedback, testing set-piece battles over and over

Thanks for the info. I looked through hench_i0_itemsp and that’s what I was looking for: InitializeFeats(), InitializeSpellCasting(), InitializeWarlockAttackSpells(), etc. Tony_K seems to have already added most of Kaedrin’s spells and feats to those routines.

OT / while you’re in the AI, you might want to fix this (if you haven’t)

rjshae Posted 19 July 2012 - 02:42 PM

1 Like