[TOTPP] Lua Scenario Template

Many thanks for the tip with the word "Abundance", Curt. I appreciate this :thumbsup:
As a non native english speaking guy I'm always a little bit afraid that I don't use the correct words or in this case an old one.

Maybe I should ask one of you guys for looking at my texts when I'm ready with the scenario.

No probs - :)

I'd be happy to proof-read your text when you wish. It would be an honour, sir!
 
Is it possible with LUA giving a nation instead of a gold bonus a science boost if a certain event occurs?

I would implement Galileo Galilei into the game with one event, where the player could choose between condemn him as a heretic or studying his works about astronomy.
If first one is choosen, the player gets gold but if the last one is choosen, the player should get a science boost.
 
From the function reference:

researchCost (get)
tribe.researchCost -> integer

Returns the research cost of the tribe.


researchProgress (get/set)
tribe.researchProgress -> integer

Returns the progress towards the current research (range between 0 and tribe.researchCost).


researching (get/set)
tribe.researching -> tech

Returns the tech the tribe is currently researching, or `nil` if not researching anything.
 
May I ask you for some support @Prof. Garfield?
This is the code I'm using for the Galileo event:
Code:
if  turn ==198 and tribe == object.tHabsburgians then
    gen.justOnce("Galileo", function()
        local Galileo = civ.ui.loadImage("Images/99_Galileo.bmp")
        local dialog = civ.ui.createDialog()
            dialog.title = "World News: Galileo Galilei"
            dialog.width = 700
            dialog:addImage(Galileo)
            local multiLineText = "The Italian astromer and physicist Galileo..."
            text.addMultiLineTextToDialog(multiLineText,dialog)
                dialog:addOption("Protect Galileo from the Catholic church. (Get a science boost).", 1)
                dialog:addOption("Condemn him too as a heretic (Get 500 Thaler).", 2)
                local choice = dialog:show()
                if choice == 1 then
                    local researchProgress
                    tribe.reseachProgress =
                elseif choice == 2 then
                    local tribe = object.tHabsburgians
                    tribe.money = tribe.money + 500
                end   
    end)
end

What parameter could I set for the research bonus? I would like to give a 50% boost for one time, if possible.
 
What parameter could I set for the research bonus? I would like to give a 50% boost for one time, if possible.
Code:
if choice == 1 then
                    tribe.reseachProgress = tribe.researchProgress + math.floor(0.5*tribe.researchCost)
                elseif choice == 2 then

This contributes 50% of the current cost of researching the next technology to the current research progress. Of course, if this bonus pushes the progress beyond 100%, those extra beakers will be wasted. I suppose you could do something like this

Code:
local researchBonus = math.floor(0.5*tribe.researchCost)
local excessResearch = (tribe.researchProgress+researchBonus)-tribe.researchCost
if excessResearch > 0 and tribe.researching ~= nil then
    civ.giveTech(tribe,tribe.researching)
    tribe.researchProgress = excessResearch
else
    tribe.researchProgress = tribe.researchProgress+researchBonus
end
With this code, supplemental research won't be wasted unless the tribe is not researching any tech when it is set to receive the bonus.
 
@Prof. Garfield do you happen to recall where you put in the code that automatically creates some units to make sure that there is a unit that can activate for events? I can't locate it and checked in a few places without seeing it in the template. Unfortunately I have such a monster of a project that I could easily be missing it. I want to take this out or at least change the coordinates to a different map where it won't matter as right now I have British Waffen SS Divisions popping up in Norway :lol:
 
@Prof. Garfield do you happen to recall where you put in the code that automatically creates some units to make sure that there is a unit that can activate for events? I can't locate it and checked in a few places without seeing it in the template. Unfortunately I have such a monster of a project that I could easily be missing it. I want to take this out or at least change the coordinates to a different map where it won't matter as right now I have British Waffen SS Divisions popping up in Norway :lol:

In parameters.lua, you can make the relevant changes:
Code:
eventTools.setGuaranteeUnitActivationType(nil)
-- these locations are used for creating units that will
-- guarantee unit activation
-- If possible, choose an out of the way area of the map
-- if none is available, you'll have to write a function
-- to find a place
local activationLocations = {
[0] = civ.getTile(0,0,0) ,
[1] = civ.getTile(0,0,0),
[2] = civ.getTile(0,0,0),
[3] = civ.getTile(0,0,0),
[4] = civ.getTile(0,0,0),
[5] = civ.getTile(0,0,0),
[6] = civ.getTile(0,0,0),
[7] = civ.getTile(0,0,0),
}
local function activationLocationFunction(tribe)
    return activationLocations[tribe.id]
end
eventTools.setGuaranteeActivationUnitLocationFunction(activationLocationFunction)

If you have some other event that needs to guarantee a unit activation, use this:

Code:
local eventTools = require("eventTools")
eventTools.guaranteeUnitActivation(tribe)
 
I would like to ask one of the LUA experts for support with the diplomacy settings.
In 1517 the Neutral civilization represents all minor Christian nations in West and East Europe. Because Neutral cities can be aligned by other nations no one except the Ottomans can make war with the Neutrals.
Is something like this possible to realize?

I also added some events like the Italian Wars were the player gets into war with France. Is it possible to set the war for a certain time period, so that the player can't negotiate with France during that time?

For example when the Italian Wars event triggers, the AI immediately tries to negotiate with me, even when I used in LUA the following code:
Code:
diplomacy.setWar(object.tFrench,object.tHabsburgians)
 
You perhaps could use the negotiationSettings.lua to perhaps cut off communications when war breaks out?
 
For example when the Italian Wars event triggers, the AI immediately tries to negotiate with me, even when I used in LUA the following code:

First, try this function:
makeAggression
civ.makeAggression(who, whom) -> void

Cancels any peace treaties between tribe `who` and tribe `whom`, and make `who` declare war on `whom`.

I think this uses the actual 'event' code for making war declarations.

diplomacy.setWar only changes the diplomacy flags, not attitudes or anything else. So, if the tribes don't "want" to be at war, they will immediately make peace through diplomacy.

In the diplomacySettings.lua file, you can uncomment the following line to forbid all diplomacy not driven by diplomacy.setRelationship functions:
Code:
--diplomacy.setEventTreatiesOnly("You may have received a message about a change in diplomacy.  This change has been undone.")

I should probably do something more flexible.

In 1517 the Neutral civilization represents all minor Christian nations in West and East Europe. Because Neutral cities can be aligned by other nations no one except the Ottomans can make war with the Neutrals.
Is something like this possible to realize?

In unitActivation.lua, you can make the following event: (untested code)
Code:
local noWarWithNeutrals = {object.tTribe1,object.tTribe2,--[[etc]]} -- list of tribes that can't be at war with the neutrals
for __,tribe in pairs(noWarWithNeutrals) do
    if diplomacy.warExists(tribe,object.tNeutrals) then
        diplomacy.clearWar(tribe,object.tNeutrals)
        diplomacy.setPeaceTreaty(tribe,object.tNeutrals)
        text.simple(text.substitute("You may have received a message that the %STRING1 are at war with the %STRING2.  This is a mistake, and peace has been restored.",{tribe.name,object.tNeutrals.name},"Forbidden War")
    end
end
 
You perhaps could use the negotiationSettings.lua to perhaps cut off communications when war breaks out?

I was thinking about to realize this by using flags. If the Italian Wars trigger occurs, the flag set on true and negotiations are not allowed, after Milan is conquered, the flag goes back to false and negotiations are available again.
I hope I can make it run with the codes Prof. Garfield provided.
 
First, try this function:
makeAggression
civ.makeAggression(who, whom) -> void

Cancels any peace treaties between tribe `who` and tribe `whom`, and make `who` declare war on `whom`.

I think this uses the actual 'event' code for making war declarations.

diplomacy.setWar only changes the diplomacy flags, not attitudes or anything else. So, if the tribes don't "want" to be at war, they will immediately make peace through diplomacy.

In the diplomacySettings.lua file, you can uncomment the following line to forbid all diplomacy not driven by diplomacy.setRelationship functions:
Code:
--diplomacy.setEventTreatiesOnly("You may have received a message about a change in diplomacy.  This change has been undone.")

I should probably do something more flexible.



In unitActivation.lua, you can make the following event: (untested code)
Code:
local noWarWithNeutrals = {object.tTribe1,object.tTribe2,--[[etc]]} -- list of tribes that can't be at war with the neutrals
for __,tribe in pairs(noWarWithNeutrals) do
    if diplomacy.warExists(tribe,object.tNeutrals) then
        diplomacy.clearWar(tribe,object.tNeutrals)
        diplomacy.setPeaceTreaty(tribe,object.tNeutrals)
        text.simple(text.substitute("You may have received a message that the %STRING1 are at war with the %STRING2.  This is a mistake, and peace has been restored.",{tribe.name,object.tNeutrals.name},"Forbidden War")
    end
end

Many thanks for the codes. Currently I'm testing them and maybe I can use flags to disable negotiations only for a certain time.
 
I've tried to use the code in the unit.Activation.lua file but it seems that the "noWarWithNeutrals" doesn't have any effect on the diplomacy. I can still declare war to the Neutrals as the AI too. LUA itself doesn't show me any errors, so the code should be fine.

Code:
local object = require("object")
local gen = require("generalLibrary")
local diplomacy = require("diplomacy")

local unitActivation = {}
function unitActivation.activateFunction(unit,source)


end

local noWarWithNeutrals = {object.tFrench,object.tHabsburgians,object.tEnglish,object.tProtestants} -- list of tribes that can't be at war with the neutrals
for __,tribe in pairs(noWarWithNeutrals) do
    if diplomacy.warExists(tribe,object.tNeutrals) then
        diplomacy.clearWar(tribe,object.tNeutrals)
        diplomacy.setPeaceTreaty(tribe,object.tNeutrals)
        text.simple(text.substitute("You may have received a message ...."))
    end
end

return unitActivation
 
I've tried to use the code in the unit.Activation.lua file but it seems that the "noWarWithNeutrals" doesn't have any effect on the diplomacy. I can still declare war to the Neutrals as the AI too. LUA itself doesn't show me any errors, so the code should be fine.

Arrange the file like this:

Code:
local object = require("object")
local gen = require("generalLibrary")
local diplomacy = require("diplomacy")

local noWarWithNeutrals = {object.tFrench,object.tHabsburgians,object.tEnglish,object.tProtestants} -- list of tribes that can't be at war with the neutrals

local unitActivation = {}
function unitActivation.activateFunction(unit,source)
for __,tribe in pairs(noWarWithNeutrals) do
   if diplomacy.warExists(tribe,object.tNeutrals) then
        diplomacy.clearWar(tribe,object.tNeutrals)
        diplomacy.setPeaceTreaty(tribe,object.tNeutrals)
        text.simple(text.substitute("You may have received a message ...."))
    end
end
end
return unitActivation

I have written some extra diplomacy functions for more granular control over who can change treaties with whom. I discovered that making sneak attacks will still work (if the tribes are not allies, of course), even though peace will be restored immediately after. If you want to PM me your scenario, I'll update the template to use the new system which overcomes this loophole.
 
@Prof. Garfield, I think I found a bug with the LUA files.
After I played my first turn, two units, which will be available later in game by technology research will be spawned once for every AI. When I play the first turn without any LUA codes, it won't occur.
I then used yout template without any changes and the bug occurs again.

So the bug could be caused by the LUA files.
 
Back
Top Bottom