Help with making placeable enemies.[Solved]

Place to get help with not working mods / modding interface.
User avatar
AdventAngel
Burner Inserter
Burner Inserter
Posts: 13
Joined: Wed Apr 20, 2016 11:20 am
Contact:

Help with making placeable enemies.[Solved]

Post 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.)
Last edited by AdventAngel on Thu May 05, 2016 3:54 am, edited 1 time in total.
My Armor Module Mods: Solar Modules, Battery Modules, Shield Modules, Fusion Modules (Not completely Balanced as of yet. I'll be posting a (hopefully) more balanced version of each mod soon.)

My Other Mods: Flying Enemies
User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Help with making placeable enemies.

Post 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.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.
User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: Help with making placeable enemies.

Post 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)
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!
User avatar
AdventAngel
Burner Inserter
Burner Inserter
Posts: 13
Joined: Wed Apr 20, 2016 11:20 am
Contact:

Re: Help with making placeable enemies.

Post by AdventAngel »

Thanks so much! It works!
My Armor Module Mods: Solar Modules, Battery Modules, Shield Modules, Fusion Modules (Not completely Balanced as of yet. I'll be posting a (hopefully) more balanced version of each mod soon.)

My Other Mods: Flying Enemies
Post Reply

Return to “Modding help”