Entity Creation not detected

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

Entity Creation not detected

Post 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.
User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm
Contact:

Re: Entity Creation not detected

Post 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
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.
TheSAguy
Smart Inserter
Smart Inserter
Posts: 1455
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

Re: Entity Creation not detected

Post by TheSAguy »

Ah, got it,
Thanks.
Post Reply

Return to “Modding help”