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

Legacy_Calgacus

  • Full Member
  • ***
  • Posts: 195
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« on: August 29, 2010, 11:29:41 pm »


               Before I allow  a character to open a door I want to check a variable on the character.  If the variable is set to 0 allow the door to open, else do not.  Can I use the onuserdefined event this way? Or will the open event finish before it can be interrupted.  If so how? 
I'd rather not prelock all the doors and then run a script in the onfailedtoopen event, that would be bad  because the player would fail to open the door (play locked door sounds) and then it would open.
               
               

               
            

Legacy_Shadooow

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


               I don't know about any way.

Guess prelocking them is only way, but you can use key instead of variable - then if the pplayer have it he wont fail to open. However if you want to do this for all doors, it maybe isn't workable, depends on the number of different variables/keys you need.

The key also appers in inventory, the best way to workaround this would be using NWNX function to change the tag of the some item (skin, PC ID, anything that every character start with).

EDIT: OnUserDefined won't let you do it, this event's usage is very limited, itss good only for day/time events executed from heartbeat or for making scripts for doors if you have some script system installed that uses all events and you don't want to mess with it.
               
               

               


                     Modifié par ShaDoOoW, 29 août 2010 - 10:50 .
                     
                  


            

Legacy_Calgacus

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


               Thanks,

the keys, that might work but would be a little awkward, my labyrinth is basically made of locked doors. so a bunch of keys appearing and disappearing as the char walks around would be ugly.  I guess I could set all doors to open only  by key but I need some to not open at all. I could set the openable doors to open by key the others to not open at all.  Then when a character opens a door he uses a key up and when he walks into the new room he gets a new key so he can open a new door.  the real issue is that I don't want a character to open two doors in the same room without first moving into the new room he opens a door into.

               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #3 on: August 30, 2010, 12:21:45 am »


               How about if you place a trigger in front of each door. If the character can open the door unlock it. If he can't, lock it if it is not already.

You could even make it a generic script to just find the closest door for to the trigger, so you dont have to have a script for each door/trigger set up.
               
               

               


                     Modifié par Lightfoot8, 29 août 2010 - 11:22 .
                     
                  


            

Legacy_Shadooow

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


               Trigger might work too, but depends on enviroment if its just for one area, guess its the best way. However getting automatically closest door from trigger won't work correctly since the location of trigger is IIRC the west-southest corner.
               
               

               
            

Legacy_Calgacus

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


               the trigger idea would mean drawing a 112 triggers and putting variables on them and still more scripting.  I think I'll go with my idea of just setting a variable on the pc when they open doors, then each rooms trigger area (i hav ethese already drawn) will check for it and if the pc has it set then they get teleported back to the place they were when the door was opened.  Unless there's an easier way to set a trigger area as being unenterable by a pc - is there?
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #6 on: August 30, 2010, 01:04:36 am »


               Ok,  Now I feel like a fool.  Use a trigger on the door itself ( A custom trap script)



set it active and uncheck the detectable/disarmable/oneshot.   You then have your trigger that will fire befor the door is opened.  Of course you will have the trap/trigger open the door.
               
               

               
            

Legacy_Calgacus

  • Full Member
  • ***
  • Posts: 195
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #7 on: August 30, 2010, 01:10:57 am »


               interesting.  will the door trigger prevent the door opening?  I guess if it fires first it can lock the door before the open event hits the door?  or does the trigger eat the open event - its own script could do the opening if checks are passed I guess?  that might be the best way.
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #8 on: August 30, 2010, 01:20:28 am »


               

Lightfoot8 wrote...

Ok,  Now I feel like a fool.  Use a trigger on the door itself ( A custom trap script)

set it active and uncheck the detectable/disarmable/oneshot.   You then have your trigger that will fire befor the door is opened.  Of course you will have the trap/trigger open the door.

+1 however dont forget to recreate this trap after the doors are opened/closed, well at least if you plan to re-use them.
               
               

               
            

Legacy_Calgacus

  • Full Member
  • ***
  • Posts: 195
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #9 on: August 30, 2010, 01:45:36 am »


               So if a door is opened it will lose its trigger?

Also, when i make my custom trap how do i select it as the trap type?  and can I suppress the "Trap Triggered" message?
               
               

               
            

Legacy_Shadooow

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


               

Calgacus wrote...
will the door trigger prevent the door opening?  I guess if it fires
first it can lock the door before the open event hits the door?  or does
the trigger eat the open event - its own script could do the opening if
checks are passed I guess?  that might be the best way.

yes it should prevent the opening the door

Calgacus wrote...

So if a door is opened it will lose its trigger?

Well depends, I wasn't correct before. LightFoot8 suggested you to set trap as NOT one shot. If you do this the trap will not goes away. The other approach is to set is as one shot, but nothing will get changed, except you have to recreate the trap, well maybe it could be used for something, but forget it for now.

