Jump to content

How may I add a line of code to a default X2Item_DefaultWeapons.uc file?


CookiesAndCreamYummy

Recommended Posts

Hi guys!

 

I need help please. I'm trying to make my very first mod adding an ability to a shotgun weapon. After digging through X2Item_DefaultWeapons.uc file within ModBuddy, here's what I'm trying to change within the default script.

 

Here is the codes of lines that the default shotgun has.

// **************************************************************************
// ***                       Shotgun                                      ***
// **************************************************************************

static function X2DataTemplate CreateTemplate_Shotgun_Conventional()
{
	local X2WeaponTemplate Template;

	`CREATE_X2TEMPLATE(class'X2WeaponTemplate', Template, 'Shotgun_CV');
	Template.WeaponPanelImage = "_ConventionalShotgun";

	Template.ItemCat = 'weapon';
	Template.WeaponCat = 'shotgun';
	Template.WeaponTech = 'conventional';
	Template.strImage = "img:///UILibrary_Common.ConvShotgun.ConvShotgun_Base";
	Template.EquipSound = "Conventional_Weapon_Equip";
	Template.Tier = 0;

	Template.RangeAccuracy = default.SHORT_CONVENTIONAL_RANGE;
	Template.BaseDamage = default.SHOTGUN_CONVENTIONAL_BASEDAMAGE;
	Template.Aim = default.SHOTGUN_CONVENTIONAL_AIM;
	Template.CritChance = default.SHOTGUN_CONVENTIONAL_CRITCHANCE;
	Template.iClipSize = default.SHOTGUN_CONVENTIONAL_ICLIPSIZE;
	Template.iSoundRange = default.SHOTGUN_CONVENTIONAL_ISOUNDRANGE;
	Template.iEnvironmentDamage = default.SHOTGUN_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');
	
	// This all the resources; sounds, animations, models, physics, the works.
	Template.GameArchetype = "WP_Shotgun_CV.WP_Shotgun_CV";
	Template.UIArmoryCameraPointTag = 'UIPawnLocation_WeaponUpgrade_Shotgun';
	Template.AddDefaultAttachment('Foregrip', "ConvShotgun.Meshes.SM_ConvShotgun_ForegripA" /*FORGRIP INCLUDED IN MAG IMAGE*/);
	Template.AddDefaultAttachment('Mag', "ConvShotgun.Meshes.SM_ConvShotgun_MagA", , "img:///UILibrary_Common.ConvShotgun.ConvShotgun_MagA");
	Template.AddDefaultAttachment('Reargrip', "ConvShotgun.Meshes.SM_ConvShotgun_ReargripA" /*REARGRIP IS INCLUDED IN THE TRIGGER IMAGE*/);
	Template.AddDefaultAttachment('Stock', "ConvShotgun.Meshes.SM_ConvShotgun_StockA", , "img:///UILibrary_Common.ConvShotgun.ConvShotgun_StockA");
	Template.AddDefaultAttachment('Trigger', "ConvShotgun.Meshes.SM_ConvShotgun_TriggerA", , "img:///UILibrary_Common.ConvShotgun.ConvShotgun_TriggerA");
	Template.AddDefaultAttachment('Light', "ConvAttachments.Meshes.SM_ConvFlashLight");

	Template.iPhysicsImpulse = 5;

	Template.fKnockbackDamageAmount = 10.0f;
	Template.fKnockbackDamageRadius = 16.0f;

	Template.UpgradeItem = 'Shotgun_MG';

	Template.StartingItem = true;
	Template.CanBeBuilt = false;

	Template.DamageTypeTemplateName = 'Projectile_Conventional';

	return Template;
}

However, I just want to add one single line in this default file which is to add: Template.Abilities.AddItem('Suppression');

// **************************************************************************
// ***                       Shotgun                                      ***
// **************************************************************************

static function X2DataTemplate CreateTemplate_Shotgun_Conventional()
{
	local X2WeaponTemplate Template;

	`CREATE_X2TEMPLATE(class'X2WeaponTemplate', Template, 'Shotgun_CV');
	Template.WeaponPanelImage = "_ConventionalShotgun";

	Template.ItemCat = 'weapon';
	Template.WeaponCat = 'shotgun';
	Template.WeaponTech = 'conventional';
	Template.strImage = "img:///UILibrary_Common.ConvShotgun.ConvShotgun_Base";
	Template.EquipSound = "Conventional_Weapon_Equip";
	Template.Tier = 0;

	Template.RangeAccuracy = default.SHORT_CONVENTIONAL_RANGE;
	Template.BaseDamage = default.SHOTGUN_CONVENTIONAL_BASEDAMAGE;
	Template.Aim = default.SHOTGUN_CONVENTIONAL_AIM;
	Template.CritChance = default.SHOTGUN_CONVENTIONAL_CRITCHANCE;
	Template.iClipSize = default.SHOTGUN_CONVENTIONAL_ICLIPSIZE;
	Template.iSoundRange = default.SHOTGUN_CONVENTIONAL_ISOUNDRANGE;
	Template.iEnvironmentDamage = default.SHOTGUN_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.Abilities.AddItem('Suppression'); //<---- I WANT TO ADD THIS....
	
	// This all the resources; sounds, animations, models, physics, the works.
	Template.GameArchetype = "WP_Shotgun_CV.WP_Shotgun_CV";
	Template.UIArmoryCameraPointTag = 'UIPawnLocation_WeaponUpgrade_Shotgun';
	Template.AddDefaultAttachment('Foregrip', "ConvShotgun.Meshes.SM_ConvShotgun_ForegripA" /*FORGRIP INCLUDED IN MAG IMAGE*/);
	Template.AddDefaultAttachment('Mag', "ConvShotgun.Meshes.SM_ConvShotgun_MagA", , "img:///UILibrary_Common.ConvShotgun.ConvShotgun_MagA");
	Template.AddDefaultAttachment('Reargrip', "ConvShotgun.Meshes.SM_ConvShotgun_ReargripA" /*REARGRIP IS INCLUDED IN THE TRIGGER IMAGE*/);
	Template.AddDefaultAttachment('Stock', "ConvShotgun.Meshes.SM_ConvShotgun_StockA", , "img:///UILibrary_Common.ConvShotgun.ConvShotgun_StockA");
	Template.AddDefaultAttachment('Trigger', "ConvShotgun.Meshes.SM_ConvShotgun_TriggerA", , "img:///UILibrary_Common.ConvShotgun.ConvShotgun_TriggerA");
	Template.AddDefaultAttachment('Light', "ConvAttachments.Meshes.SM_ConvFlashLight");

	Template.iPhysicsImpulse = 5;

	Template.fKnockbackDamageAmount = 10.0f;
	Template.fKnockbackDamageRadius = 16.0f;

	Template.UpgradeItem = 'Shotgun_MG';

	Template.StartingItem = true;
	Template.CanBeBuilt = false;

	Template.DamageTypeTemplateName = 'Projectile_Conventional';

	return Template;
}

