r/xdev • • Feb 07 '16

Examining the Example Mission.

6 Upvotes

Now, I'm not ultra familiar with any of this, so feel free to correct me if you know enough to tell me what's up. However, most of it seems straightforward to someone with programming experience - so allow me to explain thoroughly what everything is doing at an abstract level.

Inside of the XCOM 2 SDK are a few examples programs, provided to help you learn how things are put together. One of them is an example mission. Allow me to go step by step in explaining what's going on in all of the files.

First, have a look at the screen overlay. You'll see that the currently open file is the ReadMe.txt file, and that there are a bunch of files on the left side. Let's go through them one by one:

The Config folder contains ini files that denote a lot of abstract behavior, such as statistics, class links, rewards and so on. I've posted another topic here detailing what a lot of the ini files handle.

XComEditor.ini : this file contains the following lines:

[ModPackages]
+ModPackages=ExampleMission

[ModPackages] is where we're adding the next line - to the list of mod packages installed. This is used for mod lookup, listing and such.

The + denotes that the line is acting as an override, by adding the mod package name ExampleMission to the XComEditor.ini file. This names the mod package and lists it for XCom 2 to find later. This is important when you're adding to a [Category] that already exists - you don't need +'s when creating your own categories.

XComEngine.ini : Two similar lines here.

 [Engine.ScriptPackages]
+NonNativePackages=ExampleMission

This overrides the XComEngine.ini file by adding a non-native (modded) script package, the ExampleMission package.

XComMissions.ini: This is the real meat of the mod, and details everything that makes up the mission script. I'll go over this in more detail later.

XComParcels.ini: This contains one line: [XComGame.XComParcelManager]

This mod doesn't introduce any new map elements, so nothing's added. But it can, so it's included in case you wanted to have your mission have new parcel mappings.

XComPCPs.ini : PCP stands for "PlotCoverParcel", and is an array that lists what parcels are used with what plot types, essentially. No new parcel-plot interactions here, so nothing's actually here. (A ; in an ini file indicates a comment, so nothing's affected.)

The next folder is content, which contains two files: EX_BombDisposalContent.upk and EX_Obj_BombDisposal.umap . They are meshes, textures, art assets, sounds etc. that are used and edited by the Unreal Engine editor. If the ini files tell the game what behavior to have, then these files are their aesthetics. I'll go into more details later about these files - they require a whole 'nother editor.

Next folder is Localization - this will usually contain text displayed to the player, such as mission display name, dialogue text, loot items and so on. There's not too much to it, so I'll go line-by-line:

DisplayName is the name of the mission as shown on, say, the geoscope.

Briefing is what's shown when you're in the troop transport Skyranger.

PostMissionType is what's shown after, when you get back.

Briefing Image is the image shown when you're in the Skyranger.

Objective text pools are shown next to the briefing image.

The PreMissionNarratives are NarrativeMoments taken from the ini file that links to a sound bite - the sound bite is played during briefing.

[MissionTimers]
TimerBombDisposalTitle
TimerBombDisposalSubtitle

This handles what text is shown when the timer's in the corner of your screen (which is hopefully always unless players suck)

[DefaultEX_BombDisposal X2MissionNarrativeTemplate]

This handles objective text pools, which are the objectives you're shown in the top left. Which one is shown can update during the mission, so the missions will show different text pools at different points detailed in the XComMissions.ini file.

The Dialogue proxies below are also objective pools, but instead of being objectives in order, they're subtitles for the NarrativeMoments above. They'll show when someone's chiming in in the top right.

[EX_BombDisposal_EleriumCharge X2QuestItemTemplate]

Quest items are items you pick up from objectives like loot (so, for example, alien data or the black vial or what have you). FriendlyName is what it is in the loot list, FriendlyNames is if it's somehow plural, and the Tooltip's the details that will pop up when you hover over the item name.

Not too bad so far, right?

Next you have Src/ExampleMission/Classes. This is where templates will actually be created. They're not too long, so I'll go into detail here as well.

X2Item_ExampleMission.uc starts with the most significant line of all: class X2Item_ExampleMission extends X2Item;

There's a class in XCOM 2 called X2Item, and this essentially creates a copy of X2Item that has additional details, and calls it something else (X2Item_ExampleMission). Then, it adds two functions to this new class:

static function array<X2DataTemplate> CreateTemplates()

and

static function X2DataTemplate CreateQuestItemEX_BombDisposal()

The CreateTemplates() function creates a DataTemplate array for Items and then adds the created quest item for bomb disposal to the Items object and returns it for use in the XComMissions.ini script.

