Jump to content

Schematic troubles - need help badly


Xcomhadrian

Recommended Posts

Hi folks. Im currently working on a fairly simple mod to add a custom ballistic weapon to Xcom 2 as a "natural" upgrade between ballistics and magnetics. I am having one helluva time trying to get the silly thing to work properly though.

 

As a "modweapon" template I can get it to work but I cant seem to make it an "infinite" weapon (ie buy once) for universal usage. So I rewrote the entire thing using a schematic. Now every time I build the weapon in the armory it gives me the Magnetic rifle instead. I am pretty sure its because the default assault rifle states its "upgrade item" is the magnetic rifle. So I need to over-ride that to ensure when you buy my weapon you get your default weapon updated to the new model. And when you buy a magnetic weapon my gun gets updated to it instead.

 

 

How the hell do I tell the game I want to over-write the vanilla assault rifles upgrade path?

Link to comment
Share on other sites

Imho I dont think you need to change game states for this, but I could be wrong.

 

If you want to change the X2WeaponTemplate.UpgradeItem I know how to do that. In fact I am thinking about doing a mod to offer that kind of service, since stuff like this comes up allot.

shameless plug: http://forums.nexusmods.com/index.php?/topic/3830880-mod-easy-template-modifications/

 

In the meantime, what does your script to change the WeaponTemplate look like and on which screen are you listening?

Link to comment
Share on other sites

My intention is to have a weapon tier in between ballistic and magnetic for my own mod weapon. The weapon works absolutely fine with a simple template as a single purchase item. But I cannot get the game to recognize it as an infinite item with just a weapon template . So I rewrote it as two scripts; One a schematic, the other a standard weapon template. It shows up fine in the menu to build, and once built it does indeed get removed from the build screen. But it then gives me the wrong weapon.

 

Here is my schematic;

class X2Item_AARSchematics extends X2Item;





static function array<X2DataTemplate> CreateTemplates()

{

    local array<X2DataTemplate> Schematics;

    

    // Weapon Schematics

    Schematics.AddItem(CreateTemplate_AAR_Conventional_Schematic());





    return Schematics;

}



static function X2DataTemplate CreateTemplate_AAR_Conventional_Schematic()

