Ghost entities.

Place to get help with not working mods / modding interface.
someloser
Inserter
Inserter
Posts: 24
Joined: Mon May 26, 2014 5:37 am
Contact:

Ghost entities.

Post by someloser »

Hi all.

I'm working on a mod at the moment, does anyone know how to change the lifespan of an already created ghost (blueprint) entity?
DT-Extend - DyTech ores and other things.
User avatar
darius456
Fast Inserter
Fast Inserter
Posts: 222
Joined: Thu Jan 02, 2014 6:33 am
Contact:

Re: Ghost entities.

Post by darius456 »

If you want to change something related to ghost you can use command local ghostentity = game.findentitiesfiltered{area = {{-10, -10}, {10, 10}}, type="ghost"} (remember to change position) it will return entity. And then you can simply try to ghostentity.health = xxx or ghostentity.destroy(). I don't know if this will work with blueprint ghost, but with normal ghost after destroy it work.
Lenovo Y580 8GB Ram GF660m 128GB SSD W7
JamesOFarrell
Filter Inserter
Filter Inserter
Posts: 402
Joined: Fri May 23, 2014 8:54 am
Contact:

Re: Ghost entities.

Post by JamesOFarrell »

I tried to destroy a ghost as it was created in the onentitydied event handler and found that it would cause the game to crash. Just a heads up.
User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: Ghost entities.

Post by FreeER »

JamesOFarrell wrote:I tried to destroy a ghost as it was created in the onentitydied event handler and found that it would cause the game to crash.
...how did you even manage that? I tried testing this and my code doesn't even find a ghost in onentitydied? The only thing I could guess is that you tried destroying the event.entity, which is a reference to the original (dead) entity not the ghost, and attempting to destroy the already dead entity did crash Factorio to the desktop however...a bit of a "bug" there that I've never encountered before :lol:

However, if you store the original entity's position and then scan that area ontick (aka outside of onentitydied so the c++ code's had time to place it), it finds the ghost and destroys it with no problem.
here's my test code for the "working" version
test code
edit: as for the original question: I'm not certain that you can other than through the tech modifier "ghost-time-to-live", I think increasing that will increase the time of all existing ghosts...but I'm not 100% certain on that.
<I'm really not active any more so these may not be up to date>
~FreeER=Factorio Modding
- Factorio Wiki
- My Factorio Modding Guide
- Wiki Modding Guide
Feel free to pm me :)
Or drop into #factorio on irc.esper.net
JamesOFarrell
Filter Inserter
Filter Inserter
Posts: 402
Joined: Fri May 23, 2014 8:54 am
Contact:

Re: Ghost entities.

Post by JamesOFarrell »

This is what I had, it causes the game to crash. If you comment out the destroy line it will still log the ghost count so it is finding something.

Code: Select all

game.onevent(defines.events.onentitydied, function(event)
	if isKnownProxy(event.entity) then
		local ghosts =  game.findentitiesfiltered{area = {{event.entity.position.x, event.entity.position.y}, {event.entity.position.x, event.entity.position.y}}, "ghost"}
		for i, ghost in ipairs(ghosts) do
			debugLog("Ghost to destroy: " .. i)
			ghost.destroy()
		end

	end
end)
I also tried to destroy the entity before it could finish the event pipeline to see if that stopped the game from creating the ghost. it caused it to crash.. obviously :D

Thanks for the code. I come up with another solution but I still might use that to stop the ghosts from being created.
User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: Ghost entities.

Post by FreeER »

JamesOFarrell wrote:This is what I had, it causes the game to crash.
ah I see, you are essentially doing event.entity.destroy() :lol:
If you look at the findentitiesfiltered code I had (and what darius wrote) and what you have you'll notice that you simply pass "ghost" and not type="ghost", which makes "ghost" go into index 1 of the table you pass to findentitiesfiltered rather than the "type" index and so findentitiesfiltered simply ignores it and acts as if you had called findentities and returns everything at that position (which happens to be/include the entity that died, or event.entity. Try adding debugLog(event.entity.equals(ghost)) to your for loop and you'll see that it prints true (at least I'll assume that it would since I had to create the debugLog function myself (just a serpent.block proxy)...small hint, when you upload code snippets don't include function that aren't in the base game or include those functions as well, I've no idea what isKnownProxy should return so I could only strip it out).
JamesOFarrell
Filter Inserter
Filter Inserter
Posts: 402
Joined: Fri May 23, 2014 8:54 am
Contact:

Re: Ghost entities.

Post by JamesOFarrell »

Well, would you look at that, I do indeed. I used it correctly elsewhere in my code. I should have stripped that unlinked code I was just being lazy. debugLog() is not a standard function either but i figured it didn't really matter to much for the discussion. I'll be less lazy next time.
Post Reply

Return to “Modding help”