Modify vehicle entities globally
-
- Burner Inserter
- Posts: 7
- Joined: Mon Oct 05, 2020 6:33 pm
- Contact:
Modify vehicle entities globally
Hello there.
I'd like to know if there is a command I can set to disable harvesting/mining cars, tanks and spidertrons (or any specific item ID changing the text I suppose) even while I'm not in it. Just disable it completely.
It's a small detail I'd like to play with. Even if it becomes an annoyance.
Sorry I couldn't find a specific section to talk about COMMAND codes.
Thank you.
I'd like to know if there is a command I can set to disable harvesting/mining cars, tanks and spidertrons (or any specific item ID changing the text I suppose) even while I'm not in it. Just disable it completely.
It's a small detail I'd like to play with. Even if it becomes an annoyance.
Sorry I couldn't find a specific section to talk about COMMAND codes.
Thank you.
Re: Modify vehicle entities globally
Code: Select all
/c for _,e in pairs(game.player.surface.find_entities_filtered{name={"car","tank","spidertron"}}) do e.minable=false end
-
- Burner Inserter
- Posts: 7
- Joined: Mon Oct 05, 2020 6:33 pm
- Contact:
Re: Modify vehicle entities globally
Thank you for your prompt response! Boskid.
Your command will be enough but just to be clear, there is no way to make this change constant without a Mod, right?
Your command will be enough but just to be clear, there is no way to make this change constant without a Mod, right?
Last edited by Squaresoft on Mon Oct 05, 2020 7:12 pm, edited 1 time in total.
Re: Modify vehicle entities globally
Squaresoft wrote: ↑Mon Oct 05, 2020 6:57 pm Thank you for your prompt response! Boskid.
Your will be enough but just to be clear, there is no way to make this change constant without a Mod, right?
Code: Select all
/c
function on_built_entity (entity)
if (entity.name == "car") or (entity.name == "tank") or (entity.name == "spidertron") then
entity.minable=false
end
end
script.on_event(defines.events.on_built_entity, function(event)
on_built_entity (event.created_entity)
end)
script.on_event(defines.events.on_robot_built_entity, function(event)
on_built_entity (event.created_entity)
end)
script.on_event(defines.events.script_raised_built, function(event)
on_built_entity (event.entity)
end)
Re: Modify vehicle entities globally
Using script.on_event in console command has multiple issues that i hate:
a/ After save-load hooks will stop working
b/ Because of the a, the replay will break
c/ Because of the a, multiplayer will desync (assuming other players would be able to join as they would most likely get the script mismatch when joining due to difference in registered hooks)
If you want to suggest broken things, at least know and tell what are the limitations.
It is possible if you change the control.lua of your save file: you can copy everything from darkfrei code (excluding the /c from the beginning) and append it to the control.lua and then repack the save file.Squaresoft wrote: ↑Mon Oct 05, 2020 6:57 pm Your will be enough but just to be clear, there is no way to make this change constant without a Mod, right?
-
- Burner Inserter
- Posts: 7
- Joined: Mon Oct 05, 2020 6:33 pm
- Contact:
Re: Modify vehicle entities globally
Oh multiplayer desync sounds like a real problem, yeah. Thank you for that info about scripts.
About repacking my save file, if I later host said save file online/LAN will it remain without problems for them too?.
About repacking my save file, if I later host said save file online/LAN will it remain without problems for them too?.
Re: Modify vehicle entities globally
If a script is in control.lua, it will be provided to all players and will survive the save-load so it will be persistent within that game.
Re: Modify vehicle entities globally
Open your save file, there is the level.dat
all scripts are here
all scripts are here
- Attachments
-
- Save004d.zip_Save004d_level.dat - Note2.png (45.17 KiB) Viewed 5109 times
Last edited by darkfrei on Mon Oct 05, 2020 7:32 pm, edited 1 time in total.
Re: Modify vehicle entities globally
This is the console/chat history. It is only stored for the purpose of showing you the console/chat if you reopen it with a tilde.
Re: Modify vehicle entities globally
You are right, I've tried to mine the old car
-
- Burner Inserter
- Posts: 7
- Joined: Mon Oct 05, 2020 6:33 pm
- Contact:
Re: Modify vehicle entities globally
Just tried editing my savefile and it works flawlessly! Everything I wanted, thank you people ♥!.
- eradicator
- Smart Inserter
- Posts: 5207
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Modify vehicle entities globally
In the spirit of "telling the drawbacks":boskid wrote: ↑Mon Oct 05, 2020 7:10 pmIt is possible if you change the control.lua of your save file: you can copy everything from darkfrei code (excluding the /c from the beginning) and append it to the control.lua and then repack the save file.Squaresoft wrote: ↑Mon Oct 05, 2020 6:57 pm Your will be enough but just to be clear, there is no way to make this change constant without a Mod, right?
That only works if the scenario doesn't already have handlers for the same events. If @OP is playing freeplay and it's the first random forum code snippet he copies it might be fine. But with custom scenarios or accumulating snippets it'll eventually break in non-obvious ways.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Re: Modify vehicle entities globally
It's possible to extend the event handler, not replace it.
my-handler.lua:
And add it to the save file to control.lua as
my-handler.lua:
Code: Select all
function on_built_entity (entity)
if (entity.name == "car") or (entity.name == "tank") or (entity.name == "spidertron") then
entity.minable=false
end
end
local my_handler = {
events =
{
[defines.events.on_built_entity] = on_built_entity,
[defines.events.on_robot_built_entity] = on_built_entity,
[defines.events.script_raised_built] = on_built_entity,
}
}
return my_handler
Code: Select all
local handler = require("event_handler") -- see Factorio/data/core/lualib/event_handler.lua
-- (here vanilla handlers)
handler.add_lib(require("my-handler"))