[BNW] Morius Modest Mods Musings

How do i make LUA codes to work on my mods?

Take this LUA code made by Tomatekh and TarcisioCM, for example. It makes a building generate a resource (in this case, copper) nearby the city it's built.

How i make it work on my mod?

Code:
function GenerateResource(pPlayer, pCity)


--Creates a Copper resource nearby. Preference is for non-snow hills.
    for i = 1, pCity:GetNumCityPlots() - 1, 1 do
        local fPlot = pCity:GetCityIndexPlot(i)
        if not fPlot:IsMountain() then
            if fPlot:GetTerrainType() == TerrainTypes.TERRAIN_GRASS then
                if fPlot:IsHills() then
                    if fPlot:GetResourceType(-1) == (-1) then
                        fPlot:SetResourceType(GameInfoTypes.RESOURCE_COPPER, 1)
                        return true
                    end
                end
            elseif fPlot:GetTerrainType() == TerrainTypes.TERRAIN_PLAINS then
                if fPlot:IsHills() then
                    if fPlot:GetResourceType(-1) == (-1) then
                        fPlot:SetResourceType(GameInfoTypes.RESOURCE_COPPER, 1)
                        return true
                    end
                end
            elseif fPlot:GetTerrainType() == TerrainTypes.TERRAIN_DESERT then
                if fPlot:IsHills() then
                    if fPlot:GetResourceType(-1) == (-1) then
                        fPlot:SetResourceType(GameInfoTypes.RESOURCE_COPPER, 1)
                        return true
                    end
                end
            elseif fPlot:GetTerrainType() == TerrainTypes.TERRAIN_TUNDRA then
                if fPlot:IsHills() then
                    if fPlot:GetResourceType(-1) == (-1) then
                        fPlot:SetResourceType(GameInfoTypes.RESOURCE_COPPER, 1)
                        return true
                    end
                end
            end
        end
    end

--But if that fails, Copper can go pretty on much any land tile.
    for i = 1, pCity:GetNumCityPlots() - 1, 1 do
        local fPlot = pCity:GetCityIndexPlot(i)
        if not fPlot:IsMountain() then
            if fPlot:GetTerrainType() == TerrainTypes.TERRAIN_GRASS then
                if fPlot:GetResourceType(-1) == (-1) then
                    fPlot:SetResourceType(GameInfoTypes.RESOURCE_COPPER, 1)
                    return true
                end
            elseif fPlot:GetTerrainType() == TerrainTypes.TERRAIN_PLAINS then
                if fPlot:GetResourceType(-1) == (-1) then
                    fPlot:SetResourceType(GameInfoTypes.RESOURCE_COPPER, 1)
                    return true
                end
            elseif fPlot:GetTerrainType() == TerrainTypes.TERRAIN_DESERT then
                if not fPlot:GetFeatureType() == FeatureTypes.FEATURE_OASIS then
                    if fPlot:GetResourceType(-1) == (-1) then
                        fPlot:SetResourceType(GameInfoTypes.RESOURCE_COPPER, 1)
                        return true
                    end
                end
            elseif fPlot:GetTerrainType() == TerrainTypes.TERRAIN_TUNDRA then
                if fPlot:GetResourceType(-1) == (-1) then
                    fPlot:SetResourceType(GameInfoTypes.RESOURCE_COPPER, 1)
                    return true
                end
            elseif fPlot:GetTerrainType() == TerrainTypes.TERRAIN_SNOW then
                if fPlot:GetResourceType(-1) == (-1) then
                    fPlot:SetResourceType(GameInfoTypes.RESOURCE_COPPER, 1)
                    return true
                end
            end
        end
    end
    return false
end



GameEvents.CityConstructed.Add(function(iPlayer, iCity, building)
--Watch to see when a Stannary is constructed
    if building == GameInfoTypes.BUILDING_STANNARY then
        local pPlayer = Players[iPlayer]
        local pCity = pPlayer:GetCityByID(iCity)
--Try to generate a resource. Message if it fails
        if GenerateResource(pPlayer, pCity) == false then
            print("Could not place any resources.")
        end
    end
end)
 
  1. Place the code into an lua file that you have added to your mod
  2. 'Activate' the lua file as a InGameUIAddin
    see whoward69's what ModBuddy setting for what file types tutorial for the needed procedures in ModBuddy
You would edit BUILDING_STANNARY and RESOURCE_COPPER as needed. But for whatever resource you are adding to the map you would want to make sure the lua code is written properly to observe the rules for resource-placement in the SQL Database (ie, the game's base xml CIV5Resources, CIV5Resources_Inherited_Expansion2, and CIV5Resources_Expansion2 files).
 
Good news! With a big helping hand of Chrisy15 i've done my first unique LUA code. This wouldn't be possible without your support, LeeS!
 
make them hover over mountains and water(if they don't have an embarking promotion)...
 
Hello guys!

After a Little Ice Age, i'm back, with more questions!

As you may remember, i don't know nothing about LUA, so i can't do anything too complex with it.

That said, i have two projects (for now) that requires LUA, but i don't know how to make them. That's why i'm requiring your help.

First things first, i'm doing now some sort of Era Overhaul. I'm adding a pre-historical era and a Future Era. Why is that? Well, the ones we have already are awesome, but too big. While normal eras have, at most, 13 techs these eras out ther have 25 or more.

One thing i want to do is to make (when possible) all eras to have 11 techs. One Technology in particular is Unions, from Atomci Era.

Unions is a tech that requires the ressurrected Mass Media Tech, that in turn requires the Corporation tech. So Unions is a tech that comes in response to Corporations, as a form to the peuple shield themselves against Corporations trying to own them.

Ok, what this tech has? This is the fun part! (at least for me)

Unions will have 3 National Wonders The Laborer's Syndicate, the Trader's Syndicate and the National Syndicate If you have one, you can't build another.
- The Laborer's Syndicate can only be built on Order Ideology, and it's destroyed if you chose another ideology.
Laborer's Syndicate gives +4 global happiness. Allows you to build the Proletarian and all your workers can be upgraded to Proletarians. Proletarian work 25% faster than workers.
- The Trader's Syndicate can only be built on Freedom Ideology, and it's destroyed if you chose another ideology.
Trader's Syndicate give +4 gold and an additional trade route. Allows you to build the Employee and all your workers can be upgraded to Employees. Employees don't have maneintance cost and moves 3 instead of 2.
- The National Syndicate can only be built on Autocracy ideology, and it's destroyed if you chose another ideology.
National Syndicate give -10% unhappiness and allow you to build the* Young Operative and all your workers can be upgraded to young operative. Young Operatie attack and defend like the Rifleman (without the promotions, only the strength). If a syndicate is destroyed, all special worker units turn back to be a normal worker.

Make the national wonders per se, the art, and the special workers mechanics i know how to do. My problem lies in how the workers and buildings are made and how they are lost. In my mind, we need to do 4 codes:
Code one that tells If one building is built, the other two are impossible to build
Code two that tell if building is built, workers can upgrade to new worker
Code tree: if another ideology is chosen, building is deleted.
and Code four: if another ideology is chosen, new unit become worker (but can become to be new unit again when building is built)

Do you think you can help me on that? Please?
 
About Unions, i wanted to it work something like what i said, but with the followings requirements:
-No mindwrenching codes that's incompatible with everything.
- AI must know how to use the features.

But now i have more pressing need for help. I'm adding two new eras to the game, yes, you guessed right, it's "pre-historical" and future era.

But i came up with this error:

20190920110918_1.jpg

So far, so good...
20190920110924_1.jpg

Classical Era has three columns, but i added only two, classical era is taking medieval era techs...
20190920110927_1.jpg


20190920110932_1.jpg

Medieval era is taking renaissance era techs , renaissance era is taking Enlightenment era techs...
20190920110938_1.jpg

Enlightenment era is taking industrial era techs and industrial era is too big.
20190920110942_1.jpg

Industrial era is too big and it's taking modern era and atomic era techs...
20190920110946_1.jpg

modern era is too big and is taking atomic, information and future era techs.
20190920110953_1.jpg

Atomica era is too short and only have future era techs...
20190920110955_1.jpg

Information Era and future Era are empty.

What could caused this problem?
 
Back
Top Bottom