__ElectricPoweredBelts__/control.lua:28: attempt to index global 'util' (a nil value)
stack traceback:
__ElectricPoweredBelts__/control.lua:28: in main chunk
[/code]
Woops, you need to put "local util = require("util")" (probably at the top of your file)
Keysivi wrote: Thu Dec 26, 2024 8:04 am
In the case of the function 'get_trigger', the error seems to be the same, but now it points to 'insert_trigger'. As far as I understand, the problem is not only in the missing letter 'g'.
Failed to load the following mods: __ElectricPoweredBelts__/data-final-fixes.lua:33: attempt to call global 'insert_trigger' (a nil value)
stack traceback:
__ElectricPoweredBelts__/data-final-fixes.lua:33: in main chunk
Did you not copy the insert trigger function from my first suggestion?
Keysivi wrote: Thu Dec 26, 2024 8:04 am
I also took the liberty of replacing:
Now why did you do that? (It shouldn't make any difference in this particular case, but I think it's more logical the way it was)
Re: How to stop turrets from firing without electricity?
Posted: Thu Dec 26, 2024 8:15 am
by IsaacOscar
This is going to take ages, so I'll just give you a control.lua file that I've tested myself. Give me a few minutes
Re: How to stop turrets from firing without electricity?
Posted: Thu Dec 26, 2024 10:05 am
by IsaacOscar
Here you go, I've tested the flamethrower turret and it seems to work.
Change the line in data-final-fixes.lua that says 'if true' to 'if false' and reload Factorio to test the other trigger mechanism.
I also found that reducing the drain and buffer_capacity for the electric energy interfaces made testing easier.
And FYI, if you click the 'entities' button on the top-left of the map editor (the one that looks like an assembling machine), you can then select the hidden electric energy interface and see how much energy it's stored.
[*] I added local util = require("util") to the top of control.lua
I've made the following changes to data-final-fixes.lua:
I added the loop that starts with 'for _, v in pairs{data.raw["artillery-turret"]["artillery-turret"],' to data-final-fixes.lua, it was adapted from the code you posted at the start of this thread with the following changes:
I removed the energy_per_shot = "8kJ" as that does nothing
I removed the local x you where passing to data:extend as I don't know why it was there
I removed energy_usage as it seems redundant with drain
I made the loop operate specifically on the artillery and flamethrower turrets
I uncommented the insert_trigger function and put it before the first loop
I merged the two "for _, ammo in pairs{data.raw["ammo"]["artillery-shell"]," loops into one by using a single 'if'
And the following changes to control.lua:
Sadly I had to re-add the storage.entities table, as for some reason (despite it working in one of my mods), doing storage.power_enitities[event.entity] wasn't working. Now there is a 'local id = event.entity.unit_number' that takes the place of the old 'local pos' (unit_number is supposed to be globally unique, unless you create more than 4,294,967,295 entities...)
Where you do 'event.entity.type' I change it to 'event.entity.name' (event.entity.type is the name of the prototype's type, whereas event.entity.name is the prototype's name, e.g. the flamethrower turret has type 'fluid-turret' but name 'flamethrower-turret')
I've changed where it says "if event.entity.type == "artillery-shell"", to now say "if event.entity.name== "artillery-turret"" (artillery-shell is the ammo item! not the entity that fires the ammo).
To the line starting with 'script.on_event({defines.events.on_entity_died' I added defines.events.on_space_platform_pre_mined (to handle the case where the turret was deconstructed by a space platform, instead of being destroyed by damage, by a robot, or the player).
To the line starting with "if turret.disabled_by_script", I changed the 'if' to 'elseif', and added the following before it:
if not turret.valid then
interface.destroy()
storage.power_entities[id] = nil
storage.entities[id] = nil
I think this is only necessary if you destroy the turret in the editor, as I couldn't find an event to catch such destructions.
I also deleted lots of newlines before 'end', "}", and ")"s, because I prefer the way it looks.
If you don't understand any of the code, let me know and I can try and explain!
Re: How to stop turrets from firing without electricity?
Posted: Thu Dec 26, 2024 10:26 am
by IsaacOscar
Oh and I suggest changing the value of the refresh_rate to 1, and only increasing it if you get UPS drops.
Re: How to stop turrets from firing without electricity?
Posted: Thu Dec 26, 2024 1:04 pm
by Keysivi
Thank you very much! You have done a colossal job!
There is one small bug: If you install turrets through the editor, then an invisible entity "artillery-turret-power" or "flamethower-turret-power" is installed along with them, which remains in their place when the turrets are deleted.
This is not observed when installing turrets directly in the game.
I suspect that this is somehow related to:
5. To the line starting with "if turret.disabled_by_script", I changed the 'if' to 'elseif', and added the following before it:
I think I can do it myself. But if you want, you can offer a better option.
And the last thing - the data "artillery-turret-power" or "flamethower-turret-power" is not displayed when selecting "artillery-turret" or "flamethower-turret" - is there a way to fix this?
Re: How to stop turrets from firing without electricity?
Posted: Thu Dec 26, 2024 1:20 pm
by IsaacOscar
Keysivi wrote: Thu Dec 26, 2024 1:04 pm
There is one small bug: If you install turrets through the editor, then an invisible entity "artillery-turret-power" or "flamethower-turret-power" is installed along with them, which remains in their place when the turrets are deleted.
This is not observed when installing turrets directly in the game.
I suspect that this is somehow related to:
5. To the line starting with "if turret.disabled_by_script", I changed the 'if' to 'elseif', and added the following before it:
if not turret.valid then
interface.destroy()
storage.power_entities[id] = nil
storage.entities[id] = nil
I think this is only necessary if you destroy the turret in the editor, as I couldn't find an event to catch such destructions.
That code should destroy the power interface automatically (it will take at most refresh_rate ticks though). If it's not working though, my guess is you're using this on a save that had an old version of the mod, or things will be annoying. In which case I could write some code to automatically fix things if you want to keep using such saves.
I think I can do it myself. But if you want, you can offer a better option.
I'm not sure what you mean by 'two' tables, but if you want the electric energy interfaces to have different properties for the different turrets, change the 'for _, v in pairs{data.raw["artillery-turret"]["artillery-turret"], data.raw["fluid-turret"]["flamethrower-turret"]} do'
loop to
for v, energy in pairs{
[data.raw["artillery-turret"]["artillery-turret"]] = {
type = "electric",
buffer_capacity = "800kJ",
input_flow_limit = "100kW",
usage_priority = "primary-input",
drain = "10kW" },
[data.raw["fluid-turret"]["flamethrower-turret"]] = {
... }} do -- same as above, but you can use different values
And then below that where it had energy_source = { ... }, replace that with just energy_source = energy.
Keysivi wrote: Thu Dec 26, 2024 1:04 pm
And the last thing - the data "artillery-turret-power" or "flamethower-turret-power" is not displayed when selecting "artillery-turret" or "flamethower-turret" - is there a way to fix this?
Hmm, making it selectable would be possible, the problem is that it's got the same bounding box as the turret, and so hovering your mouse may show only the turret or only the power information, but with no way for the user to choose which one.
If you make the bounding box different, you could have it so you can hover over a different part, to see the interface.
The downside is that this new smaller part will need to be within range of a power pole, and not the entire turret.
Re: How to stop turrets from firing without electricity?
Posted: Thu Dec 26, 2024 1:43 pm
by IsaacOscar
Ok, to make the power selectable, try this. Immediately after the 'do' in the loop I mentioned in my previous commet, add
flags = {"not-on-map", "player-creation", "not-deconstructable","not-blueprintable", "not-upgradable"},
gui_mode = "all", -- I'm guessing this makes a GUI show up when you click it?
selection_priority = (v.selection_priority or 50) + 1, -- so hovering the cursor over the power interface and turret will select the interface
selection_box = template.selection_box, -- should be smaller than the turrets
drawing_box_vertical_extension = template.drawing_box_vertical_extension,
picture = template.picture,
This will make it visible and selectable, you can change all the stuff that uses 'template' to give it a different appearance and/or size.
Re: How to stop turrets from firing without electricity?
Posted: Thu Dec 26, 2024 5:23 pm
by Keysivi
Unfortunately, the idea is unsuccessful.
Firstly, it became impossible to interact with the turret itself, for example, to manually charge it. Plus, it is now impossible to view the data of the turret itself.
Secondly, an image of a battery was superimposed on top of the turrets.
Probably, if everything is so complicated, we will have to return to the first option.
Re: How to stop turrets from firing without electricity?
Posted: Thu Dec 26, 2024 6:28 pm
by IsaacOscar
Keysivi wrote: Thu Dec 26, 2024 5:23 pm
Firstly, it became impossible to interact with the turret itself, for example, to manually charge it. Plus, it is now impossible to view the data of the turret itself.
Re: How to stop turrets from firing without electricity?
Posted: Thu Dec 26, 2024 8:36 pm
by Keysivi
Overall, I think it's satisfactory. I still nerfed 'buffer_capacity' and 'input_flow_limit'. They were shooting for too long.
I created the mod and packed it into an archive. Since in fact - you did all the work - I indicated you as the creator of the mod.
As for posting the mod on the portal - it's up to you:
You can post it yourself on your own behalf. Or, I can do it myself.
Thank you very much for everything!
Re: How to stop turrets from firing without electricity?
Posted: Fri Dec 27, 2024 6:31 am
by IsaacOscar
Great work! I'll test it soon, in particular, I want to work out the difference between adding the flamethrower trigger to a 'Stream' TrigerDeliver, vs adding it to an 'instant' one.
Re: How to stop turrets from firing without electricity?
Posted: Sun Dec 29, 2024 12:33 pm
by Keysivi
IsaacOscar wrote: Fri Dec 27, 2024 6:31 am
Great work! I'll test it soon, in particular, I want to work out the difference between adding the flamethrower trigger to a 'Stream' TrigerDeliver, vs adding it to an 'instant' one.
Good day! So how is the mod? Have you tried it yet?
Re: How to stop turrets from firing without electricity?
IsaacOscar wrote: Fri Dec 27, 2024 6:31 am
Great work! I'll test it soon, in particular, I want to work out the difference between adding the flamethrower trigger to a 'Stream' TrigerDeliver, vs adding it to an 'instant' one.
Good day! So how is the mod? Have you tried it yet?
Sorry! Was lazy, busy, and sick. And then I was working on my own mods (I now have 9!)
I'll look at it tomorrow!
Re: How to stop turrets from firing without electricity?
Posted: Sun Dec 29, 2024 3:10 pm
by Keysivi
IsaacOscar wrote: Sun Dec 29, 2024 12:36 pm
Sorry! Was lazy, busy, and sick. And then I was working on my own mods (I now have 9!)
I'll look at it tomorrow!
Got it. Congratulations! Get well soon! Just wanted to remind you... What if you forgot?... After all, so much work has been done - it's a shame to abandon it....
I also have a small question about Unquality https://mods.factorio.com/mod/unquality . Am I right in understanding that the developers' idea with "Quality" is not the best. Because I paid attention to this mod, but I doubted - how relevant is it?
Thanks
Re: How to stop turrets from firing without electricity?
Posted: Mon Dec 30, 2024 8:14 am
by IsaacOscar
Ok, here you go.
I've made 3 major changes (other than correcting some bugs/potential-bugs):
The electric energy interface now has what I consider a nicer name and position, and it should work with all languages (not just English and Russian):
English
Screenshot 2024-12-30 173825.png (188.87 KiB) Viewed 672 times
Screenshot 2024-12-30 173846.png (168.78 KiB) Viewed 672 times
Russian
Screenshot 2024-12-30 174742.png (169.73 KiB) Viewed 672 times
Screenshot 2024-12-30 174759.png (160.03 KiB) Viewed 672 times
Flamethrower turrets now consume energy every time the stream hits an enemy, as opposed to everytime they start firing the stream. For example, this means if it starts firing but doesn't hit anything (e.g. the target moved away, or was killed by something else first), it won't consume any energy. But if the turret gets attacked by a swarm, and it sends a constant stream to kill them all, it will use a lot of energy, and not just one 'shot' worth (as it was doing before). If you have another idea for when it should use energy, let me know. (Personally, I think having it consume energy for every tick that it is shooting would be the best, but that will likely be performance heavy, and I'm not actually sure how to do that).
You can now load the mod on existing saves, any turrets that were built before the mod was activated will now require electricity, just as if they were built after loading the mod.
Here is the detailed list of changes I made to your code:
Changes
Changes to data-final-fixes.lua
you where setting an 'icon_mipmaps' field, but that doesn't exist, so I renamed it to 'icons'
you set resistances = resistances_immune, but resistances_immune didn't exist, so I had to define it
I deleted the 'local template' I asked you to add before, as you aren't using it anymore
The generated electric energy interfaces now have a localised_name, which gives the tooltip a human readable name (e.g. "Flamethrower turret (energy)"), this should work with other languages too.
The generated interface entity now have hidden=true, hiding them in various GUIs such as factroiopedia
The power interface selection_box is now at the bottom middle of the turret (so it aligns with the flashing light on the flamethrower turret, and the 'slots' on the artillery turret)
I removed the gui_mode = "all", as that gives you a GUI allowi9ng you to change the power propertied in game
I deleted the energy_production field, as you where just setting it to the default value
I deleted some old commented out code
I deleted the if 'true' thing that tried two different ways of modifying triggers, as inserting into existing triggers vs. creating new ones didn't make a difference.
The loop that added thhe turret-consume-energy trigger now adds it data.raw["stream"]["flamethrower-fire-stream"], instead of data.raw["fluid-turret"]["flamethrower-turret"].attack_parameters.ammo_type, this causes the trigger to execute everytime the flamethrower stream hits an enemey, as opposed to everytime the flamethrower starts shooting
Changes to control.lua
I deleted the call to script.on_configuration_changed, which was some old code I forgot to delete, and will break everything if it gets run!
I added a loop to script.on_init that should make the mod work with existing saves
I made energy_per_shot a table based on entity name, and changed the energy for flamethrower turrets from 8kJ to 1kJ
I moved some code to two functions 'initialise_turret' and 'destroy_turret', which are called twice (thus reducing duplicate code!)
In changelog.txt, I also changed you're "Info" category to "Features", as Info isn't a category recognised
In locale/ru/base.cfg, I deleted the entity-name category, as it's now automatically generated (see above). I also changed the "aai-vehicles-ironclad" key to "Electric_artillery_and_flamethrower_turrets"
I deleted locale/en, as it was redundant with info.json
As for publishing the mod, I'd prefer if you did it as it was you're idea, and I'm trying to only make mods for things I think should be in Factorio Vanilla.
And a completely unrelated thing I noticed when testing that it worked in Russian, the name of the space-age mod isn't translated to russian (although the description is), perhaps you can fix this on https://crowdin.com/project/factorio or post a bug report? (I don't know Russian so I don't know what it should say!).
Re: How to stop turrets from firing without electricity?
Posted: Mon Dec 30, 2024 8:27 am
by IsaacOscar
Keysivi wrote: Sun Dec 29, 2024 3:10 pm
I also have a small question about Unquality https://mods.factorio.com/mod/unquality . Am I right in understanding that the developers' idea with "Quality" is not the best. Because I paid attention to this mod, but I doubted - how relevant is it?
The reason I created the mod, is that I find space age already very complex, so I wanted to simplify it by simply removing the quality mechanic. However, the space age mod requires the Quality mod, and I want to keep the recycler (which is in the Quality mod).
I haven't actually properly played with quality though, but I've noticed people on the forums complaining about this:
Unintended extra click when setting up recipes due to the "Quality" dropdown. (11752)
Allow us to make rocket parts with quality components OR give as a method to lower quality of resources (120353, I've made a mod that fixes this!)
More Exciting Quality Effects (pls) (118785, basically there are many stats in the game that are not effected by quality, making many quality buildings practically useless)
Ability to craft lower quality with higher quality (116817, otherwise you need to build a whole smart recycling setup to really benefit from quality)
Output more fluid when using higher quality recipes (i.e. for Holmium Solution) (120829, for some reason you can use quality ingredients in a lot of fluid recipes, but it's a total waste)
Add more ways for quality to affect items (120398)
Tiles ignore quality (122146, putting quality tiles down destroys the quality!)
fish placed in water lose their quality (119548, you can't keep quality fish fresh in water, as they will lose their quality!)
(lots of people were also complaining about the names of the quality levels, even before it got released!, e.g. 108777, so I'm very surprised the developers didn't change them, maybe they just couldn't decide which set of names to change them to).
Hopefully 2.1 will come with some major changes to quality, and I might try it out then.
Re: How to stop turrets from firing without electricity?
Posted: Tue Dec 31, 2024 1:14 pm
by Keysivi
IsaacOscar wrote: Mon Dec 30, 2024 8:14 am
As for publishing the mod, I'd prefer if you did it as it was you're idea, and I'm trying to only make mods for things I think should be in Factorio Vanilla.
And a completely unrelated thing I noticed when testing that it worked in Russian, the name of the space-age mod isn't translated to russian (although the description is), perhaps you can fix this on https://crowdin.com/project/factorio or post a bug report? (I don't know Russian so I don't know what it should say!).
It's Clear. Fine. I Will Publish this mod. Thank you very much for your work and your Help!
I will make adjustments in translation .
Happy Holiday to You! I wish you all the best in the New Year!
Re: How to stop turrets from firing without electricity?
Posted: Wed Jan 08, 2025 6:46 pm
by Keysivi
Hello! I found one nasty bug. Unfortunately, the mod does not work in case of modified shells.
It seems that the mod does not define ammo_category = "artillery-shell", but name = "artillery-shell". And such shells as name = "napalm-artillery-shell", name = "atomic-artillery-shell", name = "poison-artillery-shell" - the mod ignores.
Can I register these shells through "or"? For example, like this:
for _, obj in pairs{data.raw["ammo"]["artillery-shell" or "napalm-artillery-shell" or "atomic-artillery-shell" or "poison-artillery-shell"].ammo_type, data.raw["stream"]["flamethrower-fire-stream"]} do
local action = get_trigger(obj, "action", {type = "direct"})
local action_delivery = get_trigger(action, "action_delivery", {type = "instant"})
insert_trigger(action_delivery, "source_effects", {type = "script", effect_id = "turret-consume-energy"}) end
Or will it be necessary to write a more detailed script there?
Re: How to stop turrets from firing without electricity?
Posted: Thu Jan 09, 2025 12:20 pm
by IsaacOscar
Keysivi wrote: Wed Jan 08, 2025 6:46 pm
Hello! I found one nasty bug. Unfortunately, the mod does not work in case of modified shells.
Not technically a 'bug' as I was not trying to make it work with mods.
Keysivi wrote: Wed Jan 08, 2025 6:46 pm
Can I register these shells through "or"? For example, like this:
for _, obj in pairs{data.raw["ammo"]["artillery-shell" or "napalm-artillery-shell" or "atomic-artillery-shell" or "poison-artillery-shell"].ammo_type, data.raw["stream"]["flamethrower-fire-stream"]} do
local action = get_trigger(obj, "action", {type = "direct"})
local action_delivery = get_trigger(action, "action_delivery", {type = "instant"})
insert_trigger(action_delivery, "source_effects", {type = "script", effect_id = "turret-consume-energy"}) end
local ammos = {data.raw["stream"]["flamethrower-fire-stream"]}
for _, a in pairs(data.raw["ammo"]) do
if a.ammo_category == "artillery-shell" then
table.insert(ammos, a.ammo_type) end end
for _, obj in pairs(ammos) do
-- the rest is the same code as before
local action = get_trigger(obj, "action", {type = "direct"})
local action_delivery = get_trigger(action, "action_delivery", {type = "instant"})
insert_trigger(action_delivery, "source_effects", {type = "script", effect_id = "turret-consume-energy"}) end
Re: How to stop turrets from firing without electricity?