Veterancy buff for LifeBarSize

Everything about mods can be found here.

Moderator: Morax

Veterancy buff for LifeBarSize

Postby dippydoop » 05 Feb 2018, 18:27

Hi,
I'm trying to create a buff that grows the size of a unit's life bar upon gaining veterancy levels so that they're easier to pick out in a crowd.

For more context, I'm editing another mod, Endless Levels, which allows unit veterancy to go on indefinitely. Of course, I will keep this private, but this thread might be a useful resource for future original modders.

I've never coded in lua before, so the I've tried reverse-engineering existing code for my own purposes. Currently, I've come up with the following additions:

*BuffDefinitions.lua
Code: Select all
BuffBlueprint {
    Name = 'VeterancyLifeBar',
    DisplayName = 'VeterancyLifeBar',
    BuffType = 'VETERANCYLIFEBAR',
    Stacks = 'ALWAYS',
    Duration = -1,
    Affects = {
        LifeBarSize = {
            Add = 0,
            Mult = 1.1,
        },
    },
}


*Buff.lua
Code: Select all
        elseif atype == 'LifeBarSize' then
         
         local val = BuffCalculate(unit, buffName, atype, unit:GetLifeBarSize())
         unit:SetLifeBarSize(val)


The game does work, and the existing buffs also work, except for my addition. I suspect there's a problem with my Buff.lua entry, and I may be missing another reference entirely.

Any help would be much appreciated!
dippydoop
 
Posts: 8
Joined: 05 Feb 2018, 16:30
Has liked: 2 times
Been liked: 0 time
FAF User Name: Sweetie.Belle

Re: Veterancy buff for LifeBarSize

Postby Franck83 » 05 Feb 2018, 18:35

Hi Dippydoop,

Welcome in the mod section :)

There are a limited number of affects and LifeBarSize is not one of these. You can find the complete list in the buff.lua file.
Spoiler: show
Code: Select all
-- Vanilla affects :
--- Damage (ALL)
--- RateOfFire (ALL)
--- DamageRadius (ALL)
--- MaxRadius (ALL)
--- MoveMult (ALL)
--- WeaponsEnable (ALL)
--- VisionRadius (ALL)
--- RadarRadius (ALL)
--- OmniRadius (ALL)
--- BuildRate (ALL)
--- EnergyActive (ALL)
--- MassActive (ALL)
--- EnergyMaintenance (ALL)
--- EnergyProduction (ALL)
--- MassProduction (ALL)
--- EnergyWeapon (ALL)
--- Stun (ALL)
--- MaxHealth (ALL)
--- Health (ALL)
--- Regen (ALL)

You can edit the lifebar size in the unit bp. But i don't know if you can do it in real time.

Maybe you should think using overlays (see idle engie mod).
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: Veterancy buff for LifeBarSize

Postby dippydoop » 05 Feb 2018, 19:09

Hey Franck,
I was getting the impression that I was missing something; is there no way of adding a new affect? It seems all it would have to do is pull an existing value from a blueprint file, modify it, then set the modified value as the new value for that unit.

Thanks for the idea, I've downloaded the mod you suggested. It seems like there's potential there, but it will take me a while to poke through it and understand what's going on.
dippydoop
 
Posts: 8
Joined: 05 Feb 2018, 16:30
Has liked: 2 times
Been liked: 0 time
FAF User Name: Sweetie.Belle

Re: Veterancy buff for LifeBarSize

Postby Franck83 » 05 Feb 2018, 19:15

Yes you can add a new affect, but you need to link it with an effective sim command.

is unit:SetLifeBarSize(val) an effective command ? Don't know, maybe but never seen before.

What you want to do is a UI thing not a sim one.

Overlays will grants you much more control and option with what you want to do. Maybe some dev can give you more info on overlays use.
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: Veterancy buff for LifeBarSize

Postby dippydoop » 05 Feb 2018, 20:48

