Author Topic: Door Script Modification  (Read 828 times)

Legacy_Birdman076

  • Sr. Member
  • ****
  • Posts: 320
  • Karma: +0/-0
Door Script Modification
« on: December 11, 2010, 03:08:31 pm »


               I have this door script which works wonderfully for closing and locking and has some configuration for time delay to close the door. But i'd like to also have the ability to set an int on the door to have it lock at night (so I can enable or disable depending on the door), check for class (again variable driven so I can select which class for which door), and lastly alignment. I'm sure there are other additions that could be made to make this a singular robust door handler script that covers all or almost all bases, and be totally configured via variables set on the door in question. Thanks in advance for any help provided.


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 );
  }
}

               
               

               
            

Legacy_Ulo Ironbeard

  • Newbie
  • *
  • Posts: 26
  • Karma: +0/-0
Door Script Modification
« Reply #1 on: December 11, 2010, 05:56:47 pm »


               You can do what you want using the GetIsNight and GetIsDay functions. I use something like this in my module - remember though, that locked doors can be picked!
               
               

               
            

Legacy_Birdman076

  • Sr. Member
  • ****
  • Posts: 320
  • Karma: +0/-0
Door Script Modification
« Reply #2 on: December 11, 2010, 06:15:26 pm »


               Yes, I know the functions but as I said in my post id like the ability to have the script configurable via variables that can be set on the door to do different things like if a variable DAY_NIGHT is set as true then the door will be unlocked during the day, locked at night. I'd rather have all door functionality in one script as opposed to 20 scripts to do each function of a door.
               
               

               
            

Legacy_Ulo Ironbeard

  • Newbie
  • *
  • Posts: 26
  • Karma: +0/-0
Door Script Modification
« Reply #3 on: December 11, 2010, 08:11:31 pm »


               I don't know if this will do what you want (I'm not an expert), but I added a few lines to your script. Place it in the  OnHeartbeat event of the door. It compiles, but I haven't tested it. Be sure to set the variable NIGHT_LOCKED on the door.



void main()

{

   object oDoor = OBJECT_SELF;

   //added this line

   int nNightLocked = GetLocalInt(oDoor, "NIGHT_LOCKED");

   //

   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 );

       }

       // Added Code

       if(nNightLocked == 1)

       {

       if (GetIsNight()&&GetIsOpen(OBJECT_SELF))

       {

       ActionCloseDoor(OBJECT_SELF);

       ActionDoCommand(SetLocked(OBJECT_SELF,TRUE));

       }

       else if(GetIsDawn()&&GetLocked(OBJECT_SELF))

       {

       SetLocked(OBJECT_SELF,FALSE);

   }

 }

}
               
               

               
            

Legacy_Birdman076

  • Sr. Member
  • ****
  • Posts: 320
  • Karma: +0/-0
Door Script Modification
« Reply #4 on: December 12, 2010, 01:48:00 pm »


               That helps with the Day/Night scenario which is good but I'm really after an all inclusive door handler that covers all the bases so I only need one master door script to do everything.
               
               

               
            

Legacy__Knightmare_

  • Full Member
  • ***
  • Posts: 191
  • Karma: +0/-0
Door Script Modification
« Reply #5 on: December 12, 2010, 04:14:38 pm »


               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 .
                     
                  


            

Legacy_Birdman076

  • Sr. Member
  • ****
  • Posts: 320
  • Karma: +0/-0
Door Script Modification
« Reply #6 on: December 14, 2010, 01:20:30 pm »


               Thank you Knightmare, that looks like it covers all the bases!
               
               

               
            

Legacy_TSMDude

  • Hero Member
  • *****
  • Posts: 1515
  • Karma: +0/-0
Door Script Modification
« Reply #7 on: December 14, 2010, 01:30:35 pm »


               Hey Knightmare stealing the script and adding it to our script resources.
               
               

               
            

