Better Way To Force Time/Date

Credits to TheEpsilonNaught for resolving via DayZ Modders Discord!

Having issues with your in game time not being what you set? Its probably using system time despite you setting a specific time. If so follow this quick guide.

(Based on default mission file)

Open mpmissions/dayzOffline.chernarusplus/init.c file and look for:
Code:
class CustomMission: MissionServer
inside this class you want to add this:
Code:
override void OnMissionStart()
{
    super.OnMissionStart();
    GetGame().GetWorld().SetDate(2018, 06,21, 9, 30);    //Forcing Date and Time on server!
}
Time Info
Change (2018, 06,21, 9, 30) to suit your needs, format is YEAR/DAY/MONTH/HOUR/MINUTES so example above will make it 9:30am on 21st June 2018


Heres How my init.c CustomMission Classs looks with it added at the top:


Code:
class CustomMission: MissionServer
{
    override void OnMissionStart()
    {
        super.OnMissionStart();
        GetGame().GetWorld().SetDate(2014, 11,27, 6, 30);    //Forcing Date and Time on server!
    }
    
    void SetRandomHealth(EntityAI itemEnt)
    {
        int rndHlt = Math.RandomInt(40,100);
        itemEnt.SetHealth("","",rndHlt);
    }

    override PlayerBase CreateCharacter(PlayerIdentity identity, vector pos, ParamsReadContext ctx, string characterName)
    {
        Entity playerEnt;
        playerEnt = GetGame().CreatePlayer(identity, characterName, pos, 0, "NONE");//Creates random player
        Class.CastTo(m_player, playerEnt);
        
        GetGame().SelectPlayer(identity, m_player);
        
        return m_player;
    }
    
    override void StartingEquipSetup(PlayerBase player, bool clothesChosen)
    {
/*
        player.RemoveAllItems();

        EntityAI item = player.GetInventory().CreateInInventory(topsArray.GetRandomElement());
        EntityAI item2 = player.GetInventory().CreateInInventory(pantsArray.GetRandomElement());
        EntityAI item3 = player.GetInventory().CreateInInventory(shoesArray.GetRandomElement());
*/
        EntityAI itemEnt;
        ItemBase itemBs;
        
        itemEnt = player.GetInventory().CreateInInventory("WaterBottle");
        itemBs = ItemBase.Cast(itemEnt);
        //itemBs.SetQuantity(4);  //Commented out as only need 1 Item here instead of 4 Rags
        SetRandomHealth(itemEnt);

        itemEnt = player.GetInventory().CreateInInventory("Marmalade");
        itemBs = ItemBase.Cast(itemEnt);
    }

};
 
Top