Forum > Serverside Modding

[QUESTION:WotlK] Changes for custom pets

<< < (2/3) > >>

Ascathos:
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 ?

cata123:
It`s part of beastmaster script:


--- Code: ---    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();
--- End code ---

Ascathos:

--- Code: ---    // 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();
--- End code ---

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.

cata123:
I don`t understand.
I removed the Hunter class check in pet.cpp :


--- Code: ---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;
        }
    }

--- End code ---
so that is any class have a pet, it`s a hunter pet.

schlumpf:
Please use code tags.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version