I've been trying to make an ability where mines have a chance of discovering metal-type luxury resources.
I've managed to make the resource appear but it's not connecting to the trade network; so the player doesn't actually receive the resource. They just get a mine with Gold/Silver/Copper in it. I can't figure why it's so or how I could fix this.
I've just been triggering Plot:SetResourceType on GameEvents.BuildFinished. But here's the relevant function:
I've managed to make the resource appear but it's not connecting to the trade network; so the player doesn't actually receive the resource. They just get a mine with Gold/Silver/Copper in it. I can't figure why it's so or how I could fix this.
I've just been triggering Plot:SetResourceType on GameEvents.BuildFinished. But here's the relevant function:
Code:
local iMine = GameInfoTypes.IMPROVEMENT_MINE
function MineDiscovery(iPlayer, iX, iY, iImprovement)
local pPlayer = Players[iPlayer]
if (pPlayer:IsMinorCiv()) or (pPlayer:IsBarbarian()) then
return
end
if (iImprovement ~= iMine) then
print("not mine")
return
end
--Must be in woking distance of a city you own
local bStop = true
local pPlot = Map.GetPlot(iX, iY)
for pAdjacentPlot in PlotAreaSweepIterator(pPlot, 3, SECTOR_NORTH, DIRECTION_CLOCKWISE, DIRECTION_OUTWARDS, CENTRE_INCLUDE) do
if pAdjacentPlot:IsCity() then
local pCity = pAdjacentPlot:GetPlotCity()
if pCity:GetOwner() == iPlayer then
bStop = false
break
end
end
end
if (bStop) then
return
end
local iPercentage = GetPersistentProperty("iPercentage_P" .. iPlayer)
iRandom = math.random(1,10)
print(iRandom, iPercentage)
if iRandom > iPercentage then
print("Percentage failed")
return
end
if pPlot:GetResourceType() ~= -1 then
print("Resource failed")
return
end
pPlot:SetResourceType(iLuxury, 1)
iPercentage = iPercentage - 1
if iPercentage < 1 then
iPercentage = 1
end
SetPersistentProperty("iPercentage_P" .. iPlayer, iPercentage)
end
GameEvents.BuildFinished.Add(MineDiscovery)