C++ TuT Creature AI. menu

User Tag List

Results 1 to 10 of 10
  1. #1
    Found's Avatar Banned
    Reputation
    239
    Join Date
    Mar 2009
    Posts
    642
    Thanks G/R
    1/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    C++ TuT Creature AI.

    Ok guys i found this phenomanal tut on creature AI, greatest thing ever.
    Please please please give credits to Alvanaar. GL!


    PART1



    Hi there, everyone! This is my tutorial on Creature AIs.

    In this tutorial I'll teach you a way to program a creature AI using C++.

    I will be keeping this tutorial updated. If you have any requests, questions, or need more explaining. Please say so!

    Please note: I have only just finished making this tutorial and I know it may have some mistakes in it. Please alert me of any.

    What you need:

    - Microsoft Visual C++

    - Skillz



    Introduction

    AI stands for Artificial Intelligence. Creature combat scripts are known in C++ as Creature AIs.
    This is what I'll be teaching you about in this tutorial.



    Scripting Your C++ Creature AI

    Create a .cpp file (C++ Source File) in Microsoft Visual C++.

    We'll start our creature AI with the following code:


    Code:
    Code:
    
    #include "StdAfx.h"
    #include "Setup.h"
    As I've stated in my gossip NPC tutorial, this tells the C++ compiler to include the two external files, StdAfx.h and Setup.h in this script.

    (A "#" is a preprocessor symbol and tells the C++ compiler to do whatever comes after it before compiling).

    Next comes this :

    Code:
    Code:
    
    class CreatureAI : CreatureAIScript
    {
    public:
    	ADD_CREATURE_FACTORY_FUNCTION(CreatureAI);
    	CreatureAI(Creature* pCreature) : CreatureAIScript(pCreature)
     	{
     	}
    
    protected:
    
    };


    We'll fill this in a bit more later. But, basically, what this "class" means is that it is naming the script "CreatureAI" (you can change it but it will be used later, so I recommend keeping it as it is) and in between the brackets later we will include some other functions. Don't worry about the spells yet.

    We'll then put this below that in our script:


    Code:
    Code:
    Code:
    
    	void OnCombatStart(Unit* mTarget)
    	{
            
    	}
    	
    	
    	void OnCombatStop(Unit *mTarget)
    	{
    
    	}
    	
    	void OnDied(Unit * mKiller)
    	{
    
    	}
    	
    	void AIUpdate()
    	{
    
    	}
    	
    	void SpellCast(uint32 val)
    	{
     
    	}
    
    These are our basic "functions" or "voids". Pretty friggin' self explanatory .

    We're going to tackle this one void at a time...


    Creature On Combat

    We're going to start scripting our creature AI with the OnCombatStart void:

    Code:
    Code:
    
    	void OnCombatStart(Unit* mTarget)
    	{
    
    	}
    We're going to make this NPC start its combat phase with a chat message. But we don't want it to be boring, so we'll change things up a little.
    We'll randomise it. And, in this case, I'm going to give the NPC a 50% chance to say a message, 50% chance to not. So we put this:

    Code:
    Code:
    
    void OnCombatStart(Unit* mTarget)
    	{
    		int RandomChance;
    		RandomChance = rand()%4;
    			switch(RandomChance)
    			{
    			case 0:
    				_unit->SendChatMessage(CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, "I am saying a chat message! Hoorahh!");
    				break;
    			case 1:
    				_unit->SendChatMessage(CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, "I am saying a chat message! Hoorahh!");
    				break;
    			case 2:
    				break;
    			case 3:
    				break;
    	}
    }
    What the hell does this all mean? I'll break it down for you all. From top to bottom...

    The "int" in "int RandomChance;" means that whatever follows that "int" is an integer. An "int" integer can only be a certain amount of bytes. But don't worry about that.

    The "RandomChance" after "int" is just the name of my integer. On the next line of the script, we define what this integer is.

    RandomChance = rand()%4; is saying that there is a 1 in 4 chance for this script to perform a certain function. As you can see, there is our "RandomChance" integer at the start of it.

    This part of the script: switch(RandomChance) tells the C++ engine to show all the "cases" (or "intids" in Lua) for our "RandomChance" integer.

    case 0: is just the first case or "intid". What comes below it is what happens on the 25% chance.

    [code]_unit->SendChatMessage(CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, "I am saying a chat message! Hoorahh!"); is pretty self explanatory.
    It makes the NPC send a chat message (which is "Yell" in this case, for say, change CHAT_MSG_MONSTER_YELL to "CHAT_MSG_MONSTER_YELL"). The language is "LANG_UNIVERSAL" (which is universal). The chat message in this case is "I am saying a chat message! Hoorahh!"

    The code break; used in this part of the script just tells the C++ engine that the case is over. No more actions will be performed in that case.


    Your script should look something like this so far

    Code:
    Code:
    
    #include "StdAfx.h"
    #include "Setup.h"
    
    class CreatureAI : CreatureAIScript
    {
    public:
    	ADD_CREATURE_FACTORY_FUNCTION(CreatureAI);
    	CreatureAI(Creature* pCreature) : CreatureAIScript(pCreature)
     	{
     	}
    
    protected:
    
    };
    
    
    	void OnCombatStart(Unit * mTarget)
    	{
    		int RandomChance;
    		RandomChance = rand()%4;
    			switch(RandomChance)
    			{
    			case 0:
    				_unit->SendChatMessage(CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, "I am saying a chat message! Hoorahh!");
    				break;
    			case 1:
    				_unit->SendChatMessage(CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, "I am saying a chat message! Hoorahh!");
    				break;
    			case 2:
    				break;
    			case 3:
    				break;
    	}
    }
    	void OnCombatStop(Unit * mTarget)
    	{
    
    	}
    	
    	void OnDied(Unit * mKiller)
    	{
    
    	}
    	
    	void AIUpdate()
    	{
    
    	}
    	
    	void SpellCast(uint32 val)
    	{
     
    	}
    
    Next we need to register our AI event update. This will be used throughout the script to update the current AI status. To do this we add to our

    OnCombatStart section of the script the text in red:
    Code:
    	void OnCombatStart(Unit * mTarget)
    	{
    	RegisterAIUpdateEvent(_unit->GetUInt32value(UNIT_FIELD_BASEATTACKTIME));
    		int RandomChance;
    		RandomChance = rand()%4;
    			switch(RandomChance)
    			{
    			case 0:
    				_unit->SendChatMessage(CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, "I am saying a chat message! Hoorahh!");
    				break;
    			case 1:
    				_unit->SendChatMessage(CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, "I am saying a chat message! Hoorahh!");
    				break;
    			case 2:
    				break;
    			case 3:
    				break;
    	}
    }

    We've registered the AI event update as the unit's base attack time.

    That's our OnCombatStart... for now.

    On to our "OnCombatStop".


    Creature On Combat Stop


    The OnCombatStop section of our script looks like this:
    Code:
    
    Code:
    
    	void OnCombatStop(Unit * mTarget)
    	{
    		_unit->GetAIInterface()->setCurrentAgent(AGENT_NULL);
    		_unit->GetAIInterface()->SetAIState(STATE_IDLE);
    		RemoveAIUpdateEvent();
    	}
    
    _unit->GetAIInterface()->setCurrentAgent(AGENT_NULL); sets the unit's AI agent to NULL (nothing).
    
    _unit->GetAIInterface()->SetAIState(STATE_IDLE); makes the unit stand idle and stop attacking.
    RemoveAIUpdateEvent();[/GREEN] removes the AI update event we had.


    That was fairly simple and easy, now for the OnDied.

    Creature On Died

    This part of the script is simple, unless you want to make it more advanced. However we'll keep this easy.

    Simply make our "OnDied" section of the script this:


    Code:
    	void OnDied(Unit * mKiller)
    	{
    		RemoveAIUpdateEvent();
    	}


    RemoveAIUpdateEvent(); is simply removing the AI update event. There is no need for it now.

    Now, we'll set up our spell casting. But first, let's see how our script looks so far:


    Your script should look something like this so far

    Code:
    #include "StdAfx.h"
    #include "Setup.h"
    
    class CreatureAI : CreatureAIScript
    {
    public:
    	ADD_CREATURE_FACTORY_FUNCTION(CreatureAI);
    	CreatureAI(Creature* pCreature) : CreatureAIScript(pCreature)
     	{
     	}
    
    protected:
    
    };
    
    
    	void OnCombatStart(Unit * mTarget)
    	{
    		int RandomChance;
    		RandomChance = rand()%4;
    			switch(RandomChance)
    			{
    			case 0:
    				_unit->SendChatMessage(CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, "I am saying a chat message! Hoorahh!");
    				break;
    			case 1:
    				_unit->SendChatMessage(CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, "I am saying a chat message! Hoorahh!");
    				break;
    			case 2:
    				break;
    			case 3:
    				break;
    	}
    }
    	void OnCombatStop(Unit * mTarget)
    	{
    		_unit->GetAIInterface()->setCurrentAgent(AGENT_NULL);
    		_unit->GetAIInterface()->SetAIState(STATE_IDLE);
    		RemoveAIUpdateEvent();
    	}
    	
    	void OnDied(Unit * mKiller)
    	{
    		RemoveAIUpdateEvent();
    	}
    	
    	void AIUpdate()
    	{
    
    	}
    	
    	void SpellCast(uint32 val)
    	{
     
    	}
    Last edited by Found; 12-10-2009 at 08:13 PM. Reason: Fixes

    C++ TuT Creature AI.
  2. #2
    Found's Avatar Banned
    Reputation
    239
    Join Date
    Mar 2009
    Posts
    642
    Thanks G/R
    1/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Firstly, we need to define our spells up the top of our script. In this case, I'll use 2 spells. You can add more if you want.

    We go to the top of our script, and a few lines below our "#include"s I'm going to put this:

    Code:
    Code:
    
    #define REND 47465
    #define PUMMEL 59344
    In the above code, #define means to, well, define the following text and relate it to the text a space after it.

    REND and PUMMEL are the names of my "#define"s. Make yours whatever name you want, as long as the name doesn't appear as blue in your C++ program.

    The 47465 and 59344 are the IDs of my defined spells.

    Now once the defining of the spells is done, we can proceed with our spell casting phase for our creature AI.

    Go down to this section in the script:

    Code:
    Code:
    
    class CreatureAI : CreatureAIScript
    {
    public:
    	ADD_CREATURE_FACTORY_FUNCTION(CreatureAI);
    	CreatureAI(Creature* pCreature) : CreatureAIScript(pCreature)
     	{
     	}
    
    protected:
    
    };
    
    In between the brackets ({ and }) put this:
    
    Code:
    
    rend = pummel = true;
    inforend = dbcSpell.LookupEntry(REND);
    infopummel = dbcSpell.LookupEntry(PUMMEL);
    
    Below where it says "protected". Place:
    
    Code:
    
    bool rend;
    bool pummel;
    SpellEntry *inforend, *infopummel;
    
    Note: We still haven't put anything in between the curly brackets in "SpellCast".
    Now to add everything in the "SpellCast".

    Firstly we need to see if the player has a target selected and is not currently casting a spell. One way of doing this (the way I'm going to do it) is:

    Code:
    Code:
    if(_unit->GetCurrentSpell() == NULL && _unit->GetAIInterface()->GetNextTarget())
    {
    This basically says that if the NPC has no current spell and has a next target then it will do what comes after this "if" statement.

    We'll add this under the bracket...

    Code:
    Code:
    if(rend)
                {
                    _unit->CastSpell(_unit->GetAIInterface()->GetNextTarget(), inforend, false);
                    rend = false;
    		return;
                }
    			
    			if(pummel)
    			{
    				_unit->CastSpell(_unit->GetAIInterface()->GetNextTarget(), infopummel, false);
    				pummel = false;
    				return;
    				
    			}
    What this means (I'll try to explain it so you all understand):

    rend and pummel are our bools from the top of the script. If they are set to true they will cast the spell that we.... linked.. them to at the top of our program.

    inforend and infopummel are the actual spells.

    rend = false; and pummel = false; is just setting the bools to false. We will add the resetting of the spells next.

    if(rend) and if(pummel) are pretty much saying "if(rend == true)" and "if(pummel == true)".


    Let's now put this below that code, this:

    Code:
    Code:
                if(val >= 100 && val <= 250)
    		{
    		_unit->setAttackTimer(2250, false);
    		rend = true;
    		}
    		if(val >= 650 && val <= 850)
    		{
    		_unit->setAttackTimer(3500, false);
    		pummel = true;
    		}
    if(val >= 100 && val <= 225) and if(val >= 790 && val <= 900) are "if" statements that say that if the random UInt value is between 100 and 250 then the NPC casts the spell rend. If the value is between 650 and 850 it casts pummel. We are just about to set up the random value section of our code...

    It then sets the unit's attack timer to the time above. (2250 and 3500)

    Here we go. Almost done.



    Your script should look something like this so far

    Code:
    Code:
    #include "StdAfx.h"
    #include "Setup.h"
    
    #define REND 47465
    #define PUMMEL 59344
    
    class CreatureAI : CreatureAIScript
    {
    public:
    	ADD_CREATURE_FACTORY_FUNCTION(CreatureAI);
    	CreatureAI(Creature* pCreature) : CreatureAIScript(pCreature)
     	{
    rend = pummel = true;
    inforend = dbcSpell.LookupEntry(REND);
    infopummel = dbcSpell.LookupEntry(PUMMEL);
     	}
    
    protected:
    
    bool rend;
    bool pummel;
    SpellEntry *inforend, *infopummel;
    
    };
    
    
    	void OnCombatStart(Unit * mTarget)
    	{
    		int RandomChance;
    		RandomChance = rand()%4;
    			switch(RandomChance)
    			{
    			case 0:
    				_unit->SendChatMessage(CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, "I am saying a chat message! Hoorahh!");
    				break;
    			case 1:
    				_unit->SendChatMessage(CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, "I am saying a chat message! Hoorahh!");
    				break;
    			case 2:
    				break;
    			case 3:
    				break;
    	}
    }
    	void OnCombatStop(Unit * mTarget)
    	{
    		_unit->GetAIInterface()->setCurrentAgent(AGENT_NULL);
    		_unit->GetAIInterface()->SetAIState(STATE_IDLE);
    		RemoveAIUpdateEvent();
    	}
    	
    	void OnDied(Unit * mKiller)
    	{
    		RemoveAIUpdateEvent();
    	}
    	
    	void AIUpdate()
    	{
    
    	}
    	
    	void SpellCast(uint32 val)
    	{
    	if(rend)
    	{
                    _unit->CastSpell(_unit->GetAIInterface()->GetNextTarget(), inforend, false);
                    rend = false;
    		return;
    	}
    			
    			if(pummel)
    			{
    				_unit->CastSpell(_unit->GetAIInterface()->GetNextTarget(), infopummel, false);
    				pummel = false;
    				return;
    				
    			}
                 if(val >= 100 && val <= 250)
    		{
    		_unit->setAttackTimer(2250, false);
    		rend = true;
    		}
    		if(val >= 650 && val <= 850)
    		{
    		_unit->setAttackTimer(3500, false);
    		pummel = true;
    		}
    	}
    
    
    
    
    Creature AI Update
    
    In between the brackets below "AIUpdate()", place the following:
    
    Code:
    
    void AIUpdate()
    	{
    		uint32 val = RandomUInt(1000);
    	SpellCast(val);
    	}
    
    uint32 val = RandomUInt(1000); gives us our value of "val" from the "SpellCast" part of the script.

    Setting up your Creature AI

    A few spaces below all your code enter this:

    Code:
    Code:
    void SetupCreatureAI(ScriptMgr * mgr)
    {
    	mgr->register_creature_script(NPCID, &CreatureAI::Create);
    }
    This sets up our creature AI script.

    Put your NPC's entry ID where I have: NPCID.

    Make sure that CreatureAI is the name of your "class" at the top of the script! (class CreatureAI : CreatureAIScript)

    Well done! You've created a creature AI program!!!



    The end script should look something like this!

    Note: You can comment C++ scripts with // for line comments and /* */ for block comments.

    I have commented this example script to basically show what everything does:

    Code:

    Code:
    #include "StdAfx.h"
    #include "Setup.h"
    
    #define REND 47465 // Here is the spell ID of Rend defined
    #define PUMMEL 59344 // Here is the spell ID of Pummel is defined
    
    class CreatureAI : CreatureAIScript
    {
    public:
    	ADD_CREATURE_FACTORY_FUNCTION(CreatureAI);
    	CreatureAI(Creature* pCreature) : CreatureAIScript(pCreature)
     	{
    rend = pummel = true; // The rend and pummel bools are set to "true"
    inforend = dbcSpell.LookupEntry(REND); // We look up the entry ID for the spells...
    infopummel = dbcSpell.LookupEntry(PUMMEL);
     	}
    
    protected:
    
    bool rend;
    bool pummel;
    SpellEntry *inforend, *infopummel;
    
    };
    
    
    	void OnCombatStart(Unit * mTarget) // OnCombatStart function. Occurs when the creature enters combat.
    	{
    		int RandomChance;
    		RandomChance = rand()%4;
    			switch(RandomChance)
    			{
    			case 0:
    				_unit->SendChatMessage(CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, "I am saying a chat message! Hoorahh!"); // Makes the unit send a chat message. Type: Yell, Language: Universal, Text: I am saying a chat message! Hoorahh!
    				break;
    			case 1:
    				_unit->SendChatMessage(CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, "I am saying a chat message! Hoorahh!"); // " "
    				break;
    			case 2: // Nothing happens in this case
    				break;
    			case 3: // " "
    				break;
    	}
    }
    	void OnCombatStop(Unit * mTarget) // OnCombatStop. Occurs when the creature leaves combat. (Not when it dies).
    	{
    		_unit->GetAIInterface()->setCurrentAgent(AGENT_NULL);
    		_unit->GetAIInterface()->SetAIState(STATE_IDLE);
    		RemoveAIUpdateEvent();
    	}
    	
    	void OnDied(Unit * mKiller) // OnDied. Occurs when the creature dies.
    	{
    		RemoveAIUpdateEvent(); // Removes our AI update event
    	}
    	
    	void AIUpdate() // This is our AI update event
    	{
    		uint32 val = RandomUInt(1000); // Random value. Will be used for spellcasting
    	SpellCast(val);
    	}
    	
    	void SpellCast(uint32 val) // This is where the majority of the creature's spell casting is handled.
    	{
    	if(rend) // if(rend == true)
    	{
                    _unit->CastSpell(_unit->GetAIInterface()->GetNextTarget(), inforend, false);
                    rend = false; // This sets the bool "rend" to false.
    		return;
    	}
    			
    			if(pummel) // if(pummel == true)
    			{
    				_unit->CastSpell(_unit->GetAIInterface()->GetNextTarget(), infopummel, false);
    				pummel = false; // This sets the bool "pummel" to false.
    				return;
    				
    			}
                 if(val >= 100 && val <= 250) // if our random value ("val") is higher than 100 and lower than 250 then execute the following code...
    		{
    		_unit->setAttackTimer(2250, false); // Sets the creature's attack timer to 2250
    		rend = true; // This sets the bool "rend" to true.
    		}
    		if(val >= 650 && val <= 850) // if our random value ("val") is higher than 650 and lower than 850 then execute the following code...
    		{
    		_unit->setAttackTimer(3500, false); // Sets the creature's attack timer to 3500
    		pummel = true; // This sets the bool "pummel" to true.
    		}
    	}
    
    void SetupCreatureAI(ScriptMgr * mgr)
    {
    	mgr->register_creature_script(NPCID, &CreatureAI::Create);
    }

  3. #3
    mager1794's Avatar Member
    Reputation
    356
    Join Date
    Feb 2008
    Posts
    703
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I still firmly believe he stole this tutorial from me and just changed up the words
    check out my AI Section of this

    Stepping Into C++
    Lunar Gaming - Reaching For The Stars

  4. #4
    Sounddead's Avatar Contributor
    Reputation
    160
    Join Date
    Sep 2007
    Posts
    1,126
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It does look alot like yours.. Except I found this one harder to understand for some reason. :/

    I live in a shoe

  5. #5
    Found's Avatar Banned
    Reputation
    239
    Join Date
    Mar 2009
    Posts
    642
    Thanks G/R
    1/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I dont steal tuts. I didnt see this on here so i asked the dude from ac-web to put it here and i did check the credits.

  6. #6
    mager1794's Avatar Member
    Reputation
    356
    Join Date
    Feb 2008
    Posts
    703
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I dont steal tuts. I didnt see this on here so i asked the dude from ac-web to put it here and i did check the credits.
    WOOOOO!!!

    I wasn't acussing you I was accusing him, you placed proper credits like you should, you did right, and this is very helpful since my guide seemed to get lost in the abyss. +Rep x4
    Lunar Gaming - Reaching For The Stars

  7. #7
    Link_S's Avatar Member
    Reputation
    125
    Join Date
    Dec 2008
    Posts
    293
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by L0st View Post



    Code:
    #include "StdAfx.h"
    #include "Setup.h"
    
    #define REND 47465 // Here is the spell ID of Rend defined
    #define PUMMEL 59344 // Here is the spell ID of Pummel is defined
    
    class CreatureAI : CreatureAIScript
    {
    public:
        ADD_CREATURE_FACTORY_FUNCTION(CreatureAI);
        CreatureAI(Creature* pCreature) : CreatureAIScript(pCreature)
         {
    rend = pummel = true; // The rend and pummel bools are set to "true"
    inforend = dbcSpell.LookupEntry(REND); // We look up the entry ID for the spells...
    infopummel = dbcSpell.LookupEntry(PUMMEL);
         }
    
    protected:
    
    bool rend;
    bool pummel;
    SpellEntry *inforend, *infopummel;
    
    };
    
    
        void OnCombatStart(Unit * mTarget) // OnCombatStart function. Occurs when the creature enters combat.
        {
            int RandomChance;
            RandomChance = rand()%4;
                switch(RandomChance)
                {
                case 0:
                    _unit->SendChatMessage(CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, "I am saying a chat message! Hoorahh!"); // Makes the unit send a chat message. Type: Yell, Language: Universal, Text: I am saying a chat message! Hoorahh!
                    break;
                case 1:
                    _unit->SendChatMessage(CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, "I am saying a chat message! Hoorahh!"); // " "
                    break;
                case 2: // Nothing happens in this case
                    break;
                case 3: // " "
                    break;
        }
    }
        void OnCombatStop(Unit * mTarget) // OnCombatStop. Occurs when the creature leaves combat. (Not when it dies).
        {
            _unit->GetAIInterface()->setCurrentAgent(AGENT_NULL);
            _unit->GetAIInterface()->SetAIState(STATE_IDLE);
            RemoveAIUpdateEvent();
        }
        
        void OnDied(Unit * mKiller) // OnDied. Occurs when the creature dies.
        {
            RemoveAIUpdateEvent(); // Removes our AI update event
        }
        
        void AIUpdate() // This is our AI update event
        {
            uint32 val = RandomUInt(1000); // Random value. Will be used for spellcasting
        SpellCast(val);
        }
        
        void SpellCast(uint32 val) // This is where the majority of the creature's spell casting is handled.
        {
        if(rend) // if(rend == true)
        {
                    _unit->CastSpell(_unit->GetAIInterface()->GetNextTarget(), inforend, false);
                    rend = false; // This sets the bool "rend" to false.
            return;
        }
                
                if(pummel) // if(pummel == true)
                {
                    _unit->CastSpell(_unit->GetAIInterface()->GetNextTarget(), infopummel, false);
                    pummel = false; // This sets the bool "pummel" to false.
                    return;
                    
                }
                 if(val >= 100 && val <= 250) // if our random value ("val") is higher than 100 and lower than 250 then execute the following code...
            {
            _unit->setAttackTimer(2250, false); // Sets the creature's attack timer to 2250
            rend = true; // This sets the bool "rend" to true.
            }
            if(val >= 650 && val <= 850) // if our random value ("val") is higher than 650 and lower than 850 then execute the following code...
            {
            _unit->setAttackTimer(3500, false); // Sets the creature's attack timer to 3500
            pummel = true; // This sets the bool "pummel" to true.
            }
        }
    
    void SetupCreatureAI(ScriptMgr * mgr)
    {
        mgr->register_creature_script(NPCID, &CreatureAI::Create);
    }
    The functions won't trigger, you didn't include them inside the class. I'd suggest to insert the functions inside the class instead of having them outside, appearantly; you don't have a clue what the heck you're doin'.
    Why do I need a signature?

  8. #8
    Found's Avatar Banned
    Reputation
    239
    Join Date
    Mar 2009
    Posts
    642
    Thanks G/R
    1/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ty sir (fillah)

  9. #9
    Found's Avatar Banned
    Reputation
    239
    Join Date
    Mar 2009
    Posts
    642
    Thanks G/R
    1/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow guys thanks.

  10. #10
    Sounddead's Avatar Contributor
    Reputation
    160
    Join Date
    Sep 2007
    Posts
    1,126
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Link_S View Post
    The functions won't trigger, you didn't include them inside the class. I'd suggest to insert the functions inside the class instead of having them outside, appearantly; you don't have a clue what the heck you're doin'.

    True story.

    I live in a shoe

Similar Threads

  1. Need a Player to Creature Model change
    By Piratewolf in forum WoW ME Questions and Requests
    Replies: 2
    Last Post: 01-04-2007, 06:46 PM
  2. I've been playing with dbc editing creatures and..
    By dela in forum WoW ME Questions and Requests
    Replies: 1
    Last Post: 10-10-2006, 08:32 PM
  3. Need a Player to Creature Model change
    By Piratewolf in forum World of Warcraft Model Editing
    Replies: 1
    Last Post: 08-24-2006, 09:37 PM
  4. Find a way to change items to creatures
    By xlAnonym0uslx in forum World of Warcraft Model Editing
    Replies: 18
    Last Post: 08-18-2006, 01:09 PM
  5. The best creature ever
    By Krazzee in forum World of Warcraft General
    Replies: 9
    Last Post: 07-04-2006, 02:19 PM
All times are GMT -5. The time now is 11:26 AM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search