{

    local X2SchematicTemplate Template;

    local ArtifactCost Resources;



    `CREATE_X2TEMPLATE(class'X2SchematicTemplate', Template, 'AAR_CV_Schematic');

    Template.ItemCat = 'weapon';

    Template.strImage = "img:///UILibrary_Common.ConvAssaultRifle.ConvAssault_Base";

    Template.CanBeBuilt = true;

    Template.bOneTimeBuild = true;

    Template.bInfiniteItem = true;

    Template.HideInInventory = false;

    Template.PointsToComplete = 0;

    Template.Tier = 1;

    Template.OnBuiltFn = class'X2Item_DefaultSchematics'.static.UpgradeItems;



    // Items to upgrade

    Template.ItemsToUpgrade.AddItem('AssaultRifle_CV');



    // Items being created

    Template.ReferenceItemTemplate = 'AAR_CV';

    



    // Requirements - Temporary

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

    Template.Requirements.RequiredEngineeringScore = 2;

    Template.Requirements.bVisibleIfPersonnelGatesNotMet = true;



    // Cost - Temporary

     Resources.ItemTemplateName = 'Supplies';

     Resources.Quantity = 25;

     Template.Cost.ResourceCosts.AddItem(Resources);



    Resources.ItemTemplateName = 'AlienAlloy';

     Resources.Quantity = 10;

     Template.Cost.ResourceCosts.AddItem(Resources);



    return Template;



}
 

And this is my weapon template;


class X2Item_AdvancedAssaultRifle_Weapon extends X2Item;

static function array<X2DataTemplate> CreateTemplates()
{
    local array<X2DataTemplate> Weapons;
    local X2ItemTemplateManager ItemTemplateManager;
    Weapons.AddItem(CreateTemplate_AAR_Conventional());

    ItemTemplateManager = class'X2ItemTemplateManager'.static.GetItemTemplateManager();

    AddCritUpgrade(ItemTemplateManager, 'CritUpgrade_Bsc');
    AddCritUpgrade(ItemTemplateManager, 'CritUpgrade_Adv');
    AddCritUpgrade(ItemTemplateManager, 'CritUpgrade_Sup');

    AddAimBonusUpgrade(ItemTemplateManager, 'AimUpgrade_Bsc');
    AddAimBonusUpgrade(ItemTemplateManager, 'AimUpgrade_Adv');
    AddAimBonusUpgrade(ItemTemplateManager, 'AimUpgrade_Sup');

    AddClipSizeBonusUpgrade(ItemTemplateManager, 'ClipSizeUpgrade_Bsc');
    AddClipSizeBonusUpgrade(ItemTemplateManager, 'ClipSizeUpgrade_Adv');
    AddClipSizeBonusUpgrade(ItemTemplateManager, 'ClipSizeUpgrade_Sup');

    AddFreeFireBonusUpgrade(ItemTemplateManager, 'FreeFireUpgrade_Bsc');
    AddFreeFireBonusUpgrade(ItemTemplateManager, 'FreeFireUpgrade_Adv');
    AddFreeFireBonusUpgrade(ItemTemplateManager, 'FreeFireUpgrade_Sup');

    AddReloadUpgrade(ItemTemplateManager, 'ReloadUpgrade_Bsc');
    AddReloadUpgrade(ItemTemplateManager, 'ReloadUpgrade_Adv');
    AddReloadUpgrade(ItemTemplateManager, 'ReloadUpgrade_Sup');

    AddMissDamageUpgrade(ItemTemplateManager, 'MissDamageUpgrade_Bsc');
    AddMissDamageUpgrade(ItemTemplateManager, 'MissDamageUpgrade_Adv');
    AddMissDamageUpgrade(ItemTemplateManager, 'MissDamageUpgrade_Sup');

    AddFreeKillUpgrade(ItemTemplateManager, 'FreeKillUpgrade_Bsc');
    AddFreeKillUpgrade(ItemTemplateManager, 'FreeKillUpgrade_Adv');
    AddFreeKillUpgrade(ItemTemplateManager, 'FreeKillUpgrade_Sup');

    return Weapons;
}

static function X2DataTemplate CreateTemplate_AAR_Conventional()

{
    local X2WeaponTemplate Template;

    // Basic properties copied from the conventional assault rifle
    //=====================================================================
    `CREATE_X2TEMPLATE(class'X2WeaponTemplate', Template, 'AAR_CV');
    Template.WeaponPanelImage = "_ConventionalRifle";
    Template.EquipSound = "Conventional_Weapon_Equip";
    Template.ItemCat = 'weapon';
    Template.WeaponCat = 'rifle';
    Template.WeaponTech = 'conventional';
    Template.strImage = "img:///UILibrary_Common.ConvAssaultRifle.ConvAssault_Base";
    Template.Tier = 1;

    Template.RangeAccuracy = class'X2Item_DefaultWeapons'.default.MEDIUM_CONVENTIONAL_RANGE;
    Template.BaseDamage = class'X2Item_DefaultWeapons'.default.ASSAULTRIFLE_CONVENTIONAL_BASEDAMAGE;
    Template.Aim = class'X2Item_DefaultWeapons'.default.ASSAULTRIFLE_CONVENTIONAL_AIM;
    Template.CritChance = class'X2Item_DefaultWeapons'.default.ASSAULTRIFLE_CONVENTIONAL_CRITCHANCE;
    Template.iClipSize = class'X2Item_DefaultWeapons'.default.ASSAULTRIFLE_CONVENTIONAL_ICLIPSIZE;
    Template.iSoundRange = class'X2Item_DefaultWeapons'.default.ASSAULTRIFLE_CONVENTIONAL_ISOUNDRANGE;
    Template.iEnvironmentDamage = class'X2Item_DefaultWeapons'.default.ASSAULTRIFLE_CONVENTIONAL_IENVIRONMENTDAMAGE;
    Template.NumUpgradeSlots = 1;
    Template.InventorySlot = eInvSlot_PrimaryWeapon;
    Template.Abilities.AddItem('StandardShot');    
    Template.Abilities.AddItem('Overwatch');    
    Template.Abilities.AddItem('OverwatchShot');
    Template.Abilities.AddItem('Reload');
    Template.Abilities.AddItem('HotLoadAmmo');
    Template.UIArmoryCameraPointTag = 'UIPawnLocation_WeaponUpgrade_AssaultRifle';
    Template.AddDefaultAttachment('Mag', "ConvAssaultRifle.Meshes.SM_ConvAssaultRifle_MagA", , "img:///UILibrary_Common.ConvAssaultRifle.ConvAssault_MagA");
    Template.AddDefaultAttachment('Optic', "ConvAssaultRifle.Meshes.SM_ConvAssaultRifle_OpticA", , "img:///UILibrary_Common.ConvAssaultRifle.ConvAssault_OpticA");
    Template.AddDefaultAttachment('Reargrip', "ConvAssaultRifle.Meshes.SM_ConvAssaultRifle_ReargripA", , "img:///UILibrary_Common.ConvAssaultRifle.ConvAssault_ReargripA");
    Template.AddDefaultAttachment('Stock', "ConvAssaultRifle.Meshes.SM_ConvAssaultRifle_StockA", , "img:///UILibrary_Common.ConvAssaultRifle.ConvAssault_StockA");
    Template.AddDefaultAttachment('Trigger', "ConvAssaultRifle.Meshes.SM_ConvAssaultRifle_TriggerA", , "img:///UILibrary_Common.ConvAssaultRifle.ConvAssault_TriggerA");
    Template.AddDefaultAttachment('Light', "ConvAttachments.Meshes.SM_ConvFlashLight", , "img:///UILibrary_Common.ConvAssaultRifle.ConvAssault_LightA");
    Template.iPhysicsImpulse = 5;
    Template.CanBeBuilt = True;
    Template.bInfiniteItem = true;
    Template.UpgradeItem = '';
    Template.fKnockbackDamageAmount = 5.0f;
    Template.fKnockbackDamageRadius = 0.0f;
    // Requirements
    Template.Requirements.RequiredTechs.AddItem('ProvingGrounds');
    Template.Requirements.RequiredEngineeringScore = 2;
    Template.Requirements.bVisibleIfPersonnelGatesNotMet = true;


    //=====================================================================
    // Enhancements we're making to base
    //=====================================================================
    Template.BaseDamage.Damage += 1; //Boosts base damage
    Template.CritChance += 5; //Boost critical chance
    Template.Abilities.AddItem('ChainShot'); //Confers chain shot to the bearer
    Template.GameArchetype = "WP_HK416_CV.WP_HK416_CV"; //Uses a custom archetype
    //=====================================================================
    
    return Template;
}

