[TOTPP] Lua Scenario Template

@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.

I'm not sure what you mean here. Is the bug that units are being created when they are not supposed to be? Do you have legacy events that are working differently than you expect? Or, does using the Lua Events generate an error at some point even though you haven't changed the files?
 
The bug is that these units are created but they shouldn't supposed to be. I'm a little bit surprised because it only occur when I use the LUA scripts.
LUA itself works fine and there isn't any error message.
 
In parameters.lua, did you change this line:

eventTools.setGuaranteeUnitActivationType(nil)

If so, is that the type of unit being created?

What this line does is enable creating a unit for each tribe every turn so that the tribe will have "afterPrduction" events (and, also, guaranteed promotion beyond veteran). When the unit is activated, it will immediately be deleted.

You can create the units in an out of the way location by changing this table in the same file:
Code:
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),
}

If this isn't the situation, I'll have to see the code to understand and fix the problem.
 
I didn't change anything in this file. Even if I play more turns, the created units still in the game and not automatically deleted.

Can you please send me the scenario folder you're working with, along with the unit type that is appearing (and the location, if it is consistent)? I'm going to have to play with this myself.
 
I have improved the ability to prevent treaty changes with an update to the template a couple days ago. Now, you can enable some tribes to change their treaties in game, but not others. Also, tribes at peace now shouldn't be able to sneak attack each other and get 1 free kill before the treaty is restored (I technically haven't tried this with an AI making the sneak attack, but it should still work).

To disable treaty changes, go to diplomacySettings.lua and uncomment this line:

Code:
--diplomacy.setEventTreatiesOnly("You may have received a message about a change in diplomacy.  This change has been undone.")

By default, this means that no tribes can change their treaties in game. The only way for treaties to change is by the functions in the diplomacy module.

If you want to allow certain tribes to always be able to change their treaties in game, use the following function within diplomacySettings.lua:
Code:
diplomacy.alwaysEnableTreatyChanges(tribe1,tribe2)

If you want to enable and disable in game treaty changes, use these functions within events. For example, if you want to enable treaty changes at the start of the scenario, but disable them later, put them in the onTurn event, set to apply on turn 1.
Code:
diplomacy.enableTreatyChanges(tribe1,tribe2)
diplomacy.disableTreatyChanges(tribe1,tribe2)
 
I've played a little bit around with the diplomacy modules and currently everything works like it should. For the main civs I enabled diplomacy, but disabled it for the Neutrals. No one can negotiate with them, so no one can start a war with them.
Also enable and disable of treaty changes in game working very well. When the Italian War event triggers, negotiations between Habsburg and France are disabled for ten turns. After the ten turns, negotiations with France are available again.

I'm now updating the diplomacy settings for the other events.
 
Just a casual musing - Wondering if there would be a method to give civs a gold cost, based on the number of units they have?

Such a Lua feature would mean big militaries would cost big gold budgets...Would be great for scenarios I have in mind too...:)
 
Just a casual musing - Wondering if there would be a method to give civs a gold cost, based on the number of units they have?

Such a Lua feature would mean big militaries would cost big gold budgets...Would be great for scenarios I have in mind too...:)

Here's the Lua Lesson on counting things:

https://sleague.civfanatics.com/ind...4:_Examples_and_More_Examples#Counting_Things

Every turn, or whenever, count the units, then change the tribes' money based on the number of units counted.
 
I have updated the text module to allow for using images with text.simple (basic text box creator), text.menu (menu builder) and text.displayNextOpportunity (allows you to delay showing a text box until that tribe is playing).

I have started documenting the text module, and there should be enough documentation to explain the new image features.

There is a very small chance of regression with text.menu and text.displayNextOpportunity. If the "canCancel" argument in text.menu or "broadcast" in text.displayNextOpportunity used a value other than "true", "false", or "nil", the code will not work properly if you update with the current (or future) version of text.lua. That would be rather unnatural usage in this case, but it is technically possible.
 
I've added gen.gameMechanicDistance to the General Library, as @Knighttime suggested a while ago. I believe this is how the game calculates distance for things like corruption (I used Knighttime's distance code from the corruption work he did, adding in a case for round maps) and assigning home cities to newly created units (my testing was based on newly created units).
 
Hello Prof.Garfield,

I would like to forbid certain tribes building certain improvements. For example, the Habsburgians shouldn't be able to build Mosques or Temples.
I'm currently using this code but it doesn't work. I can still build both improvements with the Habsburgians:
Code:
improvementBuild[object.iTemple.id] = {forbiddenTribes=object.tHabsburgians}

