The Loot Tables package allows you to quickly and easily add weighted probability loot tables to your game.
It’s intentionally left generic, letting you implement it any way you want. Some examples:
Award the player with items from a loot table after they complete a minigame
Throw physics enabled items out of an enemy when they die
Add an item directly the player’s inventory when they interact with something
Use a loot table for possible fish in a fishing hole
Message me on discord if you need any help implementing your specific need.
image 379×638 45.8 KB
Installation
Search for “Loot Table” in the packager.
Creating a Loot Table
Locate the Loot Table template in the template library and duplicate it
Name your new Loot Table something meaningful like “Loot Table - Boss Drops”
Right click your new Loot Table and click Edit.
In the world tree, click on your Loot Table and give it a name.
Right click the Loot Table, hover over Add → Script → lootTableItemScript
This creates a single entry in your loot table. With this you would specify a single item, and it’s weight. For every item you want to in this loot table, you would repeat step 5.
Drag this template into the word and simulate the parent - you will see the probabilities printed.
Loot Table uses weighted probabilities to determine drop rates. For example, if you had a loot table of:
Item A: 3 Item B: 1
Then the probability of dropping Item A is 75%, and the probability of dropping Item B is 25%.
Utilizing a Loot Table
To utilize a loot table, drag the template you created onto the item you want to utilize it.
Right click on your chest and add a new script - let’s call it “LootDropperScript”, and place something like this inside:
local LootDropperScript = {}
-- Script properties are defined here
LootDropperScript.Properties = {
-- Example property
--{name = "health", type = "number", tooltip = "Current health", default = 100},
}
--This function is called on the server when this entity is created
function LootDropperScript:Init()
self.lootTable = self:GetEntity().lootTableScript
end
function LootDropperScript:OnInteract()
self:GetEntity():PlayAnimation("Opening")
local itemToDrop = self.lootTable:FindItemByChance()
if itemToDrop then
GetWorld():Spawn(itemToDrop, self:GetEntity():GetPosition() + Vector.New(0, 0, 100), self:GetEntity():GetRotation())
end
end
return LootDropperScript
Now, if the player interacts with the chest, it will spawn the items just above it.