AdmiralScorpii Posted March 17, 2016 Share Posted March 17, 2016 Alright, so right now, I'm trying to change the Nanoscale Vest's stats to get rid of the HP Bonus and add a +1 Armor bonus. I've gotten some code down and it seems to work, however when I view the equipped Nanoscale Vest on a soldier, apparently there is no increased armor. I changed the NANOFIBER_VEST_HP_BONUS value back to 1 to see if it was an issue with my code and yes, it is. I don't know why the stats aren't be transferred over. Below is my code so far: This is the code for actually defining the integer values to be used for the stats class VC_UtilityItems extends X2Ability dependson (XComGameStateContext_Ability) config(VCUtilityItemStats); var config int NANOFIBER_VEST_ARMOR_BONUS; var config int NANOFIBER_VEST_ARMOR_MITIGATION_CHANCE; var config int NANOFIBER_VEST_HP_BONUS; static function array<X2DataTemplate> CreateTemplates() { local array<X2DataTemplate> Templates; Templates.AddItem(AddNanofiberVestBonusAbility()); return Templates; } static function X2AbilityTemplate AddNanofiberVestBonusAbility() { local X2AbilityTemplate Template; local X2Effect_PersistentStatChange PersistentStatChangeEffect; `CREATE_X2ABILITY_TEMPLATE(Template, 'NanofiberVestBonus'); Template.IconImage = "img:///UILibrary_PerkIcons.UIPerk_item_nanofibervest"; Template.AbilityToHitCalc = default.DeadEye; Template.AbilityTargetStyle = default.SelfTarget; Template.AbilityTriggers.AddItem(default.UnitPostBeginPlayTrigger); Template.AbilitySourceName = 'eAbilitySource_Item'; Template.eAbilityIconBehaviorHUD = EAbilityIconBehavior_NeverShow; Template.Hostility = eHostility_Neutral; Template.bDisplayInUITacticalText = false; PersistentStatChangeEffect = new class'X2Effect_PersistentStatChange'; PersistentStatChangeEffect.BuildPersistentEffect(1, true, false, false); PersistentStatChangeEffect.SetDisplayInfo(ePerkBuff_Passive, Template.LocFriendlyName, Template.GetMyLongDescription(), Template.IconImage, false, , Template.AbilitySourceName); PersistentStatChangeEffect.AddPersistentStatChange(eStat_HP, default.NANOFIBER_VEST_HP_BONUS); PersistentStatChangeEffect.AddPersistentStatChange(eStat_ArmorMitigation, default.NANOFIBER_VEST_ARMOR_BONUS); PersistentStatChangeEffect.AddPersistentStatChange(eStat_ArmorChance, default.NANOFIBER_VEST_ARMOR_MITIGATION_CHANCE); Template.AddTargetEffect(PersistentStatChangeEffect); Template.BuildNewGameStateFn = TypicalAbility_BuildGameState; Template.BuildNewGameStateFn = TypicalAbility_BuildGameState; return Template; } This is the code that actually would translate the stats over, I assume class VC_DefaultUtilityItems extends X2Item config(VCUtilityItemStats); static function array<X2DataTemplate> CreateTemplates() { local array<X2DataTemplate> Items; Items.AddItem(CreateNanoScaleVest()); return Items; } static function X2DataTemplate CreateNanoScaleVest() { local X2EquipmentTemplate Template; local ArtifactCost Resources; local ArtifactCost Artifacts; `CREATE_X2TEMPLATE(class'X2EquipmentTemplate', Template, 'NanofiberVest'); Template.ItemCat = 'defense'; Template.InventorySlot = eInvSlot_Utility; Template.strImage = "img:///UILibrary_StrategyImages.X2InventoryIcons.Inv_Nano_Fiber_Vest"; Template.EquipSound = "StrategyUI_Vest_Equip"; Template.Abilities.AddItem('NanofiberVestBonus'); Template.CanBeBuilt = true; Template.TradingPostValue = 15; Template.PointsToComplete = 0; Template.Tier = 0; Template.SetUIStatMarkup(class'XLocalizedData'.default.HealthLabel, eStat_HP, class'VC_UtilityItems'.default.NANOFIBER_VEST_HP_BONUS); Template.SetUIStatMarkup(class'XLocalizedData'.default.ArmorLabel, eStat_ArmorMitigation, class'VC_UtilityItems'.default.NANOFIBER_VEST_ARMOR_BONUS); // Requirements Template.Requirements.RequiredTechs.AddItem('HybridMaterials'); // Cost Resources.ItemTemplateName = 'Supplies'; Resources.Quantity = 30; Template.Cost.ResourceCosts.AddItem(Resources); Artifacts.ItemTemplateName = 'CorpseAdventTrooper'; Artifacts.Quantity = 2; Template.Cost.ArtifactCosts.AddItem(Artifacts); return Template; } Link to comment Share on other sites More sharing options...
Perraine Posted March 18, 2016 Share Posted March 18, 2016 Not sure if it helps (and I'll admit that I know next to nothing about the "code" in XCOM, ) but, just from what I'm reading of your code ... In DefaultGameCore.ini the Nanofiber vest is listed with a HP Bonus, plus several of the other items are listed with mitigation_chance ( = % for armor to block part of a shot) and mitigation _amount (actual amount of damage to block) not ArmorMitigation maybe the eStat name is not recognized? Also there is the Armo rStat Customizer mod that allows you to set those values for all of the full armors, perhaps something in their code might point you in the right direction? Link to comment Share on other sites More sharing options...
Yzaxtol Posted March 18, 2016 Share Posted March 18, 2016 Me and Raeli from Armor Stat Customiser use the ItemTemplateManager to find the Item, add our own stats ability to the item and then proceed to wipe their UI and replace it with our own. Once I get home I will show what I did with Spectrum, to make it +3 HP but -2 Mobility. Also as an added bonus it just injects addiitons and so won't conflict with other mods unless someone else is injecting into the same item. Link to comment Share on other sites More sharing options...
AdmiralScorpii Posted March 18, 2016 Author Share Posted March 18, 2016 Me and Raeli from Armor Stat Customiser use the ItemTemplateManager to find the Item, add our own stats ability to the item and then proceed to wipe their UI and replace it with our own. Once I get home I will show what I did with Spectrum, to make it +3 HP but -2 Mobility. Also as an added bonus it just injects addiitons and so won't conflict with other mods unless someone else is injecting into the same item.Thank you, I've been trying to tackle this for a couple days Link to comment Share on other sites More sharing options...
zingfharn Posted March 19, 2016 Share Posted March 19, 2016 (edited) Hey dude. You want to do something like this. This is my screenlistener for modifying combat stims class X2DownloadableContentInfo_ReworkedCombatStims extends UIScreenListener config(StimSettings); Event OnInit(UIScreen scr) { local X2AbilityTemplateManager abilityManager; local X2AbilityTemplate stim; local X2AbilityCharges Charges; abilityManager = class'X2AbilityTemplateManager'.static.GetAbilityTemplateManager(); forEach abilityManager.IterateTemplates(data, none) { stim = X2AbilityTemplate(data); if (stim != none && stim.name == 'CombatStims') { // do the changes // e.g. Charges = new class'X2AbilityCharges'; Charges.InitialCharges = 1; stim.AbilityCharges = Charges; } } } defaultproperties { ScreenClass = SomeScreenClassHere; // Match a screen class here. } Edited March 19, 2016 by zingfharn Link to comment Share on other sites More sharing options...
davidlallen Posted March 19, 2016 Share Posted March 19, 2016 (edited) What happens when the user changes difficulty level? I think this only affects the current difficulty. What specific screen do you recommend using? This code will trigger every time this screen is activated, so you should avoid any common screen. But you have to be sure it will trigger at least once before the user can do anything, regardless of what they do. Another approach which is guaranteed to fire one time, and affects all difficulty levels is described here:http://forums.nexusmods.com/index.php?/topic/3839560-template-modification-without-screenlisteners/ Edited March 19, 2016 by davidlallen Link to comment Share on other sites More sharing options...
zingfharn Posted March 20, 2016 Share Posted March 20, 2016 (edited) Yes. In the edge case that they change difficulty between screens, it'll break. Can't imagine that's very common though. Hook it to anything you like. Uiavengerhud works. Do 'log(Scr) as well to get an idea of what's appropriate. Edited March 20, 2016 by zingfharn Link to comment Share on other sites More sharing options...
davidlallen Posted March 20, 2016 Share Posted March 20, 2016 If they change difficulty at all, it will break. Actually the changes will just be silently ignored which is worse. Most mods that rely on screenlisteners also keep a flag, which says whether the change has already been done. Otherwise the change gets redone at every call to the screen, and I hope most people realize that hurts performance. So if the change is done, then the user changes difficulty ever after that, the template for the new difficulty is never updated. Creating all the difficulty variants at once is safer. Link to comment Share on other sites More sharing options...
zingfharn Posted March 20, 2016 Share Posted March 20, 2016 Well, break is wrong. It won't break. It just won't do anything, until they hit re-hit that screen, and check to see if things are loaded appropriately. With something like this, where you're just setting 2 values of a nanosim jacket, or the combat sims, there's minimal performance impact. In fact, performance can be greatly increased by doing a find vs an iterate, but "greatly" here is a matter of a few milliseconds (I've tested pretty extensively). And, I said, edge case. How many people do you really think are changing difficulty all the time? My guess is "practically none". Someone might change it once, but then when they come back past that screen, or reload, or go to tactical and come back to strategy, or hit the geoscape, or whatever, it'll fix itself. and, again, edge case. How many times have you changed difficulty outside of testing? The amount of work you'd do to cover it seems like wasted effort. Finally, hurting performance is honestly the least of your worries. The sheer volume of loops in the game code with "for (idx = 0; idx < Array.Length; idx++)" is terrifying. Resetting a couple of values in an item every time you come past a screen is not a big deal. Having another loop that's executed often isn't going to impact things terribly. Link to comment Share on other sites More sharing options...
Recommended Posts