Jump to content

[Fixed in v2] XP-matching script update


Recommended Posts

Alrighty - Level 1 NPCs XP extended scripts v002


* Installation


* Removal

You could just do this: Make a .txt file, copy paste the code at this message to it, make an "xpextender" folder and put the .baf files and the .txt file there, and then rename the .txt file as setup-xpextender.tp2, get the weidu.exe, and rename it as the setup-xpextender.exe ... and then run the .exe, it handles the install and uninstall neat and nice.

BACKUP ~xpextender/backup~
AUTHOR ~Grozzle @ http://forums.gibberlings3.net/index.php?s=a53dceb166b1b7b09ae66b9f0d8efd56&showtopic=26507~ 
//README ~xpextender/Readme.txt~

BEGIN ~XP Scripting~
COMPILE ~xpextender/fjxpmooc-aiscript.baf~
COPY_EXISTING ~fjxpmooc-aiscript.bcs~ ~scripts/xpscript.bs~

BEGIN ~XP Scripting~
SUBCOMPONENT ~Basic+floor for Jaheira and Khalid~
COMPILE ~xpextender/l1xpsyn.baf~
COPY_EXISTING ~l1xpsync.bcs~ ~scripts/xpscript.bs~

BEGIN BEGIN ~XP Scripting~
SUBCOMPONENT ~Dualclass support, warning this could be longer~
COMPILE ~xpextender/xpconfig.baf~
COPY_EXISTING ~xpconfig.bcs~ ~scripts/xpscript.bs~

And when the player has made their choice in the install, they just need to set the "xpscript" in game in the character customization.

PS, I have not actually tested the output, but it's likely at least very near the correct code.

Link to comment

Thanks for the pointer.

WeiDU packaging (and learning WeiDu in general) was on the to do list for when I was more sure the scripts would be useful to someone else.

Looks simple enough though. I'll have a go. Compared to the time getting the dual class script going learning some moderate WeiDu is probably trivial.



Alright, WeiDU install TP2 was a little intimidating, but I now have a working WeiDU version.

Thanks again to Jarno for the nudge - having it WeiDU feels much cleaner, even for testing.


I've bumped up to 2.1 (to denote WeiDU, a trivial addition of a new flavour of the script and updated readme).


It's called "level1npcs_xp" for now, and v2.1 can be found here


I did have some difficulty persuading it to install via setup-level1npcs_xp.exe under wine (before manually replacing the version of the exe - it seemed to be dying on the automatic version check).

Please let me know if you have issues getting it to run on Windows.

Linux folks can do a "weinstall level1npcs_xp", it's already lower case friendly.




Install Component [Level1NPCs XP matching script replacement]?
[N]o, [Q]uit or choose one:
1] Basic XP matching only (Fast)
2] Basic XP matching with minimum XP for Khalid and Jaheira (Slower)
3] Dual Class XP matching script (Slow)
NOTE: Requires Party AI enabled
4] Dual Class XP matching script with minimum XP for Khalid and Jaheira
NOTE: Requires Party AI enabled


Combined into one version of the Readme for display at install time:



Level1NPC mod Experience script replacement v2.1
These BG2 scripts replace the stock Level1NPCs experience scripts.

Instead of adding/subtracting XP in increments they attempt to wipe the NPC XP down to close to zero and than add matching XP from the PC in one lump.

* Components
The Level1NPCs XP matching script can be replaced by one of the following:

1) Basic XP matching only (Fast)
2) Basic XP matching with minimum XP for Khalid and Jaheira (Slower)
3) Dual Class XP matching script (Slow)
NOTE: Requires Party AI enabled
4) Dual Class XP matching script with minimum XP for Khalid and Jaheira
NOTE: Requires Party AI enabled

The "Basic XP matching only" is a very fast script that matches only the XP values of the PC and NPC. If either (or both) are dual classed the experience of the original class is not taken into account. This is similar to the behaviour of the original Level1NPCs XP script.

The "Basic XP matching with minimum XP for Khalid and Jaheira" is similar to the Basic XP script, but also ensures that Khalid and Jaheira have at least 2500XP if single classed or 4000XP if multi-class. This allows them to pretend to be hardened adventurers when met at the beginning of Baldur's Gate.

The "Dual Class XP matching script" versions of the script also attempt to adjust XP values to account for characters being dual classed.
As the IE script engine does not make the dual class status of a character available the script will try to store the original class of the PC/NPC and only treat characters as dual classed if a change from single to dual inactive/multi-class is detected. An "XPCONFIG" party AI script is provided to manually set the Dual Class status of characters if they are not automatically detected when dual classed.

* Installation
Must be installed after Level1NPCs

* Manually flagging a character as Dual Class
The xpconfig.bs player AI script can be used to troubleshoot the dual class flags used by the XP script.

D and C can be used to set the dual class status and original class flags used by the script.
S can be used to trigger the XP matching script run.

When finished using xpconfig on the character set the AI script back to the original value (to avoid accidentally using the xpconfig functions during play).

Function: Set dual classed flag
Hotkey: D
0) Not dual classed
1) Dual class (original class inactive)
2) Dual class (original class reactivated)
Note: Clearing dual class flag (0) will remove any original class history. This may be reset using the C hotkey.

Function: Set original class flag
Hotkey: C
0) Clear class history
1) Cleric
2) Druid
3) Fighter
4) Mage
5) Ranger
6) Thief

Function: Match NPC XP to PC (Synchronize)
Hotkey: S
Note: This triggers the same XP script used on joining the party. Party AI must be enabled.

* Issues, fixes and workarounds

Issue: Dual Class (N)PC treated as multi-class
Cause: Infinity Engine script doesn't allow direct detection of dual class status. To avoid weird results the script treats dual class characters as single class unless it was detected as single class by an earlier script run.
Workaround: Manually tag the character as dual class using the xpconfig AP script. For standard dual class characters it's only necessary to set the D flag to 1 or 2 - the appropriate values will be automatically detected on the next sych with the character.

Issue: Dual class XP does not take into account non-standard XP tables (eg. Druids using the Cleric XP table)
Workaround: Modify script lines for the approriate class with the desired values and recompile/install
Fix: Potentially read .2da files and modify script at install. (??)

Issue: Characters with non-standard dual classes are not automatically detected
Workaround: Set the appropriate Dual status and Class flags using the xpconfig AI script.

Issue: XPConfig AI script has awful +/- XP feedback
Fix: Rewrite script making use of WeiDU dialogue (with menu selection instead of hotkeys).



Link to comment
And when the player has made their choice in the install, they just need to set the "xpscript" in game in the character customization.


Ah, those fjxpmooc-aiscript.baf weren't AI script themselves, but versions that offloaded the XP processing to an AI script.


In the basic versions fjxpmooc.baf do the processing themselves (a spell on an invisible creature acting on the NPC?). In the dual class versions the XP processing is removed and they are only changing the AREA AI script on the NPC. There's no need to change the NPC customizable AI script unless they need to be flagged as dual class using the XPCONFIG utility script.


I needed the XP modification script running on the NPC as I couldn't think of a timely way to have their historical class data persist without a mess of per NPC code pushing the data into GLOBAL scope otherwise.

Link to comment

Level1NPCs XP script replacements - Version 2.2

Download version 2.2 from here


Changes: Added text description and feedback to XPCONFIG player AI script.

Cleaned up duplication of components in WeiDU package.


I had a look at dialogues this afternoon and figure that I won't be working out how to do an invisible creature dialogue for the config AI script any time soon (and am wondering if the appropriate tools are even available on Linux). On the happier side I did work out how to add dialog to the XPCONFIG script.


XPConfig now has a description (including summary of hotkeys) and returns useful messages when using the functions.

I'm content with the whole package for now, so I'm going to try and devote a little more time to exploring Ust Natha.


So - if you're inclined - Test away! Remember to backup before adding party members or using the AI script (just in case of DOOM!)


EDIT: I actually meant Save, not backup.


All bug (or other) reports gladly accepted.

Link to comment

Thanks for all the work you are putting into this.


Cheers Sergio. Let me know how it works for you.


To be honest I'd thought that I'd be doing a much more lazy job of it when I started :)


Anyway - onto Version 2.3 (also known as "This is the last one, and this time I mean it!")

Download from here


20140730: v2.3

Cleaned up packaging using REPLACE_TEXTUALLY instead of seperate dualclass version .baf files

Adding in Start/End notifications for sync

Adding "Humans NEVER multi-class" hotkey (F) in XPCONFIG

Set XPCONFIG Sync (S) function to sync the whole party if the PC is selected

Changed notification messages to be in []


WIth the "Humans are NEVER multiclass" option it's now trivially easy to get the XP matching applied to existing games as long as the game uses the standard rules for dual/multiclass races. It's now just a matter of loading the XPCONFIG script on the PC and pressing F and S - whereas before it was a matter of going to each dual class character (starting with the PC) and tagging them as dual class... then triggering a sync.

