Page 1 of 1
Change module stats in control.lua
Posted: Thu May 18, 2017 1:06 pm
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?
Re: Change module stats in control.lua
Posted: Thu May 18, 2017 1:36 pm
by Ranakastrasz
No, all of that stuff is loaded when you start the game, there is no way to change prototypes afterwards.
Re: Change module stats in control.lua
Posted: Thu May 18, 2017 8:03 pm
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.
Re: Change module stats in control.lua
Posted: Thu May 18, 2017 8:32 pm
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!
Re: Change module stats in control.lua
Posted: Thu May 18, 2017 9:09 pm
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.
Re: Change module stats in control.lua
Posted: Thu May 18, 2017 10:19 pm
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?
Re: Change module stats in control.lua
Posted: Thu May 18, 2017 11:40 pm
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)
Re: Change module stats in control.lua
Posted: Fri May 19, 2017 5:24 am
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.
Re: Change module stats in control.lua
Posted: Fri May 19, 2017 7:11 am
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?
Re: Change module stats in control.lua
Posted: Fri May 19, 2017 11:26 am
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.
Re: Change module stats in control.lua
Posted: Mon Aug 21, 2017 12:54 am
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)