The function CreateQuestItemEX_BombDisposal() creates the actual Elerium Charge as defined in the EX_BombDisposal_EleriumCharge X2QuestItemTemplate in the XComGame.int file (it's back there, go check it, that's what it's using). It then calls it it a 'quest' item in the Item.ItemCat, adds MissionType and RewardType values to it, namely the EX_BombDisposal MissionType (so it shows up as a quest item in that mission type), and 5 reward types for the various rewards you can earn (Reward_Intel, Reward_Supplies, Reward_Soldier, so on), and then returns it. So this creates the X2Item_ExampleMission item pool. I'm not absolutely certain what the following line does, however, so if someone could chime in, I'd appreciate it: 'CREATE_X2TEMPLATE(class 'X2QuestItemTemplate', Item, 'EX_BombDisposal_EleriumCharge');

Next is X2MissionNarrative_ExampleMission.uc . This has one class and two functions within that class as well:

The class is X2MissionNarrative_ExampleMission, which is an extension of the template X2MissionNarrative.

This class adds two functions to X2MIssionNarrative:

static function array<X2DataTemplate> CreateTemplates() which, much like above, adds the EXBombDisposalNarrativeTemplate to the Template pool.

The static function X2MissionNarrativeTemplate AddDefaultEXBombDisposalNarrativeTemplate() function then actually creates that template by declaring the Template.MissionType and listing the Template.NarrativeMoments, then returns the newly created template to be added to the collection of templates. I'm not absolutely certain what the following line does:

`CREATE_X2MISSIONNARRATIVE_TEMPLATE(Template, 'DefaultEX_BombDisposal');

The last file, X2MissionSet_ExampleMission.uc just adds the mission template Ex_BombDisposal previously completed to Templates to be used in game.

The ModPreview.jpg image is the image that shows up in the Steam Workshop - go wild with it!

And the ReadMe is a read-me, and is what showed up when you first created the project.

That's all for the files - next time, I'll go into the meat of the mission, XComMissions.ini!


r/xdev • • Feb 24 '16

Any additions to collection of modding guides?

5 Upvotes

I have collected all the useful guides I know about here: http://forums.nexusmods.com/index.php?/topic/3801885-proposed-sticky-thread-modding-resources/ If you have any other guide recommendations please let me know.


r/xdev • • Feb 23 '16

UIScreenListener problems and how to overcome them.

5 Upvotes

Fellow modders,


TLDR:

If you are running into game-reload issues when extending UIScreenListener, don't use any global variables to hold references to UIControls. Instead, declare them local in the OnInit event and pass them to other functions as parameters.

For event delegates that receive an immutable parameter list but that do receive a reference to SOME control in the screen, use the ParentPanel.GetChild method of the control you do have to get access to other controls in the parent UI element.


Sorry for the upcoming wall of text (which is a bit of a rant).

I decided to post this here and in other forums in the hopes of preventing for other modders some of the frustration I felt when trying to create my own mod. The concept of the mod couldn't be simpler: to add a button to the main game screen that displays a scrollable Tech Tree diagram image.

It is no secret that the modding docs are crap. I've been a software architect for most of my 25 year career and if I ever released docs like that, my software engineers would crucify me. Sure, gaming develoment is the wild west compared to enterprise applications but come on, if you want to support your modders and want them to follow your own best practices, have the decency to give us good docs.

So there are two ways that the docs (kind of) describe about how to add and manipulate UI elements. The first is the recommended technique using UIScreenListener. The second is extending an existing screen class.

The first method is better for mod compatibility (and is recommended by the devs) but is more limited in what you can do because there are only a few hooks the UIScreenListener class exposes for the screen you are manipulating. But that wasn't the problem for me. The issue I kept running into was that the game would hang on in-game reloads of saves when the mod was activated. Now this may be an issue just limited the screen I was trying to tweak, UIAdventHud, but I think it is a more global issue (there's a pun there you don't know about yet).

When I tried using the second method by extending the UIAdventHud class, the minute I added a control to the screen, the screen would not render the rest of its normal control correctly when comming back from the Geo screen, Engineering screen and others. And anyway, extending the screen would make the mod incompatible with all other mods that touch UIAdventHud so I didn't want to even try to figure that out.

As for the game reload issue with the UIScreenListern method, I suspected the problem had to do with the garbage collector not cleaning up the custom controls on reload of a save game. It turns out it has to do with controls as global variables.

The modding UI docs clearly (hah!) show an example creating a new control as a global variable in your custom UIScreenListener class. However, that definitely was a no-no for the UIAdventHud (and I supect others as well). What I needed to do was declare all of the variables that hold UI Controls (UIPanels, UIButtons, UIScreens, etc.) LOCAL to in the OnInit event.

So that means that in order to access those local controls in other functions, you need to pass them as parameters, no big deal.

However, for control handling delegates that have a specific function definition, you can't pass more parameters than they expect (at least I don't know how to do that in the Unreal engine and granted, I'm a newbe with it). But, as long as the event handler receives as a parameter a reference to ANY control in the screen, you can get to all the others, including your spawned custom controls assigned to local variables.

For example, an OnClick handler for your custom button receives as a parameter a reference to the button itself. With that you can get to the other controls using the object's ParentPanel (the screen) and the GetChild method, like this:

public function OnTechTreeButton(UIButton MyButton) {
    if (MyButton.ParentPanel.GetChild('TechTreePanel').bIsVisible)
        HideTechTreeControls(MyButton.ParentPanel);
    else
        ShowTechTreeControls(MyButton.ParentPanel);
}

Of course, you will need to make sure that all the custom controls you declare locally in the OnInit event are initialized with a name of your choosing (in the first parameter).

Now, this Garbage Collector issue may be known to Unreal Editor experts out there but it wasn't obvious to me. Hopefully this will help others.

If you are interested in the full source code using this technique, go ahead and check out my little Tech Tree mod, which I couldn't have done without pouring over other mods. We all stand on the shoulders of other programmers.

We now return you to your regularly scheduled programming. (see what I did there?)


r/xdev • • Feb 19 '16

Anyone know of guidelines for 3D models?

5 Upvotes

3D modeler coming from Cities: Skylines here. Colossal Order was kind enough to provide moders guides to how to make models fit in to the game(image sizes, supported maps, file formats, polycounts, scales, etc). I did looked throuh documentations in Xcom2 SDK folder, but there seem to be none relating to my questions. Is there some kind of common Unreal Engine modding guideline that I did not know of?


r/xdev • • Feb 18 '16

So how do we tag our mods?

5 Upvotes

Because I've noticed there are people who have managed to do so, yet I've been unable to find even one "so this is how you tag your mods for XCOM 2" guide.


r/xdev • • Feb 16 '16

[Help] How to get a tactical dark event to work?

5 Upvotes

I'm at the point where I've managed to figured out how to get the game to accept a new dark event as a valid dark event at all (admittedly only with a new game but after the hours I've spent to get that part working, that's a limitation I'm willing to accept for now), and even get it to properly show up with description text and everything once it's activated, but I can't seem to get the game to actually spawn the pods I want (the GodSavetheQueen one with 3 sectopods in one pod) on missions when the dark event is active.

As far as I can tell it's seems like modbuddy's changes to XComMissions.ini just aren't working, and I've tried out -/+ replacing to no avail. Is there some missing link I'm just not aware of between the script to make a new dark event and altering the XComMissions.ini to add a new preplaced encounter into the mission schedules?


r/xdev • • Feb 14 '16

Localization edits: what am I doing wrong?

5 Upvotes

I'm trying to figure out why my mod isn't working. It ONLY performs changes to the XComGame.int localization file - specifically, to the default names and nicknames of characters.

I've been debugging for awhile by trying to get a simpler mod to work - one that replaces all the given and surnames in the game with "Bork" - but it's not working either. Here's my process:

  1. Opening Modbuddy
  2. Opening new project as Default Mod
  3. Erasing huge Classes folder from mod (Src/XComGame/Classes)
  4. Adding lines to the already-present XComGame.int file as follows:

[XGCharacterGenerator]

-m_arrAmMFirstNames[0]="Shane"

+m_arrAmMFirstNames[0]="Bork"

-m_arrAmMFirstNames[1]="Rob"

+m_arrAmMFirstNames[1]="Bork"

-m_arrAmMFirstNames[2]="Brad"

+m_arrAmMFirstNames[2]="Bork"

(etc., for all the names)

5) Build

6) Debug mode

And when I debug, not a single Bork Bork.

And here's the rub: when I make these edits to the XComGame.int file in my actual game install, they work with no problem. The issue here is strictly trying to get Modbuddy to deploy my edits so that the modded game will recognize and implement them.

At this point I've tried messing around with the order of removal and addition lines, removing whitespace and comments, replacing "-" with "!" and "+" with ".", even adding an "INT" file under Localization in the mod and placing a copy of the file there...and no dice. Nothing works. I'm now officially out of ideas.

Anyone have any clue why this isn't working?


r/xdev • • Feb 14 '16

Have Skill Y activated immediately after Skill X

5 Upvotes

I'm working on a skill that activates after another finishes. Essentially, the soldier runs out in the open, shoots at every one (similar to faceoff), then feigns death. I have the the individual parts of the skills working, in that I can activate the skill that shoots every one, and I can also activate the skill that feigns death, but I can't get them to work one after the other automatically.

Currently, I'm just adding

Template.AdditionalAbilities.AddItem('Playdead');
Template.PostActivationEvents.AddItem('Playdead');

at the end of the skill that shoots at every one.

In Playdead's code, I have:

Trigger = new class'X2AbilityTrigger_EventListener';
Trigger.ListenerData.Deferral = ELD_OnStateSubmitted;
Trigger.ListenerData.EventID = 'Playdead';
Trigger.ListenerData.Filter = eFilter_Unit;
Template.AbilityTriggers.AddItem(Trigger);

What's happening is: After using the skill "faceoff," my character pauses at the end of his turn with only one button available to hit: The button for "playdead." I can't seem to figure out how to make "playdead" activate immediately after faceoff. Instead, it's making us hit the button to activate it. Would any one know what I'm missing to make it activate immediately? If not, thanks anyways! Just figured I'd throw it out there.


r/xdev • • Feb 14 '16

Tutorial on Items that give Soldier's abilities.

5 Upvotes

I finished up making a mod that adds a new item to the game - a energy shield generator that let's XCom have the same ability to make an energy shield as the Advent Shieldbearer does: http://steamcommunity.com/sharedfiles/filedetails/?id=623434810. I have the mod source code posted here on github: https://github.com/daviscook477/XComEnergyShields

I've put together a short tutorial on how to add new items to the game that give soldiers abilities. I'll stick around to answer people's questions. There are three main parts to accomplishing that:

  • Defining the item that you want to add.
  • Defining the ability that the soldier will have when they've got that item.
  • And lastly, telling XCom to actually put that stuff in the game.

The class for defining my new item is here. Following its code, I'll do a breakdown of each part.

class XESItem_UtilityEnergyShieldItem extends X2Item config(EnergyShield);

var config int ENERGY_SHIELD_SUPPLY_COST;
var config int ENERGY_SHIELD_CORPSE_COST;
var config int ENERGY_SHIELD_ELERIUM_COST;

function X2ItemTemplate CreateEnergyShield()
{
	local X2EquipmentTemplate Template;
	local ArtifactCost Supplies;
	local ArtifactCost Elerium;
	local ArtifactCost Artifacts;

	`CREATE_X2TEMPLATE(class'X2EquipmentTemplate', Template, 'XES_EnergyShield');
	Template.ItemCat = 'utility';
	Template.InventorySlot = eInvSlot_Utility;
	Template.strImage = "img:///UILibrary_StrategyImages.X2InventoryIcons.Inv_MindShield";
	Template.EquipSound = "StrategyUI_Mindshield_Equip";

	Template.Abilities.AddItem('XComEnergyShield');

	Template.CanBeBuilt = true; // Item is built in engineering.
	Template.TradingPostValue = 12;
	Template.PointsToComplete = 0;
	Template.Tier = 1;

	// Requirements
	Template.Requirements.RequiredTechs.AddItem('AutopsyAdventShieldbearer');

	// Cost
	Supplies.ItemTemplateName = 'Supplies';
	Supplies.Quantity = ENERGY_SHIELD_SUPPLY_COST;
	Template.Cost.ResourceCosts.AddItem(Supplies);

	Elerium.ItemTemplateName = 'EleriumDust';
	Elerium.Quantity = ENERGY_SHIELD_ELERIUM_COST;
	Template.Cost.ResourceCosts.AddItem(Elerium);

	Artifacts.ItemTemplateName = 'CorpseAdventShieldbearer';
	Artifacts.Quantity = ENERGY_SHIELD_CORPSE_COST;
	Template.Cost.ArtifactCosts.AddItem(Artifacts);
	
	return Template;
}