Legacy__Knightmare_

  • Full Member
  • ***
  • Posts: 191
  • Karma: +0/-0
Door Script Modification
« Reply #8 on: December 14, 2010, 02:38:19 pm »


               NP, please let me know if the script does in fact work as it should. I did not test it in game. If any problems show up I'll do my best to fix them. '<img'>
               
               

               
            

Legacy_Tarot Redhand

  • Hero Member
  • *****
  • Posts: 4165
  • Karma: +0/-0
Door Script Modification
« Reply #9 on: December 15, 2010, 05:52:04 pm »


               @_Knightmare_  You need to change GetclassByPosition to GetClassByPosition otherwise it won't compile and you get the dreaded Error parsing variable list error.

TR
               
               

               


                     Modifié par Tarot Redhand, 15 décembre 2010 - 05:53 .
                     
                  


            

Legacy_Birdman076

  • Sr. Member
  • ****
  • Posts: 320
  • Karma: +0/-0
Door Script Modification
« Reply #10 on: December 15, 2010, 11:37:32 pm »


               

_Knightmare_ wrote...

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.



'Image'Image

Been a bit busy with other things haven't had a chance to test it just yet sorry.'Image
               
               

               


                     Modifié par Birdman076, 15 décembre 2010 - 11:38 .
                     
                  


            

Legacy_Tarot Redhand

  • Hero Member
  • *****
  • Posts: 4165
  • Karma: +0/-0
Door Script Modification
« Reply #11 on: December 17, 2010, 12:06:53 pm »


               @_Knightmare_ There is no OnClick event for doors - see here.



TR
               
               

               
            

Legacy__Knightmare_

  • Full Member
  • ***
  • Posts: 191
  • Karma: +0/-0
Door Script Modification
« Reply #12 on: December 17, 2010, 12:39:01 pm »


               

Tarot Redhand wrote...

@_Knightmare_ There is no OnClick event for doors - see here.

TR


Hmmm, well that really stinks. I use NWN2 for everything and we have a full allotment of script slots for doors there (including all you listed in that linked post, plus OnClick, OnConversation, OnTrapTriggered, and OnDisarm). The scripting for both games is so similar I just try to also help people here.

The script should work if you can find an appropriate script slot for it to fire from... sorry about that.
               
               

               
            

Legacy_Tarot Redhand

  • Hero Member
  • *****
  • Posts: 4165
  • Karma: +0/-0
Door Script Modification
« Reply #13 on: December 17, 2010, 01:13:23 pm »


               Tell me about it. Your script that you posted inspired me to get back to scripting and I've developed a set of 4 for doors but without OnClick they are not any use for doors only placeables so I'll probably wait before I post them.



TR
               
               

               
            

Legacy_Greyfort

  • Sr. Member
  • ****
  • Posts: 442
  • Karma: +0/-0
Door Script Modification
« Reply #14 on: December 18, 2010, 05:28:31 am »


               NWN1 door scripts:

onAreaTransclick
onClose
onDamaged
onDeath
onFailToOpen
onHeartbeat
onLock
onPhysicalAttacked
onOpen
onSpellCastAt
onUnlock
onUserDefined

also for classes:
// Get the PC's various classes
int nclass1 = GetclassByPosition(1, oPC);
int nclass2 = GetclassByPosition(2, oPC);
int nclass3 = GetclassByPosition(3, oPC);
only those lines are valid there are not 4 class positions

in regaurds to :
Script should go in the OnClicked event of the door.
place in onFailToOpen script it calls the object oPC = GetClickingObject();

also you may have to divide the script up according to what you want. if you give a little more detail I can help you set up a nwn1 door useing script _Knightmare_ made it wont work as it is onFailToOpen we will have to break it up.

Edit add:  I forgot to ask did you want variables on the door or only created after door is interacted with?
               
               

               


                     Modifié par Greyfort, 18 décembre 2010 - 05:33 .