[OPEN] Need right CODE for init.c startup - please help!

deancorso

New Member
Hi, this is my first post here and I am a complete beginner in coding. I have installed my own DayZ server and I am busy modding.

But I need help with the init.c file. I want the player to spawn with some basic equipment, I have done this before but after a code change it didn't work anymore. Somewhere there is a bug, just the wrong line or something forgotten, or maybe totally total crap this way... can someone help me with this and "fix" me this file?

This is the original code with only the few lines I added (76-82)

Thanks a lot!
;)


Code:
void main()
{
    //INIT WEATHER BEFORE ECONOMY INIT------------------------
    Weather weather = g_Game.GetWeather();

    weather.MissionWeather(false);    // false = use weather controller from Weather.c

    weather.GetOvercast().Set( Math.RandomFloatInclusive(0.4, 0.6), 1, 0);
    weather.GetRain().Set( 0, 0, 1);
    weather.GetFog().Set( Math.RandomFloatInclusive(0.05, 0.1), 1, 0);

    //INIT ECONOMY--------------------------------------
    Hive ce = CreateHive();
    if ( ce )
        ce.InitOffline();

    //DATE RESET AFTER ECONOMY INIT-------------------------
    int year, month, day, hour, minute;
    int reset_month = 9, reset_day = 20;
    GetGame().GetWorld().GetDate(year, month, day, hour, minute);

    if ((month == reset_month) && (day < reset_day))
    {
        GetGame().GetWorld().SetDate(year, reset_month, reset_day, hour, minute);
    }
    else
    {
        if ((month == reset_month + 1) && (day > reset_day))
        {
            GetGame().GetWorld().SetDate(year, reset_month, reset_day, hour, minute);
        }
        else
        {
            if ((month < reset_month) || (month > reset_month + 1))
            {
                GetGame().GetWorld().SetDate(year, reset_month, reset_day, hour, minute);
            }
        }
    }
}

class CustomMission: MissionServer
{
    void SetRandomHealth(EntityAI itemEnt)
    {
        if ( itemEnt )
        {
            float rndHlt = Math.RandomFloat( 0.25, 0.65 );
            itemEnt.SetHealth01( "", "", rndHlt );
        }
    }

    override PlayerBase CreateCharacter(PlayerIdentity identity, vector pos, ParamsReadContext ctx, string characterName)
    {
        Entity playerEnt;
        playerEnt = GetGame().CreatePlayer( identity, characterName, pos, 0, "NONE" );
        Class.CastTo( m_player, playerEnt );

        GetGame().SelectPlayer( identity, m_player );

        return m_player;
    }

    override void StartingEquipSetup(PlayerBase player, bool clothesChosen)
    {
        EntityAI itemClothing;
        EntityAI itemEnt;
        ItemBase itemBs;
        float rand;

        itemClothing = player.FindAttachmentBySlotName( "Body" );
        if ( itemClothing )
        {
            SetRandomHealth( itemClothing );
            
            itemEnt = player.GetInventory().CreateInInventory( "M4A1" );
            itemEnt = player.GetInventory().CreateInInventory( "Mag_STANAG_30Rnd", 3 );
            itemEnt = player.GetInventory().CreateInInventory( "AssaultBag_Black" );
            itemEnt = player.GetInventory().CreateInInventory( "Jeans_Grey" );
            itemEnt = player.GetInventory().CreateInInventory( "M65Jacket_Olive" );
            itemEnt = player.GetInventory().CreateInInventory( "CombatBoots_Black" );
            itemEnt = player.GetInventory().CreateInInventory( "TunaCan" );
            
            SetRandomHealth( itemEnt );
        }
        
        
        itemClothing = player.FindAttachmentBySlotName( "Legs" );
        if ( itemClothing )
            SetRandomHealth( itemClothing );
        
        itemClothing = player.FindAttachmentBySlotName( "Feet" );
        if ( itemClothing )
            SetRandomHealth( itemClothing );
    }
};

Mission CreateCustomMission(string path)
{
    return new CustomMission();
}
 
Back
Top