Jump to content
RoxberrySWE

Spawngear setup in init.c - DayZ Server

Recommended Posts

Hello! I have been trying to figure out how to setup the spawngear for my server, and have watched multiple videos, read countless tutorials on how to set it up. But I seem to always do something wrong because it just wont work.

I was wondering (and hoping to be able to take the lazy route) if someone just could help me write the proper text to put into init.c?
The things I want as spawnloot can be found in the picture posted in this thread.

Thanks on before hand / Rox

spawn%20gear.png

Share this post


Link to post
Share on other sites

So, here's an example for you:

class CustomMission: MissionServer
{
    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");
        Class.CastTo(m_player, playerEnt);
 
        GetGame().SelectPlayer(identity, m_player);
 
        return m_player;
    }
 
    override void StartingEquipSetup(PlayerBase player, bool clothesChosen)
    {
 
        EntityAI itemEnt;
        ItemBase itemBs;
 
          player.RemoveAllItems();
 
        itemEnt = player.GetInventory().CreateInInventory("Rag");
        itemBs = ItemBase.Cast(itemEnt);
        itemBs.SetQuantity(2);
 
        itemEnt = player.GetInventory().CreateInInventory("TShirt_Red");
        itemBs = ItemBase.Cast(itemEnt);
 
        itemEnt = player.GetInventory().CreateInInventory("Jeans_Grey");
        itemBs = ItemBase.Cast(itemEnt);
 
        itemEnt = player.GetInventory().CreateInInventory("Sneakers_Green");
        itemBs = ItemBase.Cast(itemEnt);
 
        itemEnt = player.GetInventory().CreateInInventory("SpaghettiCan");
        itemBs = ItemBase.Cast(itemEnt);
 
    }
};

 

All you have to do is add more itemEnt and itemBs lines if you want more items, but there has to be enough inventory slots on your character to hold all the stuff you want.

So in your case, start with the backpack and then add the other things and you should be good.

Share this post


Link to post
Share on other sites

So this what I´ve head problems with. I have done this so many times but it only brakes. Where do I add a backpack tho? Just in the list there.

And also, do I HAVE to have the "Rag" line?

Edited by RoxberrySWE

Share this post


Link to post
Share on other sites
2 hours ago, RoxberrySWE said:

So this what I´ve head problems with. I have done this so many times but it only brakes. Where do I add a backpack tho? Just in the list there.

And also, do I HAVE to have the "Rag" line?

You just add and delete as you like.  So, if you wanted no rags and a backpack plus the rest of what I listed, then it would look like this:

 

class CustomMission: MissionServer
{
    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");
        Class.CastTo(m_player, playerEnt);
 
        GetGame().SelectPlayer(identity, m_player);
 
        return m_player;
    }
 
    override void StartingEquipSetup(PlayerBase player, bool clothesChosen)
    {
 
        EntityAI itemEnt;
        ItemBase itemBs;
 
          player.RemoveAllItems();
 
        itemEnt = player.GetInventory().CreateInInventory("MountainBag_Blue");
        itemBs = ItemBase.Cast(itemEnt);

        itemEnt = player.GetInventory().CreateInInventory("TShirt_Red");
        itemBs = ItemBase.Cast(itemEnt);
 
        itemEnt = player.GetInventory().CreateInInventory("Jeans_Grey");
        itemBs = ItemBase.Cast(itemEnt);
 
        itemEnt = player.GetInventory().CreateInInventory("Sneakers_Green");
        itemBs = ItemBase.Cast(itemEnt);
 
        itemEnt = player.GetInventory().CreateInInventory("SpaghettiCan");
        itemBs = ItemBase.Cast(itemEnt);
 
    }
};

 

I picked a random bag here -- you'd need to look through the types.xml file for the precise names to put here.

Share this post


Link to post
Share on other sites

Ok, thank you very much. I will try this. I will let you know if I f*ck it up or not =P

/ Rox

Share this post


Link to post
Share on other sites

Added the code you wrote, exactly as you wrote it. Got a compile error (picture)

