Jump to content
TrinityCore

Caster NPC - C++ script or Smart Scripts not working


Axdrell
 Share

Recommended Posts

Hi,

I am trying to make a novice shaman NPC (from echo isles area) attack the tikki target with a lightning bolt (spell 20802). I have tried using a Smart Script and C++ script (see below) but no luck. I looked at other scripts provided within the trinitycore source code for guidance. Yet, I am not able to get the NPC to attack the target. Below is a sample class with the intended actions scripts. Neither is working. I am able to create Smart scripts using cosmetic spells with no problem. However, the cosmetic spells do not provide the spells and the rotation I want to use. Any help you can provide is  greatly appreciated. I am able to compile the code below without errors. The C++ creature script has also been assigned to the NPC (server restarted of course). I tried creating this script in the latest version of trinitycore (shadowlands) and older trinitycore code (legion, BFA, etc).

Thanks so much.

Is it a limitation of the Wow Client?

#include "ScriptMgr.h"
#include "ScriptedCreature.h"

enum Spells
{
    SPELL_LIGHTNINGBOLT = 20802,
    SPELL_HEALINGWAVE = 72014,
    SPELL_FLAMESHOCK = 58940,
    //TESTING
    SPELL_CHAINHEAL = 72014,  //NPC=38326 - Darkspear Shaman
    SPELL_BOLT = 73212
};

 enum Events
{
    EVENT_LIGHTNINGBOLT = 1,
    EVENT_HEALINGWAVE = 2,
    EVENT_FLAMESHOCK = 3
};

enum Creatures
{
    HIT_TARGET    = 38038
};

class npc_shaman_trainee : public CreatureScript // Used by the Darkspear Shaman Novice trainee to attack a tiki practice target.
{
    public:
        npc_shaman_trainee() : CreatureScript("npc_shaman_novice") { }
        
        CreatureAI* GetAI(Creature* creature) const override
        {
            return new npc_shaman_traineeAI(creature);
        }
        
        struct npc_shaman_traineeAI : public ScriptedAI
        {
            npc_shaman_traineeAI(Creature* creature) : ScriptedAI(creature)
            {
            }
            
            EventMap events;

            void Reset() override
            {
                //_Reset();
                events.Reset();
                if (Creature* target = me->FindNearestCreature(38038, 50.0f))
                me->CastSpell(target, SPELL_LIGHTNINGBOLT, true);
            }
            
            void EnterCombat(Unit* /*who*/) override
            {
                events.ScheduleEvent(EVENT_LIGHTNINGBOLT, 8000);
                events.ScheduleEvent(EVENT_HEALINGWAVE, 12000);
                events.ScheduleEvent(EVENT_FLAMESHOCK , 10000);
            }
            
            void KilledUnit(Unit * /*victim*/) override
            {
            }
            
            void JustDied(Unit * /*victim*/) override
            {
            }

            void UpdateAI(uint32 diff) override
            {
                if (!UpdateVictim())
                    return;
                    
                events.Update(diff);

               // if (me->HasUnitState(UNIT_STATE_CASTING))
               //     return;
                    
                while (uint32 eventId = events.ExecuteEvent())
                {
                    switch (eventId)
                    {
                        case EVENT_LIGHTNINGBOLT:
                            if (Creature* target = me->FindNearestCreature(HIT_TARGET,525.0f,true))
                            {
                                if (me->GetVictim() == target)
                                {
                                //if (Unit *target = SelectTarget(SELECT_TARGET_RANDOM, 1))
                                DoCast(target, SPELL_LIGHTNINGBOLT, true);
                                }
                                events.ScheduleEvent(EVENT_LIGHTNINGBOLT, 8000);
                            }
                            break;
                            
                        case EVENT_HEALINGWAVE:
                            DoCast(me, SPELL_HEALINGWAVE);
                            events.ScheduleEvent(EVENT_HEALINGWAVE, 12000);
                            break;
                            
                        case EVENT_FLAMESHOCK:
                            if (Creature* target = me->FindNearestCreature(HIT_TARGET, 525.0f,true))
                            {
                            //if (Unit *target = SelectTarget(SELECT_TARGET_RANDOM, 1))
                            DoCast(target, SPELL_FLAMESHOCK, true);
                            }
                            events.ScheduleEvent(EVENT_FLAMESHOCK, 10000);
                            break;
                    }
                }
                
                DoMeleeAttackIfReady();
            }
        };
};

 

 

class npc_test : public CreatureScript
{
public:
    npc_test() : CreatureScript("npc_test") { }

    CreatureAI* GetAI(Creature* creature) const override
    {
        return new npc_testAI(creature);
    }

    struct npc_testAI : public ScriptedAI
    {
        npc_testAI(Creature* creature) : ScriptedAI(creature)
        {
            instance = creature->GetInstanceScript();
        }
        InstanceScript *instance;
        EventMap events;

        void Reset() override
        {
            events.Reset();
        }

        void EnterCombat(Unit* /*who*/) override
        {
            if (Creature* thrall = me->FindNearestCreature(38038, 100.0f, true))
                thrall->SetReactState(REACT_AGGRESSIVE);
            events.ScheduleEvent(EVENT_LIGHTNINGBOLT, urand(2000, 5000));
        }

        void JustDied(Unit* /*Kill*/) override
        {
          
        }

        void UpdateAI(uint32 diff) override

        {
            events.Update(diff);

            if (me->HasUnitState(UNIT_STATE_CASTING))
                return;

            while (uint32 eventId = events.ExecuteEvent())
            {
                switch (eventId)
                {
                    case EVENT_LIGHTNINGBOLT:
                        if (Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0))
                        {
                            me->CastSpell(target, SPELL_LIGHTNINGBOLT, false);
                        }
                        events.ScheduleEvent(EVENT_LIGHTNINGBOLT, urand(12000, 15000));
                        break;
                }
            }

            DoMeleeAttackIfReady();
        }
    };

};

 

void AddSC_GameAreaNPCS()
{
    new npc_shaman_trainee();
    new npc_test();
}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...