Page 1 of 1

Three problems

Posted: Thu Dec 05, 2024 7:09 am
by Keysivi
Hello! I'm working on reviving my fork and I have three problems that I can't solve. I've already racked my brains!....

Who can - please tell me!

1. How to make deepwater-explosive capsules damage the player and enemies?

2. How to make effect_id = "explosive-deepwater-explosion" only work on land?

3. How to make effect_id = "explosive-water-explosion" work with a slowdown of about 0.5 seconds?

Here is the full code of the main file:

Code: Select all

local explosion_animations = require("prototypes.deepwater-explosive.explosion-animations")
local sounds = require("__base__.prototypes.entity.sounds")

data:extend(
{
	{
		type = "projectile",
		name = "deepwater-explosive",
		flags = { "not-on-map" },
		acceleration = 0.005,	
		hidden = true,
		action = 
		{
			{
				type = "direct",
				action_delivery = 
				{
					type = "instant",				
					target_effects = 
					{
						{
							type = "set-tile",
							tile_name = "nuclear-ground",
							-- radius = 12,
							radius = 3,
							apply_projection = true,
							tile_collision_mask = { layers={water_tile=true} }
						},
						{
							type = "destroy-cliffs",
							-- radius = 9,
							radius = 1,	
							explosion_at_trigger = "explosion"
						},
						{
							type = "create-entity",
							entity_name = "mini-nuke-explosion"
						},
						{
							type = "camera-effect",
							duration = 60,
							ease_in_duration = 5,
							ease_out_duration = 60,
							delay = 0,
							strength = 6,
							full_strength_max_distance = 200,
							max_distance = 800
						},
						{
							type = "script",
							effect_id = "explosive-deepwater-explosion",
							delay = 1000,
						},
						{
							type = "invoke-tile-trigger",						
							repeat_count = 1

						},
						{
							type = "destroy-decoratives",					
							decoratives_with_trigger_only = false,
							from_render_layer = "decorative",
							include_decals = false,
							include_soft_decoratives = true,
							invoke_decorative_trigger = true,
							radius = 0.001,
							to_render_layer = "object"
						}
					}
				}
			},
			{
				type = "area",	
				radius = 2.0,	
				-- radius = 4,	
				action_delivery = 
				{
					type = "instant",				
					target_effects = 
					{
						{
							type = "damage",						
							damage = 
							{
								type = "explosion",							
								amount = 100
							}
						},
						{
							type = "create-entity",						
							entity_name = "explosion"
						}
					}
				}
			}
		},
		animation = 
		{
			animation_speed = 0.25,
			draw_as_glow = true,
			filename = "__modmashsplinterexplosivewater__/graphics/entity/explosive/explosives.png",
			frame_count = 16,
			height = 54,
			line_length = 8,
			priority = "high",
			scale = 0.5,
			shift = { 0.015625, 0.015625 },
			width = 48
		},
		light = 
		{
			intensity = 0.5,
			size = 4
		},
		shadow = 
		{
			animation_speed = 0.25,
			draw_as_shadow = true,
			filename = "__modmashsplinterexplosivewater__/graphics/entity/explosive/explosives-shadow.png",
			frame_count = 16,
			height = 40,
			line_length = 8,
			priority = "high",
			scale = 0.5,
			shift = { 0.0625, 0.1875 },
			width = 50
		}

	},
	{
		type = "capsule",
		name = "deepwater-explosive",		
		icon = "__modmashsplinterexplosivewater__/graphics/icons/deep-water-explosives.png",
		icon_size = 64,
		order = "d[acliff-explosive]",
		stack_size = 20,
		subgroup = "terrain",
		capsule_action = 
		{
			type = "throw",
			attack_parameters = 
			{
				type = "projectile",
				ammo_category = "grenade",
				activation_type = "throw",				
				cooldown = 30,
				projectile_creation_distance = 0.6,
				range = 15,
				ammo_type = 
				{
					category = "grenade",
					target_type = "position",
					action = 
					{
						{
							type = "direct",						
							action_delivery = 
							{
								type = "projectile",							
								projectile = "deepwater-explosive",
								starting_speed = 0.3
							}

						},
						{
							type = "direct",						
							action_delivery = 
							{
								type = "instant",							
								target_effects = 
								{										
									{
										type = "play-sound",
										sound = sounds.nuclear_explosion(0.9),
										play_on_target_position = false,
										-- min_distance = 200,
										max_distance = 100,
										-- 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 = 100,
										-- volume_modifier = 1,
										audible_distance_modifier = 3
									}
								}
							}
						}
					}
				}
			}
		}
	}	
})
Here is the full code of the function:

Code: Select all

require("prototypes.scripts.defines") 


local is_valid  = modmashsplinterexplosivemining.util.is_valid
local starts_with  = modmashsplinterexplosivemining.util.starts_with
local print  = modmashsplinterexplosivemining.util.print

