[TOTPP] Lua Scenario Template

Get the music option "on" ? (game/game option/"music" box)

Advice from the guy who hardly played music :D .
You could check if it works by doing (game/pick music).
Otherwise, you can also launch a music using Lua and, per exemple, a onKeyPress.

Please notice that, while sounds are overlapping, only one music is played at a time. ;)
Ugh... so silly! Did not have that box ticked. I don't know how it "un-ticked" though. Anyway, all good now. :) Thanks @Dadais !
 
In LuaParameterFiles/customMusicIntegration.lua, there is a line
Code:
local useCustomMusic = false
which must be set to true (in addition to the TOTPP music patch being enabled). Otherwise, the game will refer to whatever playlist is in <Test of Time Directory?\lua\extendedMusicSettings.lua.

I'm pretty sure that the end user doesn't need to have the Extended Music Patch installed to get custom music with customMusicIntegration.lua. The older version needed it, because files would be overwritten in the Test of Time\Music folder, and I didn't want everyone shipping code that overwrites files.
Ah OK, this is helpful to hear. So I can keep my "ToT/lua" files as they are?
 
It has come to my attention that the Legacy Event Engine has a bug. The TURN event doesn't work for parameter turn=every. The template has been updated with the fix, which is attached here as well.
 

Attachments

Hello @Prof. Garfield,

could you have a look at your LUA template files please?
I`ve downloaded them from your github server and the game shows me the following error message when I start a savegame.
1726340126416.png


I didn't change anything, I only downloaded the files and copied them into my scenario folder.
 
Hello @Prof. Garfield,

could you have a look at your LUA template files please?
I`ve downloaded them from your github server and the game shows me the following error message when I start a savegame.
View attachment 703399

I didn't change anything, I only downloaded the files and copied them into my scenario folder.
Check your rules under COSMIC2, particularly the railroad multiplier. The changeRules module expects the rules.txt file to be correct (and maybe complete). Perhaps I should make the module more permissive of errors...

Let me know if you can't fix the issue, and I'll have a closer look.
 
I've checked the multiplier entries and fixed them.
It seems that LUA has a problem with 'no' entries in rules file. I've a lot of technologies as well as units which can't be build and therefor set to 'no'.
I'm not really sure but I still remember that we had this problem already but I don't really know how we fixed it.

In my Reformation scenario I've also values within the rules file set to 'no' and LUA never showed an error message.

I've tested it on a clean rules file. When everything is set to 'nil' no problems. But if I set one value to 'no' LUA shows the following error message:
1726514818611.png
 
It seems that LUA has a problem with 'no' entries in rules file. I've a lot of technologies as well as units which can't be build and therefor set to 'no'.
I'm not really sure but I still remember that we had this problem already but I don't really know how we fixed it.

In my Reformation scenario I've also values within the rules file set to 'no' and LUA never showed an error message.

I've tested it on a clean rules file. When everything is set to 'nil' no problems. But if I set one value to 'no' LUA shows the following error message:
The changeRules module can deal with "no" as a prerequisite tech, but not as an expires tech. Perhaps I should change that.
 
If I had realised that "no" was allowed, but invalid tech codes caused the game to crash, I probably would have programmed things a bit different. "no" as an expires tech is now allowed.

I've updated the template on GitHub, but here's the specific file.

Let me know if you have any further problems.
 

Attachments

Hello, crew!
Got a Lua error popping up when I cancel founding a new city:

I checked the Lua parameter file and am unsure how to get this one fixed?
1759821872424.png

Instead of (nil) what should I enter into the field?
Cheers for any advice, and I know I am missing something obvious...
 
Hello, crew!
Got a Lua error popping up when I cancel founding a new city:

I checked the Lua parameter file and am unsure how to get this one fixed?
1759821872424.png

