Page 1 of 1

Help with making placeable enemies.[Solved]

Posted: Tue May 03, 2016 4:27 am
by AdventAngel
Hey, everyone~
I'm new to Factorio and after playing around with the data on the base mod to make other mods, I wanted to try and make something a little more complex for me.

I'm trying to make a craftable entity (such as a craftable spawner) that will act like a regular spawner. I've got almost everything set except everytime I place the entity they are set on the player force instead of the enemy and aren't attacked like normal spawners.
I think that changing the force of the entity to "enemy" instead of "player" is my problem but I don't know how to change the force of an entity the player places.

Is it possible to change the force of the placed entity (I think calling the "on_built_entity" function could do it?) and if so, what would be the code for it?
(I'm new to Lua so any help would be great! I've been using the Lua Scripting Reference on the wiki a lot for this.)

Re: Help with making placeable enemies.

Posted: Tue May 03, 2016 8:00 am
by bobingabout
Without looking things up, I can't give example code, but, you're thinking on the right lines there.

However, on_built_entity only looks for what is placed by a player, you also need to monitor on_robot_built_entity, or whatever it actually is, again, I'm not looking at any reference material here.

Re: Help with making placeable enemies.

Posted: Tue May 03, 2016 8:53 am
by prg

Code: Select all

script.on_event({defines.events.on_built_entity, defines.events.on_robot_built_entity}, function(event)
    local e = event.created_entity
    if e.name == "my-entity" then e.force = "enemy" end
end)

Re: Help with making placeable enemies.

Posted: Tue May 03, 2016 3:25 pm
by AdventAngel
Thanks so much! It works!