mod.lua and strings.lua - Explaining the content and requirements

  • Based on examples, all required and optional field for the mod.lua and strings.lua files are explained in this article.
    Die Deutsche Version gibt es hier: mod.lua und strings.lua - Erklärung und Inhalt

    Official Format by Urban Games (mod.lua)


    The basic format of the mod.lua file that is required for each mod in the root directory

    Quellcode: mod.lua

    1. function data()
    2. return {
    3. info = {
    4. name = _("Sample mod"), -- name of mod
    5. description = _("modDesc"), -- optional, description
    6. minorVersion = 0, -- minorVersion (integer)
    7. severityAdd = "WARNING", -- NONE, WARNING, CRITICAL
    8. severityRemove = "CRITICAL", --
    9. visible = true, -- optional, default: true
    10. -- if false, mod is hidden
    11. },
    12. -- options = ..
    13. -- runFn = ..
    14. -- checkActiveFn = ..
    15. }
    16. end
    Alles anzeigen

    Additional Information for TPFMM


    Basic Information

    Quellcode

    1. tfnetId = 0, -- optional, transportfever.net entry id
    2. steamId = 0, -- optional, steam workshop file id
    3. url = "https://transportfever.net" -- optional, url to mod homepage
    Authors

    Quellcode

    1. authors = { -- optional, information about authors
    2. { -- add one or multiple authors
    3. name = "Author 1", -- author name
    4. role = "CREATOR", -- CREATOR, CO_CREATOR, TESTER, BASED_ON, OTHER
    5. tfnetId = 00000, -- optional, id at transportfever.net
    6. steamId = 0000, -- optional, steam id
    7. }, -- optional, add more authors
    8. },
    Tags

    Quellcode

    1. tags = { "tag1", "tag2", "tag3" }, --optional, list of tags
    Dependencies
    Define dependencies to other mods that are required in order for the mod to function as desired, not evaluated by the game but informs mod managers which other mods to download. For the download, at least one online source has to be defined

    Quellcode

    1. dependencies = { "other_mod_1", "another_mod_1", "third_mod_1" },

    Translations (strings.lua)


    All strings put in _("") will be translated based on the strings.lua file:

    Quellcode

    1. function data()
    2. return {
    3. de = {
    4. ["my mod"] = "Mein Mod", -- call to _("my mod") will be
    5. -- replaced with "mein Mod",
    6. -- if language is german
    7. ["the description"] = "Beschreibung",
    8. -- _("the description") ⇒ "Beschreibung"
    9. },
    10. }
    11. end
    Alles anzeigen
    Note:
    If a variable is passed to the _() function, the content of the variable, not the variable name itself is passed to the function. This, in combination with global variables in lua lead to the scenario in which description and name of multiple mods where overwritten by each other in a beta patch of Transport Fever. Although this is fixed by now, Urban Games and strongly advises to only use local variables. Pesonally, I advice to not use variables for the translation function.


    Example Files


    Very simple file with single author

    Quellcode: mod.lua

    1. function data()
    2. return {
    3. info = {
    4. name = _("name"),
    5. description = _("desc"),
    6. minorVersion = 2,
    7. severityAdd = "NONE"
    8. severityRemove = "CRITICAL",
    9. authors = {
    10. {
    11. name = "John Doe",
    12. role = "CREATOR",
    13. tfnetId = 1,
    14. },
    15. },
    16. tags = {"train", "multiple_unit"},
    17. },
    18. }
    19. end
    Alles anzeigen


    Quellcode: strings.lua

    1. function data()
    2. return {
    3. en = {
    4. ["name"] = "My Train Mod",
    5. ["desc"] = "This is my first train mod. Have fun.",
    6. },
    7. de = {
    8. ["name"] = "Mein Zug Mod",
    9. ["desc"] = "Das ist mein erster Zug Mod, viel Spaß.",
    10. },
    11. }
    12. end
    Alles anzeigen
    A repaint mod, that requires the mod defined above

    Quellcode: mod.lua

    1. function data()
    2. return {
    3. info = {
    4. name = _("name"),
    5. description = _("desc"),
    6. minorVersion = 1,
    7. severityAdd = "NONE"
    8. severityRemove = "CRITICAL",
    9. authors = {
    10. {
    11. name = "jane",
    12. role = "CREATOR",
    13. tfnetId = 00000,
    14. steamId = 0000,
    15. text = "text",
    16. },
    17. {
    18. name = "John Doe",
    19. role = "BASED_ON",
    20. tfnetID = 1,
    21. },
    22. },
    23. dependencies = { "base_mod_1" },
    24. tags = {"repaint", "train", "multiple_unit"},
    25. },
    26. }
    27. end
    Alles anzeigen

    Quellcode: strings.lua

    1. function data()
    2. return {
    3. en = {
    4. ["name"] = "My Repaint Mod",
    5. ["desc"] = "My first Repaint",
    6. },
    7. de = {
    8. ["name"] = "Mein Repaint Mod",
    9. ["desc"] = "Mein erstes Repaint.",
    10. },
    11. }
    12. end
    Alles anzeigen

    1.459 mal gelesen

Kommentare 1

  • MaikC -

    By Authors kann man auch nach "role" noch ein Feld mit.
    text = "Textur",
    oder
    text = "Model",
    machen bei mehreren authoren kann man so klar stellen wer was verbrochen hat ;)