PlayerDropItemEvent¶
Triggered when a player is about to drop an item: with the Q key, by throwing it out of the inventory screen, or because it doesn't fit back into the inventory when a menu closes. It is not triggered for what a player loses on death. This event provides access to the player and the item. This event can be canceled. A canceled item goes back into the player's inventory, not necessarily into the slot it came from. If it can't go back, because there is no room for it or the player has left the server, it is deleted: a canceled item never drops. To keep an item in the hand when the Q key is pressed, intercept the PlayerDropSelectedItemEvent, which comes first.
Example: Keeping players from throwing diamonds away
spell:intercept("PlayerDropItemEvent", function(evt)
---@cast evt PlayerDropItemEvent
return evt.item.type.id ~= "diamond"
end)
while true do sleep(20) end
Fields¶
item: Item — Read-Only¶
A reference to the item that is about to be dropped. In an event queue it is a copy, as the event has already happened there.
name: string — Read-Only¶
The name of the event.
player: Player — Read-Only¶
A reference to the player who is dropping the item.