Thalassicus
Bytes and Nibblers
How can I create X units on a plot, and give them Y experience?
How can I create X units on a plot, and give them Y experience?
function createUnit(pPlayer, pPlot, sNewUnitType, iExperience)
local pNewUnit = pPlayer:InitUnit(GameInfoTypes[sNewUnitType], pPlot:GetX(), pPlot:GetY())
pNewUnit:SetExperience(iExperience)
return pNewUnit
end
function setLevel(pUnit, iExperience)
local iLevel = 1
local iLevelIncrement = iLevel * 10
while (iExperience > iLevelIncrement) do
iExperience = iExperience - iLevelIncrement
iLevel = iLevel + 1
iLevelIncrement = iLevel * 10
end
pUnit:SetLevel(iLevel)
end
function setLevel(pUnit, iExperience)
local iLevel = 1
local iLevelIncrement = iLevel * 10
while (iExperience > iLevelIncrement) do
iExperience = iExperience - iLevelIncrement
iLevel = iLevel + 1
iLevelIncrement = iLevel * 10
end
pUnit:SetLevel(iLevel)
end
It sets the level of the unit based on how much experience it has. Level 1 requires 10XP, level 2 needs 20 more, level 3 is 30 more, etc.
so unit level is just a number of used promotion? if i set unit level to e.g 2 unit:SetLevel(2) it means that unit will get first/next promotion at 30 experience? or it result that unit will be ask for first necessary promotion at 30 experience and first, second promotion could be save even when saving promotion is not checked?