Jump to content

making DownloadableContentInfo add content once only


eggroll666

Recommended Posts

i've recently made a custom character and i've got him in the game, however the game keeps adding more on each subsequential save+load.

i'm trying to make it so it adds only one per game but i can't seem to figure out how to go about doing so

 

 

static event OnLoadedSavedGame()

{

local XComGameStateHistory History;

local XComGameState NewGameState;

local XComGameState_HeadquartersXCom OldXComHQState;

local XComGameState_HeadquartersXCom NewXComHQState;

local XComGameState_Unit ItemState;

local X2CharacterTemplateManager ItemMgr;

local X2CharacterTemplate ItemTemplate;

//local CharacterPoolManager CharMgr;

 

//In this method, we demonstrate functionality that will add ExampleWeapon to the player's inventory when loading a saved

//game. This allows players to enjoy the content of the mod in campaigns that were started without the mod installed.

ItemMgr = class'X2CharacterTemplateManager'.static.GetCharacterTemplateManager();

History = `XCOMHISTORY;

 

//Create a pending game state change

NewGameState = class'XComGameStateContext_ChangeContainer'.static.CreateChangeState("Adding MonkeyBiscuits");

 

//Get the previous XCom HQ state - we'll need it's ID to create a new state for it

OldXComHQState = XComGameState_HeadquartersXCom(History.GetSingleGameStateObjectForClass(class'XComGameState_HeadquartersXCom'));

 

//Make the new XCom HQ state. This starts out as just a copy of the previous state.

NewXComHQState = XComGameState_HeadquartersXCom(NewGameState.CreateStateObject(class'XComGameState_HeadquartersXCom', OldXComHQState.ObjectID));

 

//Make the changes to the HQ state. Here we add items to the HQ's inventory

ItemTemplate = ItemMgr.FindCharacterTemplate('MonkeyBiscuits');

 

//Instantiate a new item state object using the template.

ItemState = ItemTemplate.CreateInstanceFromTemplate(NewGameState);

NewGameState.AddStateObject(ItemState);

 

//Add the newly created item to the HQ inventory

ItemState.RankUpSoldier(NewGameState);

ItemState.SetSoldierClassTemplate('Ranger');

ItemState.SetVoice('MaleVoice1_English_UK');

ItemState.SetCharacterName("Jordan", "Bananas", "Monkey Biscuits");

ItemState.SetCountry('Country_Canada');

NewGameState.AddStateObject(ItemState);

NewXComHQState.AddToCrew(NewGameState, ItemState);

ItemState.SetHQLocation(eSoldierLoc_Barracks);

NewXComHQState.HandlePowerOrStaffingChange(NewGameState);

 

 

//Commit the new HQ state object to the state change that we built

NewGameState.AddStateObject(NewXComHQState);

 

//Commit the state change into the history.

History.AddGameStateToHistory(NewGameState);

}

Link to comment
Share on other sites

I don't know the answer, but this seems pretty important. Lots of people are using the technique to add weapons, items or other objects to the game, and these mods all get the complaint that the object keeps appearing. If you find the solution, or somebody else knows, please post the 1-2 missing lines here.

 

BTW please start newer threads in the modding subforum, so that modders can look there to find all the answers.

 

EDIT: related thread here:

http://forums.nexusmods.com/index.php?/topic/3798185-added-a-new-gamestate-object-to-all-soldiers/

Edited by davidlallen
Link to comment
Share on other sites

I posted on the related thread about this in the link above. The TL;DR is I suspect that the "load saves with missing DLC" mod is breaking the logic in the base game that figures out when to call the OnLoadedSaveGame function, causing it to fire for every mod on every load, and most mods aren't prepared to handle that. Because as far as the game is concerned, the save doesn't have that mod so it needs to call the callback.

 

The workaround is to iterate the whole history looking for any gamestates you recognize. If you see one, eg a unit state with that name, dont add a new unit.

Edited by tracktwo
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...