Items in hand

Place to get help with not working mods / modding interface.
Post Reply
hreintke
Fast Inserter
Fast Inserter
Posts: 115
Joined: Mon Sep 04, 2017 6:52 pm
Contact:

Items in hand

Post by hreintke »

Hi,

I'd like to check the number of items of the player.

There is the call "get_inventory(defines.inventory.player_main)" that gives access and number of items.
But when the player selects items from that, taking it in hand that amount is removed from the inventory.

Is there a way to get the items "in hand" ?

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

Re: Items in hand

Post by darkfrei »

http://lua-api.factorio.com/latest/LuaC ... rsor_stack
http://lua-api.factorio.com/latest/LuaPlayer.html
http://lua-api.factorio.com/latest/LuaItemStack.html

Code: Select all

script.on_event(defines.events.on_player_cursor_stack_changed, function(event)
  if(player.cursor_stack.valid_for_read and player.cursor_stack.name == 'iron-ore') then
    local player = game.players[event.player_index]
    global.player_cursor_stack[event.player_index] = {name = player.cursor_stack.name, type - player.cursor_stack.type, count = player.cursor_stack.count, health = player.cursor_stack.health}
  end
end)

hreintke
Fast Inserter
Fast Inserter
Posts: 115
Joined: Mon Sep 04, 2017 6:52 pm
Contact:

Re: Items in hand

Post by hreintke »

Thanks,

Works great. I missed the "cursor" teminology

Post Reply

Return to “Modding help”