Jump to content

inventory system [stack items]


iwalidza

Recommended Posts

  1. I have an inventory system it has stack system like one slot can get just 10 apples like if i write command to give player item and i want give player like 36 apples and he have 4 apples in him inventory then him inventory he be like that 10 10 10 10 10
  2. how i can do it
Link to comment
  • Moderators
25 minutes ago, iwalidza said:

stack system

The way the items are stacked depends on the inventory system.

Basic formule:

-- generate some fake data
local item = {name = "apple", quantity = 36}


-- do the stacking
local stackSize = 10

local itemCount = item.quantity -- 36

local stacksRawCount = itemCount / stackSize

local stacksMaxCount = math.ceil(stacksRawCount) -- 4
local stacksMinCount = math.floor(stacksRawCount) -- 3


local remainingItems = itemCount % stackSize -- 6

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...