Change owner/force of objects

Place to get help with not working mods / modding interface.
Post Reply
squiddog
Inserter
Inserter
Posts: 44
Joined: Sat Mar 10, 2018 12:25 am
Contact:

Change owner/force of objects

Post 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?

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2904
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Change owner/force of objects

Post 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

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5151
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Change owner/force of objects

Post by Klonan »

There is also:

Code: Select all

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

squiddog
Inserter
Inserter
Posts: 44
Joined: Sat Mar 10, 2018 12:25 am
Contact:

Re: Change owner/force of objects

Post by squiddog »

Thanks all! Sorry it took so long for me to get back here to respond!

Post Reply

Return to “Modding help”