Please post code with code tags:
function RenameVet()
for index, unit in allUnits do
local Ukills = unit:GetStat('KILLS', 0).Value
if Ukills >= unit:GetBlueprint().Veteran.Level1 and Ukills != 0 and ( unit:GetCustomName(unit) == nil or unit:IsInCategory('COMMAND') == true ) then
local unitname = unit:GetBlueprint().General.UnitName
local newName
local temptable ;
if unit:IsInCategory('COMMAND') == true then
if Ukills >= unit:GetBlueprint().Veteran.Level5 then
newName = "<[["..username.."]]>"
elseif Ukills >= unit:GetBlueprint().Veteran.Level4 then
newName = "[["..username.."]]"
elseif Ukills >= unit:GetBlueprint().Veteran.Level3 then
newName = "<["..username.."]>"
elseif Ukills >= unit:GetBlueprint().Veteran.Level2 then
newName = "["..username.."]"
elseif Ukills >= unit:GetBlueprint().Veteran.Level1 then
newName = "<"..username..">"
else
newName = username
end
end
end
end
end
for index, unit in allUnits do
end
This is a loop. It will loop over every entry inside the table allUnits
and save it into unit
So you can access every unit inside the table allUnits
Lets say you create an table with 3 words:
WORDS = {
[1] = "Hallo",
['A'] = "12345",
[2] = "ABCDE",
}
now you are looping over the table:
for index, word in WORDS do
LOG('index: '..index)
LOG('word: '..word)
end
you will get this output:
index: 1
word: Hallo
index: A
word: 12345
index: 2
word: ABCDE
local Ukills = unit:GetStat('KILLS', 0).Value
This will get the number of kills of this unit.
You can set this value with unit:SetStat('KILLS', unitKills)
In base game this function is only used for killstatistics.
There is nothing else saved in there
unit:GetBlueprint()
This will get you the blueprint of an unit.
Here an example for an unit blueprint:
https://github.com/FAForever/fa/blob/deploy/fafdevelop/units/UAL0401/UAL0401_unit.bp
unit:GetBlueprint().Veteran.Level4
This will get the value inside Level4
, that is part of the table Veteran
inside the unit blueprint here:
https://github.com/FAForever/fa/blob/deploy/fafdevelop/units/UAL0401/UAL0401_unit.bp#L287
So unit:GetBlueprint().Veteran.Level4
will get the number 360
unit:IsInCategory('COMMAND')
This will check the blueprint category table and search for a match.
Here is a ACU blueprint, with a matching category entry:
https://github.com/FAForever/fa/blob/deploy/fafdevelop/units/UAL0001/UAL0001_unit.bp#L131
unitname = unit:GetBlueprint().General.UnitName
This will get the unitname saved inside the unitblueprint from here:
https://github.com/FAForever/fa/blob/deploy/fafdevelop/units/UAL0401/UAL0401_unit.bp#L226
Have in mind you need to remove the Translation TAG (with LOC() )before you can use this name:
unitname = LOC( unit:GetBlueprint().General.UnitName )
Finally this will rename a unit
Unit:SetCustomName(newName)