This is a read only copy without any forum functionality of the old Modcraft forum.
If there is anything that you would like to have removed, message me on Discord via Kaev#5208.
Big thanks to Alastor for making this copy!

Menu

Author Topic: [Solved][C++] c++ NPC-Script problem  (Read 1293 times)

bizzlesnaff

  • Registred Member
  • Wiki Incarnate
  • *****
  • Posts: 124
    • View Profile
[Solved][C++] c++ NPC-Script problem
« on: March 16, 2015, 04:49:35 pm »
Hey folks,

in the last two days I worked more with c++ and now I'm a little bit confused. I saw many tutorials on youtube and other websites and everytime, when the npc should say something they use the code:
Quote
 
me->MonsterYell("TEXT", LANG_UNIVERSAL, NULL);
or
me->MonsterSay("TEXT2", LANG_UNIVERSAL, NULL);

But if i use it for my server i get an error while i'm compiling

Quote
 
error C2039: 'MonsterYell': Is not an element of 'creature'
 or
error C2039: 'getVictim': Is not an element of 'creature'


I have no idea how to fix it, or which code i can use.
Maybe if it help, my whole npc script. Not written by me, just copied.
Quote
     
#include "ScriptPCH.h"
#pragma warning(disable:4373)
enum Spells
{
    // List of spells.
    // Not required to define them in this way, but will make it easier to maintain in case spellId change

    SPELL_SHADOWBOLT = 70281,
    SPELL_DOOM = 64157,
    SPELL_SUMMON = 71031,
    //Transform to Bonelord
    SPELL_TRANSFORM = 72498,
    //Melee Form Abilities
    SPELL_SOULSTRIKE = 70211,
    SPELL_NECROTICSTRIKE = 70659,
    SPELL_ICYTOUCH = 66021,
    SPELL_FRENZY = 47774,
    //Global Abilities
    SPELL_MIGHT = 74507


};




//List of gossip item texts. Items will appear in the gossip window.


class Boss_Forgotten_AmirThezad : public CreatureScript
{
    public:


        Boss_Forgotten_AmirThezad()
            : CreatureScript("Boss_Forgotten_AmirThezad")
        {
        }


        struct Boss_Forgotten_AmirThezadAI : public ScriptedAI
        {
            // *** HANDLED FUNCTION ***
            //This is the constructor, called only once when the Creature is first created
            Boss_Forgotten_AmirThezadAI(Creature* creature) : ScriptedAI(creature) {}


            // *** CUSTOM VARIABLES ****
            //These variables are for use only by this individual script.
            //Nothing else will ever call them but us.
            uint32 Shadowbolt_Timer;
            uint32 Doom_Timer;
            uint32 Summon_Timer;
            uint32 Transform_Timer;
            uint32 Soulstrike_Timer;
            uint32 Necroticstrike_Timer;
            uint32 Icytouch_Timer;
            uint32 Frenzy_Timer;
            uint32 Phase;


            // *** HANDLED FUNCTION ***
            //This is called after spawn and whenever the core decides we need to evade
            void Reset()
            {
                 Phase = 1;
                Shadowbolt_Timer = 5000;
                Doom_Timer = 16000;
                Summon_Timer = 45000;
                Soulstrike_Timer = 8000;
                Necroticstrike_Timer = 4000;
                Icytouch_Timer = 13000;
                Transform_Timer = 0;
                Frenzy_Timer = 9000;
            }




            // *** HANDLED FUNCTION ***
            // Enter Combat called once per combat
            void EnterCombat(Unit* who)
            {
                //Say some stuff
                me->MonsterYell("Ich werde euch vernichten!", LANG_UNIVERSAL, NULL);
            }


            // *** HANDLED FUNCTION ***
            // Attack Start is called when victim change (including at start of combat)
            // By default, attack who and start movement toward the victim.
            //void AttackStart(Unit* who)
            //{
            //    ScriptedAI::AttackStart(who);
            //}


            // *** HANDLED FUNCTION ***
            // Called when going out of combat. Reset is called just after.
            void EnterEvadeMode()
            {

            }


            // *** HANDLED FUNCTION ***
            //Our Receive emote function


