FieryCharizard7
Chieftain
Hello all,
I've been learning LUA for about a week now, and I think I have a handle on it, but I am unsure about making a LUA function. It will be an ability from a wonder that will increase a city's production on whatever it is currently constructing (whether a unit, building, wonder, etc.) and if a unit dies within 6 tiles of a city owned by the wonder owner, the city's production will be boosted by three times the combat strength of the unit.
I have written code below, and I am unsure which City methods should be used, as the names are somewhat vague and similar. Also, did I implement the unit pointer correctly? I wasn't 100% sure if this is the correct way to get the unit's plot.
I've been learning LUA for about a week now, and I think I have a handle on it, but I am unsure about making a LUA function. It will be an ability from a wonder that will increase a city's production on whatever it is currently constructing (whether a unit, building, wonder, etc.) and if a unit dies within 6 tiles of a city owned by the wonder owner, the city's production will be boosted by three times the combat strength of the unit.
I have written code below, and I am unsure which City methods should be used, as the names are somewhat vague and similar. Also, did I implement the unit pointer correctly? I wasn't 100% sure if this is the correct way to get the unit's plot.
Code:
-- After a unit death, checks the distance between the unit tile and the owner's cities, and if that is within 6 tiles
-- the cities' production will be increased by three times the combat strength of the unit
function ADVUnitDeathProdBoost(iPlayer)
local pPlayer = Players[iPlayer]
if pPlayer:GetBuildingClassCount(iArcoDellaVittoria) > 0 then
local pPlot = Unit:GetPlot();
local pPlayer = Players[iPlayer];
local pCity = GetNearestCity(pPlot, pPlayer);
if distanceBetween(pPlot,pCity:GetCityIndexPlot()) > 5 then
-- next 4 lines get the higher of the ranged or melee combat strength
local iCityProdBoost = Unit:GetBaseRangedCombatStrength() * 3;
if iCityProdBoost < 1 then
iCityProdBoost = Unit:GetBaseCombatStrength() * 3;
end
-- add code for boosting city production by the iUnitStrength
end
end
end
GameEventsEvents.UnitKilledInCombat.Add(ADVUnitDeathProdBoost);