How to make an item useable from the inventory?

Discuss modding questions and implementation details.
Post Reply
User avatar
Uncanny_Valley
Posts: 209
Joined: Mon Mar 23, 2015 5:47 pm

How to make an item useable from the inventory?

Post by Uncanny_Valley »

I been trying to figure out exactly how to make and item useable, as in, using it from the inventory. Is this documented somewhere? I been searching the forums and I just can't find anything about it.

Also, while I have managed to add a custom item with a ItemTemplate (as seen below), some values aren't directly obvious of what they do. Would appreciate some help. :)

[
{
"index": 151,
"name": "Casual Pants",
"baseWeight": 0.5,
"hitPoints": 150,
"capacityOrTarget": 0,
"basePrice": 5,
"enchantmentPoints": 40,
"rarity": 1,
"variants": 4,
"drawOrderOrEffect": 10,
"isBluntWeapon": false,
"isLiquid": false,
"isOneHanded": false,
"isIngredient": false,
"worldTextureArchive": 204,
"worldTextureRecord": 0,
"playerTextureArchive": 239,
"playerTextureRecord": 16
}
]

User avatar
Jay_H
Posts: 3660
Joined: Tue Aug 25, 2015 1:54 am
Contact:

Re: How to make an item useable from the inventory?

Post by Jay_H »

Not an expert myself, but one known example is from Magicono's Repair Tools mod. Rather than poking around and trying to decipher it myself, I'll link to the mod's scripts: https://github.com/magicono43/DFU-Mod_R ... er/Scripts

User avatar
Ralzar
Posts: 1963
Joined: Mon Oct 07, 2019 4:11 pm
Location: Norway

Re: How to make an item useable from the inventory?

Post by Ralzar »

If you just need to make an existing inventory item usable (instead of additional ng a new item) you can easily do it like this:

https://github.com/ajrb/dfunity-mods/bl ... sm.cs#L145


Also, if you add any new items with new indexes, make sure to register it here: viewtopic.php?f=27&t=3023
My released mods

"I feel like Ralzar specifically wrote those mods for me and then said "Use them". Just so he could watch me die more."
-FuzzyBeanPlays

User avatar
Hazelnut
Posts: 2865
Joined: Sat Aug 26, 2017 2:46 pm
Contact:

Re: How to make an item useable from the inventory?

Post by Hazelnut »

There's two different ways to do it, the first is for simple items as Ralzar showed above. Generally use this register approach for items where you're not creating a custom class for it... i.e. vanilla items you want to add use behaviour to. The other way is overriding the use method like this: https://github.com/ajrb/dfunity-mods/bl ... tem.cs#L55

Ralzars Climates & Calories mod has several custom items that I coded and they're good examples too.

Lastly, nice to see you back around UV! :)
See my mod code for examples of how to change various aspects of DFU: https://github.com/ajrb/dfunity-mods

Post Reply