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
[Solved] Artillery Projectile Created Event
[Solved] Artillery Projectile Created Event
Last edited by Ratte on Thu Jun 02, 2022 6:53 am, edited 1 time in total.
-
- Smart Inserter
- Posts: 2541
- Joined: Tue Apr 25, 2017 2:01 pm
- Contact:
Re: Artillery Projectile Created Event
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
Re: Artillery Projectile Created Event
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:
But it prints nothing when the artillery fires. I've tested this with no other mods active to be sure nothing else breaks it.
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)
-
- Smart Inserter
- Posts: 2541
- Joined: Tue Apr 25, 2017 2:01 pm
- Contact:
Re: Artillery Projectile Created Event
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...
Edit: Oh, never mind...
May want to double check that the artillery prototype has that defined?Called when an entity with a trigger prototype (such as capsules) fire an artillery projectile AND that trigger prototype defined trigger_fired_artillery="true"
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
Re: Artillery Projectile Created Event
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'd try Prototype/ArtilleryProjectile.action. Look for action_delivery.source_effects.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.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
Re: Artillery Projectile Created Event
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.FuryoftheStars wrote: ↑Wed Jun 01, 2022 9:00 pmMay want to double check that the artillery prototype has that defined?
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.Pi-C wrote: ↑Wed Jun 01, 2022 9:23 pmI'd try Prototype/ArtilleryProjectile.action. Look for action_delivery.source_effects.
The solution is:
Code: Select all
data.raw["ammo"]["artillery-shell"].ammo_type.action.action_delivery.trigger_fired_artillery = true
Thanks for the help! <3 (Literally saved me days of confusion)