I've been trying to figure out how to implement a mod where you can research shield upgrades. So, for example, shield mk 2 would go from 150 hit points to 165, 180, etc. I'd like this to be an infinite research, so after 10 researches with this example the shield would have 300 hit points.
As far as I can tell, there's no way to dynamically adjust an existing item. I wouldn't be able to alter energy-shield-mk2-equipment to have 165 hit points after a force researches shield upgrades 1. What I've been thinking about is creating new items energy-shield-mk2-u1-equipment, energy-shield-mk2-u2-equipment, etc. Then, the research completed event would trigger a search for all existing shields, which all get upgraded, and all existing assemblers, which have their production recipe changed to the new shield type.
A limitation to this approach is the problem of having the right equipment prototype available. I don't want it to be the case that to support 100 levels of the infinite research, 100 upgrades of shield have to be pre-loaded.
Is it possible to dynamically create a new item in the middle of a game?
Dynamically create new items
-
- Fast Inserter
- Posts: 187
- Joined: Fri Jan 05, 2018 5:18 pm
- Contact:
- Deadlock989
- Smart Inserter
- Posts: 2528
- Joined: Fri Nov 06, 2015 7:41 pm
Re: Dynamically create new items
No.AngledLuffa wrote: ↑Sat Feb 01, 2020 2:52 amIs it possible to dynamically create a new item in the middle of a game?
Re: Dynamically create new items
For your case, the reverse way of doing it would be to "increase shield effectiveness" which reduces the "damage" shields take. I don't know if you can modify the damage done from the event firing, but if on_entity_damaged triggers when a player has a shield, you can reduce the damage (if writable) or replenish (if not) the shield. Would need some tweaking when the damage overlaps shield and health.
I have mods! I guess!
Link
Link
-
- Fast Inserter
- Posts: 187
- Joined: Fri Jan 05, 2018 5:18 pm
- Contact:
Re: Dynamically create new items
Not unexpected. Looking at the way the damage bonuses are calculated, it looks like that is applied by default without considering the weapon stats. For example, copper ammunition in Natural Evolution has the damage defined asNo
{
type = "damage",
damage = { amount = 4 , type = "physical"}
},
There is no place to include the bullet bonus. Based on this example, I would assume there's no way to include a shield bonus on a shield's stats since no such bonus exists in the game yet. Does that sound correct?
That's a pretty interesting approach. It would also mean that the items don't need to be changed in any way, which would be much simpler.For your case, the reverse way of doing it would be to "increase shield effectiveness" which reduces the "damage" shields take.
Does the on_entity_damaged event allow for changing the damage received?
- Deadlock989
- Smart Inserter
- Posts: 2528
- Joined: Fri Nov 06, 2015 7:41 pm
Re: Dynamically create new items
Yes.AngledLuffa wrote: ↑Sat Feb 01, 2020 7:45 pmThere is no place to include the bullet bonus. Based on this example, I would assume there's no way to include a shield bonus on a shield's stats since no such bonus exists in the game yet. Does that sound correct?
Weapon bonuses apply to the whole ammo category and are set up in a technology bonus effect.
You could ask for a shield bonus effect in the modding interface requests subforum. I don't fancy your chances but on the other hand if you don't ask, you don't get. My hit rate for new features is about 20% at a wild guess.
Re: Dynamically create new items
Consider trying the following:
Create a global variable, call it for example, shield_effectiveness. Define that variable in data.lua prior to defining the entity or technology modifications. Give it an initial value of 150. Within the .lua code, specifically the entity that uses that shield, have the shield value equate to your newly created the variable, shield_effectiveness.
Next step, when you are doing the infinite research, increment that variable by 15 for each level of research. Now all you have to do is manipulate the value in the global variable shield_effectiveness.
If I understand how it should work correctly, after you create a new global variable and initialize it, it will stored within the save file, between gaming sessions.
Create a global variable, call it for example, shield_effectiveness. Define that variable in data.lua prior to defining the entity or technology modifications. Give it an initial value of 150. Within the .lua code, specifically the entity that uses that shield, have the shield value equate to your newly created the variable, shield_effectiveness.
Code: Select all
energy-shield-mk2-equipment.max_shield_value = shield_effectiveness,
If I understand how it should work correctly, after you create a new global variable and initialize it, it will stored within the save file, between gaming sessions.
- Deadlock989
- Smart Inserter
- Posts: 2528
- Joined: Fri Nov 06, 2015 7:41 pm
Re: Dynamically create new items
No.
Nothing in the Lua state is preserved from the data stage to the runtime stage.