octo
Chieftain
So I'm just learning the ins and outs of modding with Lua and I have been working on a civ that allows the player to plant crops on blank tiles. Would it be possible for somebody to look over this little bit of code and tell me if I'm on the right track or not?
The way it's intended to function is that when the unique improvement "Plant Corn" is finished being constructed this code puts a raw "Corn" resource on that tile and deletes the improvement. Sorry if this has already been covered in a tutorial somewhere, but I searched and hadn't found anything.
The way it's intended to function is that when the unique improvement "Plant Corn" is finished being constructed this code puts a raw "Corn" resource on that tile and deletes the improvement. Sorry if this has already been covered in a tutorial somewhere, but I searched and hadn't found anything.

Spoiler :
Code:
--Global--
local iCornPlanting = GameInfoTypes["IMPROVEMENT_PLANT_CORN_RESOURCE"]
local iOctoCorn = GameInfoTypes["RESOURCE_OCTO_CORN"]
--Corn--
function onCornCreated(playerID, plotX, plotY, improvementID)
if (improvementID ~= iCornPlanting) then return end
local pPlot = Map.GetPlot(X, Y)
local iImp = pPlot:GetImprovementType()
if (iImp == iCornPlanting) then
pPlot:SetResourceType(iOctoCorn, 1)
pPlot:SetImprovementType(-1)
end
end
GameEvents.BuildFinished.Add(onCornCreated)