[Solved] Artillery Projectile Created Event

Place to get help with not working mods / modding interface.
Post Reply
User avatar
Ratte
Manual Inserter
Manual Inserter
Posts: 3
Joined: Sun Jul 28, 2019 4:59 am
Contact:

[Solved] Artillery Projectile Created Event

Post by Ratte »

The Problem:
I want to try and mod artillery-projectile behavior, like spawning effects below it or colliding with defensive enemy entities on the way.
For this, I need an event listener on artillery projectile creation, to keep track of all currently flying artillery projectiles.

My Journey:
I've read through all events available, where I found: on_trigger_fired_artillery which seems like what I want, getting a event every time a shell is fired, but just registering a listener in control.lua doesn't work, can I make the vanilla artillery give me these events? If yes how?
I know I should probably add trigger_fired_artillery=true somewhere in my data.raw[ artillery-projectile? artillery-turret? projectile? ], but I don't know where.

Resources I found already:
Here is the doc for on_trigger_fired_artillery: https://lua-api.factorio.com/1.1.59/eve ... _artillery
And here is an old thread I found, which feels related, I think it's telling me to change the artillery turret somewhere, but I don't understand how exactly: Factorio Forums: Entity Creation not detected
And here are three Prototypes I think are useful, but I don't know:
https://wiki.factorio.com/Prototype/ArtilleryTurret
https://wiki.factorio.com/Prototype/ArtilleryProjectile
https://wiki.factorio.com/Prototype/Projectile
Last edited by Ratte on Thu Jun 02, 2022 6:53 am, edited 1 time in total.

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2541
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: Artillery Projectile Created Event

Post by FuryoftheStars »

Ratte wrote:
Wed Jun 01, 2022 7:15 pm
where I found: on_trigger_fired_artillery which seems like what I want, getting a event every time a shell is fired, but just registering a listener in control.lua doesn't work, can I make the vanilla artillery give me these events? If yes how?
Does something like this not work?

Code: Select all

local function ArtilleryFired(event)
	-- Whatever code you need for the actions you want to take
end

script.on_event(defines.events.on_trigger_fired_artillery, ArtilleryFired)
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles

User avatar
Ratte
Manual Inserter
Manual Inserter
Posts: 3
Joined: Sun Jul 28, 2019 4:59 am
Contact:

Re: Artillery Projectile Created Event

Post by Ratte »

Sadly no, my listener got no events.
The other thread talked about performance, and that by default this is disabled, but I don't know how to enable it.
Just to make sure again, I made this control.lua:

Code: Select all

local function ArtilleryFired(event)
	game.print("on_trigger_fired_artillery")
end
script.on_event(defines.events.on_trigger_fired_artillery, ArtilleryFired)
But it prints nothing when the artillery fires. I've tested this with no other mods active to be sure nothing else breaks it.

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2541
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: Artillery Projectile Created Event

Post by FuryoftheStars »

Hmm, for the sake of it, try "log" instead of "game.print" and then check your factorio-current.log file. There are some conditions under which game.print gets culled and won't print to screen.

Edit: Oh, never mind...
Called when an entity with a trigger prototype (such as capsules) fire an artillery projectile AND that trigger prototype defined trigger_fired_artillery="true"
May want to double check that the artillery prototype has that defined?
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles

Pi-C
Smart Inserter
Smart Inserter
Posts: 1654
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Artillery Projectile Created Event

Post by Pi-C »

Ratte wrote:
Wed Jun 01, 2022 8:23 pm
Sadly no, my listener got no events.
See here:

Code: Select all

 on_trigger_fired_artillery

Called when an entity with a trigger prototype (such as capsules) fire an artillery projectile AND that trigger prototype defined trigger_fired_artillery="true".
I know I should probably add trigger_fired_artillery=true somewhere in my data.raw[ artillery-projectile? artillery-turret? projectile? ], but I don't know where.
I'd try Prototype/ArtilleryProjectile.action. Look for action_delivery.source_effects.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

User avatar
Ratte
Manual Inserter
Manual Inserter
Posts: 3
Joined: Sun Jul 28, 2019 4:59 am
Contact:

Re: Artillery Projectile Created Event

Post by Ratte »

FuryoftheStars wrote:
Wed Jun 01, 2022 9:00 pm
May want to double check that the artillery prototype has that defined?
When searching for on_trigger_fired_artillery in the base game data, there are zero hits, so seems like it hasn't defined it by default, which makes sense, as the base game doesn't use it.
Pi-C wrote:
Wed Jun 01, 2022 9:23 pm
I'd try Prototype/ArtilleryProjectile.action. Look for action_delivery.source_effects.
Thanks for pointing me to the action_delivery, that was the place to add it, but on the artillery-shell and not the artillery-projectile.

The solution is:

Code: Select all

data.raw["ammo"]["artillery-shell"].ammo_type.action.action_delivery.trigger_fired_artillery = true
This triggers the event on_trigger_fired_artillery when the artillery shoots (and creates) the artillery-projectile.

Thanks for the help! <3 (Literally saved me days of confusion)

Post Reply

Return to “Modding help”