XP training system

Note
I'm working on a training system so that characters must find a valid trainer to be able to advance in level. So far it basically goes like this:

Set module experience slider to 0 Keep a local variable on the character to count how much experience they've earned since they last leveled (i.e. instead of gaining experience, I just add the amount they should have gained to this variable) The character has an item that will tell them how much experience they've earned. They must find an NPC (or possibly item in cases like clerics praying at shrines to level) that is capable of training their class/level (for example I have a trainer in my starting town that can train fighters, rangers, barbarians up to level 4, anyone else can't train there)

The Script, part 1
//JUST SLIGHT EDITS OF DEFAULT XP SCRIPTS void mGiveXPToCreature(object oPC, int iXP) { int iCurrent = GetLocalInt(oPC, "experience_earned"); SetLocalInt(oPC, "experience_earned", iCurrent + iXP); } void mRewardPartyXP(int XP, object oTarget,int bAllParty=TRUE) {   // * for each party member // * cycle through them and // * and give them the appropriate reward // * HACK FOR NOW if (bAllParty == TRUE) {       object oPartyMember = GetFirstFactionMember(oTarget, TRUE); while (GetIsObjectValid(oPartyMember) == TRUE) {           mGiveXPToCreature(oPartyMember, XP); oPartyMember = GetNextFactionMember(oTarget, TRUE); }   }    else {    mGiveXPToCreature(oTarget, XP); } }

The Script, part 2
Just updates of the xp functions. (this is an include file that is used in several of my other scripts, I call it my_tools)

Then we have the Creature on_Death script.

//:://///////////////////////////////////////////// //:: Default:On Death //:: NW_C2_DEFAULT7 //:: Copyright (c) 2001 Bioware Corp. //::////////////////////////////////////////////// /*   Shouts to allies that they have been killed //::////////////////////////////////////////////// //:: Created By: Preston Watamaniuk //:: Created On: Oct 25, 2001 //::////////////////////////////////////////////// //#include "NW_I0_TOOL" //USES MY ALTERED XP FUNCTIONS void main {   int nClass = GetLevelByClass(CLASS_TYPE_COMMONER); int nAlign = GetAlignmentGoodEvil(OBJECT_SELF); if(nClass > 0 && (nAlign == ALIGNMENT_GOOD || nAlign == ALIGNMENT_NEUTRAL)) {       object oKiller = GetLastKiller; AdjustAlignment(oKiller, ALIGNMENT_EVIL, 5); }   SpeakString("NW_I_AM_DEAD", TALKVOLUME_SILENT_TALK); //Shout Attack my target, only works with the On Spawn In setup SpeakString("NW_ATTACK_MY_TARGET", TALKVOLUME_SILENT_TALK); if(GetSpawnInCondition(NW_FLAG_DEATH_EVENT)) {       SignalEvent(OBJECT_SELF, EventUserDefined(1007)); } //ABOVE THIS IS JUST THE NWN DEFAULT ON_DEATH //INCREMENTS PC XP VARIABLE BASED ON LVL vs. CR   //give experience based on CR and character HitDice object oPC = GetLastKiller; float iCR = GetChallengeRating(OBJECT_SELF); int iHD = GetHitDice(oPC); int iXP1 = FloatToInt(((iCR/iHD) * 33)); int iXP2 = (iXP1/2); mGiveXPToCreature(oPC, iXP1); mRewardPartyXP(iXP2, oPC, TRUE); }
 * 1) include "NW_I0_GENERIC"
 * 1) include "my_tools"

The Script, part 3
Now for an example of a trainer script...

//CHECKS WHETHER THE PC CAN BE TRAINED HERE int StartingConditional {   object oPC = GetPCSpeaker; int iLevel = GetLevelByClass(CLASS_TYPE_FIGHTER, oPC) + GetLevelByClass(CLASS_TYPE_BARBARIAN, oPC) + GetLevelByClass(CLASS_TYPE_RANGER, oPC); // Restrict based on the player's class int iPassed = 0; if(iLevel >= 1 && GetHitDice(oPC) <= 4) iPassed = 1; return iPassed; }

Checks to see if the character is a warrior class and below level 4.

The Script, part 4
If they are an appropriate level then we charge them and actually give them the experience they earned, then reset their experience_earned varaible.

//GIVES XP EARNED TO PC AND RESETS XP VARIABLE void main {   int iXP; object oPC = GetPCSpeaker; TakeGoldFromCreature(100, oPC, TRUE); iXP = GetLocalInt(oPC, "experience_earned"); GiveXPToCreature(oPC, iXP); SetLocalInt(oPC, "experience_earned", 0); }

The Script, part 5
This is for the Module on_ActivateItem script. It tells the PC how much experience they have earned when they use their Experience Meter (the exp meter is just a misc item that I gave the Unique Power: Self Only Unlimited uses power.)

void main {   object oPC = GetItemActivator; object oItem = GetItemActivated; if (GetTag(oItem) == "ExperienceMeter") { SendMessageToPC(oPC, "You peer intently into the crystal."); SendMessageToPC(oPC, "You have earned " + IntToString(GetLocalInt(oPC, "experience_earned")) + " experience since you last trained."); } }

The Script, part 6
In the Module on_LevelUp script I heal the PC and reset their experience variable to 0.

void main {   object oPC = GetPCLevellingUp; SendMessageToPC(oPC, "You feel stronger from your training."); AssignCommand(oPC, ActionCastSpellAtObject(SPELL_HEAL, oPC, METAMAGIC_ANY, TRUE, 0, PROJECTILE_PATH_TYPE_DEFAULT, TRUE)); SetLocalInt(oPC, "experience_earned", 0); }