TofuSojo
Chieftain
I just made a mod that gives Nuclear Plants a chance to meltdown. The chance is based on the gamespeed's GrowthPercent variable, so if another mod changes that variable (such as the popular Superquick mod, which on Quick changes it from 66 to 33) my mod should use the updated number. Naturally, it ignores the other mod's change for some reason. I did make sure to enable the other mod first.
Here's my mod's lua:
Any help sorted this out would be appreciated. Thanks
Here's my mod's lua:
Code:
--0 is Marathon 300%, 1 is Epic 150%, 2 is Standard 100%, and 3 is Quick 66%
local iGameSpeed = GameInfo.GameSpeeds[Game.GetGameSpeedType()].GrowthPercent / 100
local MeltdownChance = 1 / iGameSpeed --x1 0: 0.33%, 1: 0.66%, 2: 1.00%, 3: 1.50%
--print("MeltdownChance: " .. MeltdownChance)
function CheckNuclearPlants(PlayerID)
local pPlayer = Players[PlayerID]
local iNuclearPlant = GameInfoTypes["BUILDING_NUCLEAR_PLANT"]
local iFallout = GameInfoTypes["FEATURE_FALLOUT"]
local directions = {DirectionTypes.DIRECTION_NORTHEAST, DirectionTypes.DIRECTION_EAST, DirectionTypes.DIRECTION_SOUTHEAST, DirectionTypes.DIRECTION_SOUTHWEST, DirectionTypes.DIRECTION_WEST, DirectionTypes.DIRECTION_NORTHWEST}
for pCity in pPlayer:Cities() do
local sCityName = pCity:GetName()
local pCityPlot = pCity:Plot()
local iCityX = pCity:GetX()
local iCityY = pCity:GetY()
local sText = "Nuclear Plant in " .. sCityName .. " destroyed!"
local sHeading = "Nuclear Plant Meltdown"
if pCity:IsHasBuilding(iNuclearPlant) and (math.random(1,100) <= MeltdownChance) then
pCity:SetNumRealBuilding(iNuclearPlant, 0)
--print("Nuclear Plant removed from: " .. sCityName)
for loop, direction in ipairs(directions) do
local pPlot = Map.PlotDirection(pCityPlot:GetX(), pCityPlot:GetY(), direction)
if not pPlot:IsWater() and (math.random(1,100) <= 50) then
pPlot:SetFeatureType(iFallout)
--print("Spawning Fallout near: " .. sCityName)
end
end
--print("A Nuclear Plant has had a meltdown in: " .. sCityName)
pPlayer:AddNotification(NotificationTypes.NOTIFICATION_GENERIC, sText, sHeading, iCityX, iCityY, false, false, false )
end
end
end
GameEvents.PlayerDoTurn.Add(CheckNuclearPlants)
Any help sorted this out would be appreciated. Thanks