Set the number of stacks||doc135659

September 20, 2022

Format

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

Description

Set the number of items.


Precautions

The number of items set cannot exceed the maximum stacking number of item, otherwise there will be unexpected consequences.


Parameters

Variable name type Description
count int quantity


Code Samples

On the server side of the player entity templatemount script, add the error when the registered player switches hand-held itemCallback, if the new item exists, set its item count.

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