This is why I cant follow tutorials. They are ALWAYS wrong in some way, a line in the wrong place or a . , ; : missing or in the wrong place. That´s why I asked for someone that maybe could write a finished init.c file with the spawngear I showed in the initial post. Because I have followed tutorials, videos and so on HUNDREDS of times, but there is ALWAYS something wrong. I will paste the whole init.c file here so maybe someone can see exactly what is wrong with it now.compile_error.png

 

/**
 * init.c
 *
 * DayZ Expansion Mod
 * www.dayzexpansion.com
 * © 2020 DayZ Expansion Mod Team
 *
 * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. 
 * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
 *
*/

#include "$CurrentDir:\\mpmissions\\Expansion.ChernarusPlus\\expansion\\ExpansionObjectSpawnTools.c"
#include "$CurrentDir:\\mpmissions\\Expansion.ChernarusPlus\\expansion\\missions\\MissionConstructor.c"

void main()
{
	bool loadTraderObjects = false;
	bool loadTraderNPCs = false;

	string MissionWorldName = "empty";
	GetGame().GetWorldName(MissionWorldName);

	if (MissionWorldName != "empty")
	{
		//! Spawn mission objects and traders
		FindMissionFiles(MissionWorldName, loadTraderObjects, loadTraderNPCs);
	}

	//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.02, 0.1), 1, 0);
	weather.GetRain().Set( 0, 1, 0);
	weather.GetFog().Set( 0, 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 = 8, reset_day = 10;
	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)
    {
        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");
        Class.CastTo(m_player, playerEnt);
 
        GetGame().SelectPlayer(identity, m_player);
 
        return m_player;
    }
 
    override void StartingEquipSetup(PlayerBase player, bool clothesChosen)
    {
 
        EntityAI itemEnt;
        ItemBase itemBs;
 
          player.RemoveAllItems();
 
        itemEnt = player.GetInventory().CreateInInventory("MountainBag_Blue");
        itemBs = ItemBase.Cast(itemEnt);

        itemEnt = player.GetInventory().CreateInInventory("TShirt_Red");
        itemBs = ItemBase.Cast(itemEnt);
 
        itemEnt = player.GetInventory().CreateInInventory("Jeans_Grey");
        itemBs = ItemBase.Cast(itemEnt);
 
        itemEnt = player.GetInventory().CreateInInventory("Sneakers_Green");
        itemBs = ItemBase.Cast(itemEnt);
 
        itemEnt = player.GetInventory().CreateInInventory("SpaghettiCan");
        itemBs = ItemBase.Cast(itemEnt);
 
    }
};

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

 

Edited by RoxberrySWE

Share this post


Link to post
Share on other sites

And now it starts without any errors. But the character do NOT spawn with the gear that is set in the init.c file. I have reset all player files (db and spawnpoint), reset everything. But still it is not spawning with the right gear.

I am using the Expansion mod tho, can that have anything to do with it?

Share this post


Link to post
Share on other sites
14 hours ago, RoxberrySWE said:

And now it starts without any errors. But the character do NOT spawn with the gear that is set in the init.c file. I have reset all player files (db and spawnpoint), reset everything. But still it is not spawning with the right gear.

I am using the Expansion mod tho, can that have anything to do with it?

Most likely, yes.  I am not using that mod and I believe it changes quite a lot of things.  The example I gave you is from my Deer Isle server that is up and running, but doesn't use Expansion mod.

Share this post


Link to post
Share on other sites

Hi Roxberry,

The expansion mod has a build-in spawn gear feature. 

Head over to "YOURSERVERFILE\ServerProfile\ExpansionMod\Settings\SpawnSettings.json"
In this file you can change the gear and items people spawn with. Make sure you put the items under the correct category, else you wont spawn with said item.
The expansion mod guys have setup a wiki btw, here you can see many tutorials on things you can change within their mod. https://github.com/salutesh/DayZ-Expansion-Scripts/wiki

Let me know if you run into anymore trouble!
Kind regards,
Dutchy

Share this post


Link to post
Share on other sites

Do you still need to use the #include "$CurrentDir:\\mpmissions\\Expansion.ChernarusPlus\\expansion\\ExpansionObjectSpawnTools.c" ?

It is not included in the new Expansion files.

Thanks in advance

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

×