Author Topic: Persistent date  (Read 353 times)

Legacy_Grani

  • Hero Member
  • *****
  • Posts: 1040
  • Karma: +0/-0
Persistent date
« on: January 15, 2013, 11:17:55 am »


                Does anyone have a script for persistent dates? I'm not building a single / local multi module and not a PW, but I want it to be kind of a "station" for players to visit and do some stuff when they have no other modules to play. So it's not a PW but similar to it in some aspects and so I wanted to have persistent date in it as well.

Thanks.
               
               

               
            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
Persistent date
« Reply #1 on: January 15, 2013, 03:12:24 pm »


               Although you dont think it is a PW - Technically it is.

Anything inside the nwn server can be said to be a world,
And if you are adding persistent content - it is a PW  (Persistent World)

When you say you want persistent dates - do you mean
1. Real World Dates ?
2. In-Game date progression that resumes after a reboot?


If the latter -
You will need to make use of either nwnx or the native Set/GetCampaignInt functions.

Eg- In onModLoad -



void LoadDate()
{
      int iDay =GetCampaignDBInt(GetModule(),"MOD_DAY");
      int iMonth =  GetCampaignDBInt(GetModule(),"MOD_MONTH");
      int iYear = GetCampaignDBInt(GetModule(),"MOD_YEAR");
       //Do not want to set the date to 0 0 0 - so the next if statement should accomodate that check.
      if(iDay > 0){
             SetCalendar(iDay , iMonth, iYear);
       }
}
void StoreDate()
{
      int iDay = GetCalendarDay();
      int iMonth = GetCalendarMonth();
      int iYear = GetCalendarYear();
      SetCampaignDBInt(GetModule(),"MOD_DAY",iDay);
      SetCampaignDBInt(GetModule(),"MOD_MONTH",iMonth);
      SetCampaignDBInt(GetModule(),"MOD_YEAR",iYear);

      DelayCommand(300.00,StartHB());
}
void main()
{
       LoadDate();
       StoreDate();

}

This code will load any persistently stored dates, then store the date in game on mod load, and every 5 minutes after.
You do not want to store the time/date every heartbeat - as the native bioware database functions are very laggy.
Do it every 5 minutes will be ok.


Then.
               
               

               
            

Legacy_Grani

  • Hero Member
  • *****
  • Posts: 1040
  • Karma: +0/-0
Persistent date
« Reply #2 on: January 15, 2013, 03:41:25 pm »


               

Baaleos wrote...

Although you dont think it is a PW - Technically it is.

Anything inside the nwn server can be said to be a world,
And if you are adding persistent content - it is a PW  (Persistent World)

When you say you want persistent dates - do you mean
1. Real World Dates ?
2. In-Game date progression that resumes after a reboot?


If the latter -
You will need to make use of either nwnx or the native Set/GetCampaignInt functions.

Eg- In onModLoad -



void LoadDate()
{
      int iDay =GetCampaignDBInt(GetModule(),"MOD_DAY");
      int iMonth =  GetCampaignDBInt(GetModule(),"MOD_MONTH");
      int iYear = GetCampaignDBInt(GetModule(),"MOD_YEAR");
       //Do not want to set the date to 0 0 0 - so the next if statement should accomodate that check.
      if(iDay > 0){
             SetCalendar(iDay , iMonth, iYear);
       }
}
void StoreDate()
{
      int iDay = GetCalendarDay();
      int iMonth = GetCalendarMonth();
      int iYear = GetCalendarYear();
      SetCampaignDBInt(GetModule(),"MOD_DAY",iDay);
      SetCampaignDBInt(GetModule(),"MOD_MONTH",iMonth);
      SetCampaignDBInt(GetModule(),"MOD_YEAR",iYear);

      DelayCommand(300.00,StartHB());
}
void main()
{
       LoadDate();
       StoreDate();

}

This code will load any persistently stored dates, then store the date in game on mod load, and every 5 minutes after.
You do not want to store the time/date every heartbeat - as the native bioware database functions are very laggy.
Do it every 5 minutes will be ok.


