Jump to content

Recommended Posts

Posted (edited)

Hey guys, i have setup a RealTime script to sync the server world time with the realtime, but if i want to check the Time the time will return wrong numbers.
 

        [Command("settime")]
        public void Settime(Client player, int hrs, int min)
        {
            NAPI.World.SetTime(hrs, min, 0);
            NAPI.Chat.SendChatMessageToPlayer(player, $"~g~[WELT ZEIT]~w~ Du hast die Zeit auf: ~y~{hrs}:{min}~w~Uhr gestellt.");
        }
        [Command("time")]
        public void Time(Client player)
        {
            NAPI.Chat.SendChatMessageToPlayer(player, $"~g~[SERVER]~w~ Aktuell ist es {NAPI.World.GetTime().ToString()} Uhr");
        }
    }

6efc7edd8e66f8774de47d50d7d832c6.png

btw. every minute the server will set the world time to real time.

NAPI.World.SetTime(DateTime.Now.Hour, DateTime.Now.Minute, 0);

 

Edited by Bodymenn
  • Confused 1
  • 3 weeks later...
Posted

You need to create global variables, or data with custom hour, minute and second.

 

int serverHour = 12;
int serverMin = 0;
int serverSec = 0;

private void C_SetTime(int hour, int minute, int second)
{
    NAPI.World.SetTime(hour, minute, second);
    serverHour = hour;
    serverMin = minute;
    serverSec = second;
}

 

PS: I know this thread is old, but it was unanswered and could still help for others looking to reference from it. If I am in the wrong, then please delete this and lock the thread.

Posted (edited)

Thread isn't that old, I had this problem the other day as well but only just seen this thread. Pretty fkin annoying until I booted the game up.

I was trying to build the script without loading the game and viewing the consoles SetTime > GetTime.

GetTime is random on first call, could be 12:00, 13:00, 14:00 etc, whatever it just picks a time it fancies.

 

		//Store time here
        private TimeSpan _startTime;        

		/// <summary>
        /// External method to get the time because <see cref="NAPI.World.GetTime"/> is no good
        /// </summary>
        /// <returns></returns>
        public TimeSpan GetTime() => _startTime;
        
        #region Private methods

        private void OnTimerCallback(object state)
        {
            _startTime = _startTime.Add(new TimeSpan(0, 1, 0));
            NAPI.World.SetTime(_startTime.Hours, _startTime.Minutes, _startTime.Seconds);
        }

 

 

Edited by Guest
Posted
On 1/6/2019 at 4:58 AM, Marky said:

You need to create global variables, or data with custom hour, minute and second.

 


int serverHour = 12;
int serverMin = 0;
int serverSec = 0;

private void C_SetTime(int hour, int minute, int second)
{
    NAPI.World.SetTime(hour, minute, second);
    serverHour = hour;
    serverMin = minute;
    serverSec = second;
}

 

PS: I know this thread is old, but it was unanswered and could still help for others looking to reference from it. If I am in the wrong, then please delete this and lock the thread.

To my knowledge, Marky's code seems legit. 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...