// ************  Add mappings for upgrades to attachment models/icons

static function AddCritUpgrade(X2ItemTemplateManager ItemTemplateManager, Name TemplateName)
{
    local X2WeaponUpgradeTemplate Template;

    Template = X2WeaponUpgradeTemplate(ItemTemplateManager.FindItemTemplate(TemplateName));

    //Parameters are :     AttachSocket, UIArmoryCameraPointTag, MeshName, ProjectileName, MatchWeaponTemplate, AttachToPawn, IconName, InventoryIconName, InventoryCategoryIcon, ValidateAttachmentFn
    Template.AddUpgradeAttachment('Optic', 'UIPawnLocation_WeaponUpgrade_AssaultRifle_Optic', "ConvAssaultRifle.Meshes.SM_ConvAssaultRifle_OpticB", "", 'AAR_CV', , "img:///UILibrary_Common.ConvAssaultRifle.ConvAssault_OpticB", "img:///UILibrary_StrategyImages.X2InventoryIcons.ConvAssault_OpticB_inv", "img:///UILibrary_StrategyImages.X2InventoryIcons.Inv_weaponIcon_scope");
}

static function AddAimBonusUpgrade(X2ItemTemplateManager ItemTemplateManager, Name TemplateName)
{
    local X2WeaponUpgradeTemplate Template;

    Template = X2WeaponUpgradeTemplate(ItemTemplateManager.FindItemTemplate(TemplateName));
    //Parameters are :     AttachSocket, UIArmoryCameraPointTag, MeshName, ProjectileName, MatchWeaponTemplate, AttachToPawn, IconName, InventoryIconName, InventoryCategoryIcon, ValidateAttachmentFn
    Template.AddUpgradeAttachment('Optic', 'UIPawnLocation_WeaponUpgrade_AssaultRifle_Optic', "ConvAssaultRifle.Meshes.SM_ConvAssaultRifle_OpticC", "", 'AAR_CV', , "img:///UILibrary_Common.ConvAssaultRifle.ConvAssault_OpticC", "img:///UILibrary_StrategyImages.X2InventoryIcons.ConvAssault_OpticC_inv", "img:///UILibrary_StrategyImages.X2InventoryIcons.Inv_weaponIcon_scope");
}

