Code: Select all
-- we access inventory on the character, not the player since player has no inventory while being in remote view
if player.character then
-- player is alive
local inventory = player.character.get_main_inventory() -- get_inventory() can be used too
end
Code: Select all
if player.connected then
if player.physical_controller_type == defines.controllers.editor then
-- player.character is nil, can't access inventory of the player character
if player.controller_type == defines.controllers.remote then
-- can't access any inventory at all, neither character nor editor
else
-- player.get_main_inventory() is the editor inventory
-- player.get_inventory(defines.inventory.character_main) not even correct usage, it's not a character, returns editor inventory
end
end
else
-- the player is disconnected
if player.controller_type == defines.controllers.remote then
-- can't access any inventory
elseif player.controller_type == defines.controllers.character then
local inventory = player.get_main_inventory() -- works just fine
end
end