Modcraft - The community dedicated to quality WoW modding!

Wrath of the Lich King Modding => Serverside Modding => Topic started by: Смердокрыл on July 02, 2015, 02:04:44 pm

Title: [QUESTION] Morphing item
Post by: Смердокрыл on July 02, 2015, 02:04:44 pm
Hey everyone!
Any good tutorial on making an item that morphs when worn? No spell-morphs, please, I need to use displayids.
Title: Re: [QUESTION] Morphing item
Post by: Alastor on July 02, 2015, 05:11:38 pm
ITEM >> SPELL ( with morph )

Done .. look at noggers elixir
Title: Re: [QUESTION] Morphing item
Post by: Смердокрыл on July 02, 2015, 06:53:17 pm
I hope you are just trolling
Title: Re: [QUESTION] Morphing item
Post by: bizzlesnaff on July 02, 2015, 07:39:45 pm
Quote from: "Смердокрыл"
I hope you are just trolling

Why? Thats a good idea. Can't be so difficult to copy the code and just edit the display id..

edit:
ah...see just now what you mean....

edit2:
maybe you could try to look into the databse if item XYZ has durability >0 and if not, the owner get any effect..?
Title: Re: [QUESTION] Morphing item
Post by: Смердокрыл on July 02, 2015, 08:56:37 pm
I was gonna use trinkets, so cant use durability, can I?
Title: Re: [QUESTION] Morphing item
Post by: bizzlesnaff on July 02, 2015, 09:08:09 pm
No that's not possible. But i thought u try to morph the player when the item is worn...maybe it is an translation mistake by me...worn means damaged so in wow the item is shown "red". trinkets, rings, back, neck etc. can never lose durability.
Title: Re: [QUESTION] Morphing item
Post by: Rochet2 on July 02, 2015, 10:18:53 pm
You either need to use a spell or a script.

Spell would nicely take use of the aura system incase the player has multiple morphs. Lets say he has your trinket and noggenfogger, the spell system would probably be able to restore the other when the other wears out and maybe take into account other things.

If you apply the morph on equip (or on spell cast) and then the player morphs to something else (noggenfogger) it might be a hassle to try to restore the morph from the trinket after that without checking all the time for the correct displayid.

What core do you use for the server?

Mangos based cores (mangos, cmangos, trinitycore.. ) do not have an "on equip" hook in their C++ scripting API. Unsure about arcemu ?_?
This means that you would need to modify the core to add such a hook.
A workaround for this could be .. yet again .. using a spell.
By using a spell on use for the item you can script the spell to do what you want in C++.
You can use the same spell for all items you create since you can script it to do different things according to the item entry or other data.

Did I mention a spell yet? :3

Quote from: "bizzlesnaff"
No that's not possible. But i thought u try to morph the player when the item is worn...maybe it is an translation mistake by me...worn means damaged so in wow the item is shown "red". trinkets, rings, back, neck etc. can never lose durability.
by worn he probably meant that he wanted the morph to be visible when the item is equipped/weared.
Title: Re: [QUESTION] Morphing item
Post by: Daweo on July 02, 2015, 10:21:12 pm
Quote from: "Смердокрыл"
Hey everyone!
Any good tutorial on making an item that morphs when worn? No spell-morphs, please, I need to use displayids.

You can make hook in core to catch this event. For example in TrinityCore in file Player.cpp, It is tested.

Code: [Select]
void Player::DurabilityPointsLoss(Item* item, int32 points)
.
.
.
if (pNewDurability == 0 && pOldDurability > 0 && item->IsEquipped())
{
_ApplyItemMods(item, item->GetSlot(), false);

// Morph on durability loss
SetDisplayId(999);
ChatHandler(GetSession()).PSendSysMessage("It's broken and You are morphed!");
}
.
.
.
item->SetUInt32Value(ITEM_FIELD_DURABILITY, pNewDurability);