static function AddClipSizeBonusUpgrade(X2ItemTemplateManager ItemTemplateManager, Name TemplateName)
{
    local X2WeaponUpgradeTemplate Template;

    Template = X2WeaponUpgradeTemplate(ItemTemplateManager.FindItemTemplate(TemplateName));

    Template.AddUpgradeAttachment('Mag', 'UIPawnLocation_WeaponUpgrade_AssaultRifle_Mag', "ConvAssaultRifle.Meshes.SM_ConvAssaultRifle_MagB", "", 'AAR_CV', , "img:///UILibrary_Common.ConvAssaultRifle.ConvAssault_MagB", "img:///UILibrary_StrategyImages.X2InventoryIcons.ConvAssault_MagB_inv", "img:///UILibrary_StrategyImages.X2InventoryIcons.Inv_weaponIcon_clip", class'X2Item_DefaultUpgrades'.static.NoReloadUpgradePresent);
}

static function AddFreeFireBonusUpgrade(X2ItemTemplateManager ItemTemplateManager, Name TemplateName)
{
    local X2WeaponUpgradeTemplate Template;

    Template = X2WeaponUpgradeTemplate(ItemTemplateManager.FindItemTemplate(TemplateName));

    //Parameters are :     AttachSocket, UIArmoryCameraPointTag, MeshName, ProjectileName, MatchWeaponTemplate, AttachToPawn, IconName, InventoryIconName, InventoryCategoryIcon, ValidateAttachmentFn
    Template.AddUpgradeAttachment('Reargrip', 'UIPawnLocation_WeaponUpgrade_AssaultRifle_Mag', "ConvAttachments.Meshes.SM_ConvReargripB", "", 'AAR_CV', , "img:///UILibrary_Common.ConvAssaultRifle.ConvAssault_ReargripA", "img:///UILibrary_StrategyImages.X2InventoryIcons.ConvAssault_ReargripB_inv", "img:///UILibrary_StrategyImages.X2InventoryIcons.Inv_weaponIcon_trigger");

    Template.AddUpgradeAttachment('Trigger', '', "ConvAttachments.Meshes.SM_ConvTriggerB", "", 'AAR_CV');
}

