Hi all,
I'm trying to make a Railyard district, and as part of this I want to convert all of a city's routes to railroads once construction of the Railyard is complete.
My LUA script is using stuff I've cobbled together from a few different places, it's included at the end.
I'm registering for the following event: "OnDistrictProgressChanged", then checking to see if the percent complete is 100. I'm uncertain whether the arguments I have for "OnDistrictFinished()" are accurate or not. I'm also uncertain exactly what the "districtType" argument is, whether percentComplete is from 0-100 or 0-1, etc. I think what I'm trying to do is going to work, I just need to get all the syntax and data types correct...
Essentially, this script should be simple. At 100%, I want to get all the tiles which are roads in that city and upgrade them to railroads. If pillaged, revert the roads to the player's current level. Also if the city adds a tile, it should check to see whether it's a road and make it a railroad, provided the district isn't pillaged. (These last two are probably easy if i can get the first working)
Thanks!
Edit: Also, that print statement at the beginning of "OnDistrictFinished()" isn't outputting to LUA.log when a district completes...I have the script included as an In-Game Action of type "AddGameplayScripts".
Script:
I'm trying to make a Railyard district, and as part of this I want to convert all of a city's routes to railroads once construction of the Railyard is complete.
My LUA script is using stuff I've cobbled together from a few different places, it's included at the end.
I'm registering for the following event: "OnDistrictProgressChanged", then checking to see if the percent complete is 100. I'm uncertain whether the arguments I have for "OnDistrictFinished()" are accurate or not. I'm also uncertain exactly what the "districtType" argument is, whether percentComplete is from 0-100 or 0-1, etc. I think what I'm trying to do is going to work, I just need to get all the syntax and data types correct...
Essentially, this script should be simple. At 100%, I want to get all the tiles which are roads in that city and upgrade them to railroads. If pillaged, revert the roads to the player's current level. Also if the city adds a tile, it should check to see whether it's a road and make it a railroad, provided the district isn't pillaged. (These last two are probably easy if i can get the first working)
Thanks!
Edit: Also, that print statement at the beginning of "OnDistrictFinished()" isn't outputting to LUA.log when a district completes...I have the script included as an In-Game Action of type "AddGameplayScripts".
Script:
Code:
local iRailyard = GameInfo.Districts["DISTRICT_RAILYARD"].Index
local AllRoutes = GameInfo.Routes()
local Railroad = AllRoutes[5]
function OnDistrictFinished(playerID, districtID, cityID, X, Y, districtType, era, civilization, percentComplete, Appeal, isPillaged)
print("District Type: "..tostring(districtType))
if isRailyard(districtType) then
if (percentComplete == 100) then
local city = CityManager.GetCity(playerID, cityID)
BuildRailroadsInCity(city)
end
end
end
function UpdateRailroads(owner, cityID)
local city = CityManager.GetCity(playerID, cityID)
if (city:GetDistricts:HasDistrict(DistrictType.DISTRICT_RAILYARD) then
BuildRailroadsInCity(city)
end
end
function BuildRailroadsInCity(_city)
for _ , plot in _city:GetOwnedPlots() do
if plot:isRoute() then
RouteBuilder.SetRouteType(plot, Railroad.Index)
end
end
end
function isRailyard(districtType)
return districtType == "DISTRICT_RAILYARD"
end
function OnDistrictPillaged()
end
Events.DistrictBuildProgressChanged.Add(OnDistrictFinished)
Events.DistrictPillaged.Add(OnDistrictPillaged)
--Events.CityTileOwnershipChanged.Add(UpdateRailroads)
Last edited: