Page 1 of 1

Change owner/force of objects

Posted: Sat Dec 29, 2018 2:52 am
by squiddog
Hey all!

I run an OARC server and once in a while it would be nice for the admin to be able to change the Force ("Main Force", etc.) of all of objects of a given force. The use case is when someone is banned, the admin can go in and change the force of all the objects that the banned player placed, making clean up easier, or to give that base to another player on another force.

Anyone know how to do this in LUA? For example, if the person who was banned was named "imatroll", and he had his own force (in OARC it would be "imatroll"), then loop through all objects and if they are owned by "imatroll" or belong to his force, change it to "Main Force".

Thoughts?

Re: Change owner/force of objects

Posted: Sat Dec 29, 2018 9:18 am
by darkfrei
Not tested, but see https://lua-api.factorio.com/latest/LuaSurface.html
https://wiki.factorio.com/Console
https://lua-api.factorio.com/latest/Lua ... trol.force

Get surface and force of player

Code: Select all

/c
local my_force_name = "Main Force"
local player = game.players["imatroll"]
local surface = player.surface
local force_name = player.force.name
local entities = surface.find_entities_filtered{force=force_name}
for i, entity in pairs (entities) do
  entity.force = my_force_name
end

Re: Change owner/force of objects

Posted: Sat Dec 29, 2018 12:37 pm
by Klonan
There is also:

Code: Select all

game.merge_forces(source, destination)
https://lua-api.factorio.com/latest/Lua ... rge_forces

Re: Change owner/force of objects

Posted: Sun Jan 13, 2019 2:11 pm
by squiddog
Thanks all! Sorry it took so long for me to get back here to respond!