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.
[Resolved] Who Killed the Biter...
[Resolved] Who Killed the Biter...
Last edited by TheSAguy on Wed Jul 12, 2017 5:05 pm, edited 3 times in total.
Re: Who Killed the Biter...
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.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!
Re: Who Killed the Biter...
Hey prg,prg wrote:on_entity_diedCalled 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.
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.
Last edited by TheSAguy on Sat Jul 08, 2017 8:31 pm, edited 1 time in total.
Re: Who Killed the Biter...
Yes. (Be sure to check for nil since it's optional.)
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!
- bobingabout
- Smart Inserter
- Posts: 7352
- Joined: Fri May 09, 2014 1:01 pm
- Contact:
Re: Who Killed the Biter...
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
Last edited by bobingabout on Tue Jul 11, 2017 8:00 am, edited 1 time in total.
Re: Who Killed the Biter...
Thanks so much for this, will save me hours of trail and error...