I am currently trying to program in a unique Trait for a Civilization where they are predetermined to appear near sources of Gems and Pearls, and I thought I would go about this by using The Pridelands civilization as an example. However, I do not believe the Lua I have rigged up is working (perhaps because I do not have the right setting in ModBuddy; I referred to whoward69's list but I did not see anything that was conflicting with what I had). In any case, here is the code I have:
I'm assuming I may have removed something important, or that the title of The Prideland's UA is misleading and that using their Lua code for a base was a mistake.
Any thoughts?
Code:
-- Steven_Luxuries
-- Author: Harkodos
-- Base: Tpangolin, Neirei the Forgiven
--------------------------------------------------------------
local TheCrystalGemsCiv = GameInfoTypes.CIVILIZATION_AMERICA--Civ ID;
LuxuryTab = {}
LuxuryTab[GameInfoTypes.RESOURCE_GEMS] = true
LuxuryTab[GameInfoTypes.RESOURCE_PEARLS] = true
GameEvents.PlayerCityFounded.Add(function(iPlayer, iCityX, iCityY)
if Players[iPlayer]:GetCivilizationType() == TheCrystalGemsCiv then
local kplot = Map.GetPlot(iCityX, iCityY);
local kCity = kplot:GetPlotCity();
if kCity:IsOriginalMajorCapital() then
AddGemsAndPearls(kCity)
end
end
end)
function AddGemsandPearls(kCity)
PlotCount = 0;
PlotVT = {}
for i = 1, kCity:GetNumCityPlots() -1 do
if kCity:GetCityIndexPlot(i) ~= nil then
local iPlot = kCity:GetCityIndexPlot(i);
if iPlot:GetResourceType(-1) == -1 then
if ResourceValid(iPlot) then
PlotCount = PlotCount + 1;
PlotVT[PlotCount] = iPlot;
end
end
end
end
RandomPlot = nil;
for i = 1, math.min(PlotCount, 2) do
OldRandom = RandomPlot;
RandomPlot = math.random(1, PlotCount);
while OldRandom == RandomPlot do
RandomPlot = math.random(1, PlotCount);
end
PlotVT[RandomPlot]:SetResourceType(GetResource(PlotVT[RandomPlot]), 1);
end
PlotVT = nil;
end
function GetResource(iPlot)
ResCount = 0;
ResVT = {}
for iRes, bool in pairs(LuxuryTab) do
if iPlot:CanHaveResource(iRes) then
ResCount = ResCount + 1;
ResVT[ResCount] = iRes;
end
end
if ResCount > 0 then
return ResVT[math.random(1, ResCount)];
else
print("It cannot be! It's impossibru!")
return -1;
end
end
function ResourceValid(iPlot)
for iRes, bool in pairs(LuxuryTab) do
if iPlot:CanHaveResource(iRes) then
return true;
end
end
return false;
end
Any thoughts?