It's really just a configurable return to the v1 behaviour (which is fine if you don't have human multi-class NPCs).


I've added in messages at the start and end of the XP matching. I think it's probably overkill, but seeing as the XP matching can take up to 12 seconds in worst case it might cause confusion if it doesn't say anything. The start notice also mentions the AI requirement, so hopefully that'll remind players who've turned it off.


Note that the whole party sync (XPCONFIG script, S hotkey, done by the PC) is simply a trigger for all NPCs to sync their XP.

On my Linux box the game just freezes for ten seconds when I trigger it - so I've no idea what will happen on the historic Windows XP/2000 computers that might still be running BG2.


Bug reports, praise, (moderate) abuse, general thoughts and suggestions welcome.


P.S. I've added a build folder with the perl script I use to generate the l1xpsync.baf script, along with the data files it uses to build it.

It's probably a lot easier to see what's going on from it than from the 1800 IF statements in the .BAF file.

I've also finally gotten around to adding licensing guff (GPLv3) so that it's clear that the code can be reused/adopted as necessary.

Link to comment

Version 2.3.3

Download from here


Some minor performance improvements and cleanup (Licensing match up with L1NPCs, slow XP difference version, dual class XP speedup).




Dual class code speed up

I reordered and removed breaks based on what the calculations required instead of what "made sense". This saves a second (or two) on dual class calculatons :)


Dual class code fairer on dual classed NPCs

Minor improvement to how final XP is calculated to make dual class total modifications round to the neared band instead of down. This should prevent NPCs being unfairly forced 5% lower because they have a trivial chunk of dual class XP.


Basic version slowed down

I've redone the basic version based on the basic+floor version to add the sanity checks and a one second wait back in. It now takes a second to run, but I'm not left wondering if somehow the XP will be added/removed in the wrong order.


XP match finished messages removed