Also, when i make my custom trap how do i select it as the trap type?  and can I suppress the "Trap Triggered" message?

Select any type, if does not matter if you use custom script in OnTrapTriggered which you have to do.

Unfortunately only way to get rid of trap triggered message is to delete this message from the dialog.tlk, but still best solution.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #11 on: August 30, 2010, 02:16:49 am »


               I hae decided that I do not like the trap option after testing.  The reason is that there is no way to get rid of the "you triggered a trap' from floating over your head.  



the best option seems to be to use the "OnDoorOpened' event.   In my testing  just telling the door to reclose it's self  is enough to have the door never open.  



I placed this in the Even and could not budge the door.  



void main()

{

 ActionCloseDoor(OBJECT_SELF);

}



So there is your answer.  If they have the proper var do nothing.  if they dont close the door.  



To answer you questions above.  No the door will not lose its trigger if the "oneshot" is unchecked on the trap tab.  But since i never disarmed the traps in my test this may be ther reason i was still getting the trap feed back to the PC.



When you make a custom trap script and place it in the OnTrapTriggered event it take the place of the standerd trap setting scripts, so they will not fire in addition to the custom script.





As a second note.  Since you are going to most likely be setting you doors to plot so that they can not be damaged.  You could use your door stats instead of a local int on the door for who can open it.   ( hardness/HP/fort save/reflex save/ willsave.   for exsample



void main()

{

 if (GetHardness()!= GetLocalInt(GetLastOpenedBy(),"DoorControl"))

 {

     ActionCloseDoor(OBJECT_SELF);

     PlayVoiceChat(VOICE_CHAT_CUSS,GetLastOpenedBy());

 }

}
               
               

               
            

Legacy_Calgacus

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


               

Lightfoot8 wrote...

I hae decided that I do not like the trap option after testing.  The reason is that there is no way to get rid of the "you triggered a trap' from floating over your head.  

the best option seems to be to use the "OnDoorOpened' event.   In my testing  just telling the door to reclose it's self  is enough to have the door never open.  

I placed this in the Even and could not budge the door.  

void main()
{
 ActionCloseDoor(OBJECT_SELF);
}

So there is your answer.  If they have the proper var do nothing.  if they dont close the door.  


SWEET!!!!  Thats it.

To answer you questions above.  No the door will not lose its trigger if the "oneshot" is unchecked on the trap tab.  But since i never disarmed the traps in my test this may be ther reason i was still getting the trap feed back to the PC.

When you make a custom trap script and place it in the OnTrapTriggered event it take the place of the standerd trap setting scripts, so they will not fire in addition to the custom script.


As a second note.  Since you are going to most likely be setting you doors to plot so that they can not be damaged.  You could use your door stats instead of a local int on the door for who can open it.   ( hardness/HP/fort save/reflex save/ willsave.   for exsample

void main()
{
 if (GetHardness()!= GetLocalInt(GetLastOpenedBy(),"DoorControl"))
 {
     ActionCloseDoor(OBJECT_SELF);
     PlayVoiceChat(VOICE_CHAT_CUSS,GetLastOpenedBy());
 }
}


I don't need that var on the door just the PC eg:

void main()
{
    if (TRUE == GetLocalInt(GetLastOpenedBy(),"DoorControl"))
    {
           ActionCloseDoor(OBJECT_SELF);
           PlayVoiceChat(VOICE_CHAT_CUSS,GetLastOpenedBy());
    }
}

and then in my other area triggers (covering the floor in each room)


void main()

{

    if ( pc_has_entered_a_new_room )

    {
       setLocalInt(oPC,"DoorControl", 0);
    }else{
       // do nothing
       return;
   }
   //   ...
   ///  do other stuff
   //  ...

}

Thanks !!
               
               

               


                     Modifié par Calgacus, 30 août 2010 - 01:51 .
                     
                  


            

Legacy_Calgacus

  • Full Member
  • ***
  • Posts: 195
  • Karma: +0/-0
how to: capture attempt to open door before it is opened?
« Reply #13 on: August 30, 2010, 03:07:40 am »


               thought you might like to see what it looks like: http://calgacus.game...rinthingame.bmp

this is a link to an image of the chessboard version of the labyrinth. the red areas are the walls drawn with traps, the player reveals them one by one as he bumps into them trying to move around.  The scripts make a new labyrinth each time the mini-game is played.

 The dungeon version with the doors just looks like  the standard dungeon tiles with square rooms and those big dungeon doors that rise up between the rooms.



Thanks again.
               
               

               
            

Legacy_Genisys

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


               nvm, looks like you got your answers above... '<img'>

Prelocked with fake key name (not openable) with a OnFailToOpen script is the best way to handle it all... good suggestions guys.. '<img'>
               
               

               


                     Modifié par Genisys, 30 août 2010 - 06:37 .