Author Topic: Scripts to Advance time?  (Read 370 times)

Legacy_Rowwena

  • Jr. Member
  • **
  • Posts: 62
  • Karma: +0/-0
Scripts to Advance time?
« on: July 04, 2011, 01:11:33 am »


               Hi,

Wondering if anyone knows and fairly simple way to force the
clock to advance when moving between areas?  As the default in NWN, if
you travel from one area to another time stays the same, which is fine
if it is two areas in the same city, for example. But when your area
transition is supposed to represent something such as a two day walk, or
a one week sea voyage, it would be nice if the in game clock/calendar
would advance to reflect this.

Any suggestions or links would be greatly appreciated.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Scripts to Advance time?
« Reply #1 on: July 04, 2011, 01:25:36 am »


               It is not that hard to advance the clock.  You just need to use several functions to get the current time:

GetTimeMillisecond
GetTimeSecond
GetTimeMinute
GetTimeHour
Then adjust them the way you want. then use:

SetTime

To adjust the clock to where you want it.  It would not be that hard to write a function for it. 

But first let me clearly state that this has no place in a multiplayer game.  The game clock is the same for every player in the game.  You do not want to create a system where one player moving from one area to another make the battle another player is fighting last for three days.  The real draw back to this is that it would strip any temp effects from the players fighting the battle.  The durration of things like cats grace or bulls strength it tied to the game clock.  

Even if you have all the players in one party, you would not want the clock to advance for every one that steped through.

So this should only be used in a single player game.   It that the type of module you are writing?  
               
               

               
            

Legacy_Rowwena

  • Jr. Member
  • **
  • Posts: 62
  • Karma: +0/-0
Scripts to Advance time?
« Reply #2 on: July 04, 2011, 02:11:40 am »


               Yes. I am making a single player stand alone Mod.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Scripts to Advance time?
« Reply #3 on: July 04, 2011, 03:12:17 am »


               void AdvanceClock(int hours,int days=0,int months=0,int years=0);
void AdvanceClock(int hours,int days=0,int months=0,int years=0)
{
  hours  +=GetTimeHour();
  days   +=GetCalendarDay();
  months +=GetCalendarMonth();
  years  +=GetCalendarYear();
  days   +=hours/24;
  hours  = hours%24;
  SetTime(hours,GetTimeMinute(),GetTimeSecond(),GetTimeMillisecond());
  SetCalendar(years,months,days);
}


Do you need help adding the function to your transistions?
Or can you take it from here?
               
               

               


                     Modifié par Lightfoot8, 04 juillet 2011 - 02:15 .
                     
                  


            

Legacy_Rowwena

  • Jr. Member
  • **
  • Posts: 62
  • Karma: +0/-0
Scripts to Advance time?
« Reply #4 on: July 04, 2011, 07:02:22 am »


               If you could help with how to set it into the transition please I would appreciate it. I have tried but cannot quite figure how to make it compile properly.
               
               

               
            

Legacy_CID-78

  • Sr. Member
  • ****
  • Posts: 261
  • Karma: +0/-0
Scripts to Advance time?
« Reply #5 on: July 04, 2011, 07:07:51 am »


               it's a function. you must call it from a script with the parameters you want.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Scripts to Advance time?
« Reply #6 on: July 04, 2011, 08:19:52 am »


               ok,  Here is what the script for an area transistion wold look like.  This one advances the clock 10 hours and 10 months   To change the amount of time just change the numbers feed to the function in the main body of the script.

void AdvanceClock(int hours,int days=0,int months=0,int years=0);
void AdvanceClock(int hours,int days=0,int months=0,int years=0)
{
  hours  +=GetTimeHour();
  days   +=GetCalendarDay();
  months +=GetCalendarMonth();
  years  +=GetCalendarYear();
  days   +=hours/24;
  hours  = hours%24;
  SetTime(hours,GetTimeMinute(),GetTimeSecond(),GetTimeMillisecond());
  SetCalendar(years,months,days);
}

void main()
{
  object oPC= GetEnteringObject();
  if(GetIsPC(oPC)) AdvanceClock(10,0,10);
  location lLoc =  GetLocation( GetTransitionTarget(OBJECT_SELF));
  JumpToLocation(lLoc);


               
               

               
            

Legacy_Rowwena

  • Jr. Member
  • **
  • Posts: 62
  • Karma: +0/-0
Scripts to Advance time?
« Reply #7 on: July 04, 2011, 08:47:03 am »


               Thanks so much Lightfoot. It works like a charm.

I did not really know much about the use of functions - thanks CID for pointing that out. I was able to find a working link to the NWN Wiki, and was going to try my hand at reworking their example of using a function. I will do that next time I need to do one '<img'>

Thanks again
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Scripts to Advance time?
« Reply #8 on: July 04, 2011, 09:00:20 am »


               There is really nothing spescial about functions.   If you have done any NWN scripting at all, you have already used many functions.
 
GetEnteringObject();
GetFirstPC();
SetLocalInt(oObject,sName,nValue);

They are all functions.  What they do has just already been defined elswhere.  
The only differance here is that we created a new function to advance the clock.  The declairation of the function contains information on how we are going to call the function, when we want to use it.
void AdvanceClock(int hours,int days=0,int months=0,int years=0);

and what we want the function to do once it is called.  Which is everything inbtween the { & }

The code in the function itself is never ran untill it is called from the main body of a script.
: