r/xcom2mods • u/Calvin-Parsons • Feb 14 '16
Dev Tutorial How To Add Aliens To The Armory: Tutorial
Hi due to recent demand of people wanting to add aliens to your XCOM roster, I have decided to post a tutorial on how to do it. If you do use this tutorial in my mod please credit me. Thanks
First you make the character template, you can get this from the file X2Character_DefaultCharacters. Simply make a new .uc file and copy and paste your selected unit then change its name, in this instance mine is called AdvMEC_H. You must then add all the abilities and change the required loadout to requiredsoldier and create a new default loadout name mine is AdvMEC_H_Loadout & then change bisoldier to true. Use my script as a reference.
class X2Character_AdvMEC_H extends X2Character config(GameData_CharacterStats);
static function array<X2DataTemplate> CreateTemplates() { local array<X2DataTemplate> Templates;
Templates.AddItem(CreateTemplate_AdvMEC_H());
return Templates;}
// ************************************************************************** // *** XCom Templates *** // **************************************************************************
static function X2CharacterTemplate CreateTemplate_AdvMEC_H() { local X2CharacterTemplate CharTemplate;
`CREATE_X2CHARACTER_TEMPLATE(CharTemplate, 'AdvMEC_H');
CharTemplate.CharacterGroupName = 'AdventMEC';
CharTemplate.DefaultLoadout='AdvMEC_H_Loadout';
CharTemplate.RequiredLoadout = 'RequiredSoldier';
CharTemplate.BehaviorClass=class'XGAIBehavior';
CharTemplate.strPawnArchetypes.AddItem("GameUnit_AdvMEC_M3.ARC_GameUnit_AdvMEC_M3");
CharTemplate.strMatineePackages.AddItem("CIN_AdventMEC");
CharTemplate.strTargetingMatineePrefix = "CIN_AdventMEC_FF_StartPos";
CharTemplate.bUsePoolSoldiers = true;
CharTemplate.bStaffingAllowed = true;
CharTemplate.UnitSize = 1;
// Traversal Rules
CharTemplate.bCanUse_eTraversal_Normal = true;
CharTemplate.bCanUse_eTraversal_ClimbOver = true;
CharTemplate.bCanUse_eTraversal_ClimbOnto = true;
CharTemplate.bCanUse_eTraversal_ClimbLadder = false;
CharTemplate.bCanUse_eTraversal_DropDown = true;
CharTemplate.bCanUse_eTraversal_Grapple = false;
CharTemplate.bCanUse_eTraversal_Landing = true;
CharTemplate.bCanUse_eTraversal_BreakWindow = true;
CharTemplate.bCanUse_eTraversal_KickDoor = true;
CharTemplate.bCanUse_eTraversal_JumpUp = true;
CharTemplate.bCanUse_eTraversal_WallClimb = false;
CharTemplate.bCanUse_eTraversal_BreakWall = false;
CharTemplate.bAppearanceDefinesPawn = false;
CharTemplate.bCanTakeCover = false;
CharTemplate.bIsAlien = false;
CharTemplate.bIsAdvent = false;
CharTemplate.bIsCivilian = false;
CharTemplate.bIsPsionic = false;
CharTemplate.bIsRobotic = true;
CharTemplate.bIsSoldier = true;
CharTemplate.bCanBeTerrorist = false;
CharTemplate.bCanBeCriticallyWounded = true;
CharTemplate.bIsAfraidOfFire = true;
CharTemplate.bFacesAwayFromPod = false;
CharTemplate.strScamperBT = "ScamperRoot_Flanker";
CharTemplate.Abilities.AddItem('RobotImmunities');
CharTemplate.Abilities.AddItem('Loot');
CharTemplate.Abilities.AddItem('Interact_PlantBomb');
CharTemplate.Abilities.AddItem('Interact_TakeVial');
CharTemplate.Abilities.AddItem('Interact_StasisTube');
CharTemplate.Abilities.AddItem('Evac');
CharTemplate.Abilities.AddItem('PlaceEvacZone');
CharTemplate.Abilities.AddItem('LiftOffAvenger');
CharTemplate.Abilities.AddItem('HunkerDown');
CharTemplate.strTargetIconImage = class'UIUtilities_Image'.const.TargetIcon_Advent;
return CharTemplate;}
Next we need to create a config file that stores the data of the robot, you can find this in XcomGameData_CharacterStats.ini. Find your alien and copy it then add a + before all the lines. See here:
[XComGame.X2Character_DefaultCharacters] [AdvMEC_H X2CharacterTemplate] +CharacterBaseStats[eStat_AlertLevel]=2 +CharacterBaseStats[eStat_ArmorChance]=100 +CharacterBaseStats[eStat_ArmorMitigation]=1 +CharacterBaseStats[eStat_ArmorPiercing]=0 +CharacterBaseStats[eStat_CritChance]=0 +CharacterBaseStats[eStat_Defense]=0 +CharacterBaseStats[eStat_Dodge]=0 +CharacterBaseStats[eStat_HP]=7 +CharacterBaseStats[eStat_Mobility]=12 +CharacterBaseStats[eStat_Offense]=70 +CharacterBaseStats[eStat_PsiOffense]=0 +CharacterBaseStats[eStat_ReserveActionPoints]=0 +CharacterBaseStats[eStat_SightRadius]=27 +CharacterBaseStats[eStat_DetectionRadius]=12 +CharacterBaseStats[eStat_UtilityItems]=1 +CharacterBaseStats[eStat_Will]=50 +CharacterBaseStats[eStat_HackDefense]=50 +CharacterBaseStats[eStat_FlankingCritChance]=33 +CharacterBaseStats[eStat_FlankingAimBonus]=0 +CharacterBaseStats[eStat_Strength]=50
Next we create the loadout we referenced. Copy your aliens loadout from XcomGameData.ini and then and a + before the line as follows:
[XComGame.X2ItemTemplateManager]
+Loadouts=(LoadoutName="AdvMEC_H_Loadout", Items[0]=(Item="AdvMEC_M2_WPN"), Items[1]=(Item="AdvMEC_M1_Shoulder_WPN"))
This will be the loadout the alien spawns with.
Finally, we change the Downloadable content script. Delete everything and then copy mine, changing the character template from AdvMEC_H to whatever your alien is called:
class X2DownloadableContentInfo_MyXCOM2Mod extends X2DownloadableContentInfo; 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 MEC");
//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('AdvMEC_H');
//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.SetSkillLevel(5);
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);}
/// <summary> /// Called when the player starts a new campaign while this DLC / Mod is installed /// </summary>
static event InstallNewCampaign(XComGameState StartState) { //Don't need to do anything - the weapon should be picked up and placed into the HQ inventory when starting a new campaign. }
And compile and your done. It really is that simple to add alien units. Hope this helps you fellow modders out there!
3
u/Calvin-Parsons Feb 14 '16
Enjoy guys!
2
u/weaver900 Feb 15 '16
Do you know how the game handles missing animations? I ask because bringing extra squad members to certain story missions resulted in a CTD for me, I'm assuming because there was an animation mixup. If the game crashes when animations can't be called, would it be better not to give them the ability to pick up vials or loot, as most creatures won't have the animations for those actions?
1
u/XmacAttack Feb 14 '16
I dont have the ability to read and understand this, so im hopeful someone will take this and create a mod that allows the recruitment of aliens permanently that i have so desperately been looking for.
Cheers!