Author Topic: how to: capture attempt to open door before it is opened?  (Read 2373 times)

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #15 on: August 30, 2010, 11:59:34 pm »


               Something I did was to have certain doors all locked, this was idea of a stuck door. Then when the player attacks the door it will unlock and open if they are strong enough. Similar to setting a variable but just using an attribute instead.

I also use a similar idea but extended, when you select a hovel to live it, it puts your name on the door, and thereafter only you can open that door. You need a hovel key which is where I set the variable, since it persists over server resets. Thereafter that key can only be used on that door, though others can get the keys the won't work on your door, and yours cannot be used on any othe door. In this way you don't have to make a bunch of seperate keys for each hovel door.
               
               

               


                     Modifié par ffbj, 30 août 2010 - 11:00 .
                     
                  


            

Legacy_Calgacus

  • Full Member
  • ***
  • Posts: 195
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #16 on: August 31, 2010, 02:20:17 am »


               lots of good responses, nice to see the community is still going strong.
               
               

               
            

Legacy_Genisys

  • Hero Member
  • *****
  • Posts: 961
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #17 on: August 31, 2010, 05:39:41 am »


               You like good responses?   '<img'>

Try this one...

// door_port_templ   (TEMPLATE SCRIPT)
//////////////////////////////////////////////
//Created By: Genisys (Guile)
//Created On: 8/30/10
///////////////////////////////////////////////////////////////////////////////
/*         This script goes in the OnFailToOpen or OnClicked

   Basically it allows you to teleport the clicking PC (and party possibly)
   to a waypoint or door (By using a door the PC may end up in the wrong direction).
   Make sure you set the door or object to be locked & require a fictious key
   to open it. (make up a fake key name)

   MAKE SURE you save this script under a new name BEFORE you edit it!
*/
///////////////////////////////////////////////////////////////////////////////
///////////////////IMPORTANT SETTINGS/////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
//Set this to the (tagname) of the waypoint or door which is the destination
const string DOOR_OR_WAYPOINT = "tagname";
///////////////////////////////////////////////////////////////////////////////
//Set this to TRUE if you wish to check for a key or item..
const int CHECK_FOR_ITEM_FIRST = FALSE; //Default = FALSE (Don't check)
///////////////////////////////////////////////////////////////////////////////
//Set this to TRUE if you wish to remove the item or key after they are ported
const int TAKE_KEY_ITEM = FALSE; //Default = FALSE (Don't take the key / item)
///////////////////////////////////////////////////////////////////////////////
//Set this to the (tagname) of the item to be checked for..
const string TAGNAME_OF_KEY_ITEM = "tagname";
///////////////////////////////////////////////////////////////////////////////
//Set this to TRUE if you wish to use a VFX constant for visual effect..
const int USE_VFX = FALSE; //Default = FALSE (Don't use VFXs)
///////////////////////////////////////////////////////////////////////////////
//Set this to the Default VFX to use (This MUST be a constant!)
const int VFX_TO_USE = VFX_FNF_SUMMON_MONSTER_3;
///////////////////////////////////////////////////////////////////////////////
//Set this to TRUE if you wish to teleport the WHOLE PARTY!
const int TELEPORT_PARTY = FALSE; //Default = FALSE (Don't Teleport Party)
///////////////////////////////////////////////////////////////////////////////
//Set this to TRUE if the Party Members must to be in the same area!
const int MEMBERS_IN_AREA = FALSE; //Default = FALSE (Teleport All reguardless)
///////////////////////////////////////////////////////////////////////////////
//Set this to FALSE if you don't want to teleport Summons/Familiars Also.
const int SUMMONS_TELEPORT_TOO = TRUE; //Default = TRUE (Teleport All Summons)
///////////////////////////////////////////////////////////////////////////////
/////WARNING: DON'T TOUCH ANYTHING BELOW THIS LINE!!!/////////////////////////
/////////////////////////////////////////////////////////////////////////////

