16
Serverside Modding / [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:
But if i use it for my server i get an error while i'm compiling
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.
No spoiler function here?
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?