Author: T.C.
Original Thread: [Tutorial] How to make your own historic events

How to make your own historic events
While doing some digging I cracked this method - it's quite simple to edit actually.

To start off I suggest you visit the NTW Script-o-Rama. From there you will find a basic introduction to scripting, helpful tips and advice on tools to use (mainly notepad ++). This thread assumes you have basic knowledge, all of which is available in the script-o-rama.

This method should also work for Empire:TW; I can't comment on S2TW.

Part 1 - Files Needed


You'll need to add the following db tables and files to your mod pack, as these are the ones we'll be editing:
  • events_tables
  • events_view_group_junct_tables
  • export_historic_events.lua
You'll also need to make some changes in the localisation.loc



Part 2 -The Simple Method
This method explains the how, not the why. Please refer to the advanced method for a more full explanation.

To get yourself off the ground with this quickly you'll need to begin by adding a new entry to events tables. As you can see, I've made one here called myEvent. The only columns which you need to worry about are the ones labelled "Imageas" (should be "Image", typo on my behalf), "Dynamic" and "Image2". The rest of the entries make absolutely no difference to this process, contrary to popular belief. "Dynamic" should always be set to false, Imageas and Image2 control the image used by the in game pop-up; you can edit these as you see fit.

Spoiler for events_tables






Next you need to go to events_view_group_junct_tables. Simply make a new entry with your event key and the value "all_factions", as seen below.

Spoiler for events_view_group_junct_tables








Next you need to go to export_historic_events.lua. At the end of this file you need to make a duplicate block of code, as you can see I have done. This is where the actual information about when the event triggers is stored, not the db file. You will need to edit the arguments passed to the function conditions.IsTriggerableHistoricalEvent(). (Simply put, you'll need to edit what's in between the brackets).
  • The first number (in my example, 2) is the turn in the year that the event will display.
  • The string that follows it (in my example, "myEvent") is the name of your event - this must match the db key of your event.
  • The next number is the year in which the event will fire.
  • The next string seems defunct; it always contains information about the season, but in my testing it has had no impact on the end result.
  • The final argument, context, must never be changed.
The final thing to edit in this lua file is the function effect.historical_event(). The string passed to this function is the name of your event. Again, this must match the db key of your event.

Spoiler for export_historic_events.lua








The final item we need to edit is the loc. We simply make 2 new entries:
  • events_event_text_foo
  • events_onscreen_name_foo
Where "foo" is the name of your event. Shown below is an example of this.

Spoiler for localisation




As you can see below, the event works as intended - in my case firing on the second turn of 1805.

Spoiler Alert, click show to read: 


Now for the more detailed explanation.

Part3 -Some advanced explanation

Why are most of the db values ignored?
My theory is that the .lua we edit was automatically generated pre-release. It used the data is the db columns to build the lua code - this was probably a method employed by CA so that game developers who weren't proficient in Lua could easily create and test historic events. Remember that this is a leftover from Empire, a game that had far more historic events than NTW. This is backed up by the comment at the top of the file:
"Automatically generated via export from Empire.mdb
Edit manually at your own risk"
Either way, we need to edit the Lua code directly to make any changes. It should be noted that in order to change existing events you'll need to edit the Lua code directly also.




Any more info on the function and it's conditions?
Yes. You can call the function directly by using effect.historical_event(), but this needs a context argument passed from the HistoricalEvents event. So you can only use this function inside an HistoricalEvents event block. If this is used at the start of every turn you will get a historic event message each and every turn start. It is the conditions.IsTriggerableHistoricalEvent() function that restricts it to firing once. A summary of the arguments to the two functions:





conditions.isTriggerableHistoricalEvent
  1. Turn in year
    • Type: Int
    • Notes: The turn in the given year which the event will fire on.
  2. Event name
    • Type: String
    • Notes: The db key of the event
  3. Year
    • Type: Int
    • Notes: The Year in which the event will fire
  4. Season
    • Type: String
    • Notes: Seems to be unused
  5. context
    • Type: userdata
    • Notes:Must be used with HistoricalEvents event


effect.historical_event
  1. Name
    • Type: String
    • Notes: The db key of the event
  2. context
    • Type: userdata
    • Notes:Must be used with HistoricalEvents event