Help with script - spell affecting a door


#41

Ok. I finally got it to work as intended. I actually used my original script (even if your script, Aqvilinus, was more neatly done, I still felt I could better follow what I was doing with my original script) and modified it a bit with your suggestions. Also the i_ltransmutate_ac really did the trick. I actually tried the i_ac script template before posting here on the boards but I didn’t get it to work properly, but I think it was mainly to do with the floating text not working over PCs and NPCs. By the way, I dig your VFX you put in there. :slight_smile: So here is now the i_ltransmutate_ac script:

void main()
{
	object oPC = GetItemActivator();
	object oTarget  = GetItemActivatedTarget();
	effect eVFX = EffectNWN2SpecialEffectFile("sp_transmutation_conjure.sef");

	if (GetObjectType(oTarget) == OBJECT_TYPE_CREATURE && GetTag(oTarget) == "esaspia")
	{
		AssignCommand(oTarget, SpeakString("Transmutate hits the rabbit", TALKVOLUME_TALK));
		ApplyEffectToObject(DURATION_TYPE_INSTANT, eVFX, oTarget);
		SetLocalInt(oTarget, "transmutate_triggered", TRUE);
	}
	
}

and my script (reworked with your suggestions):

#include "x2_inc_switches"

void main()
{
	int       iSpell       = GetSpellId();
	object    oTarget      = GetSpellTargetObject();
	location  lLoc         = GetSpellTargetLocation();
	float     fRadius;
	string    sName;

	object oPC = GetFirstPC();

	if (iSpell == SPELL_SOUND_BURST)
	{
		fRadius = RADIUS_SIZE_MEDIUM;
	}
	else
	if (iSpell == SPELL_DISPEL_MAGIC)
	{
		fRadius = RADIUS_SIZE_LARGE;
	}
	else
	if (iSpell == SPELL_TRUE_SEEING)
	{
		fRadius = RADIUS_SIZE_LARGE;
	}
	
	else
		return;

	sName = GetStringByStrRef(StringToInt(Get2DAString("Spells", "Name", iSpell)));
	oTarget = GetFirstObjectInShape(SHAPE_SPHERE, fRadius, lLoc, FALSE, OBJECT_TYPE_DOOR);
	while (GetIsObjectValid(oTarget))
	{
		if (GetTag(oTarget)== "door_out")
		{
			FloatingTextStringOnCreature(sName + " hits the door", OBJECT_SELF,FALSE);
			SetLocalInt(oTarget, IntToString(iSpell) + "_triggered", TRUE);
			if (GetLocalInt(oTarget, IntToString(SPELL_SOUND_BURST) + "_triggered") &&
				GetLocalInt(oTarget, IntToString(SPELL_DISPEL_MAGIC) + "_triggered"))
			{
				DestroyObject(oTarget, 0.5);
			}
            return;
		}
		oTarget = GetNextObjectInShape(SHAPE_SPHERE, fRadius, lLoc, FALSE, OBJECT_TYPE_DOOR);		
	}
	
	oTarget = GetFirstObjectInShape(SHAPE_SPHERE, fRadius, lLoc, FALSE, OBJECT_TYPE_PLACEABLE);
	while (GetIsObjectValid(oTarget))
	{
		if (GetTag(oTarget)== "PLC_NL_ROCKFCE01")
		{
			FloatingTextStringOnCreature(sName + " hits the rocks", OBJECT_SELF,FALSE);
			SetLocalInt(oTarget, IntToString(iSpell) + "_triggered", TRUE);
			if (GetLocalInt(oTarget, IntToString(SPELL_TRUE_SEEING) + "_triggered"))
			{
				DestroyObject(oTarget, 0.5);
				SetLocalInt(oPC,"rocksdestroyed",1);
			}
            return;
		}
		oTarget = GetNextObjectInShape(SHAPE_SPHERE, fRadius, lLoc, FALSE, OBJECT_TYPE_PLACEABLE);
	}
	
	oTarget = GetFirstObjectInShape(SHAPE_SPHERE, fRadius, lLoc, FALSE, OBJECT_TYPE_CREATURE);
	object spellItem = GetItemActivated();
	object oRabbit = GetObjectByTag("esaspia");
	AssignCommand(oRabbit,SetIsDestroyable(TRUE,FALSE,FALSE));
	while (GetIsObjectValid(oTarget))
	{
		if (GetTag(oTarget)== "esaspia")
		{
			if (GetIsObjectValid(spellItem) && GetTag(spellItem) == "ltransmutate")
			{
				AssignCommand(oTarget, SpeakString("Transmutate hits the rabbit", TALKVOLUME_TALK));
				SetLocalInt(oTarget, "transmutate_triggered", TRUE);
			}
			else if (iSpell == SPELL_DISPEL_MAGIC)
			{
				FloatingTextStringOnCreature(sName + " hits the rabbit", OBJECT_SELF,FALSE);
				SetLocalInt(oTarget, IntToString(iSpell) + "_triggered", TRUE);
			}
			else
			{
				FloatingTextStringOnCreature(sName + " hits the rabbit", OBJECT_SELF,FALSE);
			}
			
			if (GetLocalInt(oTarget, IntToString(SPELL_DISPEL_MAGIC) + "_triggered") &&
				GetLocalInt(oTarget, "transmutate_triggered"))
			{
				DestroyObject(oTarget, 0.5);
			}
            return;
		}
		oTarget = GetNextObjectInShape(SHAPE_SPHERE, fRadius, lLoc, FALSE, OBJECT_TYPE_CREATURE);	
	}
}

Thank you for all the help!