Here's the merged code. I used the GetIsNonHostileSpell to limit the timestamping - no idea how well it'll work, since it's in an include I don't have.
I'll let Baaleos add the ActionCast if he wanst - it's a little more involved than he's making out. You'd have to allow cheat casting to save the spell use, which comes with its own set of issues. My normal recommendation would be to simply return the spell use to the player before aborting the spell, but that'd require NWNX.
The modload code works fine. I'm guessing you only put the function in, and never the actual function call to start the delaycommand sequence.
#include "x2_inc_switches"
#include "nw_i0_spells"
#include "check_host_spell"
const int SECONDS_BETWEEN_SPELLS = 9;
void main()
{
int nSpell=GetSpellId();
int nNonHostile = GetIsNonHostileSpell(nSpell);
int nNonHostileItem;
int nCastLevel = GetCasterLevel(OBJECT_SELF);
int zInt;
object sTarget = GetSpellTargetObject();
object sItem = GetSpellCastItem();
object oArea = GetArea(oCaster);
int nJail = GetLocalInt(oArea, "JAIL");
int nPVP = GetLocalInt(oArea, "PVP");
location sLocation = GetSpellTargetLocation();
int sclass = GetLastSpellCastclass();
string sTN = GetTag(sItem);
int nType;
int a;
//Manual override...
if(GetLocalInt(oCaster, "OVERRIDE_SPELL")==1) {
//Stop them cold!
AssignCommand(oCaster, ClearAllActions());
//Though the player may show animation, nothing happens!
SetModuleOverrideSpellScriptFinished();
FloatingTextStringOnCreature("That item is too powerful for you to use!", oCaster, FALSE);
return;
}
if(!GetIsPC(OBJECT_SELF) || GetIsDM(OBJECT_SELF) || GetIsDMPossessed(OBJECT_SELF))
return; //Stop the script here..
if (!nNonHostile) {
int nTime = GetLocalInt(OBJECT_SELF, "LastCastTime");
int nUptime = GetLocalInt(GetModule(), "Uptime");
if (nTime) {
/* because LastCastTime was set, they've cast a spell, and we need to check how long ago that was */
int nDiff = nUptime-nTime;
if (nDiff < SECONDS_BETWEEN_SPELLS) {
DelayCommand(IntToFloat(nDiff),ActionCastSpellAtLocation(nSpellID, lSpell, METAMAGIC_ANY, TRUE));
SetModuleOverrideSpellScriptFinished();
SendMessageToPC(OBJECT_SELF, "Spells must be cast at least " +
IntToString(SECONDS_BETWEEN_SPELLS) + " seconds apart. Wait " +
IntToString(SECONDS_BETWEEN_SPELLS-nDiff) + "more seconds.");
} else
SetLocalInt(OBJECT_SELF, "LastCastTime", nUptime);
} else
SetLocalInt(OBJECT_SELF, "LastCastTime", nUptime);
}
//Handle Jail...
//NOTHING WORK IN JAIL!!!
if(nJail==1) {
//If it's an item!
if(sItem!=OBJECT_INVALID) {
AssignCommand(oCaster, ClearAllActions());
//Though the player may show animation, nothing happens!
SetModuleOverrideSpellScriptFinished();
return;
}
//Otherwise stop the spell COLD!
else {
AssignCommand(oCaster, ClearAllActions());
//Though the player may show animation, nothing happens!
SetModuleOverrideSpellScriptFinished();
return;
}
}
//////////////////No Spells Allowed In Area///////////////////////////////////
//If the PC is in a no casting area, no spell will be cast (even from items!)
//To set up see the above outline
if(GetLocalInt(GetArea(OBJECT_SELF), "NOCAST")==2) {
a = 0;
//If the spell is NOT Hostile then don't stop the spell!
//Note this code allows the rest of the spell hook to run on the
//non-hostile spell being cast (in town!)
if(nNonHostile!=1) {
a = 1;
}
if(a==1) {
//If using a special power or spell from an item...
//If it's not the listed special item..
//& it is in fact a valid object!
if(sItem!=OBJECT_INVALID &&
sTN != "ammo_maker" &&
sTN != "namingtool" && sTN != "colorwand") {
nType = GetBaseItemType(GetSpellCastItem());
if(nType != BASE_ITEM_POTIONS &&
nType != BASE_ITEM_ENCHANTED_POTION) {
AssignCommand(oCaster, ClearAllActions());
//Though the player may show animation, nothing happens!
SetModuleOverrideSpellScriptFinished();
FloatingTextStringOnCreature("All spells fizzle in town.", oCaster);
return;
}
}
//Make them stop what they are doing instantly!
AssignCommand(oCaster, ClearAllActions());
//Though the player may show animation, nothing happens!
SetModuleOverrideSpellScriptFinished();
FloatingTextStringOnCreature("You cannot cast that spell in this area.", oCaster);
return;
}
}
//This is what will happen if the spell was cast from an item..
if(GetSpellCastItem()!=OBJECT_INVALID) {
//If the PC uses an item on a PC, and it's one of the following spells
//Then the spell will not work on the PC, note you can add other effects
//like if you don't like the spell level restriction of a spell on an item
//you could add aditional changes to the spell here to boost power. Or, if you
//don't like some aspect of a spell and don't want players abusing it, you could
//modify the spell here to run your edited version instead. (copy/paste original)
//Don't forget to add SetModuleOverrideSpellScriptFinished(); at the end
//to stop the original script from running.
//NO ITEMS WORK IN JAIL!!!
if(GetLocalInt(GetArea(oCaster), "JAIL")==1) {
AssignCommand(oCaster, ClearAllActions());
//Though the player may show animation, nothing happens!
SetModuleOverrideSpellScriptFinished();
return;
}
////////////////////////////////////////////////////////////////////////////
//Main Script for handling spells
if(GetIsPC(sTarget)) {
switch (nSpell) {
case SPELL_EPIC_RUIN:
case SPELL_HARM:
case SPELL_DROWN:
if(GetIsPC(sTarget)) {
//Don't Cast the original spell
AssignCommand(oCaster, ClearAllActions());
SetModuleOverrideSpellScriptFinished();
}
break;
}
}
} //End if statment for items
///////////Modifications For All Individual Spells////////////////////////
switch(nSpell) {
case SPELL_ETHEREALNESS:
case SPELL_SANCTUARY:
if(nPVP>0) {
SetModuleOverrideSpellScriptFinished();
FloatingTextStringOnCreature("Sanctuary is an illegal spell in PVP Areas.", oCaster);
}
break;
case SPELL_TIME_STOP:
if(nPVP>=1) {
FloatingTextStringOnCreature("Timestop is not allowed in PVP Areas.", OBJECT_SELF, TRUE);
SetModuleOverrideSpellScriptFinished();
}
break;
}
}