Author Sticky: Post Working Scripts Here
Eboneye Posted: Monday, 08 July 02:41PM
I went round and round trying to get a trap door script to work. The problem I learned is that the PC MUST BE ABLE TO GET TO THE SIDE OF THE DOOR WITH THE RING. If the PC cannot move to that location, the action is aborted and nothing happens. So, the lesson learned is to orient the ring side of the panel in an area easily accessible to the PC or it won't work right.

Other lessons: Animation actions put on the PC take time to execute (are queued up), where other actions happen immediately. So, any code that simulates a character interacting with an object needs to take such into account.

NWScript:
//:://////////////////////////////////////////////////////////////////////////////////

//::

//:: Trapdoor_open script -- simulates going through a trap door into another location

//:: >>This performs the PC interaction, the door opening animation and <<

//:: >>the actual translocation <<

//:: This script is placed in the OnUse Event of a trap door

//:: Assumes that the mod designer has created a "return door" in the

//:: Target location.  A waypoint can probably be used if so desired.  This

//:: WORKS when using a door.  The tag used here is "SecretPassageDoor", change

//:: this to whatever you put in the TAG of the target door.

//::

//:: by Will Greenway

//:://////////////////////////////////////////////////////////////////////////////////

void main()

{

   //::///////

   //:: Get the Opener

   //::///////

   object oPC = GetLastUsedBy();

   //::///////

   //:: Get the target location -- Change "SecretPassageDoor" to your desired target object

   //::///////

   location lLoc = GetLocation(GetObjectByTag("SecretPassageDoor",0));

   //::///////

   //:: Have the PC bend over and mess with the trap door

   //::///////

   AssignCommand(oPC,PlayAnimation(ANIMATION_LOOPING_GET_LOW,1.0,2.0));

   //::///////

   //:: Have the door itself wait for the PC to do the animation

   //::///////

   ActionWait(2.0);

   //:://////

   //:: Play the door opening sound

   //:://///

   PlaySound("as_sw_metalop1");

   //:://////

   //:: Have the trap door do its open animation

   //:://///

   ActionPlayAnimation(ANIMATION_PLACEABLE_OPEN,1.0,2.0);

   //:://////

   //:: Tell the PC to jump to location.

   //:: Note the DelayCommand is added so that

   //:: the jump isn't done while animations are in progress.

   //:://///

   AssignCommand(oPC, DelayCommand(4.0,JumpToLocation(lLoc)));

   //:://////

   //:: Close the trap door (for other PCs observing)

   //:://///

   ActionPlayAnimation(ANIMATION_PLACEABLE_CLOSE,1.0,1.0);

}