Change module stats in control.lua

Place to get help with not working mods / modding interface.
nagapito
Filter Inserter
Filter Inserter
Posts: 362
Joined: Fri Jul 29, 2016 12:18 am
Contact:

Change module stats in control.lua

Post by nagapito »

I just realized that prototypes seem to be readonly after the loading process...

I tried:

Code: Select all

game.item_prototypes["speed-module"].module_effects["speed"]["bonus"] = 0.5
but had no effect

Isnt there any way of changing the bonus of a module mid-game?
User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2179
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: Change module stats in control.lua

Post by Ranakastrasz »

No, all of that stuff is loaded when you start the game, there is no way to change prototypes afterwards.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
kikker450
Inserter
Inserter
Posts: 30
Joined: Fri May 05, 2017 9:07 am
Contact:

Re: Change module stats in control.lua

Post by kikker450 »

Load the entities you want to replace with in the midgame beforehand and write some script to replace every entity (with LuaEntity not LuaEntityPrototype) with that pre-written entity when you want to.
nagapito
Filter Inserter
Filter Inserter
Posts: 362
Joined: Fri Jul 29, 2016 12:18 am
Contact:

Re: Change module stats in control.lua

Post by nagapito »

kikker450 wrote:Load the entities you want to replace with in the midgame beforehand and write some script to replace every entity (with LuaEntity not LuaEntityPrototype) with that pre-written entity when you want to.
This is not a solution! This is a hack!
Sure, currently, you need a hack to do it. That is why I am asking for a solution!

And your proposed hack is even a very bad one, iterating and replacing thousands of items....Its something that should not even cross a dev mind!
User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2179
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: Change module stats in control.lua

Post by Ranakastrasz »

Thing is, when the game developers do not provide a method of doing something in the API, then you have to make a hack.

For instance, When I was developing my Modular Armor Revamp mod, there was no way to get the armor grid's total power or shield, so I looped through the grid and added it all up instead.
There was no way to create a burner generator, so I made a battery equipment named Burner Generator, with output only, and used a script to consume fuel from your inventory and add power to it every tick.

I learned modding from Warcraft 3, which while it's scripting language was pretty awesome, had a LOT of limitations, restrictions, and bugs that you had to work around/with.

I think the best one was the one where you could add an ability to a unit which increases hitpoints, change the ability level so it adds more hitpoints (Which was never implemented so doesn't work), and then remove it, resulting in the unit ending up with less hitpoints than it started with. this was never fixed, and thank god for that, as it lets you use this to via script change the max hitpoints of units, something otherwise impossible.


Also, the mod, Hardcorio, did something very similar to this, to allow for weapon damage to increase over time, by replacing guns with slightly stronger versions of themselves as you fought with them. I was kinda irritated to learn that he had to use that kind of hack to get it to work. And yes, he had 100x versions of every weapon, although the prototypes were made via script.

Don't say that "Devs should never do this" when you are not a dev, but a modder. Hacks are normal.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
nagapito
Filter Inserter
Filter Inserter
Posts: 362
Joined: Fri Jul 29, 2016 12:18 am
Contact:

Re: Change module stats in control.lua

Post by nagapito »

See, thats the thing, I am not a modder, I am actually a developer in real life.

Maybe is because of my professional experience that my skin just crawls thinking about the hack suggested for the problem in hands! If I was replacing a gun or a power grid, I would accept it, its a hugly hack but it works and does not impact the performance.

What you are suggesting is iterating trough thousands of entities in the game, check for his items and replace the modules for a better version. And this is something that would be mostly used for endgame research, where bases are huge with hundreds of thousands of entities and modules. That, kills a game and so, its an ugly hack that is not acceptable. What good does it have a mod that you cant use because it kills your game?
User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2179
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: Change module stats in control.lua

Post by Ranakastrasz »

True enough, but if you do not have access to API intended for a purpose, then you either need to use a workaround, ask the Developers, or else give up.



In this case however, it isn't as bad as you make it out to be. Sure, you search ten thousand entities, but it will only occur a handful of times. Better yet, it is completely possible to stagger the search over multiple ticks, looking at 10-100 entities per tick, whatever it takes to not lag. It won't be instant, but if it takes 5 seconds to finish, it's not a huge deal. Also, you can, I am pretty sure, detect modules being added to machines, so catch that and replace them immediately.



That said, I would HEAVILY prefer the developers implementing API for this mechanic instead of using a hack, because it is massively simplier to then implement, maintain, and it would both run faster and use up less memory (one entry per level of module? 100 levels? thats an extra 300 module prototypes)
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
Rseding91
Factorio Staff
Factorio Staff
Posts: 15590
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Change module stats in control.lua

Post by Rseding91 »

Every prototype is read-only - this is by design. If a prototype wasn't read-only then it would need to be included in the save file and would massively increase the save size, save time, and amount of RAM used.

Because the base game was never designed for the majority of the prototypes to change it was built around them not being changeable.
If you want to get ahold of me I'm almost always on Discord.
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2905
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Change module stats in control.lua

Post by darkfrei »

Rseding91 wrote:Every prototype is read-only - this is by design. If a prototype wasn't read-only then it would need to be included in the save file and would massively increase the save size, save time, and amount of RAM used.
Now the table raw is 3-5 MB in text format. Is it problem?
User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 2179
Joined: Thu Jun 12, 2014 3:05 am
Contact:

Re: Change module stats in control.lua

Post by Ranakastrasz »

In that case, I think that this hack wouldn't be to expensive to implement as a mod, but I would still prefer if the api was added instead.
My Mods:
Modular Armor Revamp - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Easy Refineries - V16
robertpaulson
Long Handed Inserter
Long Handed Inserter
Posts: 92
Joined: Sun Jun 18, 2017 2:21 pm
Contact:

Re: Change module stats in control.lua

Post by robertpaulson »

kikker450 wrote:Load the entities you want to replace with in the midgame beforehand and write some script to replace every entity (with LuaEntity not LuaEntityPrototype) with that pre-written entity when you want to.

Well, I am currently in need of this h4x, however I just need to modify one entity (projectile) and its acceleration value. Do I still need to replace all entities or just this projectile in question? Since this is a projectile, the change should only affect the very next one created (they last only few seconds and they expire so changing existing ones will not be necessary)
Post Reply

Return to “Modding help”