Author Topic: Setting the exact time  (Read 413 times)

Legacy_Ed Venture

  • Full Member
  • ***
  • Posts: 200
  • Karma: +0/-0
Setting the exact time
« on: February 01, 2014, 02:32:17 pm »


               Wanted to set the exact game time, when a player enters an area.
This script works, but there's got to be an easier way.

 int nHr = GetTimeHour();
 int nMn = GetTimeMinute();
 int nSc = GetTimeSecond();
 int nMs = GetTimeMillisecond();
 int nYr = GetCalendarYear();
 int nMh = GetCalendarMonth();
 int nDy = GetCalendarDay();
 nDy += 12;
 if(nHr == 20)
 {
  SetTime(nHr+23,nMn,nSc,nMs);
 }
 else
 {
  if(nHr == 21)
  {
   SetTime(nHr+22,nMn,nSc,nMs);
  }
  else
  {
   if(nHr == 22)
   {
    SetTime(nHr+21,nMn,nSc,nMs);
   }
   else
   {
    if(nHr == 23)
    {
     SetTime(nHr+20,nMn,nSc,nMs);
    }
    else
    {
     if(nHr == 0)
     {
      SetTime(nHr+19,nMn,nSc,nMs);
     }
     else
     {
      if(nHr == 1)
      {
       SetTime(nHr+18,nMn,nSc,nMs);
      }
      else
      {
       if(nHr == 2)
       {
        SetTime(nHr+17,nMn,nSc,nMs);
       }
       else
       {
        if(nHr == 3)
        {
         SetTime(nHr+16,nMn,nSc,nMs);
        }
        else
        {
         if(nHr == 4)
         {
          SetTime(nHr+15,nMn,nSc,nMs);
         }
         else
         {
          if(nHr == 5)
          {
           SetTime(nHr+14,nMn,nSc,nMs);
          }
          else
          {
           if(nHr == 6)
           {
            SetTime(nHr+13,nMn,nSc,nMs);
           }
           else
           {
            if(nHr == 7)
            {
             SetTime(nHr+12,nMn,nSc,nMs);
            }
            else
            {
             if(nHr == 8)
             {
              SetTime(nHr+11,nMn,nSc,nMs);
             }
             else
             {
              if(nHr == 9)
              {
               SetTime(nHr+10,nMn,nSc,nMs);
              }
              else
              {
               if(nHr == 11)
               {
                SetTime(nHr+9,nMn,nSc,nMs);
               }
               else
               {
                if(nHr == 12)
                {
                 SetTime(nHr+8,nMn,nSc,nMs);
                }
                else
                {
                 if(nHr == 13)
                 {
                  SetTime(nHr+7,nMn,nSc,nMs);
                 }
                 else
                 {
                  if(nHr == 14)
                  {
                   SetTime(nHr+6,nMn,nSc,nMs);
                  }
                  else
                  {
                   if(nHr == 15)
                   {
                    SetTime(nHr+5,nMn,nSc,nMs);
                   }
                   else
                   {
                    if(nHr == 16)
                    {
                     SetTime(nHr+4,nMn,nSc,nMs);
                    }
                    else
                    {
                     if(nHr == 17)
                     {
                      SetTime(nHr+3,nMn,nSc,nMs);
                     }
                     else
                     {
                      if(nHr == 18)
                      {
                       SetTime(nHr+2,nMn,nSc,nMs);
                      }
                      else
                      {
                       if(nHr == 19)
                       {
                        SetTime(nHr+1,nMn,nSc,nMs);
                       }
                      }
                     }
                    }
                   }
                  }
                 }
                }
               }
              }
             }
            }
           }
          }
         }
        }
       }
      }
     }
    }
   }
  }
 }
 SetCalendar(nYr,nMh,nDy);
Ed
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Setting the exact time
« Reply #1 on: February 01, 2014, 02:45:24 pm »


               

Ed Venture wrote...

Wanted to set the exact game time, when a player enters an area.
This script works, but there's got to be an easier way.


I am assuming that not including 10 was an oversight as well as the one hour shift it produced.  If this is the case then all those if statements simplify to:

 if(nHr >= 20)   SetTime(43,nMn,nSc,nMs);
else SetTime(19, nMn, nSc, nMs);
               
               

               


                     Modifié par WhiZard, 01 février 2014 - 02:45 .
                     
                  


            

Legacy_Ed Venture

  • Full Member
  • ***
  • Posts: 200
  • Karma: +0/-0
Setting the exact time
« Reply #2 on: February 01, 2014, 03:11:29 pm »


               WhiZard ,
Oversight, what a tactful way of asking, are you stupid ?
Why, yes ! Yes I am !
Thanks for your help. I knew there had to be an easier way.
As a noob I always try to translate a script as I read it.
One more question.
if(nHr >= 20)   SetTime(43,nMn,nSc,nMs);

if(GetTheCurrentHour, Is greater or equall to 20), SetTheTime(43,and son on)
I do not understand what the int. 43 is doing.
Ed
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Setting the exact time
« Reply #3 on: February 01, 2014, 04:15:12 pm »


               43 is the solution to all your additions: 20+23, 21+22, etc.  this seems intentional as it is 24 (24 hours is one day) greater than 19.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Setting the exact time
« Reply #4 on: February 01, 2014, 04:49:55 pm »


               I am not sure you are trying to arive at 19:00 or 20:00. 12 days later. either way your script can be simplified to.

void main ()
{
   SetTime ( (12*24) + 20, GetTimeMinute(),GetTimeSecond(),GetTimeMillisecond());
}

The hours will wrap into days so there is no reason to also use the SetCalendar function. the set time function will handle both. 

EDIT:
I myself would also not worrie about the nimute and second and millsecond and just do the math to begin with and end up with. 

SetTime( 308,0,0,0);
               
               

               


                     Modifié par Lightfoot8, 01 février 2014 - 04:55 .
                     
                  


            

Legacy_Ed Venture

  • Full Member
  • ***
  • Posts: 200
  • Karma: +0/-0
Setting the exact time
« Reply #5 on: February 02, 2014, 03:05:47 pm »


               WhiZard,
Thank you ! Now it makes sense to me.
The help you and others here give is of great value to those of us that are still learning.
Thanks again,
Ed
               
               

               
            

Legacy_Ed Venture

  • Full Member
  • ***
  • Posts: 200
  • Karma: +0/-0
Setting the exact time
« Reply #6 on: February 02, 2014, 03:31:10 pm »


               Lightfoot8,
The script is set on a trigger, on a docked ship, after a 12 day trip.
I realy am a good welder and machinist, but sadly lacking in computer background.
I started as a builder, with no more than the toolset, and my own personal harddrive full of useless crap.
I have learned a great deal, through tutorials, the Lexicon, and the help of others like yourself.
I am doing my best to learn the shortcuts that have been provided to me, but still have a long way to go. But, that's okay, I enjoy the chance to learn new things.
I want to say thank you for the help, you have given me today. It is greatly appreciated.
I fixed the original script, and left it in the mod. I have pasted the scripts in this thread into a word dock I use to save scripts  for future use.
Thank you for your input,
ED