Jump to content
froggyboi

init.c problems what did i do wrong

Recommended Posts

----------this is the init.c file im trying to get it to spawn the buildings in the building.c file below.

//Include-----------------------------------------------
    #include "$CurrentDir:\\mpmissions\\dayzOffline.chernarusplus\\building.c"

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();
    //GetTesting().ExportProxyData( "7500 0 7500", 10000 );  //Center of map, radius of how far to go out and find buildings.

    //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);
            }
        }
    }
    
    Place_Trash(); // Your function with trash.
}

class CustomMission: MissionServer
{    
    void SetRandomHealth(EntityAI itemEnt)
    {
        if ( itemEnt )
        {
            int rndHlt = Math.RandomInt(55,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)
    {
        EntityAI itemTop;
        EntityAI itemEnt;
        ItemBase itemBs;
        float rand;
        
        itemTop = player.FindAttachmentBySlotName("Body");
        
        if ( itemTop )
        {
            itemEnt = itemTop.GetInventory().CreateInInventory("Rag");
            if ( Class.CastTo(itemBs, itemEnt ) )
                itemBs.SetQuantity(4);

            SetRandomHealth(itemEnt);
            
            itemEnt = itemTop.GetInventory().CreateInInventory("RoadFlare");
            SetRandomHealth(itemEnt);
            
            rand = Math.RandomFloatInclusive(0.0, 1.0);
            if ( rand < 0.35 )
                itemEnt = player.GetInventory().CreateInInventory("Apple");
            else if ( rand > 0.65 )
                itemEnt = player.GetInventory().CreateInInventory("Pear");
            else
                itemEnt = player.GetInventory().CreateInInventory("Plum");
        
            SetRandomHealth(itemEnt);
        }
    }
};
  
Mission CreateCustomMission(string path)
{
    return new CustomMission();
}

 

--------------------------------------------so then this is the building.c file

//Spawn helper function
void SpawnObject( string type, vector position, vector orientation )
{
    auto obj = GetGame().CreateObject( type, position );
    obj.SetPosition( position );
    obj.SetOrientation( orientation );
    obj.SetOrientation( obj.GetOrientation() ); //Collision fix
    obj.Update();
    obj.SetAffectPathgraph( true, false );
    if( obj.CanAffectPathgraph() ) GetGame().GetCallQueue( CALL_CATEGORY_SYSTEM ).CallLater( GetGame().UpdatePathgraphRegionByObject, 100, false, obj );
}

void main()
{
//Your custom spawned objects
SpawnObject( "Land_Mil_Fortified_Nest_Watchtower", "7957.502930 340.408936 14571.899414", "95.999649 0.000000 0.000000" );
SpawnObject( "Land_Mil_Fortified_Nest_Big", "8009.504395 339.650513 14592.424805", "0.000000 0.000000 0.000000" );
SpawnObject( "Land_Mil_Fortified_Nest_Watchtower", "8010.790527 340.496002 14580.260742", "0.000000 0.000000 0.000000" );
SpawnObject( "Land_Mil_Fortified_Nest_Watchtower", "8075.783691 341.878662 14636.828125", "0.000000 0.000000 0.000000" );
SpawnObject( "Land_Mil_Fortified_Nest_Big", "8059.665039 340.807861 14649.797852", "0.000000 0.000000 0.000000" );
SpawnObject( "Land_Mil_Guardhouse2", "8061.048340 341.129456 14637.175781", "0.000000 0.000000 0.000000" );
SpawnObject( "Land_Mil_ATC_Small", "8053.116211 349.991486 14618.275391", "0.000000 0.000000 0.000000" );
SpawnObject( "Land_Mil_Fortified_Nest_Watchtower", "8066.662109 342.326050 14686.851563", "-85.999702 0.000000 0.000000" );
void main()
{

 

-----any help would be greatly accepted thanks in advance!

Edited by froggyboi

Share this post


Link to post
Share on other sites

I can see a couple of problems:

1. In the file init.c, on line 45, it says "Place_Trash(); // Your function with trash.", but there is no such function. I don't know if this is supposed to call the function for placing the buildings, but if so, it has to be called the same as the function in buildings.c on line 23. Rename it to, for example, "AddBuildings()"

2. In the file building.c, on line 23, the function containing all the building objects and coordinates is called "main()". There already is a function called "main()" in the file init.c. You can't have two functions with the same name. Rename it AddBuildings() so it gets called by the line in step 1 above.

3. In the file building.c, on line 24, it says "void main()" again. Remove that line.

4. In the file building.c, on line 25 (line 24 if you removed the line in step 3), the curly bracket is turned the wrong way. It should be } and not {

Hope it works.

 

Edited by NoBeansForMe

Share this post


Link to post
Share on other sites

Rather than modify the init.c file, there is an easier solution using the DayZ Editor and the DayZ Editor Loader mod (plus the BuilderItems mod).  You can place exactly the way you want the building wherever you want on your specific map in a 3D editor much like the Eden Editor in Arma III.  Check the Steam Workshop page for the editor for links on how to use it.  Here's the github page for it with the best explanations, hotkeys, etc.:  https://github.com/InclementDab/DayZ-Editor/wiki

Once you've placed all your buildings (and many other objects available in the editor), you save the file.  You'll have to go hunting for it in your C drive as the file is saved in the DayZ folder in the hidden AppData/Local folder set under your User folder (so in essence it's at Users-->(yourusername)-->AppData (a 'hidden' folder)-->Local-->DayZ-->Editor folder).  The file, to which you'll have given a name during the file save routine in the editor, will have an extension .dze.

In your server and on your clients, load the mods DayZ Editor Loader and BuilderItems.  Run the server once and shutdown.  You will see a folder called "Editor" in your server profiles folder (mine is called simply ServerProfiles).  Copy the .dze file you created with the DayZ Editor into that Editor folder.

Once you start the server again, the buildings and objects you laid down and saved in the .dze file will appear.  Easier than trying to figure out an init.c file.  Hope this helps!

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×