Page MenuHomeFeedback Tracker

Spawning as random character instead of one created in main menu.
New, NormalPublic

Description

Currently you must load the main menu, select your created character and then join a server to spawn as the created character. If you join a server through the launcher your character does not get loaded and you spawn as a random character. This also happens if you have any character other than your created character selected when you join from the main menu.

Why this happens
When you load the main menu all of the character creation data gets loaded from config. When you select any character a function in MainMenu.c named OnChangeCharacter() gets called. This will load that character onto the screen and display it. Then you join a server and a function in IntroSceneCharacter.c named SaveCharacterSetup() which will find the index of the selected character's top, bottom, shoes, etc and pass them to the function SetCharacterInfo() in DayZGame.c. Then StoreLoginData() will be called which sends the data to the server.

If even one of those pieces(top, bottom, shoes) does not exist in the character creation config array, it will send a -1 in it's place, which signals the server to spawn a random character. This is the problem with joining a server from the main menu. You must have the created character selected or it will be random. It should always be the created character as a fresh spawn.

The problem with joining from the launcher is that only StoreLoginData() is called. Nothing else is loaded so the data sent to the server will always be -1 and therefore spawn a random character.

Details

Severity
Minor
Resolution
Open
Reproducibility
Always
Operating System
Windows 10
Category
Scripting
Steps To Reproduce

Join a server from the launcher, your character will be random.

OR

Select a character other than your created character in the main menu, join a server, your character will be random.

Additional Information

Suggested fix
Here is the modded DayZGame class with the fix. This ensures that the player will always spawn as their created character even if they join from the launcher.

modded class DayZGame
{
	// This method is only run by the client
	override void StoreLoginData()
	{
		// Only run if demounit has not already been set
		if (demounit.Count() == 0)
		{
	        // Get customized character
			Man m_CharacterObj = GetMenuData().CreateCharacterPerson(GameConstants.DEFAULT_CHARACTER_MENU_ID);
			
			// If it doesn't exist, do nothing and let the server create a random character as usual
			if (m_CharacterObj) 
			{
				TStringArray m_CharShirtList = new TStringArray;
				TStringArray m_CharPantsList = new TStringArray;
				TStringArray m_CharShoesList = new TStringArray;
				
				ConfigGetTextArray("cfgCharacterCreation" + " top", m_CharShirtList);
				ConfigGetTextArray("cfgCharacterCreation" + " bottom", m_CharPantsList);
				ConfigGetTextArray("cfgCharacterCreation" + " shoe", m_CharShoesList);
				
				int index_top;
				int index_bottom;
				int index_shoes;
				int index_character;
				
				Object obj = m_CharacterObj.GetInventory().FindAttachment(InventorySlots.BODY);
				if (obj)
				{
					index_top = m_CharShirtList.Find(obj.GetType());
				}
				
				obj = m_CharacterObj.GetInventory().FindAttachment(InventorySlots.LEGS);
				if (obj)
				{
					index_bottom = m_CharPantsList.Find(obj.GetType());
				}
				
				obj = m_CharacterObj.GetInventory().FindAttachment(InventorySlots.FEET);
				if (obj)
				{
					index_shoes = m_CharShoesList.Find(obj.GetType());
				}
				
				index_character = GetGame().ListAvailableCharacters().Find(m_CharacterObj.GetType());
				
				SetCharacterInfo(index_top, index_bottom, index_shoes, index_character);
			}
		}
		
		super.StoreLoginData();
	}
}

Event Timeline