/* Here is my version of the lever door. This version will allow you to
generically create doors and simply add this script to the lever. It requires no
editing script wise.
The door MUST be named LEVER_DOOR , I also assume multiple instances of
LEVER_DOOR can be made. The script finds the closest LEVER_DOOR and
unlocks/opens it or closes/locks it. PM me if you find any bugs or have
suggestions. */
/*This goes in the used event on the lever. This gets the closest door with
the tag of "LEVER_DOOR" and unlocks and opens it, or closes it and locks it.
*/
void main()
{
object oDoor ;
int nDoorLocked;
int nDoorOpen; //Is the door opened already?
string sDoorTag; //testing variable
oDoor=GetNearestObjectByTag ("LEVER_DOOR",OBJECT_SELF,1);
if ( GetIsObjectValid (oDoor) == TRUE )
{
sDoorTag = GetTag (oDoor);
nDoorLocked = GetLocked (oDoor);
nDoorOpen = GetIsOpen (oDoor);
//This part simply switches the graphics on the lever from activate to
//deactivate or vice versa.
if ( GetLocalInt ( OBJECT_SELF, "m_bActivated" )==TRUE)
{
SetLocalInt (OBJECT_SELF,"m_bActivated",FALSE);
ActionPlayAnimation ( ANIMATION_PLACEABLE_ACTIVATE);
}
else if ( GetLocalInt (OBJECT_SELF,"m_bActivated") ==FALSE)
{
SetLocalInt (OBJECT_SELF,"m_bActivated",TRUE);
ActionPlayAnimation (ANIMATION_PLACEABLE_DEACTIVATE);
}
/* this part checks if the door is locked and close if it is it unlocks and
opens.
If it is open and unlocked then it closes and locks it.
The door should have the tag LEVER_DOOR and its initial state should be
locked and closed.*/
if ( nDoorLocked && nDoorOpen==FALSE)
{
SetLocked ( oDoor,FALSE );
ActionOpenDoor ( oDoor );
}
else if ( nDoorOpen && nDoorLocked==FALSE)
{
ActionCloseDoor (oDoor);
SetLocked (oDoor,TRUE);
}
else if ( nDoorOpen==FALSE && nDoorLocked==FALSE)
{
ActionOpenDoor (oDoor);
}
}
}