Skip to content

Can I script an event that only occurs on a specific day of the month

I would like a password stored on a (door, object, or invisible creature) to change on the 11 day of each game time month. It is possible to script this without using the onheartbeat timer? If so how?

Comments

  • ForSeriousForSerious Member Posts: 466
    Good question.
    Though there is a calendar of sorts built into the game, it's been implemented as measurement tool rather then an event driver.
    For the sake answering your question: Yes you can, but it's not really any better than onHeartBeat.
    You can do it recursively by calling DelayCommand(ExecuteScript()). It's not really any better then onHeartBeat because the amount of seconds you would need to delay it by is huge, and the module level onHeartBeat will be called several times during that time either way.

    The other way to do it, is like this:
    Store a timestamp of when the password will expire. (The next 11th from the current date.)
    Now you have two options.
    1. Check if the password has expired in the main HeartBeat script. If so, change it, and update the stored timestamp.
    2. When someone tries to use/enter/accuire the password, check if it's expired and change it. This would still work if no one had tried enter the password for three months, so it didn't get changed in all that time. No one needs to know that, and because it checks for expiration first, no one's going to be able to get in with a months old password.

    Let me know if you need help with timestamps or any of the coding on it.
  • QuilistanQuilistan Member Posts: 186
    thanks for the reply!

    I have seen a time stamp script before, but I am not sure on how to check if it has advanced or not? Since the time is a month/day/year type thing. I am use to running timers and heartbeat checks.

    I am going to be away for a few days.... vacation.

    will certainly be checking back here when I get home.
  • ForSeriousForSerious Member Posts: 466
    edited August 2021
    Timestamps are not as simple as they could be, that's for sure.
    Here is what I have for timestamps.
    // Gets the timestamp that is on the 11th one month into the future.
    int GetFutureTimestamp();
    
    // Gets the current in game time stamp in format YYYYMMDD.
    int GetCurrentTimestamp();
    // Pads a two digit number with a zero if needed.
    string AddZero(int iNumber);
    
    int GetFutureTimestamp()
    {
        int iYear = GetCalendarYear();
        int iMonth = GetCalendarMonth();
        if(iMonth == 12)
        {
            // Roll over to the next year.
            iYear = iYear + 1;
            iMonth = 1;
        }
        else
        {
            iMonth = iMonth + 1;
        }
        // Make the timestamp.
        string sDate = IntToString(iYear) + AddZero(iMonth) + "11";
        return StringToInt(sDate);
    }
    int GetCurrentTimestamp()
    {
        string sTimestamp = IntToString(GetCalendarYear()) + AddZero(GetCalendarMonth()) + AddZero(GetCalendarDay());
        return StringToInt(sTimestamp);
    }
    string AddZero(int iNumber)
    {
        string sParsed = IntToString(iNumber);
        if(GetStringLength(sParsed) == 1)
        {
            return "0" + sParsed;
        }
        return sParsed;
    }
    

    After changing the password, you would call GetFutureTimestamp() and save that locally or to a database. (I think locally makes more since, unless you have some script that saves the game date over resets.)
    Then to check if it's expired it's as easy as if([savedTimestamp] < GetCurrentTimestamp()).
  • ForSeriousForSerious Member Posts: 466
    @slayster just posted an other way to do this. It might be a little more accurate and to your liking.
  • meaglynmeaglyn Member Posts: 151
    That's different. This is for in game time, that one is for real (out of game) time and timestamps.
  • BuddywarriorBuddywarrior Member Posts: 62
    edited September 2021
    Edit * retracting the idea. Was pointed out that you do not want to use OnHeartbeat, my dumb brain skipped right over that.
    Post edited by Buddywarrior on
Sign In or Register to comment.