Author Topic: Locking things at certain times of day  (Read 616 times)

Legacy_JerrodAmolyan

  • Full Member
  • ***
  • Posts: 175
  • Karma: +0/-0
Locking things at certain times of day
« on: October 16, 2013, 05:06:19 pm »


               So as it says in the title.

I'm trying to get doors lock at night, and open again in the morning, so far I haven't been able to however, not sure why. I tried making a heartbeat script for the doors

void main()
{
    object oSelf = OBJECT_SELF;

    // If it is night.    if ( GetIsNight() )    {        SetLocked(oSelf, TRUE);        SetLockKeyRequired(oSelf);        SetLockKeyTag(oSelf, "jer_masterkey");        SetLockLockable(oSelf, FALSE);    }    else    {        SetLocked(oSelf, FALSE);    }} 

So this doesn't work. I tried to make it so it locks at night, "OnFailedtoOpen" has a line which does work, that opens the door if it's daytime and doesn't if it's night. 

Any great ideas ?
               
               

               
            

Legacy_HipMaestro

  • Hero Member
  • *****
  • Posts: 2849
  • Karma: +0/-0
Locking things at certain times of day
« Reply #1 on: October 16, 2013, 06:36:56 pm »


               OnHeartbeat might miss the exact moment when the hour is reached, no?
               
               

               


                     Modifié par HipMaestro, 16 octobre 2013 - 05:41 .
                     
                  


            

Legacy_JerrodAmolyan

  • Full Member
  • ***
  • Posts: 175
  • Karma: +0/-0
Locking things at certain times of day
« Reply #2 on: October 16, 2013, 08:29:27 pm »


               Hmmm... would it then help to make it do this between hours 18 and 6 ?
               
               

               
            

Legacy_Squatting Monk

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +0/-0
Locking things at certain times of day
« Reply #3 on: October 16, 2013, 09:12:38 pm »


               Hmm... I don't see any reason the HB script wouldn't work. Have you confirmed you're actually testing it at night and not at dusk?
               
               

               
            

Legacy_Fester Pot

  • Hero Member
  • *****
  • Posts: 1698
  • Karma: +0/-0
Locking things at certain times of day
« Reply #4 on: October 16, 2013, 10:05:54 pm »


               

void main()
{

object oDoor1 = GetObjectByTag("DOOR_TAG_HERE");

if (GetIsDusk() || GetIsNight())
   {
   AssignCommand(oDoor1, SetLocked(oDoor1, TRUE));
   }
}


The above script works when using the TAG of the particular door. Not sure what all that other stuff is with those FALSE and TRUE. Perhaps it does the same thing, but I've always liked spelling things out in a script to fully understand it since I'm not a script master myself.

Perhaps that will get you going in the direction.

Additionally, I'd rather just put everything in the ModuleHeartBeat script, and close everything at the required time all at once, rather than firing scripts for every individual door.

Another option, if you don't want to go that route, is to lock all doors OnEnter of the specified area and avoid the heartbeat altogether. Then doors only lock/open when the area is entered.

FP!
               
               

               


                     Modifié par Fester Pot, 16 octobre 2013 - 09:07 .
                     
                  


            

Legacy_JerrodAmolyan

  • Full Member
  • ***
  • Posts: 175
  • Karma: +0/-0
Locking things at certain times of day
« Reply #5 on: October 16, 2013, 10:37:08 pm »


               Thanks for the answers. I'm looking to do this kind of default script with no tag, but instead oSelf, so I can just use the same script on every door. Too many heartbeat scripts can cause lots of crap I'm told, so I'm minimizing stuff by making as much defaults as possible.

Also, I did test at dusk, at night and waited till dawn, it doesn't lock '<img'>
               
               

               
            

Legacy_Squatting Monk

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +0/-0
Locking things at certain times of day
« Reply #6 on: October 16, 2013, 11:08:49 pm »


               While making the script generic instead of specific to a tag is a good idea, it's not going to do much to reduce lag from heartbeats. 100 doors running heartbeats still executes 100 heartbeat scripts, regardless of whether it's 100 scripts one time or one script 100 times.

This is why FP's suggestion to run that off the module heartbeat is a good idea. Instead of 100 scripts each checking the time of day every six seconds, the module can check it once and then, if it's night, update all the doors (and it's probably best to lock the doors once when the time of day changes rather than repeatedly every six seconds).

Also, while the module heartbeat should always fire, server load can cause NPC, placeable, and door heartbeats to lose priority, either firing less often or not at all.
               
               

               


                     Modifié par Squatting Monk, 16 octobre 2013 - 10:37 .
                     
                  


            

Legacy_kalbaern

  • Hero Member
  • *****
  • Posts: 1531
  • Karma: +0/-0
Locking things at certain times of day
« Reply #7 on: October 16, 2013, 11:11:17 pm »


               What I've seen used in several HCR Modules is that doors are set as locked when placed and you use a script in the doors OnFailToOpen event that unlocks and opens the door during the desired times, then relocks and closes it after a delay.
               
               

               
            

Legacy_JerrodAmolyan

  • Full Member
  • ***
  • Posts: 175
  • Karma: +0/-0
Locking things at certain times of day
« Reply #8 on: October 17, 2013, 10:36:58 am »


               I might just go with Kalbaern's "suggestion" it was something that I thought about already, but some players just see a locked door and think it's another key required barricade. BUT that's their loss I guess.

Squatting: Yep, I realized that too when I thought about it. The thing is though, that if there's many different scripts that do basicly the same thing, firstly it atleast crowds the already large list of scripts, and second it might produce other results of unwanted type. Of the latter I'm not sure.
The module scripts are unaccessible to me, otherwise it'd be a good idea. This project I'm doing now, is for another server, and the module scripts are handled by another fellow, so I'll have to work without using the module scripts.
               
               

               
            

Legacy_Squatting Monk

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +0/-0
Locking things at certain times of day
« Reply #9 on: October 17, 2013, 09:27:38 pm »


               

JerrodAmolyan wrote...

I might just go with Kalbaern's "suggestion" it was something that I thought about already, but some players just see a locked door and think it's another key required barricade. BUT that's their loss I guess.

Just set the door to say something like, "This door is locked for the night."

Squatting: Yep, I realized that too when I thought about it. The thing is though, that if there's many different scripts that do basicly the same thing, firstly it atleast crowds the already large list of scripts

Absolutely. Genericize scripts wherever it's practical. It's easier on the builder, decreases module size, and can improve the performance of the built-in script caching.
               
               

               
            

Legacy_JerrodAmolyan

  • Full Member
  • ***
  • Posts: 175
  • Karma: +0/-0
Locking things at certain times of day
« Reply #10 on: October 18, 2013, 08:57:28 am »


               Yeah, I made the doors speak a string when it's night, instead of opening "The door is barred from the inside at night, there's no way to open it now."
Problem is, that usually when there's a locked door to a normal looking house, the players just ignore it because typically it's just a filler for the holes in the walls '<img'>
WELL Like I said, their loss.

Now this thing works, not as I first wanted, but this solution to have the door lock and unlock on fail to open and so is maybe better, since it doesn't now have a heartbeat at all.