[Resolved] Who Killed the Biter...

Place to get help with not working mods / modding interface.
Post Reply
TheSAguy
Smart Inserter
Smart Inserter
Posts: 1449
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

[Resolved] Who Killed the Biter...

Post 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.
Last edited by TheSAguy on Wed Jul 12, 2017 5:05 pm, edited 3 times in total.

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: Who Killed the Biter...

Post 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.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

TheSAguy
Smart Inserter
Smart Inserter
Posts: 1449
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

Re: Who Killed the Biter...

Post by TheSAguy »

Thanks.

TheSAguy
Smart Inserter
Smart Inserter
Posts: 1449
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

Re: Who Killed the Biter...

Post 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.
Last edited by TheSAguy on Sat Jul 08, 2017 8:31 pm, edited 1 time in total.

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: Who Killed the Biter...

Post by prg »

Yes. (Be sure to check for nil since it's optional.)
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Who Killed the Biter...

Post 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
Last edited by bobingabout on Tue Jul 11, 2017 8:00 am, edited 1 time in total.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

TheSAguy
Smart Inserter
Smart Inserter
Posts: 1449
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

Re: Who Killed the Biter...

Post by TheSAguy »

Thanks so much for this, will save me hours of trail and error... :D

Post Reply

Return to “Modding help”