I hope I helped You...
Title: Re: [QUESTION] Morphing item
Post by: Смердокрыл on July 03, 2015, 12:26:38 am
Rochet2 and Daweo's replies look promising, other than I have no experience in C++ at all, so I dont really get what demonic rituals do I have to perform with this ancient scripts...
Title: Re: [QUESTION] Morphing item
Post by: Daweo on July 03, 2015, 12:29:37 am
Quote from: "Смердокрыл"
Rochet2 and Daweo's replies look promising, other than I have no experience in C++ at all, so I dont really get what demonic rituals do I have to perform with this ancient scripts...

So, what you really wanted? Morph on item equip or on durability loss? :)
Title: Re: [QUESTION] Morphing item
Post by: Смердокрыл on July 03, 2015, 12:33:52 am
Morph on item equip, but with the ability to morph using ANY displayid, and not only those that are attached to a certain spell/aura
Title: Re: [QUESTION] Morphing item
Post by: Daweo on July 03, 2015, 12:44:44 am
Off top of my head there are a few options.

A) Hook in Core... C++
- You would have to find in core, where the item equip is handled and there add your own code
- But, this option will definitely work...

B) Make SpellScript to any spell and that spell will be set on item equip.. C++
- So if you equip an item, the spell will be executed and then our spellscript too. And in code of spellscript wil be implementation of your Morphs.

C) DBC Edits of spells
- It may not seem, but if you dont know C++, it is the most easy method for you, but the custom patch is then needed...
Title: Re: [QUESTION] Morphing item
Post by: Смердокрыл on July 03, 2015, 12:46:34 am
Quote from: "Daweo"
C) DBC Edits of spells
This seems to be the best option for a noob like myself. But can I create a custom spell, not to destroy any existing ones?

P.S. I have  4.3.4 trinity
Title: Re: [QUESTION] Morphing item
Post by: Daweo on July 03, 2015, 12:51:24 am
Ou... I dont have any experience with DBC above 3.3.5a...
But maybe i can write a simple code...

The solution would be:
SQL table item_morph with two columns: item_id and model_id
C++ Script to handle whoch model_id should be used
Title: Re: [QUESTION] Morphing item
Post by: Смердокрыл on July 03, 2015, 12:59:47 am
Ok, you can congratulae me, because I managed to create a table!
[attachment=0:1v80o1pg]table.jpg[/attachment:1v80o1pg]
Title: Re: [QUESTION] Morphing item
Post by: Daweo on July 03, 2015, 01:49:53 am
For TrinityCore 3.3.5a the solution could be:

SQL table in world database:
Code: [Select]
CREATE TABLE IF NOT EXISTS `item_morph` (
`item_id` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0',
`morph_id` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0',
PRIMARY KEY (`item_id`)
)
COMMENT='Item Morph system'
COLLATE='utf8_general_ci'
ENGINE=MyISAM;


C++ code in Player.cpp:
Code: [Select]
Item* Player::EquipItem(uint16 pos, Item* pItem, bool update)
{
.
.
.
ApplyEquipCooldown(pItem2);

// Item Morph
QueryResult result = WorldDatabase.PQuery("SELECT model_id FROM item_morph WHERE item_id = %u", pItem2->GetEntry());

if (result)
{
Field* fields = result->Fetch();
uint32 model_id = fields[0].GetUInt32();

if (sCreatureDisplayInfoStore.LookupEntry(sObjectMgr->GetCreatureDisplay(model_id)))
SetDisplayId(model_id);
}
// END

return pItem2;
    }
.
.
.
UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_EQUIP_EPIC_ITEM, pItem->GetEntry(), slot);

// Item Morph
QueryResult result = WorldDatabase.PQuery("SELECT model_id FROM item_morph WHERE item_id = %u", pItem->GetEntry());

if (result)
{
Field* fields = result->Fetch();
uint32 model_id = fields[0].GetUInt32();

if (sCreatureDisplayInfoStore.LookupEntry(sObjectMgr->GetCreatureDisplay(model_id)))
SetDisplayId(model_id);
}
// END

