In two of my previous modules I had variations of a spellhook script (the original version of this script was made by Aqvilinus) and I wanted to implement this into the module I’m working on now. It’s a mainly a placeable (actually there’s a few of them) that is supposed to be affected (destroyed) when one of the companions (or the PC if he happens to be a wizard or sorcerer) uses Dispel Magic. All this works…BUT when testing I found a “bug” I really don’t like, and I gather this could irritate players. If you cast Dispel Magic with the companion, but just as you do this you press pause and go back to your main PC to control him, the spell won’t affect the placeable (or placeables as a matter of fact). Could I prevent this in some way in the code perhaps? Otherwise I think I’ll have to write in the journal and instruct the player how to handle this.
Here’s the spellhook script now…(Under Variables in Module Properties I have X2_S_UD_SPELLSCRIPT with ValueString my_spellhook):
//my_spellhook
//
//based on a script by Aqvilinus.
#include "x2_inc_switches"
#include "ginc_object"
void Spawn(string sCreature, string sWaypoint);
void main()
{
int iSpell = GetSpellId();
object oTarget = GetSpellTargetObject();
location lLoc = GetSpellTargetLocation();
float fRadius;
string sName;
//object oPC = GetFirstPC();
if (iSpell == SPELL_DISPEL_MAGIC)
{
fRadius = RADIUS_SIZE_LARGE;
}
else return;
sName = GetStringByStrRef(StringToInt(Get2DAString("Spells", "Name", iSpell)));
oTarget = GetFirstObjectInShape(SHAPE_SPHERE, fRadius, lLoc, FALSE, OBJECT_TYPE_PLACEABLE);
while (GetIsObjectValid(oTarget))
{
if (GetTag(oTarget)== "crystalprison")
{
FloatingTextStringOnCreature(sName + " hits the crystal", OBJECT_SELF,FALSE);
SetLocalInt(oTarget, IntToString(iSpell) + "_triggered", TRUE);
if (GetLocalInt(oTarget, IntToString(SPELL_DISPEL_MAGIC) + "_triggered"))
{
object oFence = GetObjectByTag("l_fence");
AssignCommand(oFence,SetIsDestroyable(TRUE,FALSE,FALSE));
object oFence2 = GetObjectByTag("l_fence2");
AssignCommand(oFence2,SetIsDestroyable(TRUE,FALSE,FALSE));
object oFence3 = GetObjectByTag("l_fence3");
AssignCommand(oFence3,SetIsDestroyable(TRUE,FALSE,FALSE));
object oFence4 = GetObjectByTag("l_fence4");
AssignCommand(oFence4,SetIsDestroyable(TRUE,FALSE,FALSE));
object oBarrier1 = GetObjectByTag("eff1");
AssignCommand(oBarrier1,SetIsDestroyable(TRUE,FALSE,FALSE));
object oBarrier2 = GetObjectByTag("eff2");
AssignCommand(oBarrier2,SetIsDestroyable(TRUE,FALSE,FALSE));
object oBarrier3 = GetObjectByTag("eff3");
AssignCommand(oBarrier3,SetIsDestroyable(TRUE,FALSE,FALSE));
object oBarrier4 = GetObjectByTag("eff4");
AssignCommand(oBarrier4,SetIsDestroyable(TRUE,FALSE,FALSE));
object oRay = GetObjectByTag("fx_jungle_rayproj_12");
AssignCommand(oRay,SetIsDestroyable(TRUE,FALSE,FALSE));
object oAcid = GetObjectByTag("acidb");
AssignCommand(oRay,SetIsDestroyable(TRUE,FALSE,FALSE));
DestroyObject(oTarget,0.2);
DestroyObject(oFence,0.3);
DestroyObject(oFence2,0.4);
DestroyObject(oFence3,0.5);
DestroyObject(oFence4,0.6);
DestroyObject(oBarrier1,0.7);
DestroyObject(oBarrier2,0.8);
DestroyObject(oBarrier3,0.9);
DestroyObject(oBarrier4,0.95);
DestroyObject(oRay,1.0);
DestroyObject(oAcid,1.1);
DelayCommand(1.2,Spawn("l_flsword","animswordwp"));
DelayCommand(1.2,Spawn("l_flsword","animswordwp2"));
}
return;
}
oTarget = GetNextObjectInShape(SHAPE_SPHERE, fRadius, lLoc, FALSE, OBJECT_TYPE_PLACEABLE);
}
}
void Spawn(string sCreature, string sWaypoint)
{
object oCreature = SpawnCreatureAtWP(sCreature,sWaypoint);
}