Hi, I'm hoping someone here can help me.
I'm using the Rod of Fast Buffing from the NWN Vault in the module Tortured Hearts. I got the item and its script into the game by importing it into a module with the toolset, and then copying the temporary files into the override folder. So I have three files in my override: the nss, ncs, and uti.
Problem is, everything the rod does it does twice. I will paste the NSS file here, but I have a feeling the problem is not the script itself since I haven't seen this problem mentioned anywhere else. Any ideas how to fix this?
Thanks. Here's the script:
Edit: Did a little more testing. In the original campaign the item will not store spells at all. I get invalid target errors. Also, I started a new game in Tortured Hearts and the item fires its script twice just like in my save game.
//::///////////////////////////////////////////////
//::Rod of Fast Buffing Item Event Script
/*
This is the event script for the rod of fast
buffing. This rod allows casters to group
all their buffing spells into a single action
*/
//:://////////////////////////////////////////////
#include "x2_inc_switches"
//showing spell names is a 2da file hit. When storing
//a lot of spells this can cause a significant delay
//When this value is false it will just show spell
//ID numbers.
const int knShowSpellName = TRUE;
//used to store the number of spells on the rod
const string ksNumSpells = "NumSpells";
//used as a base to store a spell ID to cast
const string ksCastSpellId = "CastSpells";
//stores the spell name when you store a spell.
const string ksCastSpellName = "SpellName";
//clears out the spells from the Rod
void ClearRodSpells(object oItem);
//returns true if oTarget is a member of the oPC's party
int GetIsPartyMember(object oPC, object oTarget);
void main()
{
int nEvent = GetUserDefinedItemEventNumber();
object oPC; //The caster
object oItem; //This item
object oTarget; //Target of Rod Use
int nSpellId; //Used to hold the ID of the current spell;
int nNumOfSpells; //Used to hold the current number of spells on the rod
string strSpellName;//Used to hold the Spell Name
int nResult = X2_EXECUTE_SCRIPT_CONTINUE;
//this handles "use" or activation of item.
if (nEvent == X2_ITEM_EVENT_ACTIVATE)
{
oItem = GetItemActivated();
oPC = GetItemActivator();
oTarget = GetItemActivatedTarget();
//Disable use in combat
if(GetIsInCombat(oPC))
{
FloatingTextStringOnCreature("Can't use rod in combat", oPC, FALSE);
return;
}
//check if the rod is targeting itself and clear out spells if it is
if(oItem == oTarget)
{
SendMessageToPC(oPC, "Clearing spells from Rod");
ClearRodSpells(oItem);
return;
}
if(!GetIsObjectValid(oTarget)
|| !GetIsPartyMember(oPC, oTarget))
{
SendMessageToPC(oPC, "The target is invalid");
return;
}
//get number of spells stored
nNumOfSpells = GetLocalInt(oItem, ksNumSpells);
SendMessageToPC(oPC, " Attempting to fast cast " + IntToString(nNumOfSpells) + " spells.");
//iterate through array of spells and store casting action
int n;
for(n = 1; n <= nNumOfSpells; n++)
{
//get spell id stored at location n
nSpellId = GetLocalInt(oItem, ksCastSpellId + IntToString(n));
//Get the name of the spell stored at location n
strSpellName = GetLocalString(oItem, ksCastSpellName + IntToString(n));
SendMessageToPC(oPC, "Casting spell "
+ strSpellName
+ " at postion "
+ IntToString(n)
+ " on item");
if(0 != nSpellId //if there was a valid spell id stored
&& 1 <= GetHasSpell(nSpellId, oPC)) //and the caster has access to the spell
{
//Store cast action. The key here is to set cheatcasting
//to false and level to 0. This will cause the caster
//to cast the spell himself using the first available
//slot.
AssignCommand(oPC,
ActionCastSpellAtObject(nSpellId
, oTarget
, METAMAGIC_ANY
, FALSE
, 0
, PROJECTILE_PATH_TYPE_DEFAULT
, TRUE));
}
}
} //This Event Handles storing the spells
else if (nEvent == X2_ITEM_EVENT_SPELLCAST_AT)
{
oItem = GetSpellTargetObject();
nSpellId = GetSpellId();
oPC = OBJECT_SELF;
nNumOfSpells = GetLocalInt(oItem, ksNumSpells) + 1;
SetLocalInt(oItem, ksNumSpells , nNumOfSpells);
SetLocalInt(oItem, ksCastSpellId + IntToString(nNumOfSpells), nSpellId);
strSpellName = (knShowSpellName)
? Get2DAString("spells", "Label", nSpellId)
: IntToString(nSpellId);
SetLocalString(oItem, ksCastSpellName + IntToString(nNumOfSpells), strSpellName);
SendMessageToPC(oPC, "Storing "
+ strSpellName
+ " at postion "
+ IntToString(nNumOfSpells)
+ " on item");
nResult = X2_EXECUTE_SCRIPT_END;
}
//Pass the return value back to the calling script
SetExecutedScriptReturnValue(nResult);
}
//returns true if oTarget is a member of the oPC's party
int GetIsPartyMember(object oPC, object oTarget)
{
if(oPC == oTarget) return TRUE;
int nPartyMember = FALSE;
object oPartyMember = GetFirstFactionMember(oPC, FALSE);
while(GetIsObjectValid(oPartyMember) == TRUE)
{
if(oPartyMember == oTarget)
{
nPartyMember = TRUE;
break;
}
oPartyMember = GetNextFactionMember(oPC, FALSE);
}
return nPartyMember;
}
//clears out the spells from the Rod
void ClearRodSpells(object oItem)
{
//get number of spells stored
int nNumOfSpells = GetLocalInt(oItem, ksNumSpells);
//iterate through array of spells and delete the local variable
int n;
for(n = 1; n <= nNumOfSpells; n++)
{
//Delete spell id stored at location n
DeleteLocalInt(oItem, ksCastSpellId + IntToString(n));
//Delete the name of the spell stored at location n
DeleteLocalString(oItem, ksCastSpellName + IntToString(n));
}
DeleteLocalInt(oItem, ksNumSpells);
}
Modifié par Weye, 07 février 2014 - 08:38 .