Then.




Thanks for the reply!
I meant in-game date progression, not real world dates.
Yeah, technically it will be Persistent World, but I meant to say that it will be local and not really suited for hosting all the time.

Will try this script, thank you!
               
               

               


                     Modifié par Grani, 15 janvier 2013 - 03:42 .
                     
                  


            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Persistent date
« Reply #3 on: January 16, 2013, 05:10:02 am »


               I use functions similar to Baaleos but you only need to store one Int. And instead of using a recursive delay or HB I just put the function all over the place (OnPlayerRest, area OnEnter/OnExit, etc.). However I do manually go in and adjust my server starting month, starting day and starting hour to 1, 1, 0. Just another way of doing it:


void SaveCurrentDateTime()
{
    int iYear  = GetCalendarYear();
    int iMonth = GetCalendarMonth();
    int iDay   = GetCalendarDay();
    int iHour  = GetTimeHour();
    int iDate  = (iYear * 8064) + ((iMonth - 1) * 672) + ((iDay -1) * 24) + iHour;

    //SetPersistentInt(GetModule(), "INT_DATE_TIME", iDate);
    SetCampaignInt("MODULE1", "DATE_TIME", iDate);
}

void LoadPersistentDateTime()
{
    //int iDate = GetPersistentInt(GetModule(), "INT_DATE_TIME");
    int iDate = GetCampaignInt("MODULE1", "DATE_TIME");
    if (iDate)
    {
        int iYear  = iDate / 8064;
        int iMonth = ((iDate % 8064) / 672) + 1;
        int iDay   = ((iDate % 672) / 24) + 1;
        int iHour  = iDate % 24;

        SetCalendar(iYear, iMonth, iDay);
        SetTime(iHour, GetTimeMinute(), GetTimeSecond(), GetTimeMillisecond());
        SaveCurrentDateTime();
    }
    else
    {
        SaveCurrentDateTime();
    }
}
               
               

               


                     Modifié par GhostOfGod, 16 janvier 2013 - 08:58 .
                     
                  


            

Legacy_Knight_Shield

  • Hero Member
  • *****
  • Posts: 812
  • Karma: +0/-0
Persistent date
« Reply #4 on: January 23, 2013, 12:50:13 am »


               Im a little confused here .

I been using this to keep date persistent .
Do I need something to advance time also?


 onmoduleload

void main()
{
   pc_export_onmoduleload();

   ExecuteScript("x2_mod_def_load",OBJECT_SELF);

object oMod = GetModule();
   event DEvent = EventUserDefined(5000);
   if(GetDateInitialized())
{
       int iDate = GetSavedDate();
       DelayCommand(HoursToSeconds(1),SignalEvent(oMod,DEvent));
       struct Date D = DecodeDate(iDate);
       SetTime(D.Hour,1,0,0);
       SetCalendar(D.Year,D.Month,D.Day);
       } else {
       SignalEvent(oMod,DEvent);
       InitializeDate();
       }
}

user defined
//::////////////////////////////////////////////////::CreatedBy:LordDelekhan//::CreatedOn:March17,2005//:://////////////////////////////////////////////#include "ld_clock_inc"

void main()
{    int nUser=GetUserDefinedEventNumber();   
switch(nUser)       
{        case 5000:           
{            object oMod = GetModule();         
  event DEvent = EventUserDefined(5000);         
  int iDate = GetCurrentDate();   
        SetSavedDate(iDate);     
      DelayCommand(HoursToSeconds(1),SignalEvent(oMod,DEvent));     
      break;         
  }     
  }}
               
               

               


                     Modifié par Knight_Shield, 23 janvier 2013 - 12:55 .
                     
                  


            

Legacy_Squatting Monk

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +0/-0
Persistent date
« Reply #5 on: January 23, 2013, 03:27:27 am »


               I'm guessing the SetSavedDate() function is saving the current date to the database? If so, that ought to do you fine. The clock advances on its own (usually, and NWNX fixes the times it doesn't), so that should be all you need.