Page 1 of 1

LuaEquipmentGrid Owner

Posted: Sun Apr 16, 2017 3:19 am
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

Re: LuaEquipmentGrid Owner

Posted: Sun Apr 16, 2017 10:08 am
by Rseding91
Equipment grids do not know who owns them so that information is not available to expose in the Lua API.

Re: LuaEquipmentGrid Owner

Posted: Tue May 02, 2017 4:37 pm
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?

Re: LuaEquipmentGrid Owner

Posted: Tue May 02, 2017 5:03 pm
by Nexela
just player.character.grid works :)

Re: LuaEquipmentGrid Owner

Posted: Tue May 02, 2017 5:05 pm
by sparr
That does shorten it significantly. Removes a lot of my concerns about repeated lua lookup times. Thanks!

Re: LuaEquipmentGrid Owner

Posted: Fri Aug 11, 2017 7:45 am
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?

Re: LuaEquipmentGrid Owner

Posted: Fri Aug 11, 2017 9:16 am
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