AddKills() not so strait forward apparently

Ok been going around in circles with AddKills.

From what I can see in SimUtils.lua line 105, we have...

unit:AddKills( unitKills )

Then in Unit.lua line 3084, we have

    AddKills = function(self, numKills)
        #Add the kills, then check veterancy junk.
        local unitKills = self:GetStat('KILLS', 0).Value + numKills
        self:SetStat('KILLS', unitKills)
        
        local vet = self:GetBlueprint().Veteran or Game.VeteranDefault
        
        local vetLevels = table.getsize(vet)
        if self.VeteranLevel == vetLevels then
            return
        end

        local nextLvl = self.VeteranLevel + 1
        local nextKills = vet[('Level' .. nextLvl)]
        
        #Since we could potentially be gaining a lot of kills here, check if we gained more than one level
        while unitKills >= nextKills and self.VeteranLevel ~= vetLevels do
            self:SetVeteranLevel(nextLvl)
            
            nextLvl = self.VeteranLevel + 1
            nextKills = vet[('Level' .. nextLvl)]
        end 
    end,

thus it should be just as simple as using within a unit script the following...

myUnit:AddKills( myUnitsKills )

However this is constantly throwing errors such as "attempt to call method `AddKills' (a nil value)". Which makes no sense at all as the script is within the units core lua and is clearly defined. What am i missing here?

Was able to work around this via self:SetStat('KILLS', 100), then later have the unit check its veterancy.

Don't get why AddKills is being so picky...

The function AddKills does not exist in the base code of FAForever. Where did you find that reference?

A work of art is never finished, merely abandoned

Its part of the default SCFA....

I take it from that statement you've thrown out the veterancy system, and thus why i can not get anything to work.

Great

So what's the new hotness for updating a units kills SIM-side?

Woot got it working!!!

This script is called from the original unit to start the transfer process.

	FlyingWaker_Transfer = function(self, unitId)
		local myDebug = true
   		if self and not self:BeenDestroyed() then
   			if myDebug then WARN('Unit.lua FlyingWaker_Transfer, to unit id: ', unitId) end

			 --Create the replacement unit
			local loc = self:GetPosition()
			local ori = self:GetOrientation()		 
			local mySpawn = CreateUnit(unitId, self:GetArmy(), loc[1], loc[2], loc[3], ori[1], ori[2], ori[3], ori[4], self:GetCurrentLayer())
			
			--Give it a moment to enter the game in fully
			WaitTicks(2)
			
			if self and not self:BeenDestroyed() then
				
				--Pass data to mySpawn
				local kills  = self:GetStat('KILLS', 0).Value
				local vetExp = self.VetExperience
				local health = self:GetHealth() or 0
				local state = self:GetFireState() or 0		
				if myDebug then WARN('	data to be passed: ', kills, vetExp, health, state) end
				mySpawn:XferData(kills, vetExp, health, state)

				--Remove the original unit
				if myDebug then WARN('	Removing original') end
				self:Destroy()
			end
		end
	end,

This script on the newly created unit receives the data, to set up the veterancy and health.

	XferData = function(self, kills, vetExp, health, state)
		if myDebug then WARN('XferData received', kills, vetExp, health, state) end
			
		if kills != nil then
			self:UpdateStat('KILLS', self:GetStat('KILLS', 0).Value + kills)
		end						
		if vetExp != nil then
			self:AddVetExperience(vetExp, false)
		end
		if health != nil then
			self:SetHealth(self, health)  
		end
		if state != nil then
			self:SetFireState(state)
		end		
	end,

@resin_smoker said in AddKills() not so strait forward apparently:

I take it from that statement you've thrown out the veterancy system

Just for reference, FAF isn't using the number of kills for calculating vet but a system based on the amount of damage done and the mass of killed units.

You can learn more about how veterancy works in FAForever on Github:

There are a lot of utility functions to help you manage veterancy via script.

A work of art is never finished, merely abandoned

@Jip Thanks m8!

Here's the progress on the unit in question: https://youtu.be/nk8EvZLw7JE
Units transition from Air to Land (and back) should appear fairly seamless.

Only thing I've not been able to do is have the unit auto-selected, if it was previously selected before the transformation. DMS had a few handy functions for this that I've not been able to figure out thus far.

Side note: I've been playing around with the idea (again) of having the Flying-walker just be an air unit. Then just manipulating the flight parameters to fake it walking. While I know this is possible, i do recall there being the issue where the air unit would tumble over the ground from playing bumper cars with the terrain. While also being able to scale shear cliffs in a very unorthodox fashion. Simply put, the pathing for air units is pretty much direct, while the land / sea units have to "think" their way around obstacles. This was fun back in the day when we were 1st messing around with the hologram units, while attempting to come up with ways to limit the overhead from the unit pathing.