View Full Version : Question about item generation

12-08-2013, 03:06 PM
Hello eluna community.

I'm currently working on a project using Eluna, and there's a question I'd like to get an answer to.

Is there a way for me to generate a loot table for a spawned monster, instead of relying on the static items in the database?
Is it possible to generate an item "on-the-fly" and add that to the database, then add it to the creature's loot table?

I'm thinking about doing it by hooking the 'CREATURE_EVENT_ON_SPAWN' event, and then replacing said creature's loot table with a loot table containing this generated item.

Is this possible at all, or would I need to reload the database to get access to the newly generated item?
If it is possible, would this stress the server much? I won't need to be able to support many players, as this is 'just' a hobby project, I'm not expecting it to gather lots of attention.

Thanks :)

12-08-2013, 03:25 PM
Creating loot on the fly? Not possible, would need to use AddItem.
Create items on the fly? Not possible.
Both require C++ and a core edit to be made properly.

12-08-2013, 03:33 PM
Okay, that's a shame. But thanks for the quick answer. I'll come up with a different solution then.

What is the maximum amount of items I can place in the item table in the database? I'm a little inexperienced with that, but if it's a large enough number, I could probably make something work that simulates the randomization of the item-system I intend to create.

12-08-2013, 03:45 PM
Hmm. 16777215 is the DB max. Core max is likely 4,294,967,295 (uint32), but its likely limited a bit by how things are handled in TC or possibly also in the client.

12-08-2013, 03:50 PM
Okay, well that will definitely be enough to serve my purpose, so that's pretty good news, thanks :)

Last question (I think), is it possible to split the loot into different tables, one for each item type, or would this be too difficult? Even if it isn't possible, I'm sure I can make do with (hopefully) 16 million items ;)

12-08-2013, 04:20 PM
Not entirely true Rochet, Laurea and I had loot created on the fly working on the server we were working on. It's very much so possible with Eluna. If you hang around, I'm sure Laurea will pitch in with the technical details on the subject.

12-08-2013, 06:20 PM
That sounds very interesting Foereaper, I'd love to hear more about it :)

12-08-2013, 07:50 PM
The old files seem to have grown legs and ran away, but let's see how much I can remember. DBC file fields assume you are using Taliis.

First off, there are two ways I know of to do random loot. The first is to use random enchantments (of the Boar and such), which requires a patch. There are two sub-approaches to do this: random suffixes, which take a suffix from ItemRandomSuffix.dbc and a base value. Fields 19-23 are references to SpellItemEnchantment.dbc, and fields 24-28 are multipliers (10,000 = base * 1). This is what Blizzard uses in WotLK. Very easy to use, but very restrictive unless you have tons and tons of suffixes with different multipliers, which results in large patches and is hard to control server-side.

The second way is random properties: it takes a property id from ItemRandomProperties.dbc, then pulls the stat type and values from SpellItemEnchantment.dbc using fields 2-6. Not restrictive and somewhat easy to use if you can make a generator to create all the DBC entries required (and there's a ton of them), but even having a cap of 100 of each stat can create large patch sizes. If I remember correctly you can have up to three properties on a single item.

The second approach, that I went with, is to generate a new item template instead of using an existing one whenever the situation calls for it - say, when a creature's loot is generated or when crafting something - which imposes the "No melee weapon equipped" problem (I was working on fixing it, but those files are lost as well), and also requires extra code in several places to delete said item template from the database when a player destroys it or the creature despawns without being looted.

I wrote up some quick code for the second approach, specifically the generation part. I have no idea if it actually works, or even compiles, but it should give you a rough idea. It's also missing checks for items that shouldn't be generated, like tradeskill materials, stackables, etc. Those cases would just return the original entry.

uint32 ObjectMgr::NewItemTemplate(uint32 entry)
ItemTemplateContainer::const_iterator itr = _itemTemplateStore.find(entry);
if (itr == _itemTemplateStore.end())
return NULL;

uint32 newEntry = 0; //This should be the current max entry (SELECT MAX FROM item_template)

_itemTemplateStore[++newEntry] = itr->second;
ItemTemplate & it = _itemTemplateStore[newEntry];

//Generate the new item. Here's an example of randomizing stats.
uint32 iLvl = it.ItemLevel + irand(-it.ItemLevel * .15f, it.ItemLevel * .1f);
it.ItemLevel = iLvl;

//For item quality, we want a diminishing chance of getting a higher quality
float chance = 30; //1 in 30 chance of receiving highest quality
float roll = frand(0, chance);

//ITEM_QUALITY_EPIC = highest quality
uint32 quality = floor(((float)ITEM_QUALITY_EPIC * 2.f * roll) / (chance + roll));
it.Quality = quality;

return newEntry;

12-08-2013, 08:42 PM
Sweet, thanks a lot!

I only plan on using parts of the original game, mainly 3d models and skill animations, so the crafting issues won't be relevant for me, at least not for a long time. I will need to code what happens when an item is deleted or if a corpse despawns, but I'm okay with that, I'll figure it out. I'll build upon your example tomorrow, and see if I can make something work.
I don't have any experience with Taliis though, do I need to know anything specific before I dive into that?

Also, is it possible to add proccing skills to items through this method?

12-08-2013, 11:58 PM
No problem at all. It's fun to see somebody else try and tackle the problems of adding diablo-style loot to a game that wasn't made for it. :)

Taliis doesn't really require any specific knowledge to use. It is a java program though, so you'll need java installed to use it. Saving files can be a bit funky and adding strings can be a pain sometimes, but that's about it.

On-hit stuff is just spells with a chance to cast that is defined in Spell.dbc, so you'd modify the spells of the new item template and add those.