Tropico 5 Opening Thoughts on Modding
#1
Okay, before everyone shouts me down for attempting to mod the game right out of the gates, let me open by saying that this is a direct result of the 2000 pop cap (which is discussed in another thread). I'm rather frustrated by this in one of my sandbox games, where I probably need at least 2500 people for my current buildings, nevermind for anything more.

I managed to extract the Lua pack using HPK Archiver 1.05 and found I was able to decompile most of the Lua's I tried. In any event, through doing this I found 2 files of interest: City.lua (which holds the forced emigration code) and _const.lua (which holds various constants, including the pop cap).

So, after a variety of different attempts to get it to load (including using my very limited knowledge of the T4 mod .lua loading) and ended up with one odd occurrence: When I directly copy-paste the extracted Lua folders into the Tropico 5 directory (image shared below) and tried to load, the game clearly is trying to load it as the Main Menu (along with everything else) gets messed up in all sorts of ways -- image shared below (plain black background, load game button doesn't work, etc.).

Tropico 5 Folder, including the extracted Lua directories (and some other junk which is irrelevant but figured I'd leave in):

[Image: http://i.imgur.com/sfFe6j6.jpg]

Main Menu Screenshot (I cropped the image quite a bit as with my resolution the full size would about 3-4 times bigger than the above image -- still gives the idea):

[Image: http://i.imgur.com/9R9Wqcs.jpg]

When I remove the Lua directories from my T5 folder, the game loads normally.

I hope the admins allow this thread to stay. In any event, I'm a self-described habitual modder.
Reply
#2
I just installed the game and took a quick peak (I cannot believe I am trying to mod before I even play the damn thing)....

You definitely do not want to copy extracted and decompiled lua files into the game folders. You leave yourself to the mercy of the decompiler which is prone to producing quite a lot of garbage.

If you place a mod file in CommonLua it appears to load. click
DarthTest.lua (Edited to fix typo: Thanks bongikairu)

Code:
OnMsg.ClassesPreprocess = function()
    const.PopLimit = 5000
    DebugPrint("YOU FOOL!.  YOU JUST MADE A MOD\n")
end

OnMsg.NewMap = function()
    DebugPrint("New Map Loaded.  Poplimit=" .. const.PopLimit .. "!\n")
end

Log file:
Code:
YOU FOOL!.  YOU JUST MADE A MOD
                                                                            @ 21403, 12542
                                                                            # 6668, 'Lua'
Loading account storage...
                                                                            @ 21419, 16
Account storage loaded successfully in 6 ms
DLC steam loaded, lua revision 181599, assets revision 18186
DLC steam loaded, lua revision 181599, assets revision 18186
                                                                            @ 22386, 967
New UI mode "Game" set in 0 ms
                                                                            @ 46738, 24352
New Map Loaded.  Poplimit=5000!


No promises but give it a shot.
Reply
#3
I registered solely so I could post this... Kalypso's hard cap on population is ridiculous. I would like to break it myself.

I have followed these steps:

1. Downloaded "HPK Archiver 1.05".
2. Unpacked Lua.hpk which output the folders CommonLua and Lua. I also got a single error: D:\Tropico 5 Modding\Lua\Config\_LuaRevision.lua Could not decompress the file.
3. Tried to open up _const.lua with Notepad++ and my file looks like this:


[Image: http://i.imgur.com/qRR2Pdk.jpg]

I can't get it to show something which I can understand and edit? I found the words PopLimit but it just says NULEOTENQNULNULNUL after it...

How can I change this so that my population limit is 5000?

Please help, I desperately want to be able to remove the limit.
Reply
#4
13thRonin, we haven't found a for sure way to mod... yet. Sorry.

Darth, I'll look into that later today.
Reply
#5
13thRonin

That looks like a complied lua script to me. Try downloading a lua decompiler, see if that works.
Reply
#6
Can someone please send me his savegame where population cap is reached?

The13thRonin, this kind of files should be edited in hex editor not text processor Smile
Reply
#7
I definitely wish the modders luck, there are a couple of mods I've already determined I want and will be the first to admit, I don't know how to make them at all.

1) The ability to turn off all invasions...hell all actions requiring military. I just want to build sometimes.

2) The ability to turn off elections. This one is less important...but they can be inconvenient sometimes.
Reply
#8
Okay, I think I may have found it.

Try putting the following in a text file in CommonLua folder (you'll have to make that folder) in the Tropico 5 directory and rename the file to a .lua

Code:
OnMsg.ClassesPreprocess = function()
    const.PopLimit = 5000
end

I was able to get 2 ships with immigrants for a total of about 90 people and got to 2100 population. This was a proof of concept test, so I didn't try to see how high I could get it.

Let me know if it works for any of you!

Credit to DarthPresidente for the "OnMsg.ClassesPreprocess = function()" loading code.

EDIT @ Darth: I did try your version, but for some reason it wouldn't work for me.
Reply
#9
It's working. At least it working for const.MilitaryExploreCost, so I assume It will work for other constants.

Other interesting constants (defaults, all in _const.lua file (decompiled)):
const.MetroStationUseThreshold = 50 * guim
const.MetroStationWalkDistance = 100 * guim
const.BuildGridTileSize = 10 * guim
const.MaximumHouseDistance = 500 * guim
const.MigrationHappinessMaxDifference = 30
const.MigrationMaxChangeFromHappiness = 75
const.MigrationEmploymentMaxDifference = 15
const.MigrationMaxChangeFromEmployment = 100
const.MigrationRandomModification = 25
const.GarageMaxDistFromRoad = 2100
const.CitizenDiscreditCost = 5000
const.CitizenBanishCost = 1000
const.CitizenActionKill = 2000
const.DefaultBuildingHP = 3000
const.TankSpeed = 5 * guim
const.CorruptionThreshold = 20000
const.MinUnexploredRadius = 3 * const.BuildGridTileSize

Interesting hint in lua files.
DLC 1 Inquisition
DLC 2 The Big Cheese
DLC 3 T-Day
DLC 4 Madness
DLC 5 The Supercomputer
DLC 6 Surfs Up!
DLC 7 Generalissimo
DLC 8 Gone Green
DLC 9 McTropico
DLC 10 Supervillain
Reply
#10
Hello,
any chance to edit the number of workers for jobs ???
Reply
#11
Is it possible to mod dx10 support in the game? Big Grin

I don't know, so I ask for some of your wisdom. Oh praise the modding mages!
Reply
#12
Imaeos: That would probably be in the actual hard code of the .exe, which is illegal to alter in any way. Aside from the legal aspect, it certainly wouldn't be as easy as setting an option like "Allow DX10", or I'm sure it would already be supported. Instead, it would require a fair amount of re-working the graphics and render code to allow for it.

Hopefully they will support it ASAP, though.

EDIT @ Abrakadabra: I haven't gotten that far yet. In a preliminary search of the extracted files, the building data seems to be stored differently from Tropico 3/4. In Tropico 3/4 each building had its own .lua file, but in my look through it didn't seem that is the case in Tropico 5... but perhaps rather all building data is stored together within a few files rather than individually.
Reply
#13
Thx KurtisB.

That it wont be easy was clear, but maybe illegal also... I didn't know that. Thx alot!
Reply
#14
(27-05-2014, 09:13 PM)MissNet Wrote: Interesting hint in lua files.
DLC 1 Inquisition
DLC 2 The Big Cheese
DLC 3 T-Day
DLC 4 Madness
DLC 5 The Supercomputer
DLC 6 Surfs Up!
DLC 7 Generalissimo
DLC 8 Gone Green
DLC 9 McTropico
DLC 10 Supervillain

10 DLCs....gah....

Nice work to everyone in this thread, I sit in awe and stupidity in regards to modding.
Reply
#15
Does anyone know how to get texture mods to work? i've tried putting them everywhere maintaining the proper folder structure but nothing seems to work, also tried to package it and have it in "Packs" folder but no dice.
Reply
#16
Looks good MissNet. Been a while since i modded Tropico 4, so Ill have to relearn everything again Tongue

Anyways, I'd like to mod some of the traits, as well as making hydroponic farms use illiterate labor. Will look into it eventually.
Reply
#17
Building Template is where a lot of the individual building data code is located (Data\BuildingTemplate) It looks like modding building stats is going to be a little more difficult than in Tropico 4.

The first hurdle is that luadec butchers the file. I used Chunkspy to 'read' a file. Rather than try to decipher Chunkspy output on a building I suggest just printing the template to the log file using DebugPrint() That will give you an idea of how the information is stored. DataInstances.Template.BuildingName

Once you know how it's stored you can manipulate it. Just playing around and using some built in functions (DataInstances.Template:FindIndexOfClass(class) ) I was able to create a mod that doubled the housing capacity of all residential buildings:

Paste to DoubleHousing.lua in Tropico 5\CommonLua or download here
Code:
OnMsg.DataLoaded = function()
    DataInstances.BuildingTemplate.Apartment[DataInstances.BuildingTemplate.Apartment:FindIndexOfClass("Residence")]["BaseCapacity"] = 20
    DataInstances.BuildingTemplate.CountryHouse[DataInstances.BuildingTemplate.CountryHouse:FindIndexOfClass("Residence")]["BaseCapacity"] = 8
    DataInstances.BuildingTemplate.House[DataInstances.BuildingTemplate.House:FindIndexOfClass("Residence")]["BaseCapacity"] = 8
    DataInstances.BuildingTemplate.Mansion[DataInstances.BuildingTemplate.Mansion:FindIndexOfClass("Residence")]["BaseCapacity"] = 8
    DataInstances.BuildingTemplate.ModernApartment[DataInstances.BuildingTemplate.ModernApartment:FindIndexOfClass("Residence")]["BaseCapacity"] = 32
    DataInstances.BuildingTemplate.Shack[DataInstances.BuildingTemplate.Shack:FindIndexOfClass("Residence")]["BaseCapacity"] = 4
    DataInstances.BuildingTemplate.Tenement[DataInstances.BuildingTemplate.Tenement:FindIndexOfClass("Residence")]["BaseCapacity"] = 24
end


Changing a building's worker total is similar. Instead of "Residence" use "Workplace" and instead of "BaseCapacity" use "BaseMaxWorkers". I wouldn't raise the max workers without changing the production. Doing so would require more workers to get the same output.

DISCLAIMER:
Right now I have no idea how the game shares data in mulitiplayer. Unless all players are running the same exact mods the results will be unpredictable.
Reply
#18
I was looking for a way to change the game speed in multiplayer and found the line in _const.lua to be exact const.MPTimeFactorMod.

Lua: http://www.mediafire.com/download/6gc0ld...ED+mod.zip
Code:
OnMsg.ClassesPreprocess = function()
    const.MPTimeFactorMod = 100
    DebugPrint("SLOWMO MP")
end
It was set to 200, 100 is the normal singleplayer speed.
Works perfectly in multiplayer and only the host needs the mod.
Reply
#19
(30-05-2014, 02:55 AM)DarthPresidente Wrote:
(27-05-2014, 11:35 PM)KurtisB Wrote: EDIT @ Abrakadabra: I haven't gotten that far yet. In a preliminary search of the extracted files, the building data seems to be stored differently from Tropico 3/4. In Tropico 3/4 each building had its own .lua file, but in my look through it didn't seem that is the case in Tropico 5... but perhaps rather all building data is stored together within a few files rather than individually.

Building Template is where a lot of the individual building data code is located (Data\BuildingTemplate) It looks like modding building stats is going to be a little more difficult than in Tropico 4.

The first hurdle is that luadec butchers the file. I used Chunkspy to 'read' a file. Rather than try to decipher Chunkspy output on a building I suggest just printing the template to the log file using DebugPrint() That will give you an idea of how the information is stored. DataInstances.Template.BuildingName

Once you know how it's stored you can manipulate it. Just playing around and using some built in functions (DataInstances.Template:FindIndexOfClass(class) ) I was able to create a mod that doubled the housing capacity of all residential buildings:

Paste to DoubleHousing.lua in Tropico 5\CommonLua or download here
Code:
OnMsg.DataLoaded = function()
    DataInstances.BuildingTemplate.Apartment[DataInstances.BuildingTemplate.Apartment:FindIndexOfClass("Residence")]["BaseCapacity"] = 20
    DataInstances.BuildingTemplate.CountryHouse[DataInstances.BuildingTemplate.CountryHouse:FindIndexOfClass("Residence")]["BaseCapacity"] = 8
    DataInstances.BuildingTemplate.House[DataInstances.BuildingTemplate.House:FindIndexOfClass("Residence")]["BaseCapacity"] = 8
    DataInstances.BuildingTemplate.Mansion[DataInstances.BuildingTemplate.Mansion:FindIndexOfClass("Residence")]["BaseCapacity"] = 8
    DataInstances.BuildingTemplate.ModernApartment[DataInstances.BuildingTemplate.ModernApartment:FindIndexOfClass("Residence")]["BaseCapacity"] = 32
    DataInstances.BuildingTemplate.Shack[DataInstances.BuildingTemplate.Shack:FindIndexOfClass("Residence")]["BaseCapacity"] = 4
    DataInstances.BuildingTemplate.Tenement[DataInstances.BuildingTemplate.Tenement:FindIndexOfClass("Residence")]["BaseCapacity"] = 24
end

Changing a building's worker total is similar. Instead of "Residence" use "Workplace" and instead of "BaseCapacity" use "BaseMaxWorkers". I wouldn't raise the max workers without changing the production. Doing so would require more workers to get the same output.

DISCLAIMER:
Right now I have no idea how the game shares data in mulitiplayer. Unless all players are running the same exact mods the results will be unpredictable.


Thank you man. Great job SmileSmileSmile
Reply
#20
Its really annoying me just how slow it is to rotate the camera, and worse no option to increase the speed for it.

Anyone see a possible fix to increasing that camera rotate speed?
Reply
#21
(30-05-2014, 12:40 PM)xeon9 Wrote: Anyone see a possible fix to increasing that camera rotate speed?

This ought to make you plenty dizzy. Paste into FastRotate.lue in Tropico 5\CommonLua\
Code:
OnMsg.ClassesPreprocess = function()
    const.DefaultCameraRTS.RotateSpeed = 600
end
Reply
#22
(30-05-2014, 04:58 PM)DarthPresidente Wrote:
(30-05-2014, 12:40 PM)xeon9 Wrote: Its really annoying me just how slow it is to rotate the camera, and worse no option to increase the speed for it.

Anyone see a possible fix to increasing that camera rotate speed?

This ought to make you plenty dizzy. Paste into FastRotate.lue in Tropico 5\CommonLua\

Code:
OnMsg.ClassesPreprocess = function()
    const.DefaultCameraRTS.RotateSpeed = 600
end

I tried it, but seemingly has no effect, I assume you meant FastRotate.lua not lue? still no worky or even tried it at RotateSpeed = 6000....
Reply
#23
(30-05-2014, 02:55 AM)DarthPresidente Wrote: Changing a building's worker total is similar. Instead of "Residence" use "Workplace" and instead of "BaseCapacity" use "BaseMaxWorkers". I wouldn't raise the max workers without changing the production. Doing so would require more workers to get the same output.

I assume that changing the capacity of an Entertainment Building or High School would work in a similar way?
Reply
#24
(30-05-2014, 05:22 PM)xeon9 Wrote: I tried it, but seemingly has no effect, I assume you meant FastRotate.lua not lue? still no worky or even tried it at RotateSpeed = 6000....

Did it affect camera rotation with the keyboard?
Reply
#25
DarthPresidente, you are my hero! Smile

Base properties located in \Lua\Game\BuildingComponents:
-Workplace.lua
-Residence.lua
-Production.lua
-ProductionPower.lua
-ProductionRaw.lua
-Service.lua

Mod Service quality:

Code:
DataInstances.BuildingTemplate.Tavern[DataInstances.BuildingTemplate.Tavern:FindIndexOfClass("Service")]["BaseInherentServiceQuality"] = 70

Mod Job Qulity:

Code:
DataInstances.BuildingTemplate.PlantationCorn[DataInstances.BuildingTemplate.PlantationCorn:FindIndexOfClass("Workplace")]["BaseInherentJobQuality"] = 60

Mod House Quality:
Code:
DataInstances.BuildingTemplate.CountryHouse[DataInstances.BuildingTemplate.CountryHouse:FindIndexOfClass("Residence")]["BaseInherentHousingQuality"] = 70

Mod output Resource amount (I tested only for plantations, for factory you should probably use "Production")
Code:
DataInstances.BuildingTemplate.PlantationCorn[DataInstances.BuildingTemplate.PlantationCorn:FindIndexOfClass("ProductionRaw")]["BaseOutputAmount"] = 400

Mod max served for service buildings:
Code:
DataInstances.BuildingTemplate.Tavern[DataInstances.BuildingTemplate.Tavern:FindIndexOfClass("Service")]["BaseInherentMaxPopulationServiced"] = 90

P.S. You have to start a new game to see all changes.
Reply
#26
(30-05-2014, 11:04 PM)MissNet Wrote: DarthPresidente, you are my hero! Smile

Base properties located in \Lua\Game\BuildingComponents:
-Workplace.lua
-Residence.lua
-Production.lua
-ProductionPower.lua
-ProductionRaw.lua
-Service.lua

Mod Service quality:

[code]
DataInstances.BuildingTemplate................


Yeeeeaaaahhh, thank you man !!!
Reply
#27
Hey darth, can you go over how to go about extracting and decompiling the luas? Its' been a long time since tropico 4.
Reply
#28
(30-05-2014, 09:15 PM)TheFirstDeity Wrote:
(30-05-2014, 05:22 PM)xeon9 Wrote: I tried it, but seemingly has no effect, I assume you meant FastRotate.lua not lue? still no worky or even tried it at RotateSpeed = 6000....

Did it affect camera rotation with the keyboard?

you mean [alt]? nope
Reply
#29
(30-05-2014, 05:22 PM)xeon9 Wrote: I tried it, but seemingly has no effect, I assume you meant FastRotate.lua not lue? still no worky or even tried it at RotateSpeed = 6000....

Odd. It worked for me when I tried it. I wonder if it's some sort of bug because I didn't think the default rotation speed was horribly slow...



(31-05-2014, 12:50 AM)makotech222 Wrote: Hey darth, can you go over how to go about extracting and decompiling the luas? Its' been a long time since tropico 4.


I can share what I do. There might be an easier way though. I used the tools already created and available for Tropico 4. See the modding threads in the Tropico 4 forums for HPK archiver and LuaDec

First I use HPK archiver to extract the packs located in Tropico 5\Packs. Some crashed the archiver but I didn't worry about those. I didn't bother with the mesh, audio, or texture packs. I extracted them to a folder (e:\Modding\Tropico 5\<PackName>)

Next I dumped luadec into e:\Modding\Tropico 5\

Next I wrote a cheap little batch file, saved it in the above folder, and ran it.

Code:
for /r %%i in (*.lua) do @rename "%%i" "%%~ni.luac"
for /r %%i in (*.luac) do luadec.exe -o "%%~dpni.lua" "%%i"

Unfortunately luadec crashed on a couple of files but for the most part it works.
Reply
#30
(26-05-2014, 07:42 AM)DarthPresidente Wrote: If you place a mod file in CommonLua it appears to load.
DarthTest.lua
Code:
OnMsg.ClassesPreprocess = function()
    const.PopLimit = 5000
    DebugPrint("YOU FOOL!.  YOU JUST MADE A MOD\n")
end

OnMsg.NewMap = function()
    DebugPrint("New Map Loaded.  Poplimit=" .. const.PopLimit .. "!"\n)
end

The second DebugPrint have a newline after quote, breaking it

btw, fixed and it's working fine now
Reply




Users browsing this thread: 1 Guest(s)