Here's an all inclusive example for you. If nothing else it can serve to steer you in a direction:
void main()
{
object oDoor = OBJECT_SELF;
float fClose;
string sClose = GetLocalString(OBJECT_SELF, "sClose");
if(sClose == "")
{
fClose = 15.0;
}
else if(sClose == "-1") return;
else
{
fClose = StringToFloat( sClose );
}
DelayCommand(fClose, ActionCloseDoor(oDoor));
if (GetLockLockable(oDoor))
{
SetLocked(oDoor, TRUE);
}
//------------------ SET LOCK BASED ON DAY/NIGHT SETTING -------------------
// Set local string on door named "LOCKED" to decide when it is locked
// Applicable entries are "DAY" and "NIGHT"
string sLocked = GetLocalString(oDoor, "LOCKED");
if(sLocked == "NIGHT")
{
if(GetIsDay()) // Daytime, close and lock door
{
if(GetIsOpen(OBJECT_SELF))
{
ActionCloseDoor(OBJECT_SELF);
}
ActionDoCommand(SetLocked(OBJECT_SELF,TRUE));
}
else if(GetIsNight()) // Night time, unlock door
{
if(GetLocked(OBJECT_SELF))
{
SetLocked(OBJECT_SELF,FALSE);
}
}
}
if(sLocked == "DAY")
{
if(GetIsNight()) // Night time, close and lock door
{
if(GetIsOpen(OBJECT_SELF))
{
ActionCloseDoor(OBJECT_SELF);
}
ActionDoCommand(SetLocked(OBJECT_SELF,TRUE));
}
else if(GetIsDay()) // Day time, unlock door
{
if(GetLocked(OBJECT_SELF))
{
SetLocked(OBJECT_SELF,FALSE);
}
}
}
//------------------ SET LOCK BASED ON ALIGNMENT -------------------
// Set local string on door called "ALIGN GE" (Alignment Good/Evil)
// Set local string on door called "ALIGN LC" (Alignment Law/Chaos)
// Applicable entries are "GOOD" and "EVIL" for the first string
// Applicable entries are "LAW" and "CHAOS" for the second string
// Optional setting for allowing True Neutral PCs through
// Set Local Int on Door called "NEUTRAL"
// Set to 1 for allowing True Neutrals through
// To restrict True Neutrals and not allow through set to 0 or don't have the int at all
object oPC = GetClickingObject(); // Get the player object that clicked on the door
int nDoorGE;
int nDoorLC;
string sDoorGE = GetLocalString(oDoor, "ALIGN GE");
if(sDoorGE == "GOOD")
{
nDoorGE == 4;
}
else if(sDoorGE == "EVIL")
{
nDoorGE == 5;
}
string sDoorLC = GetLocalString(oDoor, "ALIGN LC");
if(sDoorLC == "LAW")
{
nDoorLC == 2;
}
else if(sDoorLC == "CHAOS")
{
nDoorLC == 3;
}
// If door has an entry for "ALIGN GE" and/or "ALIGN LC" string variables
// Check to see if the PC's alignment matches the entry
// Unlock door if matched, else lock the door if no match
int nPCGE = GetAlignmentGoodEvil(oPC);
int nPCLC = GetAlignmentLawChaos(oPC);
// Good/Evil check
if(sDoorGE != "" && nPCGE == nDoorGE)
{
if(GetLocked(OBJECT_SELF))
{
SetLocked(OBJECT_SELF,FALSE);
}
else
{
SetLocked(OBJECT_SELF,TRUE);
}
}
// Law/Chaos check
if(sDoorLC != "" && nPCLC == nDoorLC)
{
if(GetLocked(OBJECT_SELF))
{
SetLocked(OBJECT_SELF,FALSE);
}
else
{
SetLocked(OBJECT_SELF,TRUE);
}
}
// Optional - allow True Neutrals through
if(GetLocalInt(oDoor, "NEUTRAL") == 1)
{
if(GetLocked(OBJECT_SELF))
{
SetLocked(OBJECT_SELF,FALSE);
}
}
//------------------ SET LOCK BASED ON class -------------------
// Set a local int of the door called "class"
// Set it to the (constant) value of the class you want to be let through
// Get the PC's various classes
int nclass1 = GetclassByPosition(1, oPC);
int nclass2 = GetclassByPosition(2, oPC);
int nclass3 = GetclassByPosition(3, oPC);
int nclass4 = GetclassByPosition(4, oPC);
// Compare PC's classes to door int variable
// If matched, unlock door, else lock door
int nDoorclass = GetLocalInt(oDoor, "class");
if((nclass1 == nDoorclass) || (nclass2 == nDoorclass) ||
(nclass3 == nDoorclass) || (nclass4 == nDoorclass))
{
if(GetLocked(OBJECT_SELF))
{
SetLocked(OBJECT_SELF,FALSE);
}
}
else
{
SetLocked(OBJECT_SELF,TRUE);
}
}
If you leave either the "LAW/CHAOS" or the "GOOD/EVIL" strings blank (no entry value), it will not check those of the player. So, you can let in all good or all evil, all lawful or all chaotic (or all True Neutrals as an optional). Or you can set both values and let in only LAWFUL GOOD, only CHAOTIC EVIL, only CHAOTIC GOOD, etc.
You will need to look up the class constant number value.
Script should go in the OnClicked event of the door. It might keep locking/unlocking the door as different variables return true throughout the script. Hopefully it will end up correct at the end.
Script untested in game but should compile with no problems.
Also, note the forums here (for whatever reason) makes the letter "C" in the word "class" lower case. You will need to change them all to an upper case "C" if you do any sort of copy/paste.
Modifié par _Knightmare_, 17 décembre 2010 - 03:06 .