Loot
Loot makes gold and items pop out of a point of the map. Each pickup arcs out, bounces on the ground, then is collected: it flies to the player who comes near it, the player walks on it, or the player presses the action key next to it. Use it for a tree that is cut, a chest, a barrel, a defeated enemy or any scripted reward. It is built in: there is nothing to install. The playground gameplayground/games/action-loot shows it in action.
Drop loot from an event
CalldropLoot() on an event (or a player) on the server. The pickups pop out of
its center:
gold: split into coins (one coin per 5 gold, 6 coins at most);items: item ids or{ itemId, amount, chance }, wherechanceis a percentage (100 by default);showNotification: show the inventory notification when an item is collected.
Collect modes
The magnet radius can depend on the player, for example with a magnet amulet:
Options
Items and their loot config
A pickup is linked to its item in the database:
- it shows the item
icon(a spritesheet id); items without an icon show a gem; - collecting it calls
player.addItem(item, amount), so the inventory, the menu and the hotbar update as usual; - gold is not an item: it shows a spinning coin and adds to
player.gold.
loot field:
The
item option of dropLoot() takes precedence over the item config.
Client presentation
The engine always animates the motion: the arc, the bounce, the idle bob, the magnet and the flight to the collector. Theloot client hook changes what is
drawn and heard:
components: components drawing a pickup, addressed by the itemloot.visual.sounds.land: played when a pickup lands;sounds.collect: played to the collector when the item has no sound.collectText: shows+5 goldor+2 Woodabove the collector. The texts use therpg.loot.goldandrpg.loot.itemtranslation keys.
kind, amount, icon,
name, color, rarity, state (flying, idle, collecting, expiring)
and progress (0 to 1 within the state):
Action Battle enemies
With@rpgjs/action-battle, add drop to the enemy rewards. The experience is
granted on defeat, the gold and the items pop as loot owned by the attacker:
drop: true uses the default settings.
Client, server and multiplayer
- Server: rolls the drops, places the pickups, checks the distance to the
players and grants the gold and items. Pickups are dynamic events with a small
hitbox and
through, so they never block movement or attacks. - Synchronized: each pickup is an event carrying a
componentsCentercomponent with its kind, icon, name, color, rarity, sound and arc settings. - Client: the built-in
rpg:lootsprite component animates the pickup and plays the sounds and the collect text for the collector. A player who joins long after the drop sees the pickups already on the ground. - Standalone RPG and MMORPG: both work the same. With
ownership: "player", pickups are scenario events that only their owner receives.