Page 1 of 1
Disable placement of specific structures
Posted: Tue Oct 24, 2017 3:37 pm
by Tami
Is it possible to disable placement of structures like laser towers without preventing laser tower tech or turrets?
Same goes for solar panels.
Re: Disable placement of specific structures
Posted: Tue Oct 24, 2017 4:19 pm
by Klonan
Tami wrote:Is it possible to disable placement of structures like laser towers without preventing laser tower tech or turrets?
Same goes for solar panels.
During prototype/data stage or during runtime?
Re: Disable placement of specific structures
Posted: Tue Oct 24, 2017 4:41 pm
by Tami
Example with /permissions settings.
Would be great to disable placement of certain structures.
If not possible with permissions (as it is yet), maybe a simble lua command script could help too if there is one. Keep in mind that the laser turrets needs to be build for certain receipe, but not be placed, same for solar for certain receipes.
Re: Disable placement of specific structures
Posted: Tue Oct 24, 2017 5:44 pm
by Klonan
Tami wrote:Example with /permissions settings.
Would be great to disable placement of certain structures.
If not possible with permissions (as it is yet), maybe a simble lua command script could help too if there is one. Keep in mind that the laser turrets needs to be build for certain receipe, but not be placed, same for solar for certain receipes.
You will have to listen to on_built_event, something like this:
Code: Select all
script.on_event(defines.events.on_built_entity, function(event)
local entity = event.created_entity
local player = game.players[event.player_index]
if entity.name == "laser-turret" then
entity.destroy()
player.insert{name = "laser-turret", count = 1}
player.print("Placing laser turrets is not allowed")
return
end
if entity.name == "entity-ghost" and entity.ghost_name == "laser-turret" then
entity.destroy()
player.print("Don't build ghosts or blueprints of laser turrets either.")
return
end
end)
Re: Disable placement of specific structures
Posted: Tue Oct 24, 2017 7:09 pm
by Tami
Thank you very much
Re: Disable placement of specific structures
Posted: Sun Apr 23, 2023 5:01 pm
by jasonrubik
Klonan wrote: Tue Oct 24, 2017 5:44 pm
Tami wrote:Example with /permissions settings.
Would be great to disable placement of certain structures.
If not possible with permissions (as it is yet), maybe a simble lua command script could help too if there is one. Keep in mind that the laser turrets needs to be build for certain receipe, but not be placed, same for solar for certain receipes.
You will have to listen to on_built_event, something like this:
Code: Select all
script.on_event(defines.events.on_built_entity, function(event)
local entity = event.created_entity
local player = game.players[event.player_index]
if entity.name == "laser-turret" then
entity.destroy()
player.insert{name = "laser-turret", count = 1}
player.print("Placing laser turrets is not allowed")
return
end
if entity.name == "entity-ghost" and entity.ghost_name == "laser-turret" then
entity.destroy()
player.print("Don't build ghosts or blueprints of laser turrets either.")
return
end
end)
From where do we listen ? Is this accomplished with your syntax contained within Control.lua in the Entities folder, or somewhere else ?
I'm new to modding, and trying to remove the module slots from assembling-machine-2 and add pipe/fluid input to the assembling-machine (grey one).
https://mods.factorio.com/mod/TierOnePr ... 6deb3409ff
EDIT !! - I meant to say that I am trying to prevent the placement of solar panels and accumulators as structures... since that's related to this thread here/// but I am also trying to change the assembling machines too !!
p.s. perhaps I will post this in a new forum thread, but I did want to reply here since it seems like an open question .
thanks
Jason
Re: Disable placement of specific structures
Posted: Mon Apr 24, 2023 1:02 pm
by mrvn
Klonan wrote: Tue Oct 24, 2017 5:44 pm
Tami wrote:Example with /permissions settings.
Would be great to disable placement of certain structures.
If not possible with permissions (as it is yet), maybe a simble lua command script could help too if there is one. Keep in mind that the laser turrets needs to be build for certain receipe, but not be placed, same for solar for certain receipes.
You will have to listen to on_built_event, something like this:
Code: Select all
script.on_event(defines.events.on_built_entity, function(event)
local entity = event.created_entity
local player = game.players[event.player_index]
if entity.name == "laser-turret" then
entity.destroy()
player.insert{name = "laser-turret", count = 1}
player.print("Placing laser turrets is not allowed")
return
end
if entity.name == "entity-ghost" and entity.ghost_name == "laser-turret" then
entity.destroy()
player.print("Don't build ghosts or blueprints of laser turrets either.")
return
end
end)
Urgs, entity.destroy() will destroy the entity so the entity is lost. It should be returned to the player.
I think a better solution to preventing placing entites, at least when you want to do it for all players for the whole game, is to simply remove the place_result property from the item:
https://wiki.factorio.com/Prototype/Item#place_result
Re: Disable placement of specific structures
Posted: Tue Apr 25, 2023 1:03 am
by jasonrubik
Yea that sounds good, as I didn't even look into the result of this code. I have been too preoccupied with the original issue. Where do we put this code ?
In other words, which folder location, and which filename ?
Control.lua ? Entities.lua ? in the root directory ? in the scripts folder ?
Re: Disable placement of specific structures
Posted: Tue Apr 25, 2023 8:19 am
by mrvn
data.lua up to data-final-fixes.lua
This is changing the prototype. Nothing runtime and can't be changed at runtime.
Re: Disable placement of specific structures
Posted: Wed Apr 26, 2023 9:31 pm
by hackamod
I have more questions than answers but:
If you want to prevent the placement in order to maintain status for an achievement, then it is probably too late to catch it after it has been placed and remove it. I am not sure, but that would be my guess.
Again I am not sure, entity flags include "placeable-player" which seems to mean the player is allowed or able to place the entity... you can probably remove that flag or something
I do not know if that will prevent bots from placing one on a ghosted blueprint either but would like to find out
Re: Disable placement of specific structures
Posted: Wed Apr 26, 2023 11:59 pm
by mrvn
hackamod wrote: Wed Apr 26, 2023 9:31 pm
I have more questions than answers but:
If you want to prevent the placement in order to maintain status for an achievement, then it is probably too late to catch it after it has been placed and remove it. I am not sure, but that would be my guess.
Again I am not sure, entity flags include "placeable-player" which seems to mean the player is allowed or able to place the entity... you can probably remove that flag or something
I do not know if that will prevent bots from placing one on a ghosted blueprint either but would like to find out
Easy enough to test yourself or read up on the definition of the flag.