static function AddReloadUpgrade(X2ItemTemplateManager ItemTemplateManager, Name TemplateName)
{
    local X2WeaponUpgradeTemplate Template;

    Template = X2WeaponUpgradeTemplate(ItemTemplateManager.FindItemTemplate(TemplateName));

    //Parameters are :     AttachSocket, UIArmoryCameraPointTag, MeshName, ProjectileName, MatchWeaponTemplate, AttachToPawn, IconName, InventoryIconName, InventoryCategoryIcon, ValidateAttachmentFn
    Template.AddUpgradeAttachment('Mag', 'UIPawnLocation_WeaponUpgrade_AssaultRifle_Mag', "ConvAssaultRifle.Meshes.SM_ConvAssaultRifle_MagC", "", 'AAR_CV', , "img:///UILibrary_Common.ConvAssaultRifle.ConvAssault_MagC", "img:///UILibrary_StrategyImages.X2InventoryIcons.ConvAssault_MagC_inv", "img:///UILibrary_StrategyImages.X2InventoryIcons.Inv_weaponIcon_clip", class'X2Item_DefaultUpgrades'.static.NoClipSizeUpgradePresent);
    Template.AddUpgradeAttachment('Mag', 'UIPawnLocation_WeaponUpgrade_AssaultRifle_Mag', "ConvAssaultRifle.Meshes.SM_ConvAssaultRifle_MagD", "", 'AAR_CV', , "img:///UILibrary_Common.UI_MagAssaultRifle.MagAssaultRifle_MagD", "img:///UILibrary_StrategyImages.X2InventoryIcons.MagAssaultRifle_MagD_inv", "img:///UILibrary_StrategyImages.X2InventoryIcons.Inv_weaponIcon_clip", class'X2Item_DefaultUpgrades'.static.ClipSizeUpgradePresent);
}

static function AddMissDamageUpgrade(X2ItemTemplateManager ItemTemplateManager, Name TemplateName)
{
    local X2WeaponUpgradeTemplate Template;

    Template = X2WeaponUpgradeTemplate(ItemTemplateManager.FindItemTemplate(TemplateName));

    //Parameters are :     AttachSocket, UIArmoryCameraPointTag, MeshName, ProjectileName, MatchWeaponTemplate, AttachToPawn, IconName, InventoryIconName, InventoryCategoryIcon, ValidateAttachmentFn
    Template.AddUpgradeAttachment('Stock', 'UIPawnLocation_WeaponUpgrade_AssaultRifle_Stock', "ConvAssaultRifle.Meshes.SM_ConvAssaultRifle_StockB", "", 'ModWeapon_CV', , "img:///UILibrary_Common.ConvAssaultRifle.ConvAssault_StockB", "img:///UILibrary_StrategyImages.X2InventoryIcons.ConvAssault_StockB_inv", "img:///UILibrary_StrategyImages.X2InventoryIcons.Inv_weaponIcon_stock");
        
}

static function AddFreeKillUpgrade(X2ItemTemplateManager ItemTemplateManager, Name TemplateName)
{
    local X2WeaponUpgradeTemplate Template;

    Template = X2WeaponUpgradeTemplate(ItemTemplateManager.FindItemTemplate(TemplateName));

    //Parameters are :     AttachSocket, UIArmoryCameraPointTag, MeshName, ProjectileName, MatchWeaponTemplate, AttachToPawn, IconName, InventoryIconName, InventoryCategoryIcon, ValidateAttachmentFn
    Template.AddUpgradeAttachment('Suppressor', 'UIPawnLocation_WeaponUpgrade_AssaultRifle_Suppressor', "ConvAssaultRifle.Meshes.SM_ConvAssaultRifle_SuppressorB", "", 'ModWeapon_CV', , "img:///UILibrary_Common.ConvAssaultRifle.ConvAssault_SuppressorB", "img:///UILibrary_StrategyImages.X2InventoryIcons.ConvAssault_SuppressorB_inv", "img:///UILibrary_StrategyImages.X2InventoryIcons.Inv_weaponIcon_barrel");

    }

defaultproperties
{
    bShouldCreateDifficultyVariants = true
}
 

When I build it I get the magnetic rifle :/

 

So I used the script from the general discussion section here by the longwar dev for altering default weapon templates to update the starting rifles to my weapon mod as its upgradeitem.

 

This is the script I used;

 

 

// FILE: UIStrategyScreenListener_Example
// AUTHOR: Amineri / Long War Studios
//
// PURPOSE: This class updates templates with difficulty variants
//---------------------------------------------------------------------------------------