Yes, I suppose I was trying to fit a square peg into a round hole.

I don't suppose you know a good resource to prime me on overlays, do you?
dippydoop
 
Posts: 8
Joined: 05 Feb 2018, 16:30
Has liked: 2 times
Been liked: 0 time
FAF User Name: Sweetie.Belle

Re: Veterancy buff for LifeBarSize

Postby Franck83 » 06 Feb 2018, 12:29

Don't know much about it, but i will take a look when i have little time.

If you want to mod, i recommend you to install Notepad++ or a software of this kind. There are search functions that are very useful.

So you can type 'Overlays' to access to all FAF files about it.

Image
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: Veterancy buff for LifeBarSize

Postby dippydoop » 06 Feb 2018, 15:58

Thanks. It seems all references to 'overlay' are in two files (one of which seems to be a duplicate). I'll admit, this is getting a bit beyond my abilities.
I'd need some kind of function to pull the veteran level from all units, then apply a particular bitmap at certain milestones (perhaps the stock veterancy icons could be used for that).
Perhaps a less performance-intensive way would be to run the check upon levelup, but I'm not sure if that would come with its own problems, like in the removal of overlays upon unit death.
dippydoop
 
Posts: 8
Joined: 05 Feb 2018, 16:30
Has liked: 2 times
Been liked: 0 time
FAF User Name: Sweetie.Belle

Re: Veterancy buff for LifeBarSize

Postby Uveso » 06 Feb 2018, 19:26

dippydoop wrote:I'd need some kind of function to pull the veteran level from all units


Please no :)

In older days we used a programmroutine/thread to scann every unit for a single variable.

But now we are using events ^^.

Take a look into the file:
Code: Select all
\lua\sim\Unit.lua


and search for:
SetVeteranLevel = function(self, level)


There you can add your function to do something at a higher veteran level.

Maybe for testing, giving the unit a unitname with self:SetCustomName('I am a veteran!')
User avatar
Uveso
Supreme Commander
 
Posts: 1788
Joined: 11 Dec 2015, 20:56
Location: Germany
Has liked: 70 times
Been liked: 291 times
FAF User Name: Uveso

Re: Veterancy buff for LifeBarSize

Postby Uveso » 06 Feb 2018, 19:45

Just in case you want to hook the function without destroying the original file;

create a blank file inside your mod:
Code: Select all
\YourMod\lua\sim\Unit.lua

and paste this into the file:

Code: Select all
-- Save the original Unit class
local oldUnit = Unit

-- Crate a new unitclass with all functions from the old Unitclass
Unit = Class(oldUnit) {

    -- Noe we are overwriting the original SetVeteranLevel  function.
    SetVeteranLevel = function(self, level)

        -- first lets call the old original SetVeteranLevel function.
        oldUnit.SetVeteranLevel(self, level)

        -- now we can add our own stuff
        -- Maybe add a Name to the unit with Vetaran Level:
        self:SetCustomName('Veteran Level '..level)
    end,

}


This way you have an non destructive hook, and it will work also after FAF updates.
User avatar
Uveso
Supreme Commander
 
Posts: 1788
Joined: 11 Dec 2015, 20:56
Location: Germany
Has liked: 70 times
Been liked: 291 times
FAF User Name: Uveso

Re: Veterancy buff for LifeBarSize

Postby dippydoop » 06 Feb 2018, 22:30

Thanks for your input, Uveso. I am learning new things, slowly!

Could you explain this line a bit more, please?
Uveso wrote:
Code: Select all
        self:SetCustomName('Veteran Level '..level)



I get that we're setting a new name for the unit as 'Veteran Level', but what does the "..level" part do? Is it an argument of some kind?
dippydoop
 
Posts: 8
Joined: 05 Feb 2018, 16:30
Has liked: 2 times
Been liked: 0 time
FAF User Name: Sweetie.Belle

Next

Return to Mods & Tools

Who is online

Users browsing this forum: No registered users and 1 guest