Anything relating to BuffBlueprints

Everything about mods can be found here.

Moderator: Morax

Anything relating to BuffBlueprints

Postby Tanksy » 10 Jan 2017, 15:28

Hello.

I'm still slowly tinkering away at modifying SupCom and I've come up with some rough ideas when thinking about unit veterancy. Ideally I would like to have two separate veterancy systems -- One for Comms, one for other Units. So far I've started by looking into the mod "Experimental Wars" and seeing how the author made use of BuffBlueprints to alter units when they reached a certain Veterancy. This mod also allows units to upgrade into different units upon certain veterancy levels -- something I wish to also incorporate into my own modifications, but done in a different manner.

His code however is.. Difficult to understand, being commented in French -- It also looks a little sloppy, so I've been writing my own following his style.

On a unit's Blueprint, I've added a section called "VetBonus", inside VetBonus is simply an entry that says "Enabled = true". In the unit's script, I check to see if vetBonus.enabled = true and then perform buffs depending on what the unit's current Veterancy level is. Below is my code. The function "OnVeteran" is used in Experimental Wars, called from the unit's "OnStopBeingBuilt" function using a callback "self:AddUnitCallback(self.OnVeteran, 'OnVeteran')" -- I'm unsure if vanilla units have this or if it's been added by the author of Experimental Wars, but I'm going to use it here because "It worked for him" (Unless there's a better way)


The unit has 14000 starting health, and as an example to see if this system would work I wanted the unit to simply gain 1000, 2000, 3000, 4000 or 5000 health based on his Veterancy level.
Code: Select all
-- Tanksy's version of ExpWars' "OnVeteran" function
   OnVeteran = function(self)
      -- Get blueprint
        local bp = self:GetBlueprint()
      
      -- Get vet level
      local vetLevel = self.VeteranLevel
      
      -- Get vetBonus
      local bpVetBonus = bp.Enabled
      
      -- If no vetBonus in bp or disabled
      if bpVetBonus != true then return end

      if vetLevel == 1 then
         BuffBlueprint {
            Name = 'VetBuff',
            DisplayName = 'VetBuff',
            BuffType = 'MAXHEALTH',
            Stacks = 'REPLACE',
            Duration = -1,
            Affects = {
               MaxHealth = {
               Add = 1000,
               Mult = 1.0,
               },
            },
         }
      elseif vetLevel == 2 then
         BuffBlueprint {
            Name = 'VetBuff',
            DisplayName = 'VetBuff',
            BuffType = 'MAXHEALTH',
            Stacks = 'REPLACE',
            Duration = -1,
            Affects = {
               MaxHealth = {
               Add = 2000,
               Mult = 1.0,
               },
            },
         }
      elseif vetLevel == 3 then
         BuffBlueprint {
            Name = 'VetBuff',
            DisplayName = 'VetBuff',
            BuffType = 'MAXHEALTH',
            Stacks = 'REPLACE',
            Duration = -1,
            Affects = {
               MaxHealth = {
               Add = 3000,
               Mult = 1.0,
               },
            },
         }
      elseif vetLevel == 4 then
         BuffBlueprint {
            Name = 'VetBuff',
            DisplayName = 'VetBuff',
            BuffType = 'MAXHEALTH',
            Stacks = 'REPLACE',
            Duration = -1,
            Affects = {
               MaxHealth = {
               Add = 4000,
               Mult = 1.0,
               },
            },
         }
      elseif vetLevel == 5 then
         BuffBlueprint {
            Name = 'VetBuff',
            DisplayName = 'VetBuff',
            BuffType = 'MAXHEALTH',
            Stacks = 'REPLACE',
            Duration = -1,
            Affects = {
               MaxHealth = {
               Add = 5000,
               Mult = 1.0,
               },
            },
         }
      end
      
      -- Apply buff
      Buff.ApplyBuff(self, 'VetBuff')
   -- End function
   end,


I'm not entirely positive that this works, and I would like some advice, and really any information that anyone knows about BuffBlueprints and how they work and how to use them. I also have a rough idea of how I can "Turn off" the vanilla veterancy bonuses by overwriting their Buffblueprints, but I'm not sure if this would be a good idea or if there's a way I can simply set those buffs to only affect a specific unit by hooking into them, avoiding the overwrite.
Tanksy
Avatar-of-War
 
Posts: 75
Joined: 31 Aug 2016, 11:39
Has liked: 1 time
Been liked: 14 times

Re: Anything relating to BuffBlueprints

Postby Franck83 » 10 Jan 2017, 16:54

Hi Tanksy,

Ideally I would like to have two separate veterancy systems


Not difficult to do. You need to hook the SetVeteranLeve lfunction in unit.lua. You can deal with commander part by adding a condition ...
Code: Select all
if table.find(bp.Categories,'COMMAND') then  self:AddXP( your_commander_xp) end

If you don't want to do destructive hooking, you can do it by subtracting the classic xp after the OldSetVeteranLevel function ;).


The unit has 14000 starting health, and as an example to see if this system would work I wanted the unit to simply gain 1000, 2000, 3000, 4000 or 5000 health based on his Veterancy level.


Easy to do again. You just need to check the veterancy level with this code :
Code: Select all
  local veteranLevel= self:GetVeteranLevel()
or if you hook in the SetVeteranLevel, the level is given in parameter 'level'

When you got the veteranLevel, you can catch a blueprint that overwrite the previous veterancy, you can do it on the fly (yes ! ;) ) in the SetVeteranLevel function :

