Welcome to AC Web.
Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Thread: NPC Stalker

  1. #1


    Join Date
    May 2008
    Location
    Land Called Finland.
    Posts
    690

    Question NPC Stalker


    REGISTER! (FREE)
    Registered members see less ads
    and also gain access to other great features.
    Hello everyone. I have question: How to make stalker npc? If anyone have any demo (Like example Lua script) to show me i would be appreciate that.

    I want to make stalker npc that checks something / starts some event etc.

  2. #2
    Did not understand very well, but seems you want an invisible to player NPC? NPC Phase ID is the trick you need, play with phases (did not work with this atm so I can't tell you what ID you should go for)

    Then you can make this npc start or check, or do the fuck you want with custom scripts.

  3. #3

    Something like CreatureAI that's invisible? The DK spell anti magic zone summons an invisible npc that casts the bubble spell.
    Duplicate the creature_template row for entry: "28306" which is the antimagiczone invisible npc and change the ScriptName to "npc_stalker" or which ever you use in C++.

    Code may be outdated for TrinityCore it's written on Sunwell Core. It should work with AzerothCore and older TC versions.

    Code:
    #include "ScriptMgr.h"
    
    enum StalkerEvents
    {
    	EVENT_DETECT = 1
    };
    
    class npc_stalker : public CreatureScript
    {
    public:
    	npc_stalker() : CreatureScript("npc_stalker") { }
    
    	struct npc_stalkerAI : public NullCreatureAI
    	{
    		npc_stalkerAI(Creature *c) : NullCreatureAI(c)
    		{
    			// Schedule initial event
    			events.ScheduleEvent(EVENT_DETECT, 1000);
    		}
    
    		EventMap events;
    		float dist = 1.0f;
    
    		void UpdateAI(uint32 diff)
    		{
    			events.Update(diff);
    			switch (events.GetEvent())
    			{
    				case EVENT_DETECT:
    				{
    					if (Player* p = me->SelectNearestPlayer(dist))
    						me->MonsterSay("Player is next to me.. do something", LANG_UNIVERSAL, me);
    
    					// Repeat the event every second
    					events.RepeatEvent(1000);
    					break;
    				}
    			}
    		}
    	};
    
    	CreatureAI* GetAI(Creature* pCreature) const
    	{
    		return new npc_stalkerAI(pCreature);
    	}
    };
    
    void AddSC_NpcStalker()
    {
    	new npc_stalker;
    };

    Last edited by Alistar; 01-26-2020 at 01:58 AM.

  4. #4
    Use MoveInLineOfSight instead

  5. #5


    Join Date
    Jan 2020
    Location
    Visual Studio C++
    Posts
    27
    Quote Originally Posted by Alistar View Post

    Something like CreatureAI that's invisible? The DK spell anti magic zone summons an invisible npc that casts the bubble spell.
    Duplicate the creature_template row for entry: "28306" which is the antimagiczone invisible npc and change the ScriptName to "npc_stalker" or which ever you use in C++.

    Code may be outdated for TrinityCore it's written on Sunwell Core. It should work with AzerothCore and older TC versions.

    Code:
    #include "ScriptMgr.h"
    
    enum StalkerEvents
    {
    	EVENT_DETECT = 1
    };
    
    class npc_stalker : public CreatureScript
    {
    public:
    	npc_stalker() : CreatureScript("npc_stalker") { }
    
    	struct npc_stalkerAI : public NullCreatureAI
    	{
    		npc_stalkerAI(Creature *c) : NullCreatureAI(c)
    		{
    			// Schedule initial event
    			events.ScheduleEvent(EVENT_DETECT, 1000);
    		}
    
    		EventMap events;
    		float dist = 1.0f;
    
    		void UpdateAI(uint32 diff)
    		{
    			events.Update(diff);
    			switch (events.GetEvent())
    			{
    				case EVENT_DETECT:
    				{
    					if (Player* p = me->SelectNearestPlayer(dist))
    						me->MonsterSay("Player is next to me.. do something", LANG_UNIVERSAL, me);
    
    					// Repeat the event every second
    					events.RepeatEvent(1000);
    					break;
    				}
    			}
    		}
    	};
    
    	CreatureAI* GetAI(Creature* pCreature) const
    	{
    		return new npc_stalkerAI(pCreature);
    	}
    };
    
    void AddSC_NpcStalker()
    {
    	new npc_stalker;
    };

    This codestyle is very outdated. No need to use class and public. It can work without it. Instead of event it's much better to use void MoveInLineOfSight.

  6. #6
    Quote Originally Posted by AzsunaDev View Post
    This codestyle is very outdated. No need to use class and public. It can work without it. Instead of event it's much better to use void MoveInLineOfSight.
    Quote Originally Posted by Alistar View Post


    Code may be outdated for TrinityCore it's written on Sunwell Core. It should work with AzerothCore and older TC versions.
    Like i've said.

  7. #7
    SWC has MoveInLineOfSight function. With your method of using eventmap you check grid every second which is waste of performance.

  8. #8


    Join Date
    May 2008
    Location
    Land Called Finland.
    Posts
    690
    I try to make a stalker that when player reach x point then stalker does something like a script or play sound / movie etc

  9. #9
    Quote Originally Posted by dansku16v View Post
    I try to make a stalker that when player reach x point then stalker does something like a script or play sound / movie etc
    Code:
    #include "ScriptMgr.h"
    
    class npc_stalker : public CreatureScript
    {
    public:
    	npc_stalker() : CreatureScript("npc_stalker") { }
    
    	struct npc_stalkerAI : public ScriptedAI
    	{
    		npc_stalkerAI(Creature *c) : ScriptedAI(c) { }
    
    		void MoveInLineOfSight(Unit* who)
    		{
    			float dist = 1.0f;
    			if (who->GetTypeId() == TYPEID_PLAYER)
    				if (who->GetExactDist2d(me) <= dist)
    					who->ToPlayer()->SendMovieStart(16); // movieId 16 - fall of the lich king
    		}
    	};
    
    	CreatureAI* GetAI(Creature* pCreature) const
    	{
    		return new npc_stalkerAI(pCreature);
    	}
    };
    
    void AddSC_NpcStalker()
    {
    	new npc_stalker;
    };
    Let me know if you're using latest TrinityCore I'll update the code.



    Last edited by Alistar; 01-26-2020 at 04:05 PM.

  10. #10


    Join Date
    May 2008
    Location
    Land Called Finland.
    Posts
    690
    Quote Originally Posted by Alistar View Post


    Code:
    #include "ScriptMgr.h"
    
    class npc_stalker : public CreatureScript
    {
    public:
    	npc_stalker() : CreatureScript("npc_stalker") { }
    
    	struct npc_stalkerAI : public ScriptedAI
    	{
    		npc_stalkerAI(Creature *c) : ScriptedAI(c) { }
    
    		void MoveInLineOfSight(Unit* who)
    		{
    			float dist = 1.0f;
    			if (who->GetTypeId() == TYPEID_PLAYER)
    				if (who->GetExactDist2d(me) <= dist)
    					who->ToPlayer()->SendMovieStart(16); // movieId 16 - fall of the lich king
    		}
    	};
    
    	CreatureAI* GetAI(Creature* pCreature) const
    	{
    		return new npc_stalkerAI(pCreature);
    	}
    };
    
    void AddSC_NpcStalker()
    {
    	new npc_stalker;
    };
    Let me know if you're using latest TrinityCore I'll update the code.



    Yeah i use Trinitycore master build. Is it any chance possible to make with SmartAI?

  11. #11
    Quote Originally Posted by dansku16v View Post
    Yeah i use Trinitycore master build. Is it any chance possible to make with SmartAI?
    Not sure but you've mentioned that you wanted the script as lua. Can you test this?
    Code:
    local stalkerEntry = 910015 -- NPC Stalker Id
    local distance = 1
    
    function Stalker_MoveLOS(event, creature, unit)
        if (unit:GetTypeId() == 4 and creature:IsWithinDistInMap(unit, distance)) then
            unit:PlayDirectSound(11466) -- Sound Id (Illidan)You are not prepared.
        end
    end
    
    RegisterCreatureEvent(stalkerEntry, 27, Stalker_MoveLOS)
    Last edited by Alistar; 01-26-2020 at 04:29 PM.

  12. #12


    Join Date
    May 2008
    Location
    Land Called Finland.
    Posts
    690
    Quote Originally Posted by Alistar View Post
    Not sure but you've mentioned that you wanted the script as lua. Can you test this?
    Code:
    local stalkerEntry = 910015 -- NPC Stalker Id
    local distance = 1
    
    function Stalker_MoveLOS(event, creature, unit)
        if (unit:GetTypeId() == 4 and creature:IsWithinDistInMap(unit, distance)) then
            unit:PlayDirectSound(11466) -- Sound Id (Illidan)You are not prepared.
        end
    end
    
    RegisterCreatureEvent(stalkerEntry, 27, Stalker_MoveLOS)
    Thanks for help.


    I got it working with SmartAI as i wanted it.

  13. #13
    You can use SmartAI + Scripts tho.

  14. #14


    Join Date
    May 2008
    Location
    Land Called Finland.
    Posts
    690
    Quote Originally Posted by molinita View Post
    You can use SmartAI + Scripts tho.
    I see that's good to know! Thanks!

  15. #15

    REGISTER! (FREE)
    Registered members see less ads
    and also gain access to other great features.
    add a condition to it too so it doesnt trigger multiple times, this could be a quest status or a member variable containing player guids for example

 

 

Posting Permissions

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