Modcraft - The community dedicated to quality WoW modding!

Wrath of the Lich King Modding => Serverside Modding => Topic started by: cata123 on September 30, 2015, 09:40:41 pm

Title: [QUESTION:WotlK] Changes for custom pets
Post by: cata123 on September 30, 2015, 09:40:41 pm
Hello.
I wanted to ask if someone made this before : What changes must be done in order to add a custom pet.
Custom pet i mean hunter type pet (with spells, eventually talents, talents that also i need to find out how to make the scheme).
The pets i intend to make can be another class also (demon, humanoid, even player models).
For the pet it will automatically make use of its added spells in combat ?
And last question - Where can i find the default stats for a creature / pet (str,agi,int) ?
Title: Re: [QUESTION:WotlK] Changes for custom pets
Post by: Morfium on October 05, 2015, 07:07:03 pm
I think you can just set the pet to "tameable".
I added exotic taming to 2.4.3 ages ago by just checking for the last beast master talent in the tree and then allowed taming those pets in the core. But the only core changes I did were to prevent every hunter from taming it and only allow beastmasters.
I'm aware there were several changes since 2.4.3 but I'd just try to set your desired pet to tamable. If you get an invalid target error on humanoids I'd look in spell.dbc if your taming spell is limited on targeting those, or in spell.cpp (old Mangos names) check SPELL_EFFECT_TAMECREATURE. Not sure if trinity still uses those names...
Title: Re: [QUESTION:WotlK] Changes for custom pets
Post by: cata123 on October 07, 2015, 12:56:01 am
Thanks for answer. I`m looking for the code where it defines which class should have pets.
And pet default status I can`t find where is defined.
Title: Re: [QUESTION:WotlK] Changes for custom pets
Post by: Ascathos on October 07, 2015, 04:47:03 am
Quote from: "cata123"
Thanks for answer. I`m looking for the code where it defines which class should have pets.
And pet default status I can`t find where is defined.
I doubt there is code for that. Only approperiate spells allow to take pets. It kind of takes the sense of writing specific code to tame. E.g., if iirc, there is a quest in the orc/troll starter area that allows you to charm a pet (or, at least, make it friendly to you).

But yeah. You could, for example, write a spellscript for a specific spell (or even the regular tame spell) that certain pets require e.g. a talent. A list containing every pet entry, a check for the class and talent and you are good to go.
Title: Re: [QUESTION:WotlK] Changes for custom pets
Post by: cata123 on October 07, 2015, 05:54:00 pm
I have a custom beastmaster that adds pets to non hunter players, eventually to add custom ones, but i see the pets do not benefit for upgrades (HP, DPS, armors), that`s why i`m looking for the part where pet status is defined, or from where it comes from.
As for the code, i found in Pet.cpp from TrinityCore, at line 841:

Code: [Select]
   //Determine pet type
    PetType petType = MAX_PET_TYPE;
    if (IsPet() && GetOwner()->GetTypeId() == TYPEID_PLAYER)
    {
        if (GetOwner()->getClass() == CLASS_WARLOCK
            || GetOwner()->getClass() == CLASS_SHAMAN        // Fire Elemental
            || GetOwner()->getClass() == CLASS_DEATH_KNIGHT) // Risen Ghoul
        {
            petType = SUMMON_PET;
        }
        else if (GetOwner()->getClass() == CLASS_HUNTER)
        {
            petType = HUNTER_PET;
            m_unitTypeMask |= UNIT_MASK_HUNTER_PET;
        }
        else
        {
            TC_LOG_ERROR("entities.pet", "Unknown type pet %u is summoned by player class %u",
                           GetEntry(), GetOwner()->getClass());
        }
    }
Title: Re: [QUESTION:WotlK] Changes for custom pets
Post by: Ascathos on October 09, 2015, 01:57:01 am
Ugh. I have to look further into the code for that kind of information.

I'll look into it and give feedback.

EDIT:

