Consumable item||doc135657

September 20, 2022

Format

 item:consume(count) 
  • The class to which the function belongs:item

Description

Consuming item.


Parameters

Variable name type Description
count int consumption


Value Returned

type Description
boolean Whether it was successfully consumed


Code Samples

On the server side of the player entity templatemount script, add the error when the registered player switches hand-held itemCallback, when the new item is not empty, consume its amount

Trigger.addHandler(this:cfg(), "HAND_ITEM_CHANGED", function(context)
    local entity = context.obj1
    local newItem = context.item
    local oldItem = context.oldItem
    if newItem then
      newItem:consume(1)
   end
  end)