Could you let me know what I did wrong with the code, please?
 
Could you let me know what I did wrong with the code, please?

What you did is completely natural, based on how other parts of the module work, but I set up forbiddenTribes (and forbiddenMaps) differently.

Code:
--      .forbiddenTribes = {[tribeID]=bool}
--          if canBuildObjectType[item.id].forbiddenTribes[tribeID] is true, then the tribe with
--          tribeID can't build item, false or nil/absent means it can

The value for forbidden tribes is a table, and the keys of that table are the forbidden tribes ID. Hence {[tribeID]=bool}.

Write it like this:

Code:
improvementBuild[object.iTemple.id] = {forbiddenTribes={[object.tHabsburgians.id]=true}

Now that you've asked this question, I'm going to see if I can update the system to accept the more natural way of specifying this. I don't remember why I did it differently, except maybe it was slightly easier to deal with behind the scenes.
 
I've updated the template so that forbidden tribes can also be specified as a list of tribe objects (the way you tried). I've attached the updated canBuild.lua file here also.
 

Attachments

I've built a "traits" module (not pushed to Github yet), which allows a scenario designer to assign traits/attributes to different Civ II objects, in order to check later if a particular object has that trait. For example, by assigning 'Light Tank', 'Medium Tank', and 'Heavy Tank' the "tank" trait, you put them into the "tank" list, and then elsewhere in your code you can check if a unit type is in the "tank" list by using the traits module functionality. The reason to use the traits module is that you don't have to build a list of "tank"s everywhere you need it, and possibly forget some. (I'm planning to build a combat bonuses module using these "traits", but that's not especially relevant here.)

The syntax is like this
Code:
traits.assign(object.uLightTank,"tank","fast","oil user","tracks")
traits.assign(object.uMediumTank,"tank","fast","oil user","tracks")
traits.assign(object.uHeavyTank,"tank","oil user","tracks")
traits.assign(object.uTruckInf,"fast","oil user","infantry","wheels")
traits.assign(object.uInfantry,"infantry","foot")

And to check
Code:
if traits.hasTrait(unit.type,"infantry") then 
if traits.hasAllTraits(unit.type,"fast","tank") then
if traits.hasAnyTrait(unit.type,"tracks","foot") then

The question I have is whether I should add pre-made empty assignment lines (i.e. traits.assign(object.zName,"sample trait")) in the object.lua generator script or not. I tried adding the line under each object.zName definition, but it cluttered the list.

Code:
-- Civilization Advances
-- recommended key prefix 'a'
object.aAdvancedFlight          = civ.getTech(0)
    traits.assign(object.aAdvancedFlight,"sample trait 1")
object.aAlphabet                = civ.getTech(1)
    traits.assign(object.aAlphabet,"sample trait 1")
object.aAmphibiousWarfare       = civ.getTech(2)
    traits.assign(object.aAmphibiousWarfare,"sample trait 1")
object.aAstronomy               = civ.getTech(3)
    traits.assign(object.aAstronomy,"sample trait 1")
object.aAtomicTheory            = civ.getTech(4)
    traits.assign(object.aAtomicTheory,"sample trait 1")
object.aAutomobile              = civ.getTech(5)   --Automobile
    traits.assign(object.aAutomobile,"sample trait 1")

Does that kind of clutter matter? Should I generate a separate trait assignment file, or maybe add the lines in their own section of object.lua? Or, does it make more sense to just let the designer figure it out and add the lines if and where they are needed?
 
What you did is completely natural, based on how other parts of the module work, but I set up forbiddenTribes (and forbiddenMaps) differently.

Code:
--      .forbiddenTribes = {[tribeID]=bool}
--          if canBuildObjectType[item.id].forbiddenTribes[tribeID] is true, then the tribe with
--          tribeID can't build item, false or nil/absent means it can

The value for forbidden tribes is a table, and the keys of that table are the forbidden tribes ID. Hence {[tribeID]=bool}.

Write it like this:

Code:
improvementBuild[object.iTemple.id] = {forbiddenTribes={[object.tHabsburgians.id]=true}

Now that you've asked this question, I'm going to see if I can update the system to accept the more natural way of specifying this. I don't remember why I did it differently, except maybe it was slightly easier to deal with behind the scenes.

Is it too possible to forbid another tribes building certain improvements?
Currently it only works when I'm using the codes for my own tribe. If I add any AI tribe, all buildings available again for all tribes.

LUA itself doesn't show me any error. The consule says that everything is alright.
 
Back
Top Bottom