create projectile with source (cause) entity and force modifiers

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
Honktown
Smart Inserter
Smart Inserter
Posts: 1025
Joined: Thu Oct 03, 2019 7:10 am
Contact:

create projectile with source (cause) entity and force modifiers

Post by Honktown »

A projectile created can't have a `cause` applied which appears in the on_entity_damaged/died event, and while the projectile can have a force applied, it doesn't propagate force modifiers (specifically damage).

In my case, the projectile is a script-created grenade. A player force can be applied, but that's the end of it. Even tried applying a last-user to the grenade.

Code: Select all

/c

local function on_entity_damaged(event)
	if event.damage_type.name == "explosion" then
		game.print("explosion damage: "..event.original_damage_amount)
	end
end
script.on_event(defines.events.on_entity_damaged, on_entity_damaged)

local function on_entity_died(event)
	if event.cause then
		game.print("cause: "..event.cause.name)
	end
	if event.force then
		game.print("force: "..event.force.name)
	end
end
script.on_event(defines.events.on_entity_died, on_entity_died)

local function script_raised_built(event)
	local entity = event.entity
	if entity.name ~= "grenade" then return end
	entity.last_user = game.players[1]
	local last_user = entity.last_user

	if last_user then
		game.print("LU? "..last_user.name)
	else
		game.print("no last user")
	end
end
script.on_event(defines.events.script_raised_built, script_raised_built)

local player = game.player
local surface = player.surface
local character = player.character
local grenade_t = {
	name = "grenade",
	position = character.position,
	source = character,
	target = player.selected,
	force = "player",
	speed = 1,
	raise_built = true,
	--[[cause = character,]]
}
surface.create_entity(grenade_t)
The request is to have both "missing" things be present: a source/cause applies to show up in events, and force damage modifiers propagate.
I have mods! I guess!
Link

Post Reply

Return to “Modding interface requests”