Instead of (nil) what should I enter into the field?
Cheers for any advice, and I know I am missing something obvious...
You have to scroll down to the bottom of the Lua console data. What you're showing is scenario loaded data, to help diagnose errors when you load a game. IIRC, the Template created (if specified) a unit with type setGuaranteeUnitActivationType for each tribe in order to ensure the "afterProduction" event happened for everyone, by making sure every tribe had a (non-fortified) unit to activate each turn. More modern versions of TOTPP have a built in afterProduction event, so they don't have leverage the onActivateUnit event (hence why I don't remember the exact details).

If you're getting an error when cancelling founding a new city, that means there is something about the onCityFounded event which causes an error if the city isn't actually founded. The onCityFounded event lets you return a function to be executed when a city is cancelled, in case you need to undo some part of the event. Since you're using an old version of the template, perhaps this is a backwards compatibility issue since old versions of the template wouldn't return a function. A quick test tells me this can happen.

In events.lua, search for civ.scen.onCityFounded

The code should look like
Code:
civ.scen.onCityFounded(function(city)
-- some code
end)
Try adding a line:
Code:
civ.scen.onCityFounded(function(city)
-- some code
return function() end
end)
If you're not sure how to do this, upload your events.lua file and I'll make the adjustment.
 
Hello, crew!
Got a Lua error popping up when I cancel founding a new city:

I checked the Lua parameter file and am unsure how to get this one fixed?
View attachment 744433
Instead of (nil) what should I enter into the field?
Cheers for any advice, and I know I am missing something obvious...
What new scenario is this a U.S. Heartland screenshot from under the error code?
 
I've (finally!) updated the template to include a new help module which is integrated with the registerCombatModifiers.lua file. Help will show what bonuses the unit is eligible for, and which ones it is currently receiving along with modified stats. You have to use the new keys attackerHelpActive and defenderHelpActive in order for the help module to include a bonus in the modified stats. Here is the documentation for the new keys

Spoiler show documentation :

Code:
--  attackerPedia = string or nil
--      if string, add this text to the attacker unit type(s)
--      describe.txt entry created by civilopedia.lua
--  defenderPedia = string or nil
--      if string, add this text to the defender unit type(s)
--      describe.txt entry created by civilopedia.lua
--  attackerHelp = string or nil
--      if string, add this text to the attacker unit type(s)
--      help entry created by help.lua
--  attackerHelpActive = string or nil
--      if string, help.lua will attempt to check if this combat
--      modifier is active, and if so, add this text to the unit's
--      help entry generated by help.lua, instead of the text
--      provided by the attackerHelp field.
--      However, all functions of the form function(attacker,defender)
--      supplied in this combatModifier must be callable with the
--      nil as the argument for the 'defender' parameter.
--      Code will check if the attackerDetail is satisfied, and check
--      if customCheck(unit,nil) is true to see if this message should be 
--      displayed.  
--      Any functions provided as values for a combatSpec key 
--      will be called with the attacker as the first argument, and nil
--      as the second argument.

--  defenderHelp = string or nil
--      if string, add this text to the defender unit type(s)
--      Help entry created by help.lua
--  defenderHelpActive = string or nil
--      if string, help.lua will attempt to check if this combat
--      modifier is active, and if so, add this text to the unit's
--      help entry generated by help.lua, instead of the text
--      provided by the defenderHelp field.
--      However, all functions of the form function(attacker,defender)
--      supplied in this combatModifier must be callable with
--      nil as the argument for the 'attacker' parameter.
--      Code will check if the defenderDetail is satisfied, and check
--      if customCheck(nil,unit) is true to see if this message should be
--      displayed.
--      Any functions provided as values for a combatSpec key
--      will be called with nil as the first argument, and the defender
--      as the second argument.


The help module also creates a "tooltip" to replace the date with the active unit's stats. Pressing 0 will open the configuration menu, which will let the player change the behaviour of the date. (You can also change whether combat power is displayed from there.)

The scenario designer will also have the ability to create commands that can execute from these help boxes. By default, a command to activate the stacked unit with the highest attack (that can still attack) is provided.

crusaders1.png

crusaders2.png


stack-help.png


I also changed the rules_lst.txt file to use the combatModifiers module, instead of a separate line in combatSettings.lua, but I don't think this will impact anyone in practice.

If anyone has a scenario recent enough to use registerCombatSettings.lua that they'd like to add this module to, contact me and I'll make the changes. There are a number of files that must be changed, and I'll need to change combatSettings.lua manually.

If you use this module and want more/different help behaviour, please ask. If I tried to make this perfect, I don't think I'd ever release it.
 
Back
Top Bottom