Author Topic: Door Script Modification  (Read 831 times)

Legacy_Greyfort

  • Sr. Member
  • ****
  • Posts: 442
  • Karma: +0/-0
Door Script Modification
« Reply #15 on: December 19, 2010, 06:55:14 am »


               /////////////////////////////////////////////
//
// created by _Knightmare_
// 12.??.2010
//
// door_all
// Altered by: Greyfort
// 12.18.2010
//
// place script in onFailToOpen of door
//
// set variables on door from the advanced tab variables button
// set door plot, set door locked, door set relockable

//door int "sClose"
//------------------ SET CLOSE DOOR DELAY -------------------
// Set a local int of the door called "sClose"
// Set it to the value you want for delay
// Default 15 second delay


//door string "LOCKED",
//------------------ SET LOCK BASED ON DAY/NIGHT SETTING -------------------
// Set local string on door named "LOCKED" to decide when it is locked
// Applicable entries are "DAY"=locked day time and "NIGHT"=locked night time


//door string "ALIGN GE" , "ALIGN LC", "NEUTRAL" ,
//------------------ 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


//door int "class"
//------------------ 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
// You can find class (constant) in lexicon

//door string"KEY"
//------------------ KEY UNLOCKED -------------------
// Set a local string of the door called "KEY"
// Set string value Tag of key item ie "castlekey"

////////////////////////////////////////////////////////////////////////////////
// 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;
object oPC = GetClickingObject(); // Get the player object that clicked on the door

//------------------ SET CLOSE DOOR DELAY -------------------
// Set a local int of the door called "sClose"
// Set it to the value you want for delay
// Default 15 second delay
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 == "DAY")
     {
     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 == "NIGHT")
     {
     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


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)
     {
     SendMessageToPC (oPC,"Good/Evil check door script fired");
     if(GetLocked(OBJECT_SELF))
           {
           SetLocked(OBJECT_SELF,FALSE);
           ActionOpenDoor(OBJECT_SELF);
            }
     else
            {
            SetLocked(OBJECT_SELF,TRUE);
            }
      }
// Law/Chaos check
if(sDoorLC != "" && nPCLC == nDoorLC)
     {
     SendMessageToPC (oPC,"Law/Chaos check door script fired");
      if(GetLocked(OBJECT_SELF))
           {
           SetLocked(OBJECT_SELF,FALSE);
           ActionOpenDoor(OBJECT_SELF);
           }
     else
           {
           SetLocked(OBJECT_SELF,TRUE);
           }
     }
// Optional - allow True Neutrals through
if(GetLocalInt(oDoor, "NEUTRAL") == 1)
     {
     if(GetLocked(OBJECT_SELF))
           {
           SetLocked(OBJECT_SELF,FALSE);
           ActionOpenDoor(OBJECT_SELF);
           //DEBUG MESSAGING
           SendMessageToPC (oPC,"NEUTRAL check door script fired");
           }
      }

//------------------ 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);
           ActionOpenDoor(OBJECT_SELF);
           //DEBUG MESSAGING
           SendMessageToPC (oPC,"class door script fired");
           }
     }
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.


It might keep locking/unlocking the door as different variables return true
throughout the script. Hopefully it will end up correct at the end.
*/

//------------------ KEY UNLOCKED -------------------
// Set a local string of the door called "KEY"
// Set string value Tag of key item ie "castlekey"

object oKey=GetObjectByTag(GetLocalString(OBJECT_SELF,"KEY"));
if(GetItemPossessor(oKey)==oPC)
   {
   SetLocked(OBJECT_SELF,FALSE);
   ActionOpenDoor(OBJECT_SELF);
   //DEBUG MESSAGING
   SendMessageToPC (oPC,"KEY check door script fired");
   }
/*
Greyfort Notes:
*/
//end of script
}
WORKING NWN1 SCRIPT:  Based on what _Knightmare_ gave as a start.
Ive tested script in toolset works great.  If you have any questions just ask we are here to help. Great script Idea _Knightmare_ I enjoyed getting it to work for nwn1. 
               
               

               


                     Modifié par Greyfort, 19 décembre 2010 - 06:57 .
                     
                  


            

Legacy__Knightmare_

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


               NP, glad somebody got it working for NWN1. '<img'>



Thanks.
               
               

               
            

Legacy_Birdman076

  • Sr. Member
  • ****
  • Posts: 320
  • Karma: +0/-0