local local_on_script_trigger_effect = function(event)
	if event.effect_id == "explosive-deepwater-explosion" and  event.target_position ~= nil then
		local surface = game.surfaces[event.surface_index]
		local entities = surface.find_entities_filtered{type={"resource"}, area = {{event.target_position.x-0.5, event.target_position.y-0.5}, {event.target_position.x+0.5, event.target_position.y+0.5}}}
		local entities = surface.find_entities_filtered{area = {{event.target_position.x-0.5, event.target_position.y-0.5}, {event.target_position.x+0.5, event.target_position.y+0.5}}}
		for k = 1, #entities do local ent = entities[k]
			if is_valid(ent) then
				ent.die()
			end
		end
		surface.set_tiles(			
			{
				{name="deepwater",position={x=event.target_position.x-0.5,y=event.target_position.y-0.5}},
				{name="deepwater",position={x=event.target_position.x-0.5,y=event.target_position.y}},
				{name="deepwater",position={x=event.target_position.x-0.5,y=event.target_position.y+0.5}},
				{name="deepwater",position={x=event.target_position.x,y=event.target_position.y-0.5}},
				{name="deepwater",position={x=event.target_position.x,y=event.target_position.y}},
				{name="deepwater",position={x=event.target_position.x,y=event.target_position.y+0.5}},
				{name="deepwater",position={x=event.target_position.x+0.5,y=event.target_position.y-0.5}},
				{name="deepwater",position={x=event.target_position.x+0.5,y=event.target_position.y}},
				{name="deepwater",position={x=event.target_position.x+0.5,y=event.target_position.y+0.5}}
			}	
		)
	end
end

script.on_event(defines.events.on_script_trigger_effect, local_on_script_trigger_effect)
Thanks!

Re: Three problems

Posted: Sun Dec 22, 2024 2:50 pm
by IsaacOscar
For problem #2, I think what your asking is for your set_tiles call to skip tiles that are not land?
If so here I suggest trying to replace your call to set_tiles with:

Code: Select all

local tiles = {}
for _, ground in pairs(find_tiles_filtered{
    area={
        {event.target_position.x-0.5, event.target_position.y-0.5}, 
        {event.target_position.x+0.5, event.target_position.y+0.5}},
    collision_mask="ground_tile"}) do
        table.insert(tiles, {name="deepwater", position=ground.position}) end
surface.set_tiles(tiles)
However, I don't actually know what 'collision_mask="ground_tile"}' will do as the documentation was practically useless, its just a guess. (perhaps collision_mask="water_tile" is the correct one to use?).

Also you have two local variables called entities, I don't know what the first is for, but I don't think the second one and the subsequent loop is necessary as https://lua-api.factorio.com/latest/cla ... #set_tiles lists a 'remove_coliding_entities' option to set_tiles, and that defaults to true.

Re: Three problems

Posted: Sun Dec 22, 2024 4:21 pm
by IsaacOscar
For problem #3, I don't know what 'explosive-water-explosion' is, as none of your code mentions it.
Also, what exactly do you mean by 'slowdown'? It starts 0.5 seconds later, or it takes 0.5 seconds longer tham normal to finish?

Re: Three problems

Posted: Mon Dec 23, 2024 6:53 am
by Keysivi
IsaacOscar wrote: Sun Dec 22, 2024 4:21 pm For problem #3, I don't know what 'explosive-water-explosion' is, as none of your code mentions it.
Also, what exactly do you mean by 'slowdown'? It starts 0.5 seconds later, or it takes 0.5 seconds longer tham normal to finish?
Sorry, I forgot to warn you. Originally, there were two identical forks. One added deep water, and the other added shallow water.

Plus, I think I got them mixed up. The problems should have been:
2. How to make effect_id = "explosive-water-explosion" only work on land?
3. How to make effect_id = "explosive-deepwater-explosion" work with a slowdown of about 0.5 seconds?

I apologize again!

I have now managed to combine both forks into one. The archive with the mod is attached to the comment.

Re: Three problems

Posted: Tue Dec 24, 2024 2:17 pm
by IsaacOscar
Ok, so you're explosive-water-explosion doesn't have a square area of affect, so my above solution to problem #2 won't work,
instead you'll have to replace your surface.set_tiles call with something like this:

Code: Select all

local tiles = {}
for _, pos in pairs{{x=event.target_position.x-2.0,y=event.target_position.y-0.5},
	{x=event.target_position.x-2.0,y=event.target_position.y},
	 -- and so on, with all the positions in your current set_tiles call
} do
	if surface.get_tile(pos).collides_with("ground-tile") then
		table.insert(tiles, {name="water-shallow", position=pos}) end end
surface.set_tiles(tiles)
I still haven't tested it, so the collision layer logic may be wrong.

Re: Three problems

Posted: Tue Dec 24, 2024 2:46 pm
by IsaacOscar
As for #3, you still didn't tell me what you meant by 'slowdown', if all you want is to delay it by 0.5 seconds, you need to do something like this:

Code: Select all

data:extend({{
	type = "projectile",
	name = "deepwater-explosive",
	... -- other fields for the projectile
	action = {{
		type = "direct",
		action_delivery = {
			type = "delayed",
			delayed_trigger = "explosive-deepwater-explosion-delay"}},
		... }}, { -- put other triggers here
	type = "delayed-active-trigger",
	name = "explosive-deepwater-explosion-delay",
	delay = 0.5*60, -- start the trigger in 0.5 seconds
	action = {
		type = "direct",
		action_delivery = {
			type = "instant",
			target_effects = {
				type = "script",
				effect_id = "explosive-deepwater-explosion" }}}}}
Now if you want the tiles to be changed gradually over 0.5 seconds, the simplest solution I can think of right now is little complicated, so I'll get back to you once I've thought about it more.

Re: Three problems

Posted: Wed Dec 25, 2024 1:09 pm
by Keysivi
Thanks for the answer! I'll try to integrate your suggestions into my mod.

Regarding point 3:

There's only one problem with the slowdown. The water tile appears at the same time as the explosion animation starts. So it visually seems like the water appeared before the explosion.... To avoid this, I need to make the water tile appear approximately in the middle of the explosion animation.

No additional effects are needed anymore.

Re: Three problems

Posted: Wed Dec 25, 2024 5:28 pm
by Keysivi
I did everything as you wrote. Everything works as required.

Thank you very much!