Page 1 of 1

How to prevent a player from dropping items over a transport belt?

Posted: Sat Jan 19, 2019 2:40 am
by PhilBeaudoin
Hi!

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)
However, when the player uses "Z" over a transport belt, the event doesn't seem to get triggered. Any idea if there is a way to get notified in this case?

Re: How to prevent a player from dropping items over a transport belt?

Posted: Sat Jan 19, 2019 3:44 pm
by Nexela
Use the permissions system to disable dropping items?
defines.input_action.drop_item

Re: How to prevent a player from dropping items over a transport belt?

Posted: Sat Jan 19, 2019 9:26 pm
by PhilBeaudoin
Thanks! For some reason I missed this permission system. Works perfectly and makes my life much easier.

Still probably worth looking into why the event is not fired when dropping on a transport belt.

Re: How to prevent a player from dropping items over a transport belt?

Posted: Sun Jan 20, 2019 2:50 am
by Nexela
PhilBeaudoin wrote: Sat Jan 19, 2019 9:26 pm Still probably worth looking into why the event is not fired when dropping on a transport belt.
That is by design and has to do with happens to an item that is put on a transport belt