Hi
So, This is my very first mod in Factorio, so my question may be simple.
How can I allow - or not - an entity to be buiid, related to its position. Typically, I want my entity to be build only if i is near a rail (exactly like for the train stop)?
Thanks
Niko
Allow an item to be build depending on its position
Re: Allow an item to be build depending on its position
Generally I would listen to the on_built_entity event for your entity and if it is in a position where you don't want the player to build it then you remove it and give the player the item back. I'm not sure though how that would work with construction robots and ghost entities.
In your specific case where you only want to allow the exact same positions as train stops (or signals) you could make a dummy entity which is actually a train stop. The player will only be able to build it next to rails and after he placed it you can remove that entity and place your actual entity instead. The player will also get the possible position markers next to the rails.
In your specific case where you only want to allow the exact same positions as train stops (or signals) you could make a dummy entity which is actually a train stop. The player will only be able to build it next to rails and after he placed it you can remove that entity and place your actual entity instead. The player will also get the possible position markers next to the rails.
Re: Allow an item to be build depending on its position
You have to make sure you account for it by not giving the item back if entity-name = entity-ghostdaniel34 wrote:Generally I would listen to the on_built_entity event for your entity and if it is in a position where you don't want the player to build it then you remove it and give the player the item back. I'm not sure though how that would work with construction robots and ghost entities.
you also might have to check for entity.ghost_name to when placing
This is nice to know. I didn't even think about it when I needed something like this.In your specific case where you only want to allow the exact same positions as train stops (or signals) you could make a dummy entity which is actually a train stop. The player will only be able to build it next to rails and after he placed it you can remove that entity and place your actual entity instead. The player will also get the possible position markers next to the rails.
edit:fixed qoutebooboo
Last edited by Nexela on Sun Aug 14, 2016 11:48 am, edited 2 times in total.
Re: Allow an item to be build depending on its position
Hey
Thanks for the answer.
I understand the idea, however, I tried to put a "Place_result" for my train-stop. This place_result would be my final item. Unfortunately, it doesn't work.It says that my train-stop required a string order.
If I set the place result as train-stop, it works, so the problem comes definitely from it.
Any idea
Thanks for the answer.
I understand the idea, however, I tried to put a "Place_result" for my train-stop. This place_result would be my final item. Unfortunately, it doesn't work.It says that my train-stop required a string order.
If I set the place result as train-stop, it works, so the problem comes definitely from it.
Any idea
Re: Allow an item to be build depending on its position
You need to place the dummy entity then destroy it and create your "real" entity
entity/item = my-fake-trainstop
entity2 = what-I-Really-want
on_built_entity
if created_entity.name = "my-fake=trainstop" then
local pos, surface, force = created_entity.position, created_entity.surface, created_entity.force
created_entity.destroy()
surface.create_entity(name="what-I-really-want", fill in the rest here)
entity/item = my-fake-trainstop
entity2 = what-I-Really-want
on_built_entity
if created_entity.name = "my-fake=trainstop" then
local pos, surface, force = created_entity.position, created_entity.surface, created_entity.force
created_entity.destroy()
surface.create_entity(name="what-I-really-want", fill in the rest here)
Re: Allow an item to be build depending on its position
It works. Awsome!
Many thanks
Many thanks