How do i check in what city's are my unit is? I know how to get the owner of the plot in which my unit is, but how do i get the city's name in which area my unit is?
local TraitPromotion = GameInfoTypes["PROMOTION_DEUSVULT"]
local TraitPromotion2 = GameInfoTypes["PROMOTION_DEUSVULT_2"]
function DeusVult(iPlayer)
local pPlayer = Players[iPlayer]
if (pPlayer:IsAlive()) then
for pUnit in pPlayer:Units() do
local pPlot = pUnit:GetPlot()
local pCity = pPlot:GetCityPurchaseID()
local pReligion = pCity:GetReligiousMajority()
if pUnit:IsHasPromotion(TraitPromotion) then
if pPlot:IsOwned() then
if pPlayer:GetReligionCreatedByPlayer() == pReligion then
pUnit:SetHasPromotion(TraitPromotion2, true)
end
end
end
end
end
end
local pReligion = pCity:GetReligiousMajority() will cause an error (and the script to abort) if the unit is not on a plot owned by a city. You need to check pPlot:IsOwned() earlier than where it is at the moment
local pReligion = pCity:GetReligiousMajority() will cause an error (and the script to abort) if the unit is not on a plot owned by a city. You need to check pPlot:IsOwned() earlier than where it is at the moment
local TraitPromotion = GameInfoTypes["PROMOTION_DEUSVULT"]
local TraitPromotion2 = GameInfoTypes["PROMOTION_DEUSVULT_2"]
function DeusVult(iPlayer)
local pPlayer = Players[iPlayer]
if pPlayer:IsAlive() then
for pUnit in pPlayer:Units() do
if pUnit:IsHasPromotion(TraitPromotion) then
local pPlot = pUnit:GetPlot()
if pPlot:IsOwned() then
local pCity = pPlot:GetCityPurchaseID()
local pReligion = pCity:GetReligiousMajority()
local rReligion = pPlayer:GetReligioncreatedByPlayer()
if pReligion == rReligion then
pUnit:SetHasPromotion(TraitPromotion2)
end
end
end
end
end
end
GameEvents.UnitSetXY.Add(DeusVult);
Trying to get my units to get 20% combat bonus when in city's territory that has your religion. Decided to do it via promotion but still getting errors even after checking the pPlot:IsOwned() earlier.
Oh! Okay, got it. Not quite there yet but now i know what i did wrong. Complete noob when it comes to modding in lua so might have some more questions coming in the future. Thank you so much!
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.