So for the spellhook script.
Spellhook is in nwn scripting almost always meant a script that can run after player cast any spell. To make this script run you need to add a variable with name X2_S_UD_SPELLSCRIPT type of string and value of name of your script ("spell_hook" for example without quotes of course) onto module. (module properties, advances, variables -> ...)
And then you need to create this script and put this inside:
void main()
{
object oCaster = OBJECT_SELF;
object oItem = GetSpellCastItem();
int nSpellId = GetSpellId();
int casterLevel = GetCasterLevel(oCaster);
if(oItem != OBJECT_INVALID && GetBaseItemType(oItem) != BASE_ITEM_POTIONS)
{//spell cast from item
string sInnate;
int nInnate;
int bestLevel, reqLevel;
int nLevel = GetLevelByclass(class_TYPE_BARD,oCaster);
if(nLevel > 0)
{
sInnate = Get2DAString("spells","Bard",nSpellId);
nInnate = StringToInt(sInnate);
if(nInnate == 0 && sInnate == "0" || nInnate > 0)
{
reqLevel = nInnate*2;
if(nLevel >= reqLevel && nLevel > bestLevel)
{
bestLevel = nLevel;
}
}
}
nLevel = GetLevelByclass(class_TYPE_CLERIC,oCaster);
if(nLevel > 0)
{
sInnate = Get2DAString("spells","Cleric",nSpellId);
nInnate = StringToInt(sInnate);
if(nInnate == 0 && sInnate == "0" || nInnate > 0)
{
reqLevel = (nInnate*2)-1;
if(nLevel >= reqLevel && nLevel > bestLevel)
{
bestLevel = nLevel;
}
}
}
nLevel = GetLevelByclass(class_TYPE_DRUID,oCaster);
if(nLevel > 0)
{
sInnate = Get2DAString("spells","Druid",nSpellId);
nInnate = StringToInt(sInnate);
if(nInnate == 0 && sInnate == "0" || nInnate > 0)
{
reqLevel = (nInnate*2)-1;
if(nLevel >= reqLevel && nLevel > bestLevel)
{
bestLevel = nLevel;
}
}
}
nLevel = GetLevelByclass(class_TYPE_PALADIN,oCaster);
if(nLevel > 0)
{
sInnate = Get2DAString("spells","Paladin",nSpellId);
nInnate = StringToInt(sInnate);
if(nInnate == 0 && sInnate == "0" || nInnate > 0)
{
reqLevel = nInnate*3+(nInnate > 1 ? 2 : 1);
if(nLevel >= reqLevel && nLevel > bestLevel)
{
bestLevel = nLevel;
}
}
}
nLevel = GetLevelByclass(class_TYPE_RANGER,oCaster);
if(nLevel > 0)
{
sInnate = Get2DAString("spells","Ranger",nSpellId);
nInnate = StringToInt(sInnate);
if(nInnate == 0 && sInnate == "0" || nInnate > 0)
{
reqLevel = nInnate*3+(nInnate > 1 ? 2 : 1);
if(nLevel >= reqLevel && nLevel > bestLevel)
{
bestLevel = nLevel;
}
}
}
nLevel = GetLevelByclass(class_TYPE_WIZARD,oCaster);
if(nLevel > 0)
{
sInnate = Get2DAString("spells","Wiz_Sorc",nSpellId);
nInnate = StringToInt(sInnate);
if(nInnate == 0 && sInnate == "0" || nInnate > 0)
{
reqLevel = (nInnate*2)-1;
if(nLevel >= reqLevel && nLevel > bestLevel)
{
bestLevel = nLevel;
}
}
}
nLevel = GetLevelByclass(class_TYPE_SORCERER,oCaster);
if(nLevel > 0)
{
sInnate = Get2DAString("spells","Wiz_Sorc",nSpellId);
nInnate = StringToInt(sInnate);
if(nInnate == 0 && sInnate == "0" || nInnate > 0)
{
reqLevel = nInnate*2;
if(nLevel >= reqLevel && nLevel > bestLevel)
{
bestLevel = nLevel;
}
}
}
if(bestLevel > casterLevel)
{
SetLocalInt(oItem,"ITEM_CASTER_LEVEL_OVERRIDE",bestLevel);
SendMessageToPC(oCaster,"DEBUG: caster level overriden: "+IntToString(bestLevel));
}
}
}
I havent tested it much except it works on my character with wizard/fighter classes casting from scroll properly. I added debug message for testing purposes. I have also disabled this feature for normal potions, crafted potions will however probably benefit from this change.
Of course this will work only if you upgrade onto 1.70, lmk if you will have troubles set this script up.
PS. for other scripters feel free to improve my ugly script, I was trying to get this done ASAP and I had not much time to think about it
EDIT: due to the bug in these forums, replace every class_ instance with uppercase class_ otherwise you wont be able to compile it
Modifié par ShaDoOoW, 16 janvier 2012 - 10:42 .