//Main Script
void main()
{
 object oPC = GetClickingObject();
 object oArea = GetArea(oPC);
 object oWay = GetObjectByTag(DOOR_OR_WAYPOINT);
 location lLoc = GetLocation(oWay);
 object oParty;
 object oKey;
 effect eVis;
 float f1 = 0.0;
 float f2 = 0.1;

//Only continue if it's a PC / DM or a DM Possessed Creature...
if (GetIsPC(oPC)|| GetIsDM(oPC) || GetIsDMPossessed(oPC))
{
 //First see if we are checking for an item or not...
 if(CHECK_FOR_ITEM_FIRST==TRUE)
 {
  oKey = GetItemPossessedBy(oPC, TAGNAME_OF_KEY_ITEM);

  //If they don't have the key, stop here..
  if(oKey == OBJECT_INVALID)
  {
   //Tell the PC why they failed..
   FloatingTextStringOnCreature("You do not have the proper item or key to use this door.", oPC, TRUE);
   return;
  }
  //Otherwise they have the key..
  else
  {
   //If we are suppose to kill the key, then do it here..
   if(TAKE_KEY_ITEM==TRUE)
   {
    DestroyObject(oKey, 0.0);
   }
  }
 //End Check for Item..
 }

 //If we are suppose to use VFXs..
 if(USE_VFX == TRUE)
 {
  eVis =  EffectVisualEffect(VFX_TO_USE, FALSE);
  ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, oPC, 0.0);
  f1 = 2.5;
  f2 = 2.6;
 }

 //First see if we are teleporting the whole party..
 if(TELEPORT_PARTY==TRUE)
 {
   oParty = GetFirstFactionMember(oPC, SUMMONS_TELEPORT_TOO);
   while(GetIsObjectValid(oParty))
   {
    if(MEMBERS_IN_AREA==TRUE)
    {
     //If the Party Member is in the same area as the PC..
     if(GetArea(oParty)==oArea)
     {
      DelayCommand(f1, AssignCommand(oParty, ClearAllActions()));
      DelayCommand(f2, AssignCommand(oParty, ActionJumpToLocation(lLoc)));
     }
    }
    //Otherwise jump all party members!!
    else
    {
      DelayCommand(f1, AssignCommand(oParty, ClearAllActions()));
      DelayCommand(f2, AssignCommand(oParty, ActionJumpToLocation(lLoc)));
    }
    oParty = GetNextFactionMember(oPC, SUMMONS_TELEPORT_TOO);
   }

 //End Teleport Party Check..
 }

 //Otherwise see if we should teleport familiars & summons too
 else
 {
    //If we are suppose to teleport Summons / Familiars..
  if(SUMMONS_TELEPORT_TOO==TRUE)
  {
   oParty = GetFirstFactionMember(oPC, TRUE);
   while(GetIsObjectValid(oParty))
   {
    if(GetMaster(oParty)==oPC)
    {
     DelayCommand(f1, AssignCommand(oParty, ClearAllActions()));
     DelayCommand(f2, AssignCommand(oParty, ActionJumpToLocation(lLoc)));
    }
    oParty = GetNextFactionMember(oPC);
   }
  }
 }

 //Always teleport the PC / DM
 DelayCommand(f1, AssignCommand(oPC, ClearAllActions()));
 DelayCommand(f2, AssignCommand(oPC, ActionJumpToLocation(lLoc)));

//End valid check for PC / DM / Dm Possessed Creatures..
}

//Do nothing if it's not a PC / DM / or DM Possessed Creature..

//Main Script End
}

'B)'
               
               

               


                     Modifié par Genisys, 31 août 2010 - 01:21 .
                     
                  


            

Legacy_ehye_khandee

  • Hero Member
  • *****
  • Posts: 1415
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #18 on: August 31, 2010, 12:20:23 pm »


               Lots of errors in the script supplied.  ... for example, lines 96-120 are totally hashed. oPC is set at start as "object oPC = GetClickingObject();" the lines 96-120 will ONLY function on the oPC, meanwhile it runs through all iterations of the oPC's party pointlessly.  Though, somehow, you got the code fixed in the next section dealing with familiars.



I think you did not test this at all.



               
               

               
            

Legacy_Genisys

  • Hero Member
  • *****
  • Posts: 961
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #19 on: August 31, 2010, 02:23:18 pm »


               I didn't test it 100% no, sorry, and thank you for pointing out my errors.. '<img'>



I hope it's fixed now.. '<img'>
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #20 on: August 31, 2010, 02:27:52 pm »


               

ehye_khandee wrote...

Lots of errors in the script supplied.  ... for example, lines 96-120 are totally hashed. oPC is set at start as "object oPC = GetClickingObject();" the lines 96-120 will ONLY function on the oPC, meanwhile it runs through all iterations of the oPC's party pointlessly.  Though, somehow, you got the code fixed in the next section dealing with familiars.

I think you did not test this at all.

I really wonder you even take the time. When someone throws there script, a really loong script without any description what it does, I ignore it.
               
               

               
            