Code: Select all
BuffBlueprint {
         Name = 'MyBuff',
         DisplayName = 'MyBuff',
         BuffType = 'VETERANCYHEALTH', -- (you need to use VETERANCYHEALTH if you want to replace the current veterancy health buff. If you use another name, it will create another buff category that will stack with the other buffs)
         Stacks = 'REPLACE',
         Duration = -1,
         Affects = {
            MaxHealth = {
               DoNoFill = true,
               Add = 1000 * veteranLevel , -- 1000 per veterancy level
               Mult = 1,
               },
            },
         }
         Buff.ApplyBuff( self, 'MyBuff' )


Nota: i use the last FAF version. it gots an ADDXP function that not exists in the FA steam version. If you wanna use FA steam version, you can use
Code: Select all
self.Sync.xp = your_xp
to save your xp and
Code: Select all
self.xp
to get it.

Good luck !
Alliance of Heroes Mod is out ! Try it ! It's in the Mod Vault !
User avatar
Franck83
Evaluator
 
Posts: 538
Joined: 30 Dec 2016, 11:59
Location: France
Has liked: 114 times
Been liked: 122 times
FAF User Name: Franck83

Re: Anything relating to BuffBlueprints

Postby Sprouto » 10 Jan 2017, 20:46

The existing veteran functions should meet your requirements for giving unique health and regen buffs to any unit.

The base game already has two default buffs for all units -- Health and Regen. The two buffs will generate a standard health and regeneration buff for any unit upon achieving a veteran level. The Health buff adds a percentage of the original Health to the unit, while the Regen buff increases the regen rate of the unit. These default buffs cover ALL units that don't have their own Buff section entries.

If you look at most of the units, you should see a Buffs section in it's blueprint. In almost all cases, it will specify a unique REGEN buff. This is used to override the default buff for that particular unit ID. This is how the ACU gets a unique REGEN buff that is different from the default buff.

Following that example, if what you want is a unique HEALTH buff, then you can use the Buffs section in a units' blueprint to give that effect, without writing any additional code. Just keep in mind that the default health buff uses a multiplier to the units original Health -- so a 5% increase in HP would have a value of 1.05 -- BUT -- the regen buff uses an additive formula -- so the actual value is added directly.

Obviously, this concept is easily extended. Most of the code governing it can be found in the UNIT.LUA file. The specifics of the default buffs are created in the Unit class definition (ie. - what the buff is called and if it is a multiplied or additive effect, etc.). The code which will create the custom unit buff on the fly starts in the function SETVETERANLEVEL which originates in an earlier function called CHECKVETERANLEVEL.

This should get you started without having to resort to someone else's mod.
Sprouto
Priest
 
Posts: 366
Joined: 08 Sep 2012, 05:40
Has liked: 54 times
Been liked: 74 times
FAF User Name: Sprouto

Re: Anything relating to BuffBlueprints

Postby Tanksy » 10 Jan 2017, 20:52

Thanks for the reply, Franck.

I didn't realise the game has things like "AddXP", I thought the Veteran system strictly used kills?

Can you explain to me what "DoNoFill" does that you've included in your code snippet?

Do I use self:GetVeteranLevel() inside the unit's script?

Thanks for the reply, Sprouto.

Thanks for pointing me to those things. I wasn't aware that you could use a Buffs section in blueprints. I'll take a look at Unit.lua too, thanks.

Do you think it would be possible to specify the exact buffs a unit gets?
I'm thinking something like this -- If possible, change the SetVeteranLevel/CheckVeteranLevel functions so that you can specify the Buff Type and Affects in the unit's Blueprint? Then in the unit blueprint put something like "Buffs = { Health = 1000, Regen = 10, Speed = 2 }", which would tell my custom SetVeteranLevel function to use buffs that give 1000 health * vet level, 10 Regen * vet level and 2 speed * vet level..

Hmm.
Tanksy
Avatar-of-War
 
Posts: 75
Joined: 31 Aug 2016, 11:39
Has liked: 1 time
Been liked: 14 times

Re: Anything relating to BuffBlueprints

Postby Franck83 » 10 Jan 2017, 23:43

I didn't realise the game has things like "AddXP", I thought the Veteran system strictly used kills?


The original FA game use kills to set veterancy. FAF use a more realistic XP system. Because on original game if you kill a Tech 1 bot or a Tech 4 experimental, it gives 1 kill. That 's not satisfactory. Equilibrium mod goes much deeper with an XP system that use XP from mass unit cost.

