Open/Close spell script

Asset Information and Discussion for Scripting, Area Design, and More

Moderators: Moderator, Developer, DM

Dagesh
Posts: 891
Joined: Mon Jan 16, 2012 11:03 pm

Open/Close spell script

Unread post by Dagesh »

Copying and pasting doesn't seem to keep the spacing right. Ni modo.

OPEN/CLOSE
Transmutation
Level: Brd 0, Sor/Wiz 0
Components: V, S, F
Casting Time: 1 standard action
Range: Close (25 ft. + 5 ft./2 levels)
Target: Object weighing up to 30 lb. or portal that can be opened or closed
Duration: Instantaneous
Saving Throw: Will negates (object)
Spell Resistance: Yes (object)
You can open or close (your choice) a door, chest, box, window, bag, pouch, bottle, barrel, or other container. If anything resists this activity (such as a bar on a door or a lock on a chest), the spell fails. In addition, the spell can only open and close things weighing 30 pounds or less. Thus, doors, chests, and similar objects sized for enormous creatures may be beyond this spell’s ability to affect.

Focus
A brass key.
Hidden: show

Code: Select all


#include "x2_inc_spellhook"

void main()
{

    if (!X2PreSpellCastCode())
    {
        return;
    }

    //Declare major variables
    object oTarget = GetSpellTargetObject();
	
	if( GetObjectType( oTarget ) != ( OBJECT_TYPE_DOOR | OBJECT_TYPE_PLACEABLE ) )
	return;

    int nCasterLevel    = GetCasterLevel( OBJECT_SELF );

    effect eVis = EffectVisualEffect( VFX_IMP_MAGIC_RESISTANCE_USE  );

    if( GetLocked( oTarget ) )
	{// Can't open locked objects with this spell!
		FloatingTextStringOnCreature( "Locked!", OBJECT_SELF, 0 ); 
		return;
	}

    if( GetObjectType( oTarget ) == OBJECT_TYPE_DOOR )
	{
        if( GetIsOpen( oTarget ) )
		{
            AssignCommand( oTarget, ActionCloseDoor( oTarget ) );
        }
        else
		{
            AssignCommand( oTarget, ActionOpenDoor( oTarget ) );
        }
    }
    else if( GetObjectType( oTarget ) == OBJECT_TYPE_PLACEABLE )
	{
        if( GetIsOpen( oTarget ) )
		{
            AssignCommand( oTarget, ActionPlayAnimation( ANIMATION_PLACEABLE_CLOSE  ) );
        }
        else
		{
            AssignCommand( oTarget, ActionPlayAnimation( ANIMATION_PLACEABLE_OPEN  ) );
        }
    }

    ApplyEffectToObject( DURATION_TYPE_INSTANT, eVis, oTarget );

}
ουκ εστιν ωδε, ηγερθη γαρ καθως ειπεν



PCs:
Rorick Runegraph (Check out Rorick's Rune of Light)
Ckalthea Chenfur
Aeric
Squire Brevin of Lathander

Return to “NWN2 Toolset Development”