• 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-Multi Trinity Core shared boss health

merudin

New member
I'm writing a custom script and I have problems with shared boss hp. Basicaly I do not know how to make 2 npcs share health. So if someone is willing to help me it would be awesome :).
 

Rochet2

Moderator / Eluna Dev
Sharing health in itself may not be completely trivial thing because the NPCs can have different debuffs applied to them and both in practice need to keep a separate health pool.
You should try different approaches for where you keep the actual health they have or how you manage what is the real health of the NPCs.

Here is one example:
You need to create the NPCs with the same health.
Then make an CreatureScript for them in C++.
Then in the script you should make the creatures know each other in one way or another. For example by storing the guids in the instance script or by making the creatures know each other's database guids
or by making them know each other's entries so they can make a search etc etc etc.
Then use the damage hook: void OnDamage(Unit* /*attacker*/, Unit* /*victim*/, uint32& /*damage*/) { }
and in it you can search for the NPCs and damage both of them with the given damage. Also it might be a good idea to do something like:
A, B = GetCreatures()
A:Damage(damage)
B:Damage(damage)
hp = std::min(A:GetHealth(), B:GetHealth())
A:SetHealth(hp)
B:SetHealth(hp)
Or similar to ensure they have the same health. - Note that Im unsure how such would work when one of the NPCs dies for example.
 

MrPixelMC

Member
Take a look at Illidari Council's code, I believe it gets the guids of the 4 NPCs, stores them and shares damage (damage / 4) between them. This is the part you should be looking at to get an idea how to do it:
Code:
    void DamageTaken(Unit* done_by, uint32 &damage) override
    {
        if (done_by == me)
            return;

        damage /= 4;
        for (uint8 i = 0; i < 4; ++i)
        {
            if (Creature* unit = ObjectAccessor::GetCreature(*me, Council[i]))
                if (unit != me && damage < unit->GetHealth())
                {
                    unit->ModifyHealth(-int32(damage));
                    unit->LowerPlayerDamageReq(damage);
                }
        }
    }
 
Top