Loot
Inherits: Resource
Resource containing a weighted list of loot items for random generation.
Description
The Loot resource represents a loot table containing a weighted list of LootItem resources. It provides functionality for weighted random selection of items, commonly used in survival games for treasure chests, enemy drops, and resource gathering. Items with higher weights are more likely to be selected during random generation.
The loot system supports configurable rolls functionality, inspired by Minecraft-style loot tables. You can set minimum and maximum roll counts to generate multiple items in a single loot generation call. For example, setting min_rolls=2 and max_rolls=4 will generate between 2-4 items each time the loot table is used.
The total weight is calculated automatically from all contained loot items, and the random selection uses this total to ensure proper probability distribution.
Properties
Array[LootItem] |
|
|
|
|
|
|
|
|
|
|
Methods
Array[LootItem] |
get_random_items(rolls: |
|
get_total_weight() const |
Property Descriptions
Array of LootItem resources that define what items can be generated and their relative probabilities. Each loot item contains an item ID, weight for probability calculation, and minimum/maximum amount ranges.
int
max_rolls = 1
🔗
void set_max_rolls(value:
int
)int
get_max_rolls()
Maximum number of rolls when generating random items. Combined with min_rolls to define a range for random roll count generation. Must be greater than or equal to min_rolls. For fixed roll counts, set this equal to min_rolls.
int
min_rolls = 1
🔗
void set_min_rolls(value:
int
)int
get_min_rolls()
Minimum number of rolls when generating random items. Combined with max_rolls to define a range for random roll count generation. Must be at least 1. For fixed roll counts, set this equal to max_rolls.
String
name = ""
🔗
void set_name(value:
String
)String
get_name()
Optional name for this loot table, useful for identification and organization in the inventory database.
Method Descriptions
Array[LootItem] get_random_items(rolls: int
= -1) const 🔗
Returns an array of randomly selected LootItem resources. When rolls
is -1 (default), uses the configured roll range (min_rolls to max_rolls) with a random number of rolls within that range. When rolls
is a positive number, uses that exact number of rolls, overriding the configured range. Each roll is an independent weighted selection from the loot table. Returns an empty array if no valid items can be generated.
float
get_total_weight() const 🔗
Calculates and returns the total weight of all LootItem resources in this loot table. This is used internally for weighted random selection calculations.