Page 1 of 1

Entity Creation not detected

Posted: Wed Apr 27, 2016 4:22 pm
by TheSAguy
Hi,

I'm creating a unit in my projectile code, but that unit creation is not being detected in my control.lua.
I think the problem is with "defines.events.on_built_entity", should I use something else since it's created in the projectile?
Or is the problem with how I have my projectile setup.

Here is my Control code:

Code: Select all

script.on_event(defines.events.on_robot_built_entity, function(event) On_Built(event) end)
script.on_event(defines.events.on_built_entity, function(event) On_Built(event) end)
------------------------------
-- Detection code
function On_Built(event)
	--- unit cluster was created
	writeDebug("Cluster Unit Created") -- <-- Does not get to this step!
	if event.created_entity.name == "unit-cluster" then
		event.created_entity.damage(1, game.forces.neutral,physical)
	end	
end
Projectile Code Section:

Code: Select all

    type = "projectile",
    name = "Infected-Projectile-Worm",
    flags = {"not-on-map"},
    acceleration = 0.05,
    action =
    {
      type = "direct",
      action_delivery =
      {
        type = "instant",
        target_effects =
        {
		  {
			type = "create-entity",
			entity_name = "unit-cluster"
          },
		  {
            type = "damage",
            damage = {amount = 10*NE_Difficulty, type = "explosion"}
          },
        }
      }
    },
Thanks.

Re: Entity Creation not detected

Posted: Wed Apr 27, 2016 4:39 pm
by Adil
Indeed you should use something else. You should mark projectile prototype as trigger_created entity and catch event on_trigger_created_entity.
Here are samples of usage from Guntrain mod:
in prototype of attack
in control code

Re: Entity Creation not detected

Posted: Wed Apr 27, 2016 4:50 pm
by TheSAguy
Ah, got it,
Thanks.