Legacy_ehye_khandee

  • Hero Member
  • *****
  • Posts: 1415
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #21 on: August 31, 2010, 06:36:32 pm »


               It is my habit to 'read code like a novel' and run it in my brain. I spot LOADS of errors in other ppls scripts this way. '<img'>



Always try to test your scripts before posting if at all, it avoids mis-informing others and wasting their time.

               
               

               
            

Legacy_Genisys

  • Hero Member
  • *****
  • Posts: 961
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #22 on: August 31, 2010, 09:57:42 pm »


               What's smoking?
               
               

               
            

Legacy_ehye_khandee

  • Hero Member
  • *****
  • Posts: 1415
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #23 on: August 31, 2010, 10:56:58 pm »


               

Genisys wrote...

What's smoking?





If you smell smoke, get out of the building!
               
               

               
            

Legacy_Redunct

  • Jr. Member
  • **
  • Posts: 85
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #24 on: August 31, 2010, 11:19:58 pm »


               Genisys had the right idea, script in the onFailToOpen, require a key and no key specified.

This should work, put it in the OnFailToOpen:

Void Main()
{
object oPC = GetClickingObject();
if (GetLocalInt(OBJECT_SELF,"Opened")!=0)
{
return;
}

SetLocalInt(OBJECT_SELF,"Opened",1);

if (//Place Condtional Here)
{
ActionUnlockDoor(OBJECT_SELF);
ActionOpenDoor(OBJECT_SELF);
return;
}
// Place What to do on failure here.

DelayCommand(1.0f, SetLocalInt(OBJECT_SELF,"Opened",0));
}


The Local Integer prevents the infinite loop that this kind of script is prone to. If you would like to make a check every time the player tries to open the door, you'd do it like this:

Void Main()
{
object oPC = GetClickingObject();
if (GetLocalInt(OBJECT_SELF,"Opened")!=0)
{
return;
}

SetLocalInt(OBJECT_SELF,"Opened",1);
DelayCommand(1.0f, SetLocalInt(OBJECT_SELF,"Opened",0));
if (//Place Condtional Here)
{
ActionUnlockDoor(OBJECT_SELF);
ActionOpenDoor(OBJECT_SELF);
return;
}
// Place What to do on failure here.
}



Then, place a Lock command and a Close command on a trigger or something. I'm sure you can figure out the rest.
               
               

               


                     Modifié par Redunct, 31 août 2010 - 10:20 .
                     
                  


            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #25 on: September 01, 2010, 12:00:30 am »


               Here is one for EK to look at:

void main()
{
object oPC = GetLastAttacker();
object oDatabase = GetItemPossessedBy(oPC, "database");
object oKey = GetItemPossessedBy(oPC, "KeyHovelKey");
object oDoor = OBJECT_SELF;
string sHovelOwner =  GetName (oPC,FALSE);
string sDoorName =  (sHovelOwner + "'s Hovel");
string sDoorName1 =  GetName (oDoor,FALSE);
    {
      if ((sDoorName1 == sDoorName) && (GetIsObjectValid (oKey)))
                  {
                  FloatingTextStringOnCreature("Your hovel door opens!", oPC,TRUE);
                  SetLocalInt(oDatabase,"HovelO", 1);
                  ActionUnlockObject(oDoor);
                  AssignCommand(oDoor, ActionOpenDoor(oDoor));
                  AssignCommand(oPC, ClearAllActions(TRUE));
                  return;
                  }
         //if the door name and the owners name match and they have the key open door.
         if ((GetLocalInt(oDatabase, "HovelO") < 1) && (GetIsObjectValid (oKey)) && (GetName (oDoor) == "Door"))
                  {
                  FloatingTextStringOnCreature("Your hovel door opens!", oPC,TRUE);
                  SetLocalInt(oDatabase,"HovelO", 1);
                  ActionUnlockObject(oDoor);
                  SetName (oDoor, sDoorName);
                  AssignCommand(oDoor, ActionOpenDoor(oDoor));
                  AssignCommand(oPC, ClearAllActions(TRUE));
                  }
        //key and Hovel Ownership ownership ok.  Now check that the door is fresh
        //that is unowned by another owner.  Thus the check for the Door name.
        //Original name of door must be Door.
       else if ((GetLocalInt(oDatabase, "Hovel0") > 0 ) || (sDoorName != sDoorName1))
         {
         {FloatingTextStringOnCreature("You already own a hovel, or wrong hovel!", oPC,TRUE);
         return;
         }
         //name on door an PC don't match plus local int indicates Hove Ownership

 }
}
}
This is not persistent, it is though with the rent a hovel program. So your get your name on the door temporarily. I just used bashing instead of on fail to open.
               
               

               


                     Modifié par ffbj, 31 août 2010 - 11:33 .
                     
                  


            

Legacy_Calgacus

  • Full Member
  • ***
  • Posts: 195
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #26 on: September 01, 2010, 12:41:05 am »


               Thanks,
Mabe I'll go with this algo:
1)when the labyrinth gets initailized all doors get cloased and locked -
2) labyrinth gets craved by  unlocked some doors,
3) when  player opens a door a var gets set on them - DoorControl = 1
4) when a player enters a room-trigger the var gets checked
4b) if the var ==1 then the players number of moves left gets decremented and the var gets reset to 0.

