Disable placement of specific structures

Place to get help with not working mods / modding interface.
Tami
Fast Inserter
Fast Inserter
Posts: 157
Joined: Tue Nov 19, 2013 11:29 am
Contact:

Disable placement of specific structures

Post 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.
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5406
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Disable placement of specific structures

Post 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?
Tami
Fast Inserter
Fast Inserter
Posts: 157
Joined: Tue Nov 19, 2013 11:29 am
Contact:

Re: Disable placement of specific structures

Post 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.
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5406
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Disable placement of specific structures

Post 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)
Tami
Fast Inserter
Fast Inserter
Posts: 157
Joined: Tue Nov 19, 2013 11:29 am
Contact:

Re: Disable placement of specific structures

Post by Tami »

Thank you very much
jasonrubik
Manual Inserter
Manual Inserter
Posts: 2
Joined: Sat Aug 13, 2022 3:02 am
Contact:

Re: Disable placement of specific structures

Post 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
mrvn
Smart Inserter
Smart Inserter
Posts: 5969
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Disable placement of specific structures

Post 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
jasonrubik
Manual Inserter
Manual Inserter
Posts: 2
Joined: Sat Aug 13, 2022 3:02 am
Contact:

Re: Disable placement of specific structures

Post by jasonrubik »

mrvn wrote: Mon Apr 24, 2023 1:02 pm
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

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 ?
mrvn
Smart Inserter
Smart Inserter
Posts: 5969
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Disable placement of specific structures

Post by mrvn »

data.lua up to data-final-fixes.lua

This is changing the prototype. Nothing runtime and can't be changed at runtime.
hackamod
Long Handed Inserter
Long Handed Inserter
Posts: 62
Joined: Mon Apr 25, 2022 2:39 pm
Contact:

Re: Disable placement of specific structures

Post 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
mrvn
Smart Inserter
Smart Inserter
Posts: 5969
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Disable placement of specific structures

Post 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.
Post Reply

Return to “Modding help”