class UIStrategyScreenListener_Example extends UIScreenListener;

var bool UpdatedTemplates;

function bool IsInStrategy()
{
return `HQGAME != none && `HQPC != None && `HQPRES != none;
}

// This event is triggered after a screen is initialized
event OnInit(UIScreen Screen)
{
local X2ItemTemplateManager ItemTemplateManager;
local X2WeaponTemplate Template;
local int DifficultyIndex, OriginalDifficulty, OriginalLowestDifficulty;
local XComGameState_CampaignSettings Settings;
local XComGameStateHistory History;

if(IsInStrategy() && !UpdatedTemplates)
{

History = `XCOMHISTORY;
Settings = XComGameState_CampaignSettings(History.GetSingleGameStateObjectForClass(class'XComGameState_CampaignSettings'));

OriginalDifficulty = Settings.DifficultySetting;
OriginalLowestDifficulty = Settings.LowestDifficultySetting;

//get access to item element template manager
ItemTemplateManager = class'X2ItemTemplateManager'.static.GetItemTemplateManager();
if (ItemTemplateManager == none)
{
`Redscreen("LW Example : failed to retrieve ItemTemplateManager");
return;
}

for( DifficultyIndex = `MIN_DIFFICULTY_INDEX; DifficultyIndex <= `MAX_DIFFICULTY_INDEX; ++DifficultyIndex )
{
Settings.SetDifficulty(DifficultyIndex, true);

//update weapon templates as desired
Template = X2WeaponTemplate(ItemTemplateManager.FindItemTemplate('AssaultRifle_CV'));
if(Template != none)
{
Template.UpgradeItem = ''AAR_CV";
ItemTemplateManager.AddItemTemplate(Template, true);
}
}

//restore difficulty settings
Settings.SetDifficulty(OriginalLowestDifficulty, true);
Settings.SetDifficulty(OriginalDifficulty, false);
}
UpdatedTemplates = true;
}

// 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;
}
Edited by Xcomhadrian
Link to comment
Share on other sites

 

If you want to change the X2WeaponTemplate.UpgradeItem I know how to do that. In fact I am thinking about doing a mod to offer that kind of service, since stuff like this comes up allot.

shameless plug: http://forums.nexusmods.com/index.php?/topic/3830880-mod-easy-template-modifications/

 

 

 

 

So if I use your method would this work?

 

 

// XcomAAR_CV.ini
ChangeSets=(Type="Weapon", Target[0]="AssaultRifle_CV", \\
  Mods[0]=(Type="UpgradeItem", Value="AAR_CV"), \\
)
Link to comment
Share on other sites

Thats about the Idea, yeah. I would have to add a new ModType (most likely "SetUpgradeItem") but that should be easy enough.

 

But I have taken a look at the the script you use to update the AssaultRifle Template and it looks fine. You can get away without the

ItemTemplateManager.AddItemTemplate(Template, true);
line, since the template is already there and its a referential type, but thats not harmfull.
However since it's not working in the end, there has to be a piece of the puzzle missing. Changing the UpgradeItem alone seems not to be enough.
Link to comment
Share on other sites

Thanks for spotting that, I started the code as "modweapon_cv" and then changed to "AAR_cv" to ensure there was no conflicts with any other modweapons causing the problem for me.

 

After doing some more reading it appears as if there may be an UpgradeTemplate. If that is the case then Its no wonder my code didnt work as it wasnt even looking for that. Now I need to find that and alter it. Sheesh. For a supposedly "simple" mod this is turning in to one helluva effort :/

Edited by Xcomhadrian
Link to comment
Share on other sites

So I think I finally figured out what was the problem stopping the script working. It has to be run twice. Once for the weapon template and again for the weapons schematics. The schematics specifically list the object to update and what its going to be when doing so.

 

So I reckon its a case of altering both the "AssaultRifle_CV" and the "AssaultRifle_MG_Schematic" files.

Edited by Xcomhadrian
Link to comment
Share on other sites

  • Recently Browsing   0 members

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