Lua custom items#8550
Conversation
5b08ea5 to
3831ad4
Compare
c68cf6e to
c917f56
Compare
…dUniqueItem with app_fatal(fmt::format(...)).
d61d89a to
eb19ecf
Compare
|
Love this! |
It can be done, I only created a weapon because it would be a more complex example but I can try to create a consumable. @HoofedEar do you have anything specific in mind? |
There was a problem hiding this comment.
Pull request overview
This PR enables Lua-defined custom items by allowing mods to register custom cursor/drop graphics and sounds, and by routing item animation/sound lookups through helper functions that safely handle custom cursor IDs. It also adjusts save-loading to better preserve modded items.
Changes:
- Add custom cursor/drop graphic + sound registration APIs and safe lookup helpers (
GetItemAnimType,GetItemInvSnd,GetItemDropSnd). - Expose Lua APIs to define items/uniques and register associated graphics/sounds.
- Update inventory/stash/store UI call sites to use the new helpers; add unit tests and wire them into CMake.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| test/custom_items_test.cpp | Adds unit tests for new item anim/sound lookup and custom item registration behavior. |
| Source/tables/itemdat.cpp | Clears custom cursor sprites before reloading item data. |
| Source/qol/visual_store.cpp | Uses GetItemInvSnd instead of direct table lookup. |
| Source/qol/stash.cpp | Uses GetItemInvSnd instead of direct table lookup. |
| Source/qol/itemlabels.cpp | Uses GetItemAnimType instead of direct table lookup. |
| Source/lua/modules/items.cpp | Adds Lua APIs for adding items/uniques and registering graphics/sounds. |
| Source/loadsave.cpp | Preserves unpacked items when heroitems data can’t be loaded/recreated. |
| Source/items.h | Declares new custom item APIs and exposes ItemCAnimTblSize. |
| Source/items.cpp | Implements custom drop anim/sound registries + safe lookup helpers. |
| Source/inv.cpp | Uses GetItemInvSnd instead of direct table lookup. |
| Source/cursor.h | Declares custom cursor sprite registration/free APIs. |
| Source/cursor.cpp | Implements custom cursor sprite storage and lookup in GetInvItemSprite. |
| CMake/Tests.cmake | Adds custom_items_test to the test suite. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Coming from that source mod I was working on, where I added an item that turns a normal equipment into a magical one, I remember having to define what the cursor sprite would be when consumed, and then the effect that applies it. But I believe I went the route of creating a spell, so consuming the item was similar to reading a scroll. But I'm not sure what the best way to do that in Lua would be hmm. I guess "recreating" a scroll with a different name might be a good starting point? |
Hmm, if you have that spell already created, I think the new item can be used as a scroll. I can try that! But the new spell cannot be created using only lua, right? |
I believe yes, for certain effects we'd probably have to write custom code Definitely not trying to scope creep this haha just thinking out loud |
|
You need to add
|
Done! |
3a7ff02 to
8269f25
Compare
e6b1b06 to
0c1fcaf
Compare
PR to enable custom items using Lua
Loading regular diablo save files do not break.
Example of Mod - Katar (as a sword)
katar.mp4
File with the mod katar.mpq
katar_mod.zip