Comment on page
🎒
InventoryService
Service for handling inventory actions.
Example usage:
-- Set up a 20% chance to drop an emerald when damaging enemies
Events.EntityDamage(function(event)
if not event.fromEntity then
return
end
-- Only give emeralds when random between 1 and 5 is 1
if math.random(1, 5) ~= 1 then
return
end
local fromPlayer = event.fromEntity:getPlayer()
if fromPlayer then
InventoryService.giveItem(fromPlayer, ItemType.EMERALD, 1, true)
end
end)
Gives a player a specified number of an item. If
playWorldEffect
is true, an effect will play showing the recipient getting their items.Returns amount of specified item the player has (0 if they have none).
Removes the amount of the item from the player's inventory.
Clears all items from the player's inventory.
Returns a table of the amount of each item the player has in their inventory - including armor and hand items.
Example:
local player = PlayerService.getPlayerByDisplayName("quinticat")
local inv = InventoryService.getInventory(player)
for i, data in ipairs(inv) do
print(player.name .. " has " .. data.amount .. " " .. data.itemType)
end
Last modified 2mo ago