Add the ability to influence item loot in lua

Post Reply
Anyone
Long Handed Inserter
Long Handed Inserter
Posts: 70
Joined: Mon Apr 25, 2016 11:02 am
Contact:

Add the ability to influence item loot in lua

Post by Anyone »

TL;DR
Rocks drop stone, I can clear it on_entity_mined, but I can't prevent it from spilling on the floor when it dies. I would like to have some form of change in either the LuaEntity, event or game mechanic to change this behavior.

What ?
When talking about loot, I'm talking about the "expected resources" of things like rocks:
Image

Code: Select all

-- decoratives.lua
name = "sand-rock-big",
type = "simple-entity",
minable =
{
  mining_particle = "stone-particle",
  mining_time = 5,
  results = {{name = "stone", amount_min = 19, amount_max = 25}}
},
loot =
{
  {item = "stone", probability = 1, count_min = 10, count_max = 15}
},
Working on a soft-mod, I cannot influence the actual entity, which is fine, but I did expect to be able to somehow be able to prevent the items from spilling. In the "on_player_mined_entity" event I have access to the "buffer", which contains the stone ore as it would be moved to my player inventory after mining it. When the entity dies however (on_entity_died), I don't have access to such buffer as the items do not go into the player inventory, the stone spills on the ground.

I propose either, or both of the following in the LUA api, or follow the third option:
- Add a list of items that would be spilled on the ground if an entity dies, which works similar to the buffer when mining it
- Add the ability to alter the LuaEntity "loot table" without having to make a mod
- Don't spill the stone (or coal) when the rock dies (gun fire, biters, explosions, driving against it etc)

Why ?
I feel like this is missing because it's a bit of an odd one. Spilling contents seems to not be desired too much and has actually been removed to prevent certain grieving. However, for my custom soft-mod, the only alternative is to make rocks immune to damage and making sure they only get mined.

To illustrate why I would like to prevent them from spilling, please watch this video, but imagine killing all the rocks instead of mining them and ending up with thousands of stone laying around: https://www.youtube.com/watch?v=qsOtkgOt00E

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

Re: Add the ability to influence item loot in lua

Post by Rseding91 »

The "loot" system is specifically designed to drop on entity death so making it not drop the one time it was meant to would make no sense.

As for adjusting the "loot" table runtime - that's not supported. Prototypes are never allowed to be altered runtime - the entire game is built on that.

I'm not against using the same system in entity died as mined but it's not quite that simple since the place that sends the died event is unrelated to the place that drops the loot.
If you want to get ahold of me I'm almost always on Discord.

Anyone
Long Handed Inserter
Long Handed Inserter
Posts: 70
Joined: Mon Apr 25, 2016 11:02 am
Contact:

Re: Add the ability to influence item loot in lua

Post by Anyone »

The "loot" system is specifically designed to drop on entity death
A lot of systems designed in Factorio can be altered, hence I figured it would be more in line if we could intercept this.
As for adjusting the "loot" table runtime - that's not supported
I don't mind altering the entity, but that would mean the entity had actual contents (I expected it to be in the inventory).
I'm not against using the same system in entity died as mined but it's not quite that simple since the place that sends the died event is unrelated to the place that drops the loot.
I also ran into the case that if I want to programmatically remove a rock, `die()` will also spill contents but `mine_entity()` won't work without a player.

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

Re: Add the ability to influence item loot in lua

Post by Rseding91 »

If you just want to remove a rock with no side effects just destroy() it. It doesn't die, it isn't mined - it just stops existing.
If you want to get ahold of me I'm almost always on Discord.

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3699
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Add the ability to influence item loot in lua

Post by DaveMcW »

What OP really wants is data.lua mod features without the hassle of synchronizing mods in multiplayer.

Which I believe is coming in 0.17.

Anyone
Long Handed Inserter
Long Handed Inserter
Posts: 70
Joined: Mon Apr 25, 2016 11:02 am
Contact:

Re: Add the ability to influence item loot in lua

Post by Anyone »

If you just want to remove a rock with no side effects just destroy() it. It doesn't die, it isn't mined - it just stops existing.
The problem with is that the `LuaEntity` becomes invalid after use and sequential event listeners will break.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Add the ability to influence item loot in lua

Post by eradicator »