The dual class script will now always do something the player can see (even if it's only adding 0 XP), so I've removed the finished matching message which was there mainly to give some idea if the script had died/not run.


Single XP lump variant

I had some ideas about applying a difference in XP but was party stopped by the lack of a AddLocals() IE script command :(

The experimental workaround version (which I knocked up to satisfy morbid curiousity) is included.

It's painfully slow (even by the standards of the other dual class scripts), but maybe someone really, really, needs to have their NPC experience applied in one step and doesn't mind their game feezing for several seconds every time it happens...


Dual licensed with CC3

I finally thought to look to see what L1NPCs is licensed as and added in permission for my code to be integrated into L1NPCs (if desired) using Creative Commons 3.


Added generator scripts for basic, basicfloor and dualdiff variants

The build/ directory now contains the perl scripts used to generate all variants of the XP script.




EDIT 20140806: v2.4 is in the works, loading dual class XP tables from xplevel.2da. I think I have it going nicely, but I'll do a reinstall with the level cap reinstated over the next few days to confirm it's working.

Link to comment

Version 2.4.1 - Custom XP Table support (from xplevel.2da)

Download from here


Custom XP table support! (If you'd asked me a week ago, I would have said it was probably never going to happen :) )


So, it's definitely finished now, unless someone finds a bug.


I'm off to do a bit of armour customisation with Full Plate and Packing Steel!


Change log:



20140803: v2.3.4
Added some Wait(#)s to the whole party sync to give illusion of order. This also gives time for the PC dual class variables to be set by Player2 before Player3-5 start to sync.
20140806: v2.4
Experimental reading XP table for standard classes from xplevel.2da
20140807: v2.4.1
Rebuilt Difference version to use xplevel.2da
Cleaned up installer using INCLUDE for common installation steps of dual class versions
Fixed loop bug in (!!) sanity check code for PC that would stop it exiting properly


Link to comment

1- how do I use that archive you uploaded? Do I just unrar it into the level1 npc already extracted in another folder?

2- Can I still tweak npcs attributes? ;)

1. You download the archive, you extract it to the game folder, and you run the setup-level1npcs_xp.exe in the game folder and answer all the questions asked... so you manually install the mod, then you start the game, go to the characters stat screen and push the Customize, you select the script the mod installs and then wait it to take action. The script screen has a description for the actions it has, so presumably you can read it.

2. Dah, yeah. But you need other tools to do that. Like the primary Level 1 NPCs mod.

Link to comment

Hmmm - things that should go in the Readme :)


The XPCONFIG AI script is only needed if your game isn't picking up that a character isn't dual classed (usually if they were already dual classed when they joined the party and the script first ran).

For new games (using standard classes) the script should pick up any characters you change to dual class.


* Installation order
Must be installed after Level One NPCs.

This (and other WeiDU based installers, such as Level1NPCs) should be installed after non-WeiDU mods that replace BG2 files.


* Installation

0. Download the Level1NPCs_XP zip
1. Virus scan the Level1NPCs_XP zip
2. Unzip the Level1NPCs_XP zip into the Baldur's Gate 2 installation location
3a. Windows: run setup-level1npcs_xp.exe (ie. <your bg2 path>\setup-level1npcs_xp.exe
3b Linux: Install weidu for linux (from weidu.org)
cd <bg2 folder>
weinstall level1npcs_xp
3c OS X: ? ? ? ?


Q: Do I need to start a new game to use the replacement scripts
A: No, but if you use it in an ongoing game you'll need to tell the scripts which characters are already dual classed (using the XPCONFIG AI script hotkey D) or tell the script that you're using standard rules for dual class characters (hotkey F)

Link to comment

Thanks for giving it a go. As far as I know you're at least half the test group. :)

Let me know if any of the readme is nonsense, bugs, performance etc.


EDIT: I just did an unzip/reinstall to test a couple of truly minor changes, so just to prove it's not scary:



First, unpack the zip into your BG2 install directory:

desktop@steamos:~/BG2_C/gog/bg2$ unzip ../linux_patches/level1npcs_xp.v2.4.2.zip
Archive:  ../linux_patches/level1npcs_xp.v2.4.2.zip
  inflating: setup-level1npcs_xp.exe  
   creating: level1npcs_xp/
   creating: level1npcs_xp/basic/
  inflating: level1npcs_xp/basicfloor/fjxpmooc.baf  
  inflating: level1npcs_xp/changelog.txt~  
  inflating: level1npcs_xp/setup-level1npcs_xp.tp2~

Then start the installer

(weinstall on linux, or just setup-level1npcs_xp.exe in Windows)

desktop@steamos:~/BG2_C/gog/bg2$ weinstall level1npcs_xp
weidu --log setup-level1npcs_xp.debug  level1npcs_xp.tp2 setup-level1npcs_xp.tp2 level1npcs_xp/level1npcs_xp.tp2 level1npcs_xp/setup-level1npcs_xp.tp2
[weidu] WeiDU version 23600
Using Language [English (it tastes like tea and crumpets)]

Would you like to display the readme? [Y]es [N]o

Install Component [Level1NPCs XP matching script replacement]?
[N]o, [Q]uit or choose one:
 1] Basic XP matching only (Fast)
 2] Basic XP matching with minimum XP for Khalid and Jaheira (Slower)
 3] Dual Class matching script (Slower)
    NOTE: Requires Party AI enabled.
 4] Dual Class matching script with minimum XP for K+J (Slower)
    NOTE: Requires Party AI enabled. RECOMMENDED
 5] Dual class, difference calculator version (Very slow)
    NOTE: Requires Party AI enabled. Experimental. DO NOT USE 

Installing [Dual Class matching script with minimum XP for K+J (Slower)
    NOTE: Requires Party AI enabled. RECOMMENDED] [v2.4.2]

SUCCESSFULLY INSTALLED      Dual Class matching script with minimum XP for K+J (Slower)
    NOTE: Requires Party AI enabled. RECOMMENDED

Press ENTER to exit.


Interesting CODE colour highlighting...



Link to comment

Do you wish me to try something in particular? A dual-class in particular? Uncommon kits (like Barbarian that are dualclassed to mage)?

I could give it a go and start experimenting for half an hour in a free-from-mod environment. But I need a few days before starting to play again ;)

Link to comment

If you're running Windows just confirmation that it installs would be nice.

Apart from that, let me know how long the in game clock freezes up for when the script runs (either having an NPC join or manually triggering with XPCONFIG).


I've mainly been playing with a Dual Class PC, but the same dual class script is used on the NPCs, so I'm reasonably confident it works properly for multi/single class PCs/NPCs. If you're keen try out some combinations and check it's working as expected.

Otherwise, just play as normal and if anything unexpected/weird pops up let me know and hang onto a save game from before and after so I can pester you to check varaibles. with Shadowkeeper.


Over the course of a run through of BGT the script will probably run 15-30 times, depending on if you have Level1NPCs set to run it when rejoining or only on joining.

Link to comment


This topic is now archived and is closed to further replies.

  • Create New...