Page 1 of 1
Convert to enemy entity tool
Posted: Fri Aug 19, 2016 8:41 am
by aubergine18
For testing mods, it would be really useful if there was a way to click on one of my own entities on the map, maybe whilst holding a specific tool (item), to turn it in to an enemy entity (creating enemy player/force in the process if required).
When the entity is clicked, the mod deletes it and replaces it with the same entity but owned by enemy player. (Or just change the player without deleting it, if that's possible).
With the same tool in hand, if I click an enemy entity it then turns it back in to my entity.
Used in conjunction with CreativeMode, this would make testing mods a load faster. And it would also be a good example mod showing how to create custom 'tools' which can be used to have effect on buildings.
Re: Convert to enemy entity tool
Posted: Sat Aug 20, 2016 9:28 am
by prg
data.lua
Code: Select all
data:extend({
{
type = "selection-tool",
name = "forcechanger",
icon = "__base__/graphics/icons/grass.png",
stack_size = 1,
flags = {"goes-to-quickbar"},
selection_color = { r = 0, g = 1, b = 1 },
alt_selection_color = { r = 0, g = 1, b = 1 },
selection_mode = {"buildable-type"},
alt_selection_mode = {"buildable-type"},
selection_cursor_box_type = "copy",
alt_selection_cursor_box_type = "copy",
},
})
control.lua
Code: Select all
script.on_event(defines.events.on_player_selected_area, function(event)
if event.item ~= "forcechanger" then return end
for _, entity in pairs(event.entities) do
if entity.force == game.forces.enemy then entity.force = "player"
elseif entity.force == game.forces.player then entity.force = "enemy"
end
end
end)
Just a proof of concept, would still need a technology and recipe to become a proper mod. Also could use a GUI to select which force to convert into which other force, currently enemy <-> player is just hardcoded.
Re: Convert to enemy entity tool
Posted: Sat Aug 27, 2016 11:25 pm
by aubergine18
Sorry I only just saw your reply - I'll give it a try, many thanks!!
Re: Convert to enemy entity tool
Posted: Sat Aug 27, 2016 11:44 pm
by Nexela
I am also working on a mod that will have this ability, Among many other things

Re: Convert to enemy entity tool
Posted: Sun Aug 28, 2016 2:23 am
by Supercheese
Why not just hover over the entity with the cursor and execute the command:
Code: Select all
/c game.player.selected.force = "enemy"
?
Re: Convert to enemy entity tool
Posted: Sun Aug 28, 2016 10:09 am
by prg
Supercheese wrote:Why not just hover over the entity with the cursor and execute the command:
Code: Select all
/c game.player.selected.force = "enemy"
?
Less wear and tear on the keyboard if you want to change the owner of a whole base as you can just drag a rectangle around it.