            // *** HANDLED FUNCTION ***
            //Update AI is called Every single map update (roughly once every 50ms if a player is within the grid)
            void UpdateAI(const uint32 uiDiff)
            {
                //Out of combat timers
                if (!me->getVictim())
                {




                }


                //Return since we have no target
                if (!UpdateVictim())
                    return;
                if (((me->GetHealth()*100 / me->GetMaxHealth()) < 50) && (Phase == 1))
                    {
                        me->MonsterYell("Raaaargh....ich...verändere...mich..", LANG_UNIVERSAL, NULL);
                        Phase = 2;
                    }
                if (((me->GetHealth()*100 / me->GetMaxHealth()) < 47) && (Phase == 2))
                {
                    Phase = 3;
                }
                if (((me->GetHealth()*100 / me->GetMaxHealth()) < 1) && (Phase == 3))
                {
                    Phase = 4;
                    me->MonsterYell("Ich...bin...verloren...Ich habe euch...enttäuscht, mein Meister!", LANG_UNIVERSAL, NULL);
                }
                        if (Phase == 1)
                        {
                            if (Shadowbolt_Timer <= uiDiff)
                            {
                                if (Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0))
                                DoCast(target, SPELL_SHADOWBOLT);
                                Shadowbolt_Timer = 5000;
                            }
                            else
                                Shadowbolt_Timer -= uiDiff;




                            if (Doom_Timer <= uiDiff)
                            {


                            if (Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0))
                            DoCast(target, SPELL_DOOM);

                            Doom_Timer = 16000;
                            }
                            else Doom_Timer -= uiDiff;



                            if (Summon_Timer <= uiDiff)
                            {
                                DoCast(me->getVictim(), SPELL_SUMMON);
                                Summon_Timer = 45000;
                            }
                            else
                                Summon_Timer -= uiDiff;
                        }


                        if(Phase == 2)
                        {
                            if (Transform_Timer <= uiDiff)
                            {
                            DoCast(me->getVictim(), SPELL_TRANSFORM);
                            Transform_Timer = 45000;
                            }
                            else Transform_Timer -= uiDiff;
                        }
                        if(Phase == 3)
                        {
                            if (Frenzy_Timer <= uiDiff)
                            {
                                DoCast(me, SPELL_FRENZY);
                                Frenzy_Timer = 9000;
                            }
                            else Frenzy_Timer -= uiDiff;
                            if (Soulstrike_Timer <= uiDiff)
                            {
                            DoCast(me->getVictim(), SPELL_SOULSTRIKE);
                            Soulstrike_Timer = 8000;
                            }
                                        else
                                            Soulstrike_Timer -= uiDiff;
                            if (Necroticstrike_Timer <= uiDiff)
                            {
                            DoCast(me->getVictim(), SPELL_NECROTICSTRIKE);
                            Necroticstrike_Timer = 4000;
                            }
                                        else
                                            Necroticstrike_Timer -= uiDiff;
                        if (Icytouch_Timer <= uiDiff)
                            {


                            if (Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0))
                            DoCast(target, SPELL_ICYTOUCH);

                            Icytouch_Timer = 13000;
                            }
                            else Icytouch_Timer -= uiDiff;
                        }





                DoMeleeAttackIfReady();
            }
        };


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




};


//This is the actual function called only once durring InitScripts()
//It must define all handled functions that are to be run in this script
void AddSC_Boss_Forgotten_AmirThezad()
{
    new Boss_Forgotten_AmirThezad();
}


No spoiler function here?
« Last Edit: May 03, 2015, 12:31:08 pm by Admin »

Kaev

  • Contributors
  • Creator of Worlds
  • *****
  • Posts: 308
    • View Profile
Re: [C++] c++ NPC-Script problem
« Reply #1 on: March 18, 2015, 07:46:04 am »
creature->MonsterYell, creature->MonsterSay, creature->MonsterWhisper etc. doesn't exist anymore.
You should use creature->Yell, creature->Say, creature->Whisper and so on. Just remove the Monster. :)

Do you need the getVictim stuff? It's empty, so you could delete it.
Otherwise, it could be just GetVictim() instead of me->getVictim() now, but i'm not sure about this and can't test it right now.
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

Ascathos

  • Moderators
  • Creator of Worlds
  • *****
  • Posts: 1129
    • View Profile
Re: [C++] c++ NPC-Script problem
« Reply #2 on: March 19, 2015, 12:33:32 pm »
Remove the getVictim(). Keep it was me, because you want the boss as target.

Also, TC switched completey to the CamelCase-Naming.
error C2039: 'getVictim': Is not an element of 'creature'
getVictim has to be GetVictim().
« Last Edit: January 01, 1970, 01:00:00 am by Admin »