return pItem;
}
.
.
.
void Player::QuickEquipItem(uint16 pos, Item* pItem)
{
.
.
.
UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_EQUIP_EPIC_ITEM, pItem->GetEntry(), slot);

// Item Morph
QueryResult result = WorldDatabase.PQuery("SELECT model_id FROM item_morph WHERE item_id = %u", pItem->GetEntry());

if (result)
{
Field* fields = result->Fetch();
uint32 model_id = fields[0].GetUInt32();

if (sCreatureDisplayInfoStore.LookupEntry(sObjectMgr->GetCreatureDisplay(model_id)))
SetDisplayId(model_id);
}
// END


Did not test, but should work... However this only morph player on equip and doesnt demorph on unequip...
Title: Re: [QUESTION] Morphing item
Post by: bizzlesnaff on July 03, 2015, 03:35:41 am
Is  there maybe a solution with smartscripts?
I remember one item, which do exact the thing you are looking for.
The ID should be 17142 [Shard of the Defiler]. This sword morph you into a demon, and demorph you after remove the item.
But the Item has no script in the database...so I'm confused..:)


edit:

oh..my bad. This sword just use a spell on the player...nevermind :(
Title: Re: [QUESTION] Morphing item
Post by: Ascathos on July 03, 2015, 01:26:04 pm
Quote from: "Daweo"
For TrinityCore 3.3.5a the solution could be:

SQL table in world database:
Code: [Select]
CREATE TABLE IF NOT EXISTS `item_morph` (
`item_id` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0',
`morph_id` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0',
PRIMARY KEY (`item_id`)
)
COMMENT='Item Morph system'
COLLATE='utf8_general_ci'
ENGINE=MyISAM;


C++ code in Player.cpp:
Code: [Select]
Item* Player::EquipItem(uint16 pos, Item* pItem, bool update)
{
.
.
.
ApplyEquipCooldown(pItem2);

// Item Morph
QueryResult result = WorldDatabase.PQuery("SELECT model_id FROM item_morph WHERE item_id = %u", pItem2->GetEntry());

if (result)
{
Field* fields = result->Fetch();
uint32 model_id = fields[0].GetUInt32();

if (sCreatureDisplayInfoStore.LookupEntry(sObjectMgr->GetCreatureDisplay(model_id)))
SetDisplayId(model_id);
}
// END

return pItem2;
    }
.
.
.
UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_EQUIP_EPIC_ITEM, pItem->GetEntry(), slot);

// Item Morph
QueryResult result = WorldDatabase.PQuery("SELECT model_id FROM item_morph WHERE item_id = %u", pItem->GetEntry());

if (result)
{
Field* fields = result->Fetch();
uint32 model_id = fields[0].GetUInt32();

if (sCreatureDisplayInfoStore.LookupEntry(sObjectMgr->GetCreatureDisplay(model_id)))
SetDisplayId(model_id);
}
// END

return pItem;
}
.
.
.
void Player::QuickEquipItem(uint16 pos, Item* pItem)
{
.
.
.
UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_EQUIP_EPIC_ITEM, pItem->GetEntry(), slot);

// Item Morph
QueryResult result = WorldDatabase.PQuery("SELECT model_id FROM item_morph WHERE item_id = %u", pItem->GetEntry());

if (result)
{
Field* fields = result->Fetch();
uint32 model_id = fields[0].GetUInt32();

if (sCreatureDisplayInfoStore.LookupEntry(sObjectMgr->GetCreatureDisplay(model_id)))
SetDisplayId(model_id);
}
// END


Did not test, but should work... However this only morph player on equip and doesnt demorph on unequip...
A cleaner execution would be creating a new spell and have it morph.
Title: Re: [QUESTION] Morphing item
Post by: Смердокрыл on July 03, 2015, 06:23:14 pm
Quote from: "Ascathos"
A cleaner execution would be creating a new spell and have it morph.
We've aready came up with this and now Im trying to get my noobish brain understand the spell.dbc structure.

p.s. Please dont make quotes be 99% of your comment, especially when theyre that large)