Page 1 of 1

[0.15] Dead character inventory

Posted: Mon May 01, 2017 12:52 pm
by mexmer
hello, anyone has ideas or knowledge about inventory access for dead characters?

seems following construct no longer works

Code: Select all

function on_player_died(event)
	local player = game.players[event.player_index]
	if player ~= nil then
			for i = 1, #storeinventories, 1 do
				local inventoryid = storeinventories[i]
				local playerinventory = player.get_inventory(inventoryid)
				for j = 1, #playerinventory, 1 do
						if playerinventory[j].valid and playerinventory[j].valid_for_read then
							local item = playerinventory[j]
							--[[ do something here ]]--
						end
				end
			end
	end
end
valid and valid_for_read always return false

mind this code was working in 0.14

Re: [0.15] Dead character inventory

Posted: Mon May 01, 2017 1:13 pm
by Nexela
You are aware that players drop corpses that contain their loot when they die?

Also you probably want on_player_pre_died or whatever it is called

Re: [0.15] Dead character inventory

Posted: Mon May 01, 2017 1:29 pm
by mexmer
Nexela wrote:You are aware that players drop corpses that contain their loot when they die?

Also you probably want on_player_pre_died or whatever it is called
you sure about that corpse? because my corpse lays on rails after i got hit by train, and there is nothing to pickup.

i will move what i need into on_pre_playerd_died, as you suggest, will think about better solution later.

thanks for then info :mrgreen:

Re: [0.15] Dead character inventory

Posted: Mon May 01, 2017 1:47 pm
by Nexela
Player corpses on tracks seem to be hard to open, (they are just chests) If you mine the track up you should be able to loot your corpse

Re: [0.15] Dead character inventory

Posted: Mon May 01, 2017 2:30 pm
by mexmer
Nexela wrote:Player corpses on tracks seem to be hard to open, (they are just chests) If you mine the track up you should be able to loot your corpse
btw. can't find any info about lootable corpse. when did that change?

if corpses were lootable, i will not need mod for storing inventory and craft queue in first place :D