User Tag List

Results 1 to 3 of 3

Thread: Trinity Core shared boss health

  1. #1
    Lurking Member
    Join Date
    Sep 2016
    Posts
    1
    XP
    13
    Level
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Trinity Core shared boss health

    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 :).

  2. #2
    Moderator / Eluna Dev <span style='color: #FF0000'><span class='glow_8B0000'>Rochet2</span></span>'s Avatar
    Join Date
    Apr 2013
    Location
    Finland
    Posts
    1,860
    XP
    13,531
    Level
    35
    Thanks
    95
    Thanked 592 Times in 419 Posts
    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.
    Awards:
    Support LOL Scripter Facepalm! Raffle Winner
    rochet2.github.io - Home of great codes

  3. #3
    Member MrPixelMC's Avatar
    Join Date
    Oct 2016
    Location
    Spain
    Posts
    44
    XP
    234
    Level
    2
    Thanks
    0
    Thanked 10 Times in 10 Posts
    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);
                    }
            }
        }
    Achievements:
    Member Level II 31 days registered
    Stay classy.


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •