a way to detect when a rocket launcher is used

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
User avatar
MewMew
Long Handed Inserter
Long Handed Inserter
Posts: 55
Joined: Thu May 19, 2016 11:02 am
Contact:

a way to detect when a rocket launcher is used

Post by MewMew »

Can not find a way to detect when spidertron shoots a rocket.
For players "on_player_ammo_inventory_changed" works,
but a bit limited since it is called after a players ammo inventory was changed.

Adding an event "on_vehicle_ammo_inventory_changed" would work out,
since one could use "find_entities_filtered" to get the created rocket type projectile.
Does not seem very efficient, but would work.

Goal is to have more control over the usage of nukes and rockets.
For example making nuke projectiles not being able to detonate in a certain area of the surface.
Pi-C
Smart Inserter
Smart Inserter
Posts: 1742
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: a way to detect when a rocket launcher is used

Post by Pi-C »

MewMew wrote: Sun Aug 23, 2020 4:54 pm Can not find a way to detect when spidertron shoots a rocket.
For players "on_player_ammo_inventory_changed" works,
but a bit limited since it is called after a players ammo inventory was changed.
Haven't tested this yet, but rockets aren't bullet magazines where you have to fire ten bullets before one magazine is removed. Wouldn't shooting a rocket register in the ammo inventory almost immediately?

And again, haven't tested yet (I've only seen the spidertron icon in the tech tree so far and have never built the entity). There may be a kind of whacky workaround: Listen to on_entity_damaged and filter for damage_type == "explosion". The event will give you the entity that did the damage as "cause", so you could check if a spidertron has shot something that exploded. However, that isn't very precise because it will register with a delay (not when the rocket is fired, but when it hits something) and may not register at all if it didn't do any damage (e.g. because the target has full immunity against explosion, or because it has been killed by something and the rocket exploded right in the middle of nowhere).

About checking the inventory: From what I've read, spidertrons go through a lot of ammo very fast, so acting on every change of the ammo inventory may be as bad as my attempt to act on every change of the player's main inventory -- which killed UPS because players did incredibly stupid and unexpected things like running on a belt while picking up items! :-D
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
User avatar
MewMew
Long Handed Inserter
Long Handed Inserter
Posts: 55
Joined: Thu May 19, 2016 11:02 am
Contact:

Re: a way to detect when a rocket launcher is used

Post by MewMew »

"on_entity_damaged" is not a good option, it is too resource heavy for small tasks like this.
Would prefer to get the projectile somehow.
Post Reply

Return to “Modding interface requests”