Page 1 of 1

[0.9.2] getitemcount in onentitydied when ghosts are active

Posted: Wed Mar 05, 2014 7:43 pm
by drs9999
I have these lines of code in the onEntityDied-event:

Code: Select all

if (event.entity.type == "container") or (event.entity.type == "smart-container") then
		local wasteAmount = event.entity.getitemcount("toxic-waste")
		if wasteAmount > 0 then
			game.pollute(event.entity.position, wasteAmount * 10)
		end
end
It works fine and as intended as long as ghostbuildings are not researched. After that getitemcount will always return 0.

Any idea for a workaround or is it a bug?

Re: getitemcount + ghostbuildings

Posted: Wed Mar 05, 2014 8:11 pm
by ficolas
Not sure if it is a bug or not, it is weird, so I guess it is.
For a workarround you can store every container entity in a glob table with the onbuildentity event, land store its waste contents every tick, and if in a tick it is not valid, then pollute what it had in the previous tick.

Re: getitemcount + ghostbuildings

Posted: Mon Mar 10, 2014 5:14 pm
by kovarex
Yes, this is a bug, as the item is transferred to ghost and it's contents are cleared before the event is called, we should fix this, so I'm moving this to bug reports.

Re: [0.9.2] getitemcount in onentitydied when ghosts are act

Posted: Wed Mar 12, 2014 6:51 am
by slpwnd
This is now fixed for the 0.9.3.