You can't just append this to the end of the unit.lua file because the function is "inside" the unit class definition.
You need a hook for the unitclass.
Create a file in your mod/hook folder:
- Code: Select all
\Mods\YOURMODNAME\hook\lua\sim\Unit.lua
Then copy & paste this into the Unit.lua file:
- Code: Select all
-- Save/store the original Unit class
local OldUnit = Unit
-- create a new unitclass with the same name (overwrite the original) and use as base the OldUnit class
Unit = Class(OldUnit) {
-- This overwrites the original CreateVeterancyBuffs function
CreateVeterancyBuffs = function(self, level)
local healthBuffName = 'VeterancyMaxHealth' .. level -- Currently there is no difference between units, therefore no need for unique buffs
local regenBuffName = self:GetUnitId() .. 'VeterancyRegen' .. level -- Generate a buff based on the unitId - eg. uel0001VeterancyRegen3
if not Buffs[regenBuffName] then
-- Maps self.techCategory to a number so we can do math on it for naval units
local techLevels = {
TECH1 = 1,
TECH2 = 2,
TECH3 = 3,
COMMAND = 3,
SUBCOMMANDER = 4,
EXPERIMENTAL = 5,
}
local techLevel = techLevels[self.techCategory] or 1
-- Treat naval units as one level higher
if techLevel < 4 and EntityCategoryContains(categories.NAVAL, self) then
techLevel = techLevel + 1
end
-- Regen values by tech level and veterancy level
local regenBuffs = {
{1, 2, 3, 4, 5}, -- T1
{3, 6, 9, 12, 15}, -- T2
{6, 12, 18, 24, 30}, -- T3 / ACU
{9, 18, 27, 36, 45}, -- SACU
{25, 50, 75, 100,125}, -- Experimental
}
BuffBlueprint {
Name = regenBuffName,
DisplayName = regenBuffName,
BuffType = 'VeterancyRegen',
Stacks = 'REPLACE',
Duration = -1,
Affects = {
Regen = {
Add = regenBuffs[techLevel][level],
},
},
}
end
return {regenBuffName, healthBuffName}
end,
}
Now you can play around with it.