make on_player_mined_entity raisable by script
Posted: Sun May 14, 2017 8:37 pm
The event on_player_mined_entity is called just before an entity is mined and allows mods to change the resulting items. My problem: if I want to support this behavior in my mod, which emulates mining by user, I am not able to create the buffer inventory:
My problem is: I can deliver the list of stacks as a table, but the other mod expects a LuaInventory.
Therefore I need either a method, with which I can create a buffer inventory myself or the C++ side which delivers the raised event to other mods, has to convert the buffer to a LuaInventory and back.
Code: Select all
-- mod a
script.on_event(defines.events.on_player_mined_entity, function (event)
event.buffer.insert{name = "coal"}
end)
Code: Select all
-- mod b
-- raise event for an entity which will be destroyed
script.raise_event(defines.events.on_player_mined_entity, {
tick = game.tick,
player_index = player.index,
buffer = {
{ name = "raw-wood" }
},
)
-- insert modified buffer
for _, stack in pairs(buffer) do
player.insert(stack)
end
Therefore I need either a method, with which I can create a buffer inventory myself or the C++ side which delivers the raised event to other mods, has to convert the buffer to a LuaInventory and back.