[1.0.0] create_effect for entities appears not to react to 'script' type.

Place to get help with not working mods / modding interface.
Post Reply
Kingdud
Long Handed Inserter
Long Handed Inserter
Posts: 76
Joined: Sat Dec 16, 2017 3:23 am
Contact:

[1.0.0] create_effect for entities appears not to react to 'script' type.

Post by Kingdud »

Control.lua:

Code: Select all

local function do_dump(o)
   if type(o) == 'table' then
      local s = '{ '
      for k,v in pairs(o) do
         if type(k) ~= 'number' then k = '"'..k..'"' end
         s = s .. '['..k..'] = ' .. do_dump(v) .. ','
      end
      return s .. '} '
   else
      return tostring(o)
   end
end

function on_script_trigger_effect(event)
	local nuke_death_zone = 300

	if event.effect_id == "chart-nuke-area" then
		game.print("Asking game to generate for us")
	end
	if event.effect_id == "nuke-landed" then
		game.print("Nuke go boom")
	end
	log("Got trigger from " .. event.effect_id .. " " .. do_dump(event.target_position) .. " " .. do_dump(event.target_entity) .. " " .. do_dump(event.source_position) .. " " .. do_dump(event.source_entity))
end

script.on_event(defines.events.on_script_trigger_effect, on_script_trigger_effect)
data.lua:

Code: Select all

data.raw["artillery-flare"]["artillery-flare"].created_effect = 
	{
		type = "direct",
		action_delitery =
		{
			type = "instant",
			target_effects =
			{
				{
					type = "script",
					effect_id = "chart-nuke-area"
				}
			}
		}
	}
	
data:extend(
{
	{
		type = "artillery-projectile",
		name = "atomic-artillery-projectile",
		flags = {"not-on-map"},
		acceleration = 0,
		direction_only = true,
		reveal_map = true,
		map_color = {r=1, g=1, b=0},
		picture =
		{
			filename = "__AtomicArtillery__/graphics/entity/artillery-projectile/hr-atomic-shell.png",
			width = 64,
			height = 64,
			scale = 0.5,
		},
		shadow =
		{
			filename = "__base__/graphics/entity/artillery-projectile/hr-shell-shadow.png",
			width = 64,
			height = 64,
			scale = 0.5,
		},
		chart_picture =
		{
			filename = "__AtomicArtillery__/graphics/entity/artillery-projectile/atomic-artillery-shoot-map-visualization.png",
			flags = { "icon" },
			frame_count = 1,
			width = 64,
			height = 64,
			priority = "high",
			scale = 0.25,
		},
		--Damage rebalanced via https://nuclearsecrecy.com/nukemap/ to match an airbusrt 7kt warhead (roughly the energy yield from 30Kg of u235 in a little-boy style fission nuke) with all values (500m air burst)
		-- Note: Radius of 1340 too large, breaks map generation.
		-- 750 also too large.
		action =
		{
			type = "direct",
			action_delivery =
			{
			  type = "instant",
			  target_effects =
			  {
				{
					type = "script",
					effect_id = "nuke-landed"
				},
				--Damage effects			
				{
					--Technically kills everything at once, but we can't get a nice radar update without this.
					type = "nested-result",
					action = 
					{
						--Roughly the thermal pulse and moderate wind damage limit.
						radius = death_zone_size,
						type = "area",
						action_delivery = {
							type = "instant",
							target_effects = {
								{
									type = "damage",
									damage = { amount = 5000, type = "impact" },
								},
							},
						},
					},
				},
				{
				  --Fireball size
				  type = "destroy-cliffs",
				  radius = fireball_size,
				  explosion = "explosion"
				},
				--Sound effects
				{
				  type = "play-sound",
				  sound = sounds.nuclear_explosion(0.9),
				  play_on_target_position = false,
				  -- min_distance = 200,
				  max_distance = fireball_size*15,
				  -- volume_modifier = 1,
				  audible_distance_modifier = 3
				},
				{
				  type = "play-sound",
				  sound = sounds.nuclear_explosion_aftershock(0.4),
				  play_on_target_position = false,
				  -- min_distance = 200,
				  max_distance = fireball_size*45,
				  -- volume_modifier = 1,
				  audible_distance_modifier = 3
				},
				--Graphical effects
				{
				  type = "set-tile",
				  tile_name = "nuclear-ground",
				  radius = fireball_size,
				  apply_projection = true,
				  tile_collision_mask = { "water-tile" },
				},
				{
				  type = "create-entity",
				  entity_name = "nuke-explosion"
				},
				{
				  type = "camera-effect",
				  effect = "screen-burn",
				  duration = 60,
				  ease_in_duration = 5,
				  ease_out_duration = 60,
				  delay = 0,
				  strength = 6,
				  full_strength_max_distance = fireball_size*15,
				  max_distance = fireball_size*45
				},
				{
				  type = "create-entity",
				  entity_name = "huge-scorchmark",
				  check_buildability = true,
				},
				{
				  type = "invoke-tile-trigger",
				  repeat_count = 1,
				},
				{
				  type = "destroy-decoratives",
				  include_soft_decoratives = true, -- soft decoratives are decoratives with grows_through_rail_path = true
				  include_decals = true,
				  invoke_decorative_trigger = true,
				  decoratives_with_trigger_only = false, -- if true, destroys only decoratives that have trigger_effect set
				  radius = fireball_size -- large radius for demostrative purposes
				},
				-- {
				  -- type = "create-decorative",
				  -- decorative = "nuclear-ground-patch",
				  -- spawn_min_radius = 11.5,
				  -- spawn_max_radius = 12.5,
				  -- spawn_min = 30,
				  -- spawn_max = 40,
				  -- apply_projection = true,
				  -- spread_evenly = true
				-- },
			  }
			}
		},
		final_action =
		{
			type = "direct",
			action_delivery =
			{
				type = "instant",
				target_effects =
				{
					{
						type = "create-entity",
						entity_name = "small-scorchmark",
						check_buildability = true
					}
				}
			}
		},
		animation =
		{
			filename = "__base__/graphics/entity/bullet/bullet.png",
			frame_count = 1,
			width = 3,
			height = 50,
			priority = "high"
		}
	},})
Test case:
  1. Load artillery turret with nuclear shell (or put the same 'script, nuke-landed' text in a normal artillery shell to save needing the artwork from the AtomicArtillery mod I'm hacking on)
  2. Fire shell at distant target
  3. Observe console output
  4. Wait for shell to impact
  5. Observe console output
Expected Results:
  1. Load artillery turret with nuclear shell (or put the same 'script, nuke-landed' text in a normal artillery shell to save needing the artwork from the AtomicArtillery mod I'm hacking on)
  2. Fire shell at distant target
  3. "Asking game to generate for us" appears in console instantly once the arty strike is called down
  4. Wait for shell to impact
  5. "Nuke go boom" appears just as shell impacts ground
Actual Results:
  1. Load artillery turret with nuclear shell (or put the same 'script, nuke-landed' text in a normal artillery shell to save needing the artwork from the AtomicArtillery mod I'm hacking on)
  2. Fire shell at distant target
  3. No result from the created_effect modifications appears to be present.
  4. Wait for shell to impact
  5. "Nuke go boom" appears just as shell impacts ground
Either I don't understand something about how created_effect differs from the trigger definitions for artillery shells (it shouldn't?!) or there's some bug preventing script types from working with the created_effect property for some reason?

Rseding91
Factorio Staff
Factorio Staff
Posts: 13219
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [1.0.0] create_effect for entities appears not to react to 'script' type.

Post by Rseding91 »

Moving to modding help. You miss-spelled one of your variables.

I recommend going into the config file, un-commenting the line "check-unused-prototype-data=false" and setting it to true. It will tell you every time you write some data.lua definition that the game is not using (something you typoed).

In your example:
1.861 Warning PrototypeLoader.cpp:202: Value ROOT.artillery-flare.artillery-flare.created_effect.action_delitery was not used.
If you want to get ahold of me I'm almost always on Discord.

Post Reply

Return to “Modding help”