IMPROVED LEVER/DOOR CODE
Actually, got it to work by using the OnHeartbeat (Bad.. Bad Days..)
Here is the code I used.
Two objects,
The gate on the city wall, and a lever to open it.
Gate Tag = WallDoor
Gate settings = Closed, Locked
Lever Settings = Activated, Usable
Script for Lever OnHeartbeat
NWScript: void main()
{
object oDoor = GetObjectByTag ("WallDoor");
if ( GetLocalInt( OBJECT_SELF, "m_bActivated" ) == FALSE )
{
ActionWait(10.0);
SetLocalInt( OBJECT_SELF, "m_bActivated", TRUE );
PlayAnimation( ANIMATION_PLACEABLE_ACTIVATE );
ActionCloseDoor(oDoor);
SetLocked(oDoor, TRUE);
}
}
Code for Lever OnUsed
NWScript: void main()
{
object oDoor = GetObjectByTag ("WallDoor");
if ( GetLocalInt( OBJECT_SELF, "m_bActivated" ) == TRUE )
{
SetLocalInt( OBJECT_SELF, "m_bActivated", FALSE );
PlayAnimation( ANIMATION_PLACEABLE_DEACTIVATE );
SetLocked(oDoor, FALSE);
ActionOpenDoor(oDoor);
}
else
{
SetLocalInt( OBJECT_SELF, "m_bActivated", TRUE );
PlayAnimation( ANIMATION_PLACEABLE_ACTIVATE );
ActionCloseDoor(oDoor);
SetLocked(oDoor, TRUE);
}
}
When you pull the lever, the gate will open, and remain open for 10
seconds (although it seems shorter.. perhaps because of the heartbeat?),
then close and relock.
If the lever is pulled again before the door is closed, it will close
normally, instead of waiting for the timer to expire.
Thanks to "Spectator" in the irc.stratics.com #nwnscript channel for the
help. And thanks for all the suggestions here.
|