I've building a mod where I need to prevent a player from dropping items on the ground with the "Z" keystroke. The mod uses the god-controller so I cannot use set the drop_item_distance = 0 in the prototype.
This piece of code works most of the time:
Code: Select all
script.on_event(defines.events.on_player_dropped_item, function(e)
-- Dropping is not allowed.
local player = game.players[e.player_index]
local item_on_ground = e.entity
add_item_to_cursor_quickbar_or_inventory(player, item_on_ground.stack.name, item_on_ground.stack.count)
item_on_ground.destroy()
end)