Door Script Modification
« Reply #17 on: December 19, 2010, 02:33:03 pm »


               
//-------------------------------- class Type Constants ------------------------
//::
//::                            Base classes
//::
//::    class_TYPE_BARBARIAN - 0      class_TYPE_PALADIN -  6
//::    class_TYPE_BARD -      1      class_TYPE_RANGER -   7
//::    class_TYPE_CLERIC -    2      class_TYPE_ROGUE -    8
//::    class_TYPE_DRUID -     3      class_TYPE_SORCERER - 9
//::    class_TYPE_FIGHTER -   4      class_TYPE_WIZARD -   10
//::    class_TYPE_MONK -      5
//::
//::                            Prestige classes
//::
//::    class_TYPE_SHADOWDANCER -     27
//::    class_TYPE_HARPER -           28
//::    class_TYPE_ARCANE_ARCHER -    29
//::    class_TYPE_ASSASSIN -         30
//::    class_TYPE_BLACKGUARD -       31
//::    class_TYPE_DIVINECHAMPION -   32 (Champion of Torm)
//::    class_TYPE_WEAPON_MASTER -    33
//::    class_TYPE_PALE_MASTER -      34
//::    class_TYPE_SHIFTER -          35
//::    class_TYPE_DWARVENDEFENDER -  36
//::    class_TYPE_DRAGONDISCIPLE -   37
//::
//------------------------------------------------------------------------------

Here are the class constants per the lexicon. Thank you for working on this and getting it to work it will come in very handy and help me eliminate a couple of handfuls of scripts from the PW I am working on. '<img'>
               
               

               


                     Modifié par Birdman076, 19 décembre 2010 - 02:34 .
                     
                  


            

Legacy_Tarot Redhand

  • Hero Member
  • *****
  • Posts: 4165
  • Karma: +0/-0
Door Script Modification
« Reply #18 on: December 19, 2010, 05:24:57 pm »


               Inspired by _knightmare_ here are a couple more scripts for locking/unlocking doors.

//----------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------

//::///////////////////////////////////////////////
//:: Name       Special Key
//:: FileName   scr_special_key
//:: Copyright © 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*

*/
//:://////////////////////////////////////////////
//:: Created By: Tarot Redhand
//:: Created On: 18th December 2010
//:://////////////////////////////////////////////

//#include needed for HasItem

#include "nw_i0_plot"

void SpecialKey(object oDoor, object oPC, string sKeyTag, string sFailMessage = "", int iDestroyItemOnSuccess = FALSE)

//simple routine to unlock a door oDoor if a specific item sKeyTag (tag of item) is carried by oPC
//if the item is not in oPC's inventory, oDoor "speaks" sFailMessage
//Note - oDoor is opened at the same time as it is unlocked
//Start with oDoor locked and call this from oDoor's OnFailToOpen event

{
if(HasItem(oPC, sKeyTag))
{
       SetLocked(oDoor, FALSE);
       if(iDestroyItemOnSuccess)
           DestroyObject(GetObjectByTag(sKeyTag));
       AssignCommand(oDoor, ActionOpenDoor(oDoor));
   }
   else
   {
       if(sFailMessage != "")
           SpeakString(sFailMessage);
   }
}

//----------------------------------------------------------------------------------------------------------------

void main()
{
   //put call to SpecialKey here
}

//----------------------------------------------------------------------------------------------------------------
//next script
//----------------------------------------------------------------------------------------------------------------

/*
//:://////////////////////////////////////////////
//:: Name     Unlocked By Spell
//:: FileName scr_unlok_by_spl
//:: Copyright © 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*

*/
//:://////////////////////////////////////////////
//:: Created By: Tarot Redhand
//:: Created On: 18th September 2010
//:://////////////////////////////////////////////

void UnlockedBySpell(object oDoor, int iTargetSpell = SPELL_DISPEL_MAGIC)

//very simple routine to unlock lockable object oDoor when a specific spell intTargetSpell
//is cast at it otherwise oDoor will be locked
//call this function from the void main() part of the script that services an OnSpellCastAt event

{
   if(GetLastSpell() == iTargetSpell)
       SetLocked(oDoor, FALSE);
   else
       SetLocked(oDoor, TRUE);
}

//----------------------------------------------------------------------------------------------------------------

void main()
{
   //call UnlockedBySpell from here uncomment the next line to try
   //UnlockedBySpell(OBJECT_SELF, SPELL_LIGHT);
   
}

//----------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------

TR
               
               

               


                     Modifié par Tarot Redhand, 19 décembre 2010 - 05:27 .