Page 1 of 1
[Resolved] Who Killed the Biter...
Posted: Sat Jul 08, 2017 5:02 pm
by TheSAguy
Hi,
I have some new enemies that have a new force I created (Vampire) and want to do something each time they kill the normal biters (Force.enemy)
How will I do the check to see who killed the biter?
I can only thing of doing it that when the normal biter dies, look in a small radius around it, and if it finds the new force, Vampire, assume it did the killing.
Is there another/better way of doing this?
Thanks.
Re: Who Killed the Biter...
Posted: Sat Jul 08, 2017 5:20 pm
by prg
on_entity_died
Called when an entity dies.
Contains
entity :: LuaEntity
cause :: LuaEntity (optional): The entity that did the killing if available.
force :: LuaForce (optional): The force that did the killing if any.
Re: Who Killed the Biter...
Posted: Sat Jul 08, 2017 5:30 pm
by TheSAguy
Thanks.
Re: Who Killed the Biter...
Posted: Sat Jul 08, 2017 7:43 pm
by TheSAguy
prg wrote:on_entity_died
Called when an entity dies.
Contains
entity :: LuaEntity
cause :: LuaEntity (optional): The entity that did the killing if available.
force :: LuaForce (optional): The force that did the killing if any.
Hey prg,
I have a follow-up question, so "on_entity_died" gives me the info on the killed unit.
What if I also want to do something with the unit that did the killing. Can I access the "cause" unit and do something with it?
Thanks.
Re: Who Killed the Biter...
Posted: Sat Jul 08, 2017 8:15 pm
by prg
Yes. (Be sure to check for nil since it's optional.)
Re: Who Killed the Biter...
Posted: Mon Jul 10, 2017 9:39 am
by bobingabout
Assuming you're using this example: (The important part being function(event))
Code: Select all
script.on_event(defines.events.on_entity_died, function(event)
local recently_deceased_entity = event.entity
local time_of_death = event.tick
for _, player in pairs(game.players) do
player.print("Let it be known that " .. recently_deceased_entity.name ..
" died a tragic death on tick " .. time_of_death)
end
end)
Code: Select all
if event.cause then
--do stuff to event.cause here
end
Re: Who Killed the Biter...
Posted: Mon Jul 10, 2017 8:53 pm
by TheSAguy
Thanks so much for this, will save me hours of trail and error...