Page 1 of 1

Question about turrets and their weapon behaviour

Posted: Wed May 08, 2019 7:13 pm
by MrFactorio
Hello guys,

I downloaded a mod that made the SMG and pistol an aiming weapon with real projectiles coming out of the guns if normal bullets were used.
I managed to expand this behaviour to all kind of bullets for the named weapons and the vehicles.

But I am not able to do this for the turrets so far. For the hand and vehicle weapons I could just replace their ammo_type with a new ammo that behaves a bit like a single shotgun bullet.
But how can I do this for the gun turrets? They already use the same bullets and should behave like the weapons but they dont. Is there something I dont know about gun turrets? Is there some kind of "instahit" flag that overwrites the ammo behavior?

Can anyone help me out please?

Re: Question about turrets and their weapon behaviour

Posted: Thu May 09, 2019 7:47 pm
by Deadlock989
I've done this in my mod and it works just fine. You will have to tweak the turret's attack parameters a bit to get the animations right but it works straight away if you updated the ammo correctly or created new ammo types from scratch. You will also have to change the "force condition" setting of the projectiles if you don't want your own turrets to wreck your own base.

Without seeing your code it's hard to suggest what's wrong.

Re: Question about turrets and their weapon behaviour

Posted: Thu May 09, 2019 8:31 pm
by MrFactorio
The code is very simple. For the base bullets this is what the original mod does:

Code: Select all

local am_type = {
   category = "bullet",
   target_type = "direction",
   action = {
      {
		 type = "direct",
		 action_delivery = {
			{
			   type = "projectile",
			   projectile = 'shotgun-pellet',
			   starting_speed = 1.1,
			   direction_deviation = 0.1,
			   range_deviation = 0.3,
			   max_range = 30,
			   source_effects = {
			  {
				 type = "create-explosion",
				 entity_name = "explosion-gunshot"
			  }
			   },
			   target_effects = {
			  {
				 type = "damage",
				 damage = {
				amount = 5,
				type = "physical"
				 }
			  }
			   }
			}
		}
      }
   }
}
data.raw.ammo['firearm-magazine'].ammo_type = am_type
And thats it. This will make all weapons of vehicles and the player to have real projectiles the player can aim. But the turrets are not effected by this and I dont know why.

Re: Question about turrets and their weapon behaviour

Posted: Thu May 09, 2019 9:15 pm
by Deadlock989
Hmm. That looks different to how I've done it. I create a series of new projectiles and the damage actions are defined in each projectile, not in the ammo type itself. The ammo type only has the visual gunshot "explosion" (the muzzle flash) and the projectile defined in its action deliveries. It could be that in your case, the turret is just applying the damage directly because it's defined in the ammo to be applied directly. If it is defined in the projectile instead then it is only applied when the projectile collides with something.

Creating an ammo type for an ammo item:

Code: Select all

function get_bullet_ammo_type(base_damage, colour)
	local name = colour.."-"..base_damage
    return {
        action = {
            {
                action_delivery = {
                    source_effects = {
                        {
                            entity_name = "explosion-gunshot",
                            type = "create-explosion"
                        }
                    },
                    type = "instant"
                },
                type = "direct"
            },
            {
                action_delivery = {
                    direction_deviation = 0.05,
                    max_range = DIR.ammo.range.magazine,
                    projectile = name,
                    range_deviation = 0,
                    starting_speed = DIR.projectile_speed.bullet,
                    type = "projectile"
                },
                repeat_count = 1,
                type = "direct"
            }
        },
        category = "bullet",
        target_type = "entity"
    }
end
Creating a new projectile for that ammo type:

Code: Select all

function create_projectile(base_damage, colour)
	local name = colour.."-"..base_damage
	if not data.raw.projectile[name] then
		data:extend({{
			name = name,
			type = "projectile",
			acceleration = 0,
			action = {
				action_delivery = {
					target_effects = {
						damage = {
							amount = base_damage,
							type = "physical"
						},
						type = "damage"
					},
					type = "instant"
				},
				type = "direct"
			},
			animation = {
				filename = DIR.projectiles_path.."/bullet.png",
				tint = DIR.bullet_colours[colour],
				frame_count = 1,
				height = 50,
				priority = "high",
				width = 3
			},
			collision_box = {{-0.05,-0.25},{0.05,0.25}},
			direction_only = true,
			flags = {"not-on-map"},
			force_condition = "not-same",
		}})
	end
end