I saved it and did an overwrite saved and then tested it. But I was getting 4 errors during debug which points out to unknown properties to 4 other Ability files.

So, after I copied and pasted the original X2Item_DefaultWeapons.uc file back. Debug started working again. So, I thought, I guess it won't let me add a line of code to a default script. I've been searching google in ways to add a code of line to a default script within the game with no luck.

 

So with no luck, I also tried modifying XComGameData.ini file to have this:

[XComGame.X2Item_DefaultWeapons]
// **************************************************************************
// ***                       Shotgun                                      ***
// **************************************************************************
static function X2DataTemplate CreateTemplate_Shotgun_Conventional()
{
+Template.Abilities.AddItem('Suppression');
}

static function X2DataTemplate CreateTemplate_Shotgun_Magnetic()
{
+Template.Abilities.AddItem('Suppression');
}

static function X2DataTemplate CreateTemplate_Shotgun_Beam()
{
+Template.Abilities.AddItem('Suppression');
}

With some luck on my side, I was able to test debug the game. However, this modification didn't work =(...

 

Can someone please help me here in how I may get or add a line of code to a default script. I am so forever lost and Thank you =)

Link to comment
Share on other sites

Thank you for your suggestion. However, it will benefit me in the future to gain this knowledge of how to do this. After all, I have many ideas that I've been thinking in regards to tweaking some stuff in the game. So, please do care in helping me out in attaining this knowledge. I am somewhat familiar with C++. But all I do to override a script is write the same class with my method to overwrite and do either alias a method or write a new one and the line of code I desire. However, in this game of programming language, its either not allowed or I'm doing it wrong :(

 

 

EDIT:

 

Actually, its not possible to achieve my request. I just read from somewhere that it is not possible to make additional code or override a STATIC method. Well, isn't that so darn cruel... I think I'm about to go sit my corner and cry...:(

 

EDIT2:

 

After running some few tests, I've found that dependson which is new to meh but it overwrites an entire script which it worked in my case. However, I've screwed something up LoL because the weapon damage stats does not show nor applying or taking damage work in battle at all. What I did was this:

1. Created X2Effect_DefaultWeapons_Overwrite.UC file in my mod class folder.

2. Copied and pasted the entire script from DefaultWeapons to the overwrite and added my line of code from above.

3. Changed the heading in the new script to read:

class X2Item_Default_Weapons_Overwrite extends X2Item config(GameData_WeaponData) dependson(X2Item_DefaultWeapons);

 

As what I stated, the damage system seems to stop where enemy attacks nor my own does any damage and the weapons stats does not show up in the interface. Do I have to change something else as well since I overwrote a default script?

Edited by CookiesAndCreamYummy
Link to comment
Share on other sites

Modifying Templates in this way is not the recommended way of doing it. In your mod, you have a file X2DownloadableContentInfo_Mod.uc

 

In there, you can have the following code:

static event OnPostTemplatesCreated()
{

	local X2ItemTemplateManager ItemManager;
	local array<X2DataTemplate> DifficultyVariants;
	local X2DataTemplate ShotgunTemplate;

	ItemManager = class'X2ItemTemplateManager'.static.GetItemTemplateManager();
	ItemManager.FindDataTemplatesAllDifficulties('Shotgun_CV', DifficultyVariants);

	foreach DifficultyVariants(ShotgunTemplate)
	{
		X2WeaponTemplate(ShotgunTemplate).Abilities.AddItem('Suppression');
	}
	// need to do that for other shotguns too ...
}

Since you do have programmin experience, you should know what a for loop is and do that for all three tiers.

Edited by robojumper
Link to comment
Share on other sites

  • Recently Browsing   0 members

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