/*1. Script Name: autogate

2. What it does: Automatically makes a guard close and lock a specified gate at night and open it again in the morning (failsafes added galore).

3. Notes: All in the script

4. The Script itself: */




//::///////////////////////////////////////////////
//:: autogate - a script to make a guard automatically close and lock a specified
//:: gate at night, and open it again the morning (failsafes added galore).
//:://////////////////////////////////////////////
/*
Info: This script makes a NPC close and lock a specified Gate/Door at
Dusk and opens it again at Dawn.
Installation: 1. Select the NPC you wish to act as guard
2. Go to the script pane and push the "Edit" button in front
of the "On Spawn" script
3. Go down the file and remove the two "//" before the
"SetSpawnInCondition(NW_FLAG_HEARTBEAT_EVENT);".
This will make the game run the User Defined Event
Number 1001, which is the one this script uses
4. Push the "Save As" button (The floppy disk with one arrow
on) and save the new script under a new name, such as
"gate_guard" or something like that.
5. Exit from the script and push the "Edit" button in front
of the "OnUserDefined".
6. Replace all the text there with this script
7. Change the "Gate" tag down bellow in the Options area
with the tag of your gate or door
8. Push the Compile button in the upper left corner of the
screen, save it as "autogate" or anything else you wish
9. Exit the script and save the NPC by pushing the "Ok" button
ENJOY!
*/
//:://////////////////////////////////////////////
//:: Created By: Night Stalker
//:: E-mail: Mikkel4@ofir.dk
//:: Feedback and suggestions greatly appreciated
//:: Created On: July 29, 2002
//:://////////////////////////////////////////////
#include "NW_I0_GENERIC"
void main()
{
//****************************************************************************//
// Options //
//****************************************************************************//
// The object we want to close and lock
object oDoor = GetNearestObjectByTag("Gate");
//****************************************************************************//
// Integers //
//****************************************************************************//
// Is the Gate closed?
int iClosed;
// Time
int iNight = 0;
int iDay = 0;
// Makes sure that the Guard will not try to open the Gate again the same day
int iDoneDay = 0;
// Makes sure that the Guard will not try to open the Gate again the same night
int iDoneNight = 0;
//****************************************************************************//
// Start of Script //
//****************************************************************************//

int nUser = GetUserDefinedEventNumber();

if(nUser == 1001) //HEARTBEAT
{
if(!IsInConversation(OBJECT_SELF) && !GetIsFighting(OBJECT_SELF))
{
//****************************************************************************//
// Check Time //
//****************************************************************************//
// It is Night or Dusk
if
((
GetIsNight() == TRUE
||
GetIsDusk() == TRUE
) &&
GetLocalInt(OBJECT_SELF, "iNight") == 0
)
{
SetLocalInt(OBJECT_SELF, "iNight", 1);
SetLocalInt(OBJECT_SELF, "iDay", 0);
}
// It is Day or Dawn
if
((
GetIsDay() == TRUE
||
GetIsDawn() == TRUE
) &&
GetLocalInt(OBJECT_SELF, "iDay") == 0
)
{
SetLocalInt(OBJECT_SELF, "iNight", 0);
SetLocalInt(OBJECT_SELF, "iDay", 1);
}
//****************************************************************************//
// Check State of Gate //
//****************************************************************************//
if
(
GetIsOpen(oDoor)
)
{
SetLocalInt(OBJECT_SELF, "iClosed", 0); //No, the gate is not closed
}
else
{
SetLocalInt(OBJECT_SELF, "iClosed", 1); //Yes, the gate is closed
}
//****************************************************************************//
// Start of the main script //
//****************************************************************************//
/* Checks if it is Dusk or Night and if gate is still there and
unlocked. If these requirements are met, then lock the gate*/
if
(GetLocalInt(OBJECT_SELF, "iNight") == 1) //Is it time to close the Gate?
{
if
(GetIsObjectValid(oDoor)) //Is the Gate still there?
{
if
(GetLocalInt(OBJECT_SELF, "iClosed") == 0) //Is the Gate Closed?
{
if
(GetLocalInt(OBJECT_SELF, "iDoneNight") == 0) //Have I done my Job for tonight?
{
ClearAllActions();
ActionCloseDoor(oDoor); //Close the Gate
SetLocked(oDoor, TRUE); //Lock the Gate
SetLocalInt(OBJECT_SELF, "iDoneNight", 1); //I have done my work for tonight
SetLocalInt(OBJECT_SELF, "iDoneDay", 0); //I have not done my work for today
ActionDoCommand(WalkWayPoints()); //Walk back to your Post/Waypoints
}
}
}
}
if
(GetLocalInt(OBJECT_SELF, "iNight") == 1) //Is it time to close the Gate?
{
if
(GetIsObjectValid(oDoor)) //Is the Gate still there?
{
if
(GetLocalInt(OBJECT_SELF, "iClosed") == 1) //Is the Gate Closed?
{
if
(GetLocalInt(OBJECT_SELF, "iDoneNight") == 0) //Have I done my Job for tonight?
{
ClearAllActions();
SetLocked(oDoor, TRUE);
SetLocalInt(OBJECT_SELF, "iDoneNight", 1); //I have done my work for tonight
SetLocalInt(OBJECT_SELF, "iDoneDay", 0); //I have not done my work for today
ActionDoCommand(WalkWayPoints()); //Walk back to your Post/Waypoints
}
}
}
}
/* Checks if it is Dawn or Day and if gate is still there and
locked. If these requirements are met, then open and unlock the gate*/
if
(GetLocalInt(OBJECT_SELF, "iDay") == 1) //Is it time to open the Gate?
{
if
(GetIsObjectValid(oDoor)) //Is the Gate still there?
{
if
(GetLocalInt(OBJECT_SELF, "iClosed") == 1) //Is the Gate Closed?
{
if
(GetLocalInt(OBJECT_SELF, "iDoneDay") == 0) //Have I already Opened the Gate?
{
ClearAllActions();
SetLocked(oDoor, FALSE); //Unlock the Gate
ActionOpenDoor(oDoor); //Open the Gate
SetLocalInt(OBJECT_SELF, "iDoneDay", 1); //I have done my work for today
SetLocalInt(OBJECT_SELF, "iDoneNight", 0); //I have not done my work for tonight
ActionDoCommand(WalkWayPoints()); //Walk back to your Post/Waypoints
}
}
}
}
}
}
}





//Change and rip it as much as you like .
//W00T! My first script!