• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

TrinityCore 3.3.5 Pet cast same spell as its owner

Intouch

Respected Member
I am trying to code a script which will let my pet (guardian) to cast the exact same (specific) spell I cast. Just pet will cast that spell on its target.

I tried to code some custom scripts in pet scripts for it but it didn't worked well at all.

So for instance, if player cast spell with spell id 12345 or spell id 54321, then pet has to cast it on its own target. If spell is not matching any of that spell ids then it should do nothing.

Any ideas?

~ Sincerely, Intouch!

P.S: For some reason it detected my core as mangos and I wasn't able to edit it so I put "TrinityCore 3.3.5" in topic name.
 
Last edited:

MrPixelMC

Member
This is probably not the best way to do it but it will most likely work:
Make a PlayerScript, and use OnPlayerSpellCast, make a switch with spell ID and use cases to check if the spell the player casted must be cast by Pet too or not. If it is, then do:
Code:
Pet* pet = player->GetPet();
if (pet)
{
   pet->CastSpell(pet->GetVictim(), spell);
}
You might want to add a few other if checks and/or modify to fit your needs, that's up to you.
I didn't test this, so I don't know if it will work, but I believe it should.
 

Intouch

Respected Member
I tried something like this and I couldn't get it working at all (errors):

Code:
class spell_clone_test : public PlayerScript
{
public:
	spell_clone_test() : PlayerScript("spell_clone_test") {}

    void OnPlayerSpellCast(Player* player, Spell* spell, bool skipCheck)
    {
        Pet* pet = player->GetPet();

        if (!player)
            return;

        if (!pet)
            return;

        [COLOR="#FF0000"]switch (player->GetSpellInfo()->Id)[/COLOR] -- // PROBLEM HERE
        {
            case 12345: // test spell #1
                pet->CastSpell(pet->GetVictim(), 12345);
                break;
            case 54321: // test spell #2
                pet->CastSpell(pet->GetVictim(), 54321);
                break;
            default:
                break;
        }
    }
};
 

MrPixelMC

Member
I tried something like this and I couldn't get it working at all (errors):

Code:
class spell_clone_test : public PlayerScript
{
public:
	spell_clone_test() : PlayerScript("spell_clone_test") {}

    void OnPlayerSpellCast(Player* player, Spell* spell, bool skipCheck)
    {
        Pet* pet = player->GetPet();

        if (!player)
            return;

        if (!pet)
            return;

        [COLOR="#FF0000"]switch (player->GetSpellInfo()->Id)[/COLOR] -- // PROBLEM HERE
        {
            case 12345: // test spell #1
                pet->CastSpell(pet->GetVictim(), 12345);
                break;
            case 54321: // test spell #2
                pet->CastSpell(pet->GetVictim(), 54321);
                break;
            default:
                break;
        }
    }
};

Don't use "player->GetSpellInfo()->Id", notice how OnPlayerSpellCast already has "Spell* spell" declared, which means you can directly use "spell".
 

Intouch

Respected Member
Tried to change it to:

Code:
switch (player->spell)

and to

Code:
switch (spell)

but it didn't worked

Can you give me example, please?
 

MrPixelMC

Member
Tried to change it to:

Code:
switch (player->spell)

and to

Code:
switch (spell)

but it didn't worked

Can you give me example, please?

Tested and working:
Code:
	void OnSpellCast(Player* player, Spell* spell, bool /* skipCheck */)
	{
		if (!player)
			return;

		uint32 spellID = spell->GetSpellInfo()->Id;
		switch (spellID)
		{
                // Add all spells you want the pet to copy here
		case 18381:
		case 30513:
			Pet* pet = player->GetPet();

			if (pet)
			{
				pet->CastSpell(pet->GetVictim(), spellID);
			}
			break;

		default:
			break;
		}
	}

Explanation:
When player casts spell, OnSpellCast gets triggered, we use spell->GetSpellInfo()->Id to retrieve the ID of the spell and store it in a variable for easier use. then create a switch with spellID so you can manage which spells get copied, you do not have to put the code in each case, if you put all cases and then the code it works correctly. If the spell matches a case, then we check if player has pet, if player does have pet then pet casts the spell at his own victim (this means player's victim does not necessarily have to be the same as pet's victim).
 
Top