Loot - time to live?

Place to get help with not working mods / modding interface.
Post Reply
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Loot - time to live?

Post by aubergine18 »

Is there any way to set TTL for loot? I've added some loot to certain trees but the downside is that a forest fire will yield lots of it and it appears to just stay on the map forever if not collected. I'd ideally want it to disappear after a few hundred ticks.
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13223
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Loot - time to live?

Post by Rseding91 »

No, item-on-ground never goes away unless picked up or destroyed by a mod. It doesn't have any kind of tick logic because that would add a ton of extra CPU time that would need to be spent on each item dropped which is wasteful.
If you want to get ahold of me I'm almost always on Discord.

User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: Loot - time to live?

Post by aubergine18 »

Several mods (including one I'm working on) add loot to trees, biters, buildings, etc. A single forest fire can litter the map with tree loot, even if that loot is rare, due to number of trees in a forest. Add in long-range turrets (like "Additional Turrets" mods' artillery) and the map starts getting covered in uncollected loot.

It seems possible to define additional `item-on-ground` prototypes... if TTL was added to item-on-ground type, but not the default prototype, it shouldn't affect the majority of things on ground? A new 'loot' item-on-ground could be defined that incorporates TTL and maybe use that specifically for loot? It could have long TTL like biter corpses.

Or maybe I can find a way to convert existing item-on-ground to one of the following entity types that support TTL (or equivalent) setting: remnants, flying-text, particle-source, particle, combat-robot, rail-remnants, corpse...? Failing that, it looks like keeping a list of all loot created (not sure if loot creation triggers event yet) and manually destroying it via script after specific amount of time.
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.

User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm
Contact:

Re: Loot - time to live?

Post by Adil »

Why not just detect entity death, find all the loot it drops and push them into some lua tracker-timer?
(Just don't use game tick for the timer as it will break the mod in 2.26 years of playing)
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.

Zeblote
Filter Inserter
Filter Inserter
Posts: 973
Joined: Fri Oct 31, 2014 11:55 am
Contact:

Re: Loot - time to live?

Post by Zeblote »

Rseding91 wrote:It doesn't have any kind of tick logic because that would add a ton of extra CPU time that would need to be spent on each item dropped which is wasteful.
Why would the individual items need tick logic just to destroy them after a certain time? Surely this can be done much faster!

Rseding91
Factorio Staff
Factorio Staff
Posts: 13223
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Loot - time to live?

Post by Rseding91 »

Zeblote wrote:
Rseding91 wrote:It doesn't have any kind of tick logic because that would add a ton of extra CPU time that would need to be spent on each item dropped which is wasteful.
Why would the individual items need tick logic just to destroy them after a certain time? Surely this can be done much faster!
It already is, they take zero CPU time because they don't have any logic to them and they're staying that way.
If you want to get ahold of me I'm almost always on Discord.

User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: Loot - time to live?

Post by aubergine18 »

Would it be possible to get a `.loot` property added to `on_entity_died` events? It would be array of any loot created by the destruction of that entity, or `nil` if there was no loot.

I'm going to try what @Adil suggests but with some tweaks:

Code: Select all

--pseudo code

create initial time bucket

on_entity_died:
  scan area around entity to find loot
    store loot in most recent "time bucket" array

on_tick:
  tick % few minutes?
    create new time bucket
    delete oldest time bucket and any valid entities it contains
Obviously scanning local area when entity destroyed is a time-consuming way to find loot, hence the desire to have a list of loot in on_entity_destroyed event.
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13223
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Loot - time to live?

Post by Rseding91 »

Loot isn't generated at the point in time when the entity_died event is called. Also adding the loot entities to every entity died event would also add a bunch of extra CPU time to every entity died event listener because it would need to make all of those entity references for every listening mod on every event call.

I suggest you simply skip the loot idea since it's not what you actually want. Add in the items you want as the mining result of the entity with a low probability to get them so they only show up when the player mines the tree (or deconstructs it).
If you want to get ahold of me I'm almost always on Discord.

Post Reply

Return to “Modding help”