Spellbook creator

What it does
Takes a "spellbook" and creates a random amount of spells based on the DM's Guide to spellbooks (for the spell levels, not the distribution) Creates all spells in the game in the wizard/sorcerer except a few that didn't have standard scrolls.

The Script
The first script is the nwn_spellbook script, which should be included in the OnItemActivate script for the module

script one
void openSpellBook(object spellBook, object oUser); string lookupLevel1; string lookupLevel2; string lookupLevel3; string lookupLevel4; string lookupLevel5; string lookupLevel6; string lookupLevel7; string lookupLevel8; string lookupLevel9; void openSpellBook(object spellBook, object oUser) {   string bookTag = GetTag(spellBook); // number of each level to create; int lvl1 = 0; int lvl2 = 0; int lvl3 = 0; int lvl4 = 0; int lvl5 = 0; int lvl6 = 0; int lvl7 = 0; int lvl8 = 0; int lvl9 = 0;

// calculate the number of scrolls in the book int spells; int total = Random(100)+1; if (total <= 40) spells = 1; else if (total <= 63) spells = 2; else if (total <= 77) spells = 3; else if (total <= 85) spells = 4; else if (total <= 91) spells = 5; else if (total <= 95) spells = 6; else if (total <= 98) spells = 7; else if (total <= 100) spells = 8; //generate the spells; int rand; int counter; for (counter = 0; counter < spells; counter++) {       rand = Random(100)+1; // low level if (bookTag == "minor_spellbook") {           if (rand <= 50) lvl1++; else if (rand <= 95) lvl2++; else if (rand <= 100) lvl3++; }       // mid level else if (bookTag == "spellbook") {           if (rand <= 5) lvl2++; else if (rand <= 65) lvl3++; else if (rand <= 95) lvl4++; else if (rand <= 100) lvl5++; }       // high level else if (bookTag == "major_spellbook") {           if (rand <= 5) lvl4++; else if (rand <= 50) lvl5++; else if (rand <= 70) lvl6++; else if (rand <= 85) lvl7++; else if (rand <= 95) lvl8++; else if (rand <= 100) lvl9++; }   } WriteTimestampedLogEntry("Lvls: "+IntToString(lvl1)+" "+IntToString(lvl2)+" "+IntToString(lvl3)+" "+IntToString(lvl4)+" "+IntToString(lvl5)+" "+IntToString(lvl6)+" "+IntToString(lvl7)+" "+IntToString(lvl8)+" "+IntToString(lvl9)); WriteTimestampedLogEntry("Giving spells to: " + GetName(oUser)); // generate the scrolls on the user int i;   for (i = 0; i < lvl1; i++) CreateItemOnObject(lookupLevel1, oUser, 1); for (i = 0; i < lvl2; i++) CreateItemOnObject(lookupLevel2, oUser, 1); for (i = 0; i < lvl3; i++) CreateItemOnObject(lookupLevel3, oUser, 1); for (i = 0; i < lvl4; i++) CreateItemOnObject(lookupLevel4, oUser, 1); for (i = 0; i < lvl5; i++) CreateItemOnObject(lookupLevel5, oUser, 1); for (i = 0; i < lvl6; i++) CreateItemOnObject(lookupLevel6, oUser, 1); for (i = 0; i < lvl7; i++) CreateItemOnObject(lookupLevel7, oUser, 1); for (i = 0; i < lvl8; i++) CreateItemOnObject(lookupLevel8, oUser, 1); for (i = 0; i < lvl9; i++) CreateItemOnObject(lookupLevel9, oUser, 1);

// destroy the book //   SetPlotFlag(spellBook, FALSE); //   DestroyObject(spellBook); } string lookupLevel1 {   int index = Random(13); string out = "nw_it_sparscr"; if (index == 0) out = out+"103"; if (index == 1) out = out+"104"; if (index == 2) out = out+"105"; if (index == 3) out = out+"106"; if (index == 4) out = out+"107"; if (index == 5) out = out+"108"; if (index == 6) out = out+"109"; if (index == 7) out = out+"110"; if (index == 8) out = out+"111"; if (index == 9) out = out+"112"; if (index == 10) out = out+"113"; if (index == 11) out = out+"114"; if (index == 12) out = out+"211"; WriteTimestampedLogEntry(out); return out; } string lookupLevel2 {   int index = Random(18); string out = "nw_it_sparscr"; if (index == 0) out = out+"202"; if (index == 1) out = out+"203"; if (index == 2) out = out+"204"; if (index == 3) out = out+"205"; if (index == 4) out = out+"206"; if (index == 5) out = out+"207"; if (index == 6) out = out+"208"; if (index == 7) out = out+"209"; if (index == 8) out = out+"210"; if (index == 9) out = out+"212"; if (index == 10) out = out+"213"; if (index == 11) out = out+"214"; if (index == 12) out = out+"216"; if (index == 13) out = out+"217"; if (index == 14) out = out+"219"; if (index == 15) out = out+"220"; if (index == 16) out = out+"221"; if (index == 17) out = out+"222"; WriteTimestampedLogEntry(out); return out; } string lookupLevel3 {   int index = Random(17); string out = "nw_it_sparscr"; if (index == 0) out = out+"218"; if (index == 1) out = out+"302"; if (index == 2) out = out+"303"; if (index == 3) out = out+"304"; if (index == 4) out = out+"305"; if (index == 5) out = out+"306"; if (index == 6) out = out+"307"; if (index == 7) out = out+"308"; if (index == 8) out = out+"309"; if (index == 9) out = out+"310"; if (index == 10) out = out+"311"; if (index == 11) out = out+"312"; if (index == 12) out = out+"313"; if (index == 13) out = out+"314"; if (index == 14) out = out+"315"; if (index == 15) out = out+"316"; if (index == 16) out = out+"510"; WriteTimestampedLogEntry(out); return out; } string lookupLevel4 {   int index = Random(17); string out = "nw_it_sparscr"; if (index == 0) out = out+"302"; if (index == 1) out = out+"402"; if (index == 2) out = out+"403"; if (index == 3) out = out+"404"; if (index == 4) out = out+"405"; if (index == 5) out = out+"406"; if (index == 6) out = out+"407"; if (index == 7) out = out+"408"; if (index == 8) out = out+"409"; if (index == 9) out = out+"410"; if (index == 10) out = out+"411"; if (index == 11) out = out+"412"; if (index == 12) out = out+"413"; if (index == 13) out = out+"414"; if (index == 14) out = out+"415"; if (index == 15) out = out+"416"; if (index == 16) out = out+"418"; WriteTimestampedLogEntry(out); return out; } string lookupLevel5 {   int index = Random(13); string out = "nw_it_sparscr"; if (index == 0) out = out+"417"; if (index == 1) out = out+"502"; if (index == 2) out = out+"503"; if (index == 3) out = out+"504"; if (index == 4) out = out+"505"; if (index == 5) out = out+"506"; if (index == 6) out = out+"507"; if (index == 7) out = out+"508"; if (index == 8) out = out+"509"; if (index == 9) out = out+"511"; if (index == 10) out = out+"512"; if (index == 11) out = out+"513"; if (index == 12) out = out+"514"; WriteTimestampedLogEntry(out); return out; } string lookupLevel6 {   int index = Random(14); string out = "nw_it_sparscr"; if (index == 0) out = out+"602"; if (index == 1) out = out+"603"; if (index == 2) out = out+"604"; if (index == 3) out = out+"605"; if (index == 4) out = out+"606"; if (index == 5) out = out+"607"; if (index == 6) out = out+"608"; if (index == 7) out = out+"609"; if (index == 8) out = out+"610"; if (index == 9) out = out+"612"; if (index == 10) out = out+"611"; if (index == 11) out = out+"613"; if (index == 12) out = out+"614"; if (index == 13) out = out+"615"; WriteTimestampedLogEntry(out); return out; } string lookupLevel7 {   int index = Random(8); string out = "nw_it_sparscr"; if (index == 0) out = out+"702"; if (index == 1) out = out+"703"; if (index == 2) out = out+"704"; if (index == 3) out = out+"705"; if (index == 4) out = out+"706"; if (index == 5) out = out+"707"; if (index == 6) out = out+"709"; if (index == 7) out = out+"803"; WriteTimestampedLogEntry(out); return out; } string lookupLevel8 {   int index = Random(8); string out = "nw_it_sparscr"; if (index == 0) out = out+"802"; if (index == 1) out = out+"804"; if (index == 2) out = out+"805"; if (index == 3) out = out+"806"; if (index == 4) out = out+"807"; if (index == 5) out = out+"808"; if (index == 6) out = out+"809"; if (index == 7) out = out+"810"; WriteTimestampedLogEntry(out); return out; } string lookupLevel9 {   int index = Random(12); string out = "nw_it_sparscr"; if (index == 0) out = out+"902"; if (index == 1) out = out+"903"; if (index == 2) out = out+"904"; if (index == 3) out = out+"905"; if (index == 4) out = out+"906"; if (index == 5) out = out+"907"; if (index == 6) out = out+"908"; if (index == 7) out = out+"909"; if (index == 8) out = out+"910"; if (index == 9) out = out+"911"; if (index == 10) out = out+"912"; if (index == 11) out = out+"913"; WriteTimestampedLogEntry(out); return out; }

Script two
The second script is the entry into the OnItemActivate script itself

void main {   object oActivated = GetItemActivated; object oUser = GetItemActivator; string oItem = GetTag(oActivated); if ((oItem == "spellbook") || (oItem == "minor_spellbook") || (oItem == "major_spellbook")) {       openSpellBook(oActivated, oUser); } }
 * 1) include "nwn_spellbook"

footnote
The script was commented, but I lose the edit when I hit the ATI editor issues so I will update it again when I get the will.

Enjoy! I hope someone gets some use out of it. It does add just a small bit to the game, and always puts a smile on my wizard/sorcerer friends when they find one! It is like found money!