Could you sample how you add the pet to the hunter ?
Title: Re: [QUESTION:WotlK] Changes for custom pets
Post by: cata123 on October 09, 2015, 11:01:30 am
It`s part of beastmaster script:

Code: [Select]
   Creature *creatureTarget = m_creature->SummonCreature(entry, player->GetPositionX(), player->GetPositionY()+2, player->GetPositionZ(), player->GetOrientation(), TEMPSUMMON_CORPSE_TIMED_DESPAWN, 500);
    if(!creatureTarget) return;

    Pet* pet = player->CreateTamedPetFrom(creatureTarget, 0);

    if(!pet) return;

        // kill original creature
    creatureTarget->setDeathState(JUST_DIED);
    creatureTarget->RemoveCorpse();
    creatureTarget->SetHealth(0);

    pet->SetPower(POWER_HAPPINESS, 1048000);

    // prepare visual effect for levelup
    pet->SetUInt32Value(UNIT_FIELD_LEVEL, player->getLevel() - 1);
    pet->GetMap()->AddToMap((Creature*)pet);
        // visual effect for levelup
    pet->SetUInt32Value(UNIT_FIELD_LEVEL, player->getLevel());

    if(!pet->InitStatsForLevel(player->getLevel()))
        TC_LOG_ERROR("scripts", "Pet Create fail: no init stats for entry %u", entry);
        pet->UpdateAllStats();

    // caster have pet now
        player->SetMinion(pet, true);

        pet->SavePetToDB(PET_SAVE_AS_CURRENT);
        pet->InitTalentForLevel();
        player->PetSpellInitialize();
Title: Re: [QUESTION:WotlK] Changes for custom pets
Post by: Ascathos on October 09, 2015, 01:27:06 pm
Code: [Select]
   // Summon creature. If this fails for some reason, cancel function
    Creature* creatureTarget = m_creature->SummonCreature(entry, player->GetPositionX(), player->GetPositionY()+2, player->GetPositionZ(), player->GetOrientation(), TEMPSUMMON_CORPSE_TIMED_DESPAWN, 500);
    if (!creatureTarget)
        return;

    // Create a tamed pet out of previously summoned creature. If this fails, cancel function.
    Pet* pet = player->CreateTamedPetFrom(creatureTarget, 0);

    if (!pet)
    {
        // We have to make sure that these summons are not abused for some reason. Remove them.
        creatureTarget->setDeathState(JUST_DIED);
        creatureTarget->RemoveCorpse();
        creatureTarget->SetHealth(0);
        return;
    }
   
    // If pet creation was successful, remove the original creature.
    creatureTarget->setDeathState(JUST_DIED);
    creatureTarget->RemoveCorpse();
    creatureTarget->SetHealth(0);

    // Creature was successfully summoned. We can set it as pet now.
    player->SetMinion(pet, true);
   
    // Set happiness level for newly summoned creature
    pet->SetPower(POWER_HAPPINESS, 1048000);

    // prepare visual effect for levelup
    pet->SynchronizeLevelWithOwner();
   
    pet->GetMap()->AddToMap((Creature*)pet);
    // visual effect for levelup


    if (!pet->InitStatsForLevel(pet->getLevel()))
        TC_LOG_ERROR("scripts", "Pet Create fail: no init stats for entry %u", entry);
   
    pet->UpdateAllStats();

    pet->SavePetToDB(PET_SAVE_AS_CURRENT);
    pet->InitTalentForLevel();
    player->PetSpellInitialize();

There. A bit cleaner.


It fails in Guardian::InitStatsForLevel(uint8 petlevel)
You need to add to the class check to make sure it's approperiate.
Title: Re: [QUESTION:WotlK] Changes for custom pets
Post by: cata123 on October 09, 2015, 02:27:34 pm
I don`t understand.
I removed the Hunter class check in pet.cpp :

Code: [Select]
if (GetOwner()->getClass() == CLASS_WARLOCK
            || GetOwner()->getClass() == CLASS_SHAMAN        // Fire Elemental
            || GetOwner()->getClass() == CLASS_DEATH_KNIGHT) // Risen Ghoul
        {
            petType = SUMMON_PET;
        }
        else
        {
            petType = HUNTER_PET;
            m_unitTypeMask |= UNIT_MASK_HUNTER_PET;
        }
    }
so that is any class have a pet, it`s a hunter pet.
Title: Re: [QUESTION:WotlK] Changes for custom pets
Post by: schlumpf on October 09, 2015, 02:50:42 pm
Please use code tags.
Title: Re: [QUESTION:WotlK] Changes for custom pets
Post by: cata123 on October 10, 2015, 03:33:17 pm
Well, looks like seems to work correctly now, stats seem fine for all non-hunter classes.
Title: Re: [QUESTION:WotlK] Changes for custom pets
Post by: Ascathos on October 10, 2015, 03:44:48 pm
Quote from: "cata123"
Well, looks like seems to work correctly now, stats seem fine for all non-hunter classes.
Alright, glad to hear that. Note any more issues if there comes one up.