Anyone wrote:
Mon Oct 01, 2018 7:46 pm
Rseding91 wrote:
Mon Oct 01, 2018 12:02 am
If you just want to remove a rock with no side effects just destroy() it. It doesn't die, it isn't mined - it just stops existing.
The problem with is that the `LuaEntity` becomes invalid after use and sequential event listeners will break.
If the entity becomes invalid no further events for that entity will be raised. So all you need to worry is what you do in your own event after destroying the entity.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Anyone
Long Handed Inserter
Long Handed Inserter
Posts: 70
Joined: Mon Apr 25, 2016 11:02 am
Contact:

Re: Add the ability to influence item loot in lua

Post by Anyone »

If the sequential events are not raised, the scenario breaks

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Add the ability to influence item loot in lua

Post by eradicator »

Anyone wrote:
Sat Oct 06, 2018 9:25 am
If the sequential events are not raised, the scenario breaks
Are you saying your scenario relys on invalid events? Either one of us must be misunderstanding something here. But i can't say much more without examples/code/reasons.

Btw, i'm totally for a .buffer in on_died. Dynamic loot would be quite nice to have. (For fun stuff like damage-type based loot or similar :D).
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Anyone
Long Handed Inserter
Long Handed Inserter
Posts: 70
Joined: Mon Apr 25, 2016 11:02 am
Contact:

Re: Add the ability to influence item loot in lua

Post by Anyone »

Not it does not rely on invalid events, it relies on an event not being invalidated until it's finished.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Add the ability to influence item loot in lua

Post by eradicator »

Anyone wrote:
Fri Oct 12, 2018 9:10 pm
Not it does not rely on invalid events, it relies on an event not being invalidated until it's finished.
Can't say i understand what you mean by that. You might try posting in modding help.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Anyone
Long Handed Inserter
Long Handed Inserter
Posts: 70
Joined: Mon Apr 25, 2016 11:02 am
Contact:

Re: Add the ability to influence item loot in lua

Post by Anyone »

eradicator wrote:
Sat Oct 13, 2018 8:24 am
Anyone wrote:
Fri Oct 12, 2018 9:10 pm
Not it does not rely on invalid events, it relies on an event not being invalidated until it's finished.
Can't say i understand what you mean by that. You might try posting in modding help.
Events have event listeners. This is a sequential set of actions. If there are 15 listeners and at the 10th listener the entity becomes invalid, the last 5 listeners will not function. If one of those event listeners contains a functionality you need for your scenario to work, it completely kills the core mechanic.


Another issue not being able to disable spilled loot is performance. The further away it has to check, the slower it gets. In my scenario there's limited space due to void tiles, meaning it can be that it has to search for a free slot in a huuuuuge range (easily 100+ tiles), meaning the whole server freezes for seconds up to a minute.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Add the ability to influence item loot in lua

Post by eradicator »

Anyone wrote:
Sun Oct 14, 2018 10:31 am
eradicator wrote:
Sat Oct 13, 2018 8:24 am
Anyone wrote:
Fri Oct 12, 2018 9:10 pm
Not it does not rely on invalid events, it relies on an event not being invalidated until it's finished.
Can't say i understand what you mean by that. You might try posting in modding help.
Events have event listeners. This is a sequential set of actions. If there are 15 listeners and at the 10th listener the entity becomes invalid, the last 5 listeners will not function. If one of those event listeners contains a functionality you need for your scenario to work, it completely kills the core mechanic.
Without a detailed example this is hard to judge. If you have 15 different listeners (all for killing rocks?), and i.e. listener 9 destroys the event entity, what do you want listeners 10-15 to do without the entity (for the hypothetical case that they were raised anyway)?

Edit: from looking at the video (Rimtorio?) it looks like you simply want a rock that doesn't drop loot in the first place (i.e. a custom prototype), or is there supposed to be some way to get rock later anyway?
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

thedarkbunny
Inserter
Inserter
Posts: 46
Joined: Mon Oct 23, 2017 10:46 pm
Contact:

Re: Add the ability to influence item loot in lua

Post by thedarkbunny »

As I understood it, a rock should be mineable with a pick as normal (thus generating stone), but shouldn't drop stone when mined with, say, a grenade.

Post Reply

Return to “Implemented mod requests”