Do I use self:GetVeteranLevel() inside the unit's script ?
Yes, the self is because unit is an instance of a class object. The self report to the unit itself. So if you wanna ref to a unit in unit.lua, you may use self. Sometimes you may refer to instigator which is the unit that deal the event (the instigator deal damages for example). Sometimes in others files, you will need to catch the unit (from id for example like in ui with GetUnitById(id)) then call it like this Unit:GetVeteranLevel().

Do you think it would be possible to specify the exact buffs a unit gets?
Yes. You can find the affects in buff.lua. It can be MaxHealth, Regen, Damage, DamageRadius, MaxRadius, MoveMult, Stun, WeaponsEnable, VisionRadius, RadarRadius, OmniRadius, BuildRate, EnergyActive, MassActive, EnergyMaintenance, MassMaintenance, EnergyProduction, MassProduction, EnergyWeapon, RateOfFire.

like sprouto said, for example :
Code: Select all
BuffBlueprint {
         Name = 'MyBuff',
         DisplayName = 'MyBuff',
         BuffType = 'VETERANCYHEALTH', -- (you need to use VETERANCYHEALTH if you want to replace the current veterancy health buff. If you use another name, it will create another buff category that will stack with the other buffs)
         Stacks = 'REPLACE',
         Duration = -1,
         Affects = {
          MaxHealth = {
               DoNoFill = true,
               Add = 1000 * veteranLevel , -- 1000 per veterancy level
               Mult = 1,
               },
          RateOfFire= {
               DoNoFill = true,
               Add = 0 ,
               Mult = 1.5,
               },
          MaxRadius= {
               DoNoFill = true,
               Add =5 * veteranLevel ,
               Mult =1,
               },
            },
         }
         Buff.ApplyBuff( self, 'MyBuff' )


A buff that give 1000 health bonus per veteran level, + 50% rate of fire and a +5 radius per veteran level.
Alliance of Heroes Mod is out ! Try it ! It's in the Mod Vault !
User avatar
Franck83
Evaluator
 
Posts: 538
Joined: 30 Dec 2016, 11:59
Location: France
Has liked: 114 times
Been liked: 122 times
FAF User Name: Franck83

Re: Anything relating to BuffBlueprints

Postby Franck83 » 11 Jan 2017, 00:02

Do I use self:GetVeteranLevel() inside the unit's script ?


I read your question too fast :). Sorry, if you are talking about individual unit scripts and not unit.lua, you wanna use self, if self refers to the unit.

An example from the Aeon ACU script UAL0001_script.lua.

Code: Select all
OnCreate = function(self)
        AWalkingLandUnit.OnCreate(self)
        self:SetCapturable(false)
        self:SetWeaponEnabledByLabel('ChronoDampener', false)
        self:SetupBuildBones()
        self:HideBone('Back_Upgrade', true)
        self:HideBone('Right_Upgrade', true)       
        self:HideBone('Left_Upgrade', true)           
        # Restrict what enhancements will enable later
        self:AddBuildRestriction( categories.AEON * (categories.BUILTBYTIER2COMMANDER + categories.BUILTBYTIER3COMMANDER) )
      self.HasAdvancedEngineering = false
    end,


Here, self refers to the unit and we are talking about the unit creation.

But in
Code: Select all
Weapons = {
        DeathWeapon = Class(AIFCommanderDeathWeapon) {},
        RightDisruptor = Class(ADFDisruptorCannonWeapon) {},
        ChronoDampener = Class(ADFChronoDampener) {},
        OverCharge = Class(ADFOverchargeWeapon) {

            OnCreate = function(self)
                ADFOverchargeWeapon.OnCreate(self)
                self:SetWeaponEnabled(false)
                self.AimControl:SetEnabled(false)
                self.AimControl:SetPrecedence(0)
            self.unit:SetOverchargePaused(false)
            end,


self refers here to the weapon, and on create talks about the weapon creation.

self depends of the class in the context. You need to read the code carefully.
Alliance of Heroes Mod is out ! Try it ! It's in the Mod Vault !
User avatar
Franck83
Evaluator
 
Posts: 538
Joined: 30 Dec 2016, 11:59
Location: France
Has liked: 114 times
Been liked: 122 times
FAF User Name: Franck83

Re: Anything relating to BuffBlueprints

Postby Tanksy » 19 Jan 2017, 02:47

Thanks for the answers, everyone. I've bookmarked this page and archived it for later if I need it. Really great stuff :D
Tanksy
Avatar-of-War
 
Posts: 75
Joined: 31 Aug 2016, 11:39
Has liked: 1 time
Been liked: 14 times

Re: Anything relating to BuffBlueprints

Postby Franck83 » 19 Jan 2017, 22:30

Tanksy wrote:Can you explain to me what "DoNoFill" does that you've included in your code snippet?


I'm not certain, but it may mean that the max health bonus will not include instant heal. So it will increase Health max but not current health.
Alliance of Heroes Mod is out ! Try it ! It's in the Mod Vault !
User avatar
Franck83
Evaluator
 
Posts: 538
Joined: 30 Dec 2016, 11:59
Location: France
Has liked: 114 times
Been liked: 122 times
FAF User Name: Franck83


Return to Mods & Tools

Who is online

Users browsing this forum: No registered users and 1 guest