No more need to mess with the doors.

The alternative is to check the var whenever a door is opened and then close the door immediately if DoorControl == 1.   Then if the player entes a new area ( ie other than the last area trigger he was in) then that means the player has backtracked and will need to have his moved decremented twice ... UNLESS the area moved to was through the door but was also one that had been visited before ( but how would my script know? ) in which case his moves gets decremented once.   If I put the decrement move call in the door onopen script then a player could backtrack a long way through all those previously opened doors.

Seems the simplest solution is the first mentioned in this post.  The trouble with it is that the players will need to understand how that rule works or they could lose many turns just by pacing about idly.
Moves? Turns?   Yes, After every so many player moves (going from one room to another is a move) the dungeons monster moves and tries to hunt down the player.  The player gets so many moves per turn, then the gets its turn but the monster moves fewer rooms per turn than the player but can move through locked doors and sniff the player out.

Thanks again, I'm sure those tricks you all gave me will come in handy later.
               
               

               


                     Modifié par Calgacus, 31 août 2010 - 11:47 .
                     
                  


            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #27 on: September 01, 2010, 12:49:12 am »


               Just something else to add to the long and fabled history of messing with doors. How many have , been iviserated, mangled, mutilated, murdered, and otherwise messed up by doors? When you go into the dungeion in my world and see a locked door you stop, and that's what you should do, mostly...hehehe.

I must digress briefly to recapitulate an amusing antidote from my first campaign world.  We had a locked door to deal with and I started bashing it.  My companion began taking damage and continued to do so, and ran down the hall.  I continued to bash the door having no idea that I wasl damaging him every time I hit the door.  Well he never came back, though he survived as we finally figured out what was happening.  He healed up and I bashed the door once more just for fun.  That's when he left.  That was one of my early scripts.
               
               

               


                     Modifié par ffbj, 31 août 2010 - 11:53 .
                     
                  


            

Legacy_ehye_khandee

  • Hero Member
  • *****
  • Posts: 1415
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #28 on: September 01, 2010, 01:07:18 am »


               I think the efficient way to handle it is ->

LOCK all doors, and require NO key, setting each to an impossibly high DC for unlock.

Don't sweat having the door make clunky noises (some doors are just noisier than others).

Use the OnFailToOpen to check for a var on the PC named the same as the TAG of the door. If TRUE, open the door.

Use the OnAcquire script to set the respective vars on the PC when they pick up the right 'key/item' and destroy same in inventory to keep all inventories cleaner.

This means one brief script on the door, maybe 2-4 lines at most, and maybe 3 lines per door in the OnAcquire script. Pretty minimal in code, minimal in inventory; easy meat.

If you want to justify the noise of the door, - if it opens, just have it put text above the PC informing them that the door is a tight fit in the frame and gave some resistance, which the PC overcame.

My 2 cents worth.

':wizard:' 
               
               

               
            

Legacy_ehye_khandee

  • Hero Member
  • *****
  • Posts: 1415
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #29 on: September 01, 2010, 01:12:30 am »


               

ffbj wrote...

Here is one for EK to look at:

This is not persistent, it is though with the rent a hovel program. So your get your name on the door temporarily. I just used bashing instead of on fail to open.



Friend, 
   That script seems suspect to me. A bit of overkill in this instance, but more, you are using

AssignCommand(oDoor, ActionOpenDoor(oDoor));

oDoor = OBJECT_SELF

Never use AssignCommand on OBJECT_SELF as it can cause issues in a module. Commands not assigned execute on the OBJECT_SELF anyway.

*salute*

:innocent:




Still more efficiency can be had by not declaring the oDoor variable and just using OBJECT_SELF in its place where needed.
               
               

               


                     Modifié par ehye_khandee, 01 septembre 2010 - 12:13 .