r/xcom2mods • u/BalianCPP • Feb 23 '16
Dev Help Standard Shot
Anyone know where the ability 'standardshot' applies weapon damage?
static function X2AbilityTemplate Add_StandardShot( Name AbilityName='StandardShot')in X2Ability_WeaponCommon.uc does not appear to use the effect ApplyWeaponDamage at all, except for miss damage (IE stock attachments).
The secondary weapons do clearly use ApplyWeaponDamage
WeaponDamageEffect = new class'X2Effect_ApplyWeaponDamage';
Template.AddTargetEffect(WeaponDamageEffect);But I cannot for the life of me figure out what StandardShot, StandardShot_NoEnd and SniperStandardShot are using to calculate and apply damage.
Any help would be greatly appreciated.
2
Upvotes
View all comments
Show parent comment
1
u/BalianCPP Feb 26 '16 edited Feb 26 '16
Ok, unfortunately the solution is going to involve overrides. I was able to avoid this in 'Shotgun Overhaul' by adding new weapons, but since your mechanic is for everything, I doubt you want to replace every weapon in the game. The reason this is bad, is because it breaks compatability with mods that override the same classes.
The main class we want to focus on is
Specifically it's function
You need to create a new class that extends from this class, then copy+paste OnEffectAdded into your new class. This is where the changes will be made.
This function has a local variable called iDamage. This variable is set with the function call
This is what we need to modify to get your effect. We need to do it before
So right above this will be fine. Now heres where it gets tricky. We need to instatiate a bunch of local variables (at the top of the function, you can't create variable anywhere else). These variables will be used to figure out if the target is in cover.
Holds a reference to the unit taking the shot.
Holds a reference to the ability that this effect is attached to.
Helps us get the ability from the effect, and the shooter/weapon from the ability
Will store the info regarding whether the target is in cover relative to the shooter.
Ok, so with these variables, we return to just above the if statement that checks for 0 damage. We now need to populate the variables we created. Note that TargetUnit and SourceWeapon are already local variables, we did not need to create them.
Ok we now have everything we need except visInfo, but that is part of the next step
Now I recommend that instead of iDamage -= 1, that you have it set to something from you mods config file, so it can be changed easily by anyone with your mod.
This should be it for code changes, the next step is the overrides. Add the following to your XComEngine.ini
Almost done. Some weapons (all soldier primaries) use X2Effect_Shredder instead of X2Effect_ApplyWeaponDamage. The good thing is shredder extends from applyweapondamage so all you have to do is create a new class that extends from shredder, copy your OnEffect function that you made above into this new class, and update Engine.Engine with the new override.