LuaEquipmentGrid Owner

Things that we aren't going to implement
Post Reply
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

LuaEquipmentGrid Owner

Post by Nexela »

Another one for grids

LuaEquipmentGrid Owner the entity/item_stack that this grid belongs too.

Useful during on_player_put_item so you know where the grid is

Rseding91
Factorio Staff
Factorio Staff
Posts: 13250
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: LuaEquipmentGrid Owner

Post by Rseding91 »

Equipment grids do not know who owns them so that information is not available to expose in the Lua API.
If you want to get ahold of me I'm almost always on Discord.

sparr
Smart Inserter
Smart Inserter
Posts: 1331
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: LuaEquipmentGrid Owner

Post by sparr »

Rseding91 wrote:Equipment grids do not know who owns them so that information is not available to expose in the Lua API.
So every time the event fires to tell me a player put a foo_equipment in a grid, I need to walk the tree down to game.players.get_inventory(defines.inventory.defines.inventory.player_armor)[1].grid.get_contents()["foo_equipment"] to see if they are now wearing one? And I need to keep track of that count in a global so that next time the event fires I can see if they added one vs put it in another grid that I don't care about?

Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: LuaEquipmentGrid Owner

Post by Nexela »

just player.character.grid works :)

sparr
Smart Inserter
Smart Inserter
Posts: 1331
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: LuaEquipmentGrid Owner

Post by sparr »

That does shorten it significantly. Removes a lot of my concerns about repeated lua lookup times. Thanks!

User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2919
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: LuaEquipmentGrid Owner

Post by Optera »

In case mods add grids to vehicles.
How would you access the locomotive or car the player put the equipment into?

Do we have to keep track of all equipment inside all vehicles and parse through that to find changes?

Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: LuaEquipmentGrid Owner

Post by Nexela »

Code: Select all

on_put_equipment(event)
  local player = games.players[event.player_index]
  if player.opened and player.opened.grid == event.grid then
     entity_putting_in = player.opened
  end
end

Post Reply

Return to “Won't implement”