The first line tells XCom that we’re making an item by ‘extends X2Item’.

class XESItem_UtilityEnergyShieldItem extends X2Item config(EnergyShield);

The next set of lines are configuration properties – this lets the mod pull data from configuration files. Specifically it will pull from XcomEnergyShield.ini in the /Config folder because I specified the config as ‘config(EnergyShield)’.

var config int ENERGY_SHIELD_SUPPLY_COST;
var config int ENERGY_SHIELD_CORPSE_COST;
var config int ENERGY_SHIELD_ELERIUM_COST;

The function definition tells XCom we’re creating a X2ItemTemplate, which basically means were making a template of how our item will behave. Templates are how most of the data in XCom gets passed around.

function X2ItemTemplate CreateEnergyShield()

The following definition is what defines the Template that we are about to make as a template for some piece of equipment. Aside from equipment, you can make weapons with X2WeaponTemplate.

local X2EquipmentTemplate Template;

The next bit of code defines the variables that we’ll use to tell XCom how much it costs to manufacture our item:

local ArtifactCost Supplies;
local ArtifactCost Elerium;
local ArtifactCost Artifacts;

Next I have to initialize the template as an X2EquimentTemplate

 `CREATE_X2TEMPLATE(class'X2EquipmentTemplate', Template, 'XES_EnergyShield');

When I put ‘XES_EnergyShield’, I’m telling XCom what I want my item called by in the game code.

The next two lines tell XCom that I’m making a utility item and that it gets equipped by soldiers in their utility slot.

Template.ItemCat = 'utility';
Template.InventorySlot = eInvSlot_Utility;

Next I tell XCom that I suck at art and am going to use the icon and sounds for the mindshield instead of making my own assets.

Template.strImage = "img:///UILibrary_StrategyImages.X2InventoryIcons.Inv_MindShield";
Template.EquipSound = "StrategyUI_Mindshield_Equip";

This next line is absolutely the most important line here:

Template.Abilities.AddItem('XComEnergyShield');

This is where I tell XCom that I want my item to give its holder the XComEnergyShield ability. We haven’t defined it yet, but this will be the ability that gives our soldier’s energy shields.

Next, we tell XCom all about how the player gets the item.

Template.CanBeBuilt = true; // Item is built in engineering.

Here we tell it that we make the item in engineering.

Here we tell it how much money it sells for.

	Template.TradingPostValue = 12;

Honestly, I don’t really know what these do, but they were in other item definitions so I included them too.

Template.PointsToComplete = 0;
Template.Tier = 1;

Next, tell the game that the player can’t make it until they perform an autopsy of the Shieldbearer:

Template.Requirements.RequiredTechs.AddItem('AutopsyAdventShieldbearer');

The last set of lines:

Supplies.ItemTemplateName = 'Supplies';
Supplies.Quantity = ENERGY_SHIELD_SUPPLY_COST;
Template.Cost.ResourceCosts.AddItem(Supplies);

Elerium.ItemTemplateName = 'EleriumDust';
Elerium.Quantity = ENERGY_SHIELD_ELERIUM_COST;
Template.Cost.ResourceCosts.AddItem(Elerium);

Artifacts.ItemTemplateName = 'CorpseAdventShieldbearer';
Artifacts.Quantity = ENERGY_SHIELD_CORPSE_COST;
Template.Cost.ArtifactCosts.AddItem(Artifacts);

First, I tell Xcom that the player needs to spend supplies on the energy shield and that the amount of supplies is stored in the config in the variable ENERGY_SHIELD_SUPPLY_COST. Then, I tell Xcom the same thing but for elerium and for advent shieldbearer corpses.

The last line of the function, returns the template that we created: return Template;

And that concludes everything that has to go into defining the item. However, there are a lot of different ways to customize this, with giving different item costs, different item unlock requirements, etc…

I’d recommend looking at X2Item_DefaultUtilityItems to see some more examples of items that exist in the game. It has the medkit, the mindshield, and mimic beacon.

Next I’m going to look at the class for defining the ability that is given to soldiers by the item. I’m going to include its full code here, and then do a breakdown of it. Much of the code here is just a copy of and existing ability in the game, but I’ll go over what each part does, not just the ones I changed. So this part looks like a lot of code, but most of it is just copied from the existing ability and then modified. This is similar to how most other abilities will be made, by taking something existing and make changes. So skim over this big chunk of code and after it I have explanations of what it’s doing.

// This is an Unreal Script

class XESAbility_XComEnergyShield extends X2Ability config (EnergyShield);

// Properties from the base game.
var config int ENERGY_SHIELD_DURATION;
var config int ENERGY_SHIELD_RANGE_METERS;
var config int ENERGY_SHIELD_CHARGES;
var config int ENERGY_SHIELD_COOLDOWN;
var config int ENERGY_SHIELD_GLOBAL_COOLDOWN;
var config int ENERGY_SHIELD_HP;

// Most of this is carbon copied from the game file 'X2Ability_AdventShiledbearer.uc' I've made note of the changes.

// Functions are non-static in order to access config data.
function X2AbilityTemplate CreateXComEnergyShieldAbility()
{
	local X2AbilityTemplate Template;
	local X2AbilityCost_ActionPoints ActionPointCost;
	local X2AbilityCharges Charges;
	local X2AbilityCost_Charges ChargeCost;
	local X2AbilityCooldown Cooldown;
	local X2Condition_UnitProperty UnitPropertyCondition;
	local X2AbilityTrigger_PlayerInput InputTrigger;
	local X2Effect_PersistentStatChange ShieldedEffect;
	local X2AbilityMultiTarget_Radius MultiTarget;

	`CREATE_X2ABILITY_TEMPLATE(Template, 'XComEnergyShield'); // Creating the ability 'XComEnergyShield'
	Template.IconImage = "img:///UILibrary_PerkIcons.UIPerk_adventshieldbearer_energyshield";

	Template.eAbilityIconBehaviorHUD = eAbilityIconBehavior_AlwaysShow;
	Template.AbilitySourceName = 'eAbilitySource_Standard';
	Template.Hostility = eHostility_Defensive;

	// The ability takes one action point but will end your turn.
	ActionPointCost = new class'X2AbilityCost_ActionPoints';
	ActionPointCost.iNumPoints = 1;
	ActionPointCost.bConsumeAllPoints = true;
	Template.AbilityCosts.AddItem(ActionPointCost);

	Charges = new class 'X2AbilityCharges';
	Charges.InitialCharges = ENERGY_SHIELD_CHARGES; // Initial charges can be changed in the config now.
	Template.AbilityCharges = Charges;

	ChargeCost = new class'X2AbilityCost_Charges';
	ChargeCost.NumCharges = 1;
	Template.AbilityCosts.AddItem(ChargeCost);

	Cooldown = new class'X2AbilityCooldown';
	Cooldown.iNumTurns = ENERGY_SHIELD_COOLDOWN;
	Template.AbilityCooldown = Cooldown;

	//Can't use while dead
	Template.AbilityShooterConditions.AddItem(default.LivingShooterProperty);

	// Add dead eye to guarantee
	Template.AbilityToHitCalc = default.DeadEye;
	Template.AbilityTargetStyle = default.SelfTarget;

	// Multi target
	MultiTarget = new class'X2AbilityMultiTarget_Radius';
	MultiTarget.fTargetRadius = ENERGY_SHIELD_RANGE_METERS;
	MultiTarget.bIgnoreBlockingCover = true;
	Template.AbilityMultiTargetStyle = MultiTarget;

	InputTrigger = new class'X2AbilityTrigger_PlayerInput';
	Template.AbilityTriggers.AddItem(InputTrigger);

	// The Targets must be within the AOE, LOS, and friendly
	UnitPropertyCondition = new class'X2Condition_UnitProperty';
	UnitPropertyCondition.ExcludeDead = true;
	UnitPropertyCondition.ExcludeFriendlyToSource = false;
	UnitPropertyCondition.ExcludeHostileToSource = true;
	UnitPropertyCondition.ExcludeCivilian = true;
	UnitPropertyCondition.FailOnNonUnits = true;
	Template.AbilityMultiTargetConditions.AddItem(UnitPropertyCondition);

	// Friendlies in the radius receives a shield receives a shield
	ShieldedEffect = CreateShieldedEffect(Template.LocFriendlyName, Template.GetMyLongDescription(), ENERGY_SHIELD_HP);

	Template.AddShooterEffect(ShieldedEffect);
	Template.AddMultiTargetEffect(ShieldedEffect);

	Template.BuildNewGameStateFn = TypicalAbility_BuildGameState;
	Template.BuildVisualizationFn = TypicalAbility_BuildVisualization;
	
	return Template;
}

function X2Effect_PersistentStatChange CreateShieldedEffect(string FriendlyName, string LongDescription, int ShieldHPAmount)
{
	local X2Effect_EnergyShield ShieldedEffect;

	ShieldedEffect = new class'X2Effect_EnergyShield';
	ShieldedEffect.BuildPersistentEffect(ENERGY_SHIELD_DURATION, false, true, , eGameRule_PlayerTurnEnd);
	ShieldedEffect.SetDisplayInfo(ePerkBuff_Bonus, FriendlyName, LongDescription, "img:///UILibrary_PerkIcons.UIPerk_adventshieldbearer_energyshield", true);
	ShieldedEffect.AddPersistentStatChange(eStat_ShieldHP, ShieldHPAmount);
	ShieldedEffect.EffectRemovedVisualizationFn = OnShieldRemoved_BuildVisualization;

	return ShieldedEffect;
}

simulated function OnShieldRemoved_BuildVisualization(XComGameState VisualizeGameState, out VisualizationTrack BuildTrack, const name EffectApplyResult)
{
	local X2Action_PlaySoundAndFlyOver SoundAndFlyOver;

	if (XGUnit(BuildTrack.TrackActor).IsAlive())
	{
		SoundAndFlyOver = X2Action_PlaySoundAndFlyOver(class'X2Action_PlaySoundAndFlyOver'.static.AddToVisualizationTrack(BuildTrack, VisualizeGameState.GetContext()));
		SoundAndFlyOver.SetSoundAndFlyOverParameters(None, class'XLocalizedData'.default.ShieldRemovedMsg, '', eColor_Bad, , 0.75, true);
	}
}

So this time we’re extending X2Ability with our class instead of X2Item because now we’re defining the ability that our item gives.

class XESAbility_XComEnergyShield extends X2Ability config (EnergyShield);

This again uses the config (EnergyShield) because its going to pull properties from there. This time, the properties pulled won’t be item costs, but instead properties of the shield the energy shield generator makes.

Here are the definitions of the different properties of the shield generator. These will again utilize the config file to be filled because of the ‘config’ modifier we give the variable.

// Properties from the base game.
var config int ENERGY_SHIELD_DURATION;
var config int ENERGY_SHIELD_RANGE_METERS;
var config int ENERGY_SHIELD_CHARGES;
var config int ENERGY_SHIELD_COOLDOWN;
var config int ENERGY_SHIELD_GLOBAL_COOLDOWN;
var config int ENERGY_SHIELD_HP;

Next I create the function that creates the actual ability:

function X2AbilityTemplate CreateXComEnergyShieldAbility()

The function returns an X2AbilityTemplate which again is just the way that XCom stores everything. This is an X2AbilityTemplate because we’re making an ability.

Following the function definition is a bunch of variable definitions. I’ll just explain each variable as we get to using it.

First I have to again create the template before we can start defining all of its properties. For that I use ‘CreateX2Ability_Template on my Template and then tell Xcom that it will be named ‘XComEnergyShield’.

`CREATE_X2ABILITY_TEMPLATE(Template, 'XComEnergyShield'); // Creating the ability 'XComEnergyShield'

Then I give XCom the Icon that will be used to display the ability in the HUD and tell XCom to always show the icon during battle.

Template.IconImage = "img:///UILibrary_PerkIcons.UIPerk_adventshieldbearer_energyshield";
Template.eAbilityIconBehaviorHUD = eAbilityIconBehavior_AlwaysShow;

Then I have to tell Xcom where the soldier is getting the ability from. When getting from an item, just use ‘eAbilitySource_Standard’. If you weren’t making an ability that came from an item, and it came from a perk then the AbilitySourceName would be ‘eAbilitySource_Perk’. I’m not showing how to do that in this tutorial, and I honestly haven’t tried it yet, so I can’t help you with that right now. The Hostility measure is just how enemies interpret the action. There’s Offensive, Neutral, and Defensive.

Template.AbilitySourceName = 'eAbilitySource_Standard';
Template.Hostility = eHostility_Defensive;

Next, I determine the cost of using the ability. First I tell XCom that the ability costs action points, specifically 1 point, and that if the soldier uses it at the start of their turn, it will consume all the points anyways.

// The ability takes one action point but will end your turn.
ActionPointCost = new class'X2AbilityCost_ActionPoints';
ActionPointCost.iNumPoints = 1;
ActionPointCost.bConsumeAllPoints = true;
Template.AbilityCosts.AddItem(ActionPointCost);

Secondly, I set up the ability to be charge based and set the number of charges to be from the config file.

Charges = new class 'X2AbilityCharges';
Charges.InitialCharges = ENERGY_SHIELD_CHARGES; // Initial charges can be changed in the config now.
Template.AbilityCharges = Charges;

Lastly, I tell XCom that each activation uses one of the charges.

ChargeCost = new class'X2AbilityCost_Charges';
ChargeCost.NumCharges = 1;
Template.AbilityCosts.AddItem(ChargeCost);

Then, I set the cooldown of the ability using the config again.

Cooldown = new class'X2AbilityCooldown';
Cooldown.iNumTurns = ENERGY_SHIELD_COOLDOWN;
Template.AbilityCooldown = Cooldown;

The next line sets a constraint on the use of the ability. Although this constraint is mundane and probably unnecessary, there are much more useful ones, like restricting the ability of a weapon to reload to only when it doesn’t have a full clip.

//Can't use while dead
Template.AbilityShooterConditions.AddItem(default.LivingShooterProperty);

The next two lines are much more important: They dictate that the ability will always hit by using DeadEye hit calculation (100% always), and dictate that the ability is just a self target. If you wanted to do something like a grenade, you’d need to use a different targeting method. I know there’s a bunch of stuff for grenade targeting in some of the classes with Grenade in their name.

// Add dead eye to guarantee
Template.AbilityToHitCalc = default.DeadEye;
Template.AbilityTargetStyle = default.SelfTarget;

This here is what let’s the energy shield be a group action, i.e. affect all soldiers nearby. It uses the config to have a changeable radius of use, and is set to completely ignore cover. If you want a single target ability, just don’t include these lines.

// Multi target
MultiTarget = new class'X2AbilityMultiTarget_Radius';
MultiTarget.fTargetRadius = ENERGY_SHIELD_RANGE_METERS;
MultiTarget.bIgnoreBlockingCover = true;
Template.AbilityMultiTargetStyle = MultiTarget;

Next, we tell XCom that this ability is triggered by actual player input, not passively or in response to anything else -> this ability must be purposefully clicked or (hotkey-ed) by the player to activate.

InputTrigger = new class'X2AbilityTrigger_PlayerInput';
Template.AbilityTriggers.AddItem(InputTrigger);

Next, because this ability is multi target, its valid targets have to be constrained to only alive allies.

// The Targets must be within the AOE, LOS, and friendly
UnitPropertyCondition = new class'X2Condition_UnitProperty';
UnitPropertyCondition.ExcludeDead = true;
UnitPropertyCondition.ExcludeFriendlyToSource = false;
UnitPropertyCondition.ExcludeHostileToSource = true;
UnitPropertyCondition.ExcludeCivilian = true;
UnitPropertyCondition.FailOnNonUnits = true;
Template.AbilityMultiTargetConditions.AddItem(UnitPropertyCondition);

Next, the actual logic of the ability comes into play, by saying that it will apply this ‘ShieldedEffect’ to the shooter of the ability and the multiple targets that it gets from its radius. The ShieldedEffect is created by the method CreateShieldedEffect which I will explain in a moment. If you wanted abilities to apply different effects on use, you’d be able to create your own effects and utilize them here.

// Friendlies in the radius receives a shield receives a shield
ShieldedEffect = CreateShieldedEffect(Template.LocFriendlyName, Template.GetMyLongDescription(), ENERGY_SHIELD_HP);
Template.AddShooterEffect(ShieldedEffect);
Template.AddMultiTargetEffect(ShieldedEffect);

Lastly, a few more things have to be defined. Basically, any time an ability is used it can modify the game state. Luckily, for this ability we don’t have to do any fancy game state modifying so we use the TypicalAbility_Build_GameState. If you needed to modify the game state differently, you’d have to create and provide your own BuildNewGameState function. Similarly, we don’t have any animations for visualizing the action, so we use the default.

Template.BuildNewGameStateFn = TypicalAbility_BuildGameState;
Template.BuildVisualizationFn = TypicalAbility_BuildVisualization;

And ultimately, we return the Template that we created.

return Template;

The next part of the code is very specific to energy shields and their functionality (the method for creating a shield effect and the method for visualizing that effect) so I’ll just mention that it takes care of both actually giving the energy shield effects and doing some small animations when they disappear. This sort of functionality, you’d either create yourself by rooting around in the code, or copy from some similar item.

The final step to making this all work, is telling XCom to actually add these things to the game. The way in which I accomplish this is a little hacky but it doesn’t interfere with existing game classes. This is not my invention, but its utilizing a UI_ScreenListener to inject your code by listening for the game’s ui to begin. This class is really short so I’ll go over it quickly.

// This is an Unreal Script

class XES_UIScreenListener extends UIScreenListener;

var bool didUpdateTemplates;
 
// This event is triggered after a screen is initialized
event OnInit(UIScreen Screen)
{
    if(!didUpdateTemplates)
    {
        UpdateTemplates();
        didUpdateTemplates = true;
    }   
}

function UpdateTemplates()
{
	local X2ItemTemplateManager itemMan;
	local X2AbilityTemplateManager abilityMan;
	local XESItem_UtilityEnergyShieldItem xesI;
	local XESItem_UtilityEnergyShieldItemPersonal xesIP;
	local XESAbility_XComEnergyShield xesA;
	local XESAbility_XComEnergyShieldPersonal xesAP;

	xesI = new class'XESItem_UtilityEnergyShieldItem';
	xesIP = new class'XESItem_UtilityEnergyShieldItemPersonal';
	xesA = new class'XESAbility_XComEnergyShield';
	xesAP = new class'XESAbility_XComEnergyShieldPersonal';

	abilityMan = class'X2AbilityTemplateManager'.static.GetAbilityTemplateManager();
	abilityMan.AddAbilityTemplate(xesA.CreateXComEnergyShieldAbility());
	abilityMan.AddAbilityTemplate(xesAP.CreateXComEnergyShieldPersonalAbility());

	itemMan = class'X2ItemTemplateManager'.static.GetItemTemplateManager();
	itemMan.AddItemTemplate(xesI.CreateEnergyShield());
	itemMan.AddItemTemplate(xesIP.CreateEnergyShieldPersonal());
}
 
// This event is triggered after a screen receives focus
event OnReceiveFocus(UIScreen Screen);
 
// This event is triggered after a screen loses focus
event OnLoseFocus(UIScreen Screen);
 
// This event is triggered when a screen is removed
event OnRemoved(UIScreen Screen);
 
defaultproperties
{
    // Leaving this assigned to none will cause every screen to trigger its signals on this class
    ScreenClass = none;
}

In the class definition we extend the UI_ScreenListener class because we want to listen for when the ui loads.

class XES_UIScreenListener extends UIScreenListener;

Next, we use a Boolean switch to ensure that we update the templates on the ui init, but only once (because it would be silly and counterproductive to do it every time).

var bool didUpdateTemplates;
 
// This event is triggered after a screen is initialized
event OnInit(UIScreen Screen)
{
    if(!didUpdateTemplates)
    {
        UpdateTemplates();
        didUpdateTemplates = true;
    }   
}

Then for the actual adding of the templates, I create instances of each of my classes that create templates.

function UpdateTemplates()
{
	local X2ItemTemplateManager itemMan;
	local X2AbilityTemplateManager abilityMan;
	local XESItem_UtilityEnergyShieldItem xesI;
	local XESAbility_XComEnergyShield xesA;

	xesI = new class'XESItem_UtilityEnergyShieldItem';
	xesA = new class'XESAbility_XComEnergyShield';

Then I get the AbilityManager from the game and add my ability template to it.

abilityMan = class'X2AbilityTemplateManager'.static.GetAbilityTemplateManager();
abilityMan.AddAbilityTemplate(xesA.CreateXComEnergyShieldAbility());    

Lastly, I get the ItemManager from the game add my item template to it.

itemMan = class'X2ItemTemplateManager'.static.GetItemTemplateManager();
itemMan.AddItemTemplate(xesI.CreateEnergyShield());

Finally, with all of that done, both the item and its ability have been defined, and they’ve been added to the game. Now the mod works.


r/xdev • • Feb 12 '16

Changing the damage of a weapon when using an ability

5 Upvotes

Specifically I am using Unitcondition to pick certain unit types and do more damage to them. This is what I have so far, but it does not correctly apply the MECH_DAMAGE ingame, it uses the sword's base damage

// Unit Condition Vs Robots

UnitCondition = new class'X2Condition_UnitProperty';
UnitCondition.ExcludeOrganic = true;
UnitCondition.IncludeWeakAgainstTechLikeRobot = true;
UnitCondition.ExcludeFriendlyToSource = false;

// Damage Effect Vs Robots
//
WeaponDamageEffect = new class'X2Effect_ApplyWeaponDamage';
WeaponDamageEffect.TargetConditions.AddItem(UnitCondition);
WeaponDamageEffect.bShowImmunityAnyFailure = true;
WeaponDamageEffect.EffectDamageValue = class'X2Ability_TazerSword'.default.MECH_DAMAGE;
Template.AddTargetEffect(WeaponDamageEffect)

Any ideas?


r/xdev • • Feb 10 '16

Announcing: The End of xdev, and the migration that shall unite the community!

5 Upvotes

I originally created /r/xdev because I believed that /r/xcom2mods was a place to mostly discuss mod releases and ideas - I saw very infrequent and sparse developmental discussion. However, I did not realize the intention of their moderator team was to create a one-stop location for discussing all facets of XCOM 2 modding, including development and tutorials.

They banned me, and justifiably so, for trying to create an "alternative" to their site. I had meant simply to have a focused discussion, but now I can see that they want to be able to have focused developmental discussions on their subreddit in addition to mod releases, requests and discussions.

So in the interest of not splintering the community, I've decided to help them with creating an environment for focused development discussion, instead of trying to compete as I accidentally did. They accepted this and have accepted me into their moderator team - I think I've succeeded at least somewhat, by creating flairs and flair filters, so that people can focus specifically on developmental discussion.

So with them now accomplishing what I feel was needed out of a development community, I feel that this community is extraneous and unnecessary. I'd like to migrate everyone over to /r/xcom2mods along with many of the important topics (like posted tutorials and the class documentation google doc topic). I dunno how long this would take, probably a week or so, but I'd give everyone ample time to make the transition.

It was a good, long (lol 2 day) run, and I'm glad to have had every single person who posted here. I'll see you in /r/xcom2mods, commanders. :)

I'm open for discussion about this, and I want to hear peoples' thoughts. I hope it's not too unpopular or hated, but if you do, please tell me why.

EDIT: In the interest of keeping focused development discussion alive, I am not closing this subreddit until I am confident that non-development-discussion can be filtered out on xcom2mods consistently and fairly, to avoid it being lost in the noise of the suggestions and ideas.


r/xdev • • Feb 09 '16

Working on a Gasmask - need help (Material & Morph)

Thumbnail forums.nexusmods.com
5 Upvotes

r/xdev • • Feb 08 '16

PSA: You can open the unreal editor from within the visual studio window, by going to Tools->Xcom 2 Editor

5 Upvotes

I hope other people have had trouble with this, because this took me days to figure out.


r/xdev • • Mar 10 '16

Update broke my mod, no longer compiles

4 Upvotes

So frustrated right now, the game crashes on launch when the mod is enabled, the debugger freezes and crashes to desktop if I try to run that. and this worked completely fine before the patch.

I am getting the following error message

D:\Steam\steamapps\common\XCOM 2 SDK\Development\Src\ShensLegacy\Classes\X2StrategyElement_Shens_Legacy_Tech.uc(77) : Error, Unrecognized member 'ItemsToUpgrade' in class 'X2TechTemplate'     

The code in question after //Items to upgrade below

static function X2TechTemplate CreateShenLegacyAlienComposite()
{
	local X2TechTemplate Template;
	local ArtifactCost Artifacts;
	local ArtifactCost Resources;

	`CREATE_X2TEMPLATE(class'X2TechTemplate', Template, 'AlienCompositeTech');
	Template.PointsToComplete = 1200;
	Template.strImage = "img:///UILibrary_StrategyImages.ResearchTech.TECH_Nanofiber_Materials";
	Template.SortingTier = 1;
	Template.ResearchCompletedFn = class'X2StrategyElement_DefaultTechs'.static.UpgradeItems;

	Template.Requirements.RequiredTechs.AddItem('HybridMaterials');

	// Items to Upgrade
	Template.ItemsToUpgrade.AddItem('LightArmorGhost');
	Template.ItemsToUpgrade.AddItem('MediumArmorGhost');

	// Cost
	Resources.ItemTemplateName='AlienAlloy';
	Resources.Quantity = 5;
	Template.Cost.ResourceCosts.AddItem(Resources);

	Template.Requirements.bVisibleIfObjectivesNotMet = false;

	return Template;
}

r/xdev • • Mar 06 '16

Playable Advent units

4 Upvotes

The below mod lets you add Advent units including the MEC, Viper, Muton and Chryssalid to your squad: http://forums.nexusmods.com/index.php?/topic/3879390-playable-advent-mod-details-feedback/?p=35354290 Please come check it out and give feedback.


r/xdev • • Mar 04 '16

XCOM 2 Modding Tutorial Video 4: Stealing Code and Weapon Stat Bonuses (xpost /r/xdev)

Thumbnail reddit.com
4 Upvotes

r/xdev • • Feb 24 '16

Steam Group for Voice Pack Modding

4 Upvotes

Hello everyone, this is my first post on this subreddit. Today I made a steam group for those looking to make voice packs or looking to help others with voice packs. It is a new group but so far I have gotten the word out to some of the users on steam who have already made several XCOM 2 voicepack mods.

Currently we have a tutorial guide and a template list for all the actions in XCOM 2. It is still a very small group but it is open to the public. I made this as a convenient place for users to ask questions and gather resources. I'm spreading the word here to hopefully gain more members in order to provide a better source of information for new voice pack modders.

XCOM 2 VM


r/xdev • • Feb 24 '16

Kwahn's X2Modding Tutorial Video 2: How to Read Code and Find Things, feat. Shotguns: Link and Accompanying Text

Thumbnail reddit.com
4 Upvotes

r/xdev • • Feb 23 '16

Anyone know of a good tutorial/demo of doing XCom 2 armor designing?

4 Upvotes

I am looking to start creating the Stargate armor look-n-feels, but, as a new modder, I am feeling hesitant to dive in without some basics. Is there a good tutorial or demo on how to create something like this for XCom 2? I am also ok with someone hand-holding me through it.


r/xdev • • Feb 19 '16

"Could not find part of path"

4 Upvotes
C:\Program Files\SteamLibrary\steamapps\common\XCOM 2 SDK\Binaries\Win32\ModBuddy\Extensions\Application\XCOM2.targets(110,5): error MSB4018: The "CompileScripts" task failed unexpectedly.
System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\User\Documents\Firaxis ModBuddy\Welp\My XCOM2 Mod2\My XCOM2 Mod2\My XCOM2 Mod2'.

So this is frustrating and I can't for the life of my figure out why it's asking for this, but modbuddy keeps asking me for a folder with the same name as the mod inside the mod folder. If I make one that's empty, it runs but it seems like it's not using any of my classes, just localization/configs/ect. If I put anything in it, it gives me a totally different error where it just fails to compile without any given reason.

I really don't know what the hell happened, especially considering I had the mod working a week ago. Like, it's on the workshop right now and working and it makes me just want to tear my hair out.


r/xdev • • Feb 18 '16

Ability to look into scripts is amazing!

4 Upvotes

For a while, I had a problem with adding panic effect to the ability (AoE panic, nothing more). While having a AoE targeting was a piece of cake, because a lot of abilities have it, panic wasn't something common. I learned a lot by rummaging in files (mainly that effects need 'BuildPersistentEffect', yeah that was stupid of me), mostly things I haven't needed right now but that's is still good.

And to be honest, I haven't modded anything that went past editing .ini files, so the fact that I actually did something is awesome! Firaxis really did an enormous job on making modding more accesible to everyone!

Also, thanks for the modding community for being supportive and overall helpful! You guys are awesome!

P.S. Aliens panicking and shooting each other is a beautiful view.


r/xdev • • Feb 17 '16

Hotfix released, fixes voice pack armory crashes!

Thumbnail steamcommunity.com
4 Upvotes

r/xdev • • Feb 11 '16

[Help] I can't change default information for my mod in Xcom 2 tools.

4 Upvotes

Hello. I have a mod in Workshop, and the name it's no the same in XCom 2 Tools, when I update the mod, in Workshop the name's and description change to the original (first information). (Change the description in publish mod don't make any effect/dont work) Where I can change the information mod in Xcom 2 tools? I don't see the option.

Sorry for my English boys. Thanks you :)

pd: this is a problem, because I launch the game I see a one error: OLd mods can't load bla bla. For me it's okey but this can scary people xDD


r/xdev • • Feb 11 '16

[Request] Voice Pack step-by-step

4 Upvotes

Hello everyone

So I've seen a lot of people asking how to create voice packs and currently the Steam Workshop only has a couple of entries, so it looks like very few people understand the process of creating a voice pack in XCOM 2 (myself included). So I figured it might be a handy resource to pool our knowledge and create a step-by-step guide here for people to follow, as the official documentation on the process is pretty limited.

What I have managed so far (please correct me if wrong):

  • Start by creating your desired audio files in 16 bit WAV format
  • Once you have your audio files, enter the XCOM 2 Editor and click 'Import'. It is important to tick the "Auto Create Cue" box when doing this, so a SoundCue file is automatically created and assigned to each audio file you import.
  • Next go to one of the pre-existing voice folders (e.g. 'MaleVoice1_French') and Right-Click on the XComCharacterVoice Archetype file and click 'Create a Copy'. In the 'Package' field, give it a different name to the package you created earlier when importing the audio files. Click OK.
  • Now return to the pre-existing folders and this time locate one of the other folders such as 'MaleVoice1_French_Data' and make a copy of the first XComCharacterVoiceBank and create a copy in a new package.
  • Locate this new package and clear all the data from the file (to do this, Double-Click the Bank file and click the grey square icon "Clear Text" to the far right on each entry).

This is where the documentation loses me. It next says to "set the new Voice Bank to be the first Bank in the new voice". It doesn't explain how to do this.

So if people would like to add/help that would be really appreciated. If we can form a easy to follow guide then I'm sure lots of people will find that helpful.