@"Kretol"
Okay!
So, after preforming the fun task that is tracking down all the dependencies to compile TrinityCore I took a quick look into the source code. It's been a looong time but basically this would be the deal, you need to register a new item script class for morph items, this class inherits ItemScript and has a function OnUse which handles code when the item is activated, so the dirt simplest way of doing this would be to make a script for each morph ID you wanted to create and compile it each time for separate items. A fancier way of doing it would be to make a generic handler script that pulled the associated display ID match from a database table that links item GUIDs to display IDs or something similar.
Below I'm pasting an excerpt from cs_modify.cpp which contains the handler for the GM Morph command:
Code:
static bool HandleModifyMorphCommand(ChatHandler* handler, const char* args)
{
if (!*args)
return false;
uint16 display_id = (uint16)atoi((char*)args);
Unit* target = handler->getSelectedUnit();
if (!target)
target = handler->GetSession()->GetPlayer();
// check online security
else if (target->GetTypeId() == TYPEID_PLAYER && handler->HasLowerSecurity(target->ToPlayer(), ObjectGuid::Empty))
return false;
target->SetDisplayId(display_id);
return true;
}
As we can see the obvious part here is assign the target based on the user's target OR just target themselves, then use the SetDisplayId function in the Unit class. (Plus some security / sanity checks, etc.)
So like.... super roughly in untested code, you're looking at adding something like the following in the item_scripts.cpp file:
Code:
class item_morph_player : public ItemScript
{
public:
item_morph_player() : ItemScript("item_morph_player") { }
bool OnUse(Player* player, Item* item, SpellCastTargets const& /*targets*/) override
{
player->SetDisplayId(XXXXXXX);
return true;
}
};
Again, untested but that should really be it for the simple version. Don't forget you need to register the new class and then associate it to an item which I think is just a database field in the items table. If the above doesn't work you may have to cast Player to Unit, but if memory serves it shouldn't be necessary.
Note that the above is only morphing the user, to do a toggle you'd need to do a check on the player's display ID and if it is different set it to that, otherwise demorph them back to the default display ID, relevant code should be easily located in the Handle Demorph block in cs_modify.cpp.
Let me know if you want any further info.
Cheers.