UW2_PRC8/_module/nss/rodfastcast.nss
Jaysyn904 2bb2c470e0 Updated to PRC8
Updated to PRC8.  Further function integration.  Fixed NPC onDeath script.   Full compile.  Updated release archive.
2024-02-20 22:24:11 -05:00

149 lines
4.8 KiB
Plaintext

//::///////////////////////////////////////////////
//::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"
#include "prc_inc_spells"
//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";
void main()
{
int nEvent = GetUserDefinedItemEventNumber();
object oPC; //The caster
object oItem; //This item
object oTarget;
int SS;
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();
//get number of spells stored
nNumOfSpells = GetLocalInt(oItem, ksNumSpells);
//Make sure they are targeting a legal creature!
if(oTarget != oPC)
{
//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));
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));
}
}
}
else
{
SendMessageToPC(oPC, "You cannot target yourself!");
}
} //This Event Handles storing the spells
else if (nEvent == X2_ITEM_EVENT_SPELLCAST_AT)
{
oItem = PRCGetSpellTargetObject();
nSpellId = PRCGetSpellId();
oPC = OBJECT_SELF;
//This tells us what position to store the spell on
nNumOfSpells = GetLocalInt(oItem, ksNumSpells) + 1;
//Increment how many spells have been cast on the rod..
SS = GetLocalInt(oItem, "SS") + 1;
//If they are attempting to store more than 5 erase all!
if(SS>=6)
{
SendMessageToPC(oPC, "You can only charge the rod with 5 spells, all spells have been cleared.");
//Delete the spells stored on the rod..
DeleteLocalInt(oItem, "CastSpells1");
DeleteLocalInt(oItem, "CastSpells2");
DeleteLocalInt(oItem, "CastSpells3");
DeleteLocalInt(oItem, "CastSpells4");
DeleteLocalInt(oItem, "CastSpells5");
//Remove the stored spell count..
SetLocalInt(oItem, ksNumSpells, 0);
//Removed the Stored Spell Count from the item..
SetLocalInt(oItem, "SS", 0);
return;
}
//Spell Storing...
SetLocalInt(oItem, ksNumSpells , nNumOfSpells);
SetLocalInt(oItem, ksCastSpellId + IntToString(nNumOfSpells), nSpellId);
//Store how many spells are stored on the Rod
SetLocalInt(oItem, "SS", SS);
strSpellName = (knShowSpellName)
? Get2DAString("spells", "Label", nSpellId)
: IntToString(nSpellId);
//Store the Spell Name at the proper position on the rod..
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);
}