Page 1 of 1

Add a damage parameter for projectiles to surface.create_entity

Posted: Tue Apr 22, 2025 8:58 pm
by safthelamb@gmail.com
I am spawning projectiles at runtime with an `on_script_trigger_effect`, but they are not inheriting the damage modifiers from projectile damage technologies. I am setting the source and cause entities when available, but the projectiles still only apply the base projectile's damage. I spoke with Rseding91 and he mentioned an API call for setting the damage modifier from script when creating the projectile is what's currently missing. The code I'm using to spawn the projectile is:

Code: Select all

    local projectile = surface.create_entity{
      name = "smart-rounds-magazine",
      source = event.source_entity,
      position = event.source_position,
      force = event.source_entity and event.source_entity.force,
      target = event.target_entity or event.target_position,
      cause = event.cause_entity,
      item = ammo_stack, -- gotten from the source_entity, has no effect
      speed = 0.5
    }
And the force it's spawned with does have the correct modifiers defined, though since the modifier is coded into the projectile at spawn and inherits it from the item, not the source entity, it makes sense that this doesn't work as it currently stands. Adding a damage_modifier parameter to the surface.create_entity function call for projectiles would entirely fix this issue.

Aside/details:
It would also be potentially handy for the script_trigger_effect event to have an item parameter that could be used here, since the quality of the ammo item used would also be valuable, though that I can determine from the source_entity and isn't strictly necessary as a result.

The reason I'm using a script to spawn the projectile rather than using a projectile trigger delivery is because:
1) the direction_deviation effect isn't applied for projectiles spawned with the ammo_type's target_type set to "entity" (which is important for this effect to work).
2) when the same projectiles are fired at asteroids, they don't actually have a target_entity set, and instead just a target_position. I'm assuming this is for understandable optimization reasons, but the target_position given doesn't account for target leading, so when an asteroid is moving perpendicular to or away from the turret, almost all of the projectiles "hit" where the asteroid was and don't do any damage as a result, which causes a lot of ammunition to be wasted attempting to hit the target.
If those issues were solved instead (and could be done in a performant way), that would greatly improve the performance of my mod since I wouldn't need to use on_script_trigger_effect for each projectile fired. While the direction_deviation is a visual polish thing, the aspect that's important for the gameplay is the target leading when the target is converted to a position, since that wastes a lot of bullets and defeats the purpose of the ammo being resource-efficient.

Thank you for reading!

Re: Add a damage parameter for projectiles to surface.create_entity

Posted: Tue Apr 22, 2025 9:11 pm
by curiosity
There's no damage modifier or ammo category read on a projectile either.

Re: Add a damage parameter for projectiles to surface.create_entity

Posted: Wed Apr 23, 2025 8:01 pm
by Rseding91
I've added these for the next release:

base_damage_modifiers and bonus_damage_modifiers when creating projectile types through LuaSurface::create_entity().
LuaEntity::base_damage_modifiers and bonus_damage_modifiers read/write.

Re: Add a damage parameter for projectiles to surface.create_entity

Posted: Thu Apr 24, 2025 5:59 pm
by safthelamb@gmail.com
Thank you! Looking forward to it

Re: Add a damage parameter for projectiles to surface.create_entity

Posted: Thu Apr 24, 2025 6:20 pm
by safthelamb@gmail.com
I also noticed that projectiles spawned don't have a quality even when specified while spawning:

Code: Select all

game.print("ammo_quality="..(ammo_stack and ammo_stack.quality.name or "nil"))
    local projectile = surface.create_entity{
      name = "smart-rounds-magazine",
      source = event.source_entity,
      position = event.source_position,
      force = event.source_entity and event.source_entity.force,
      target = event.target_entity or event.target_position,
      cause = event.cause_entity,
      quality = ammo_stack and ammo_stack.quality or nil,
      speed = 0.5
    }
The above code successfully prints "uncommon" when uncommon ammo is being fired, but the damage dealt by the projectile is unaffected. I'm assuming the effect of quality is similarly accounted for and applied to the damage_modifiers when spawned in the source code? And thus the damage_modifiers calculated should take quality into account as well when spawning since projectiles don't have a quality in general. (I'm already underway on implementing this, it's not a problem unless this is a bug and not by design)

Re: Add a damage parameter for projectiles to surface.create_entity

Posted: Thu Apr 24, 2025 6:58 pm
by Rseding91
All damage outside of what's defined in the projectile prototype is done through the the modifiers on the projectile depending on what created the projectile and how it wants to effect the values.

Re: Add a damage parameter for projectiles to surface.create_entity

Posted: Fri Apr 25, 2025 10:13 pm
by safthelamb@gmail.com
OK great, thanks for the clarification!