User Tag List

Page 1 of 2 1 2 LastLast
Results 1 to 7 of 9

Thread: [C++]Script for revive

  1. #1
    Enthusiast
    Join Date
    Feb 2015
    Posts
    23
    XP
    1,597
    Level
    11
    Thanks
    5
    Thanked 1 Time in 1 Post

    [Solved][C++]Script for revive

    Hi guys, i've got a litlle problem with one of my scripts. I'm using Core rev. 905685516092+.
    Script itself:
    Code:
    #include "ScriptPCH.h"
    #include "ScriptMgr.h"
    
    class questRevive : public CreatureScript
    {
    public:
            questRevive() : CreatureScript("questRevive"){ }
    
            bool OnQuestComplete(Player* player, Creature* creature, Quest const* quest)
            {
                            if(quest->GetQuestId() != 26000)
                                    return false;
                            player->ResurrectPlayer(0.5f);
                            player->SpawnCorpseBones();
                            return true;
            }
    };
    
    void AddSC_questRevive()
    {
            new questRevive();
    }

    Script should revive player after he will finish quest with id 26000. It has been added to "custom_script_loaded.cpp"
    Thank you for any help
    Last edited by madman1851; 08-07-2016 at 01:51 PM.
    Achievements:
    1 year registered Level X

  2. #2
    Moderator <span style='color: #FF1493'><span class='glow_000000'>Vitrex</span></span>'s Avatar

    Join Date
    Sep 2013
    Location
    Vilnius , Lithuania
    Posts
    1,049
    XP
    1,000,667
    Level
    174
    Thanks
    283
    Thanked 137 Times in 97 Posts
    Quote Originally Posted by madman1851 View Post
    Hi guys, i've got a litlle problem with one of my scripts. I'm using Core rev. 905685516092+.
    Script itself:
    Code:
    #include "ScriptPCH.h"
    #include "ScriptMgr.h"
    
    class questRevive : public CreatureScript
    {
    public:
            questRevive() : CreatureScript("questRevive"){ }
    
            bool OnQuestComplete(Player* player, Creature* creature, Quest const* quest)
            {
                            if(quest->GetQuestId() != 26000)
                                    return false;
                            player->ResurrectPlayer(0.5f);
                            player->SpawnCorpseBones();
                            return true;
            }
    };
    
    void AddSC_questRevive()
    {
            new questRevive();
    }

    Script should revive player after he will finish quest with id 26000. It has been added to "custom_script_loaded.cpp"
    Thank you for any help
    Edited your post , added code tag, please make sure to use it next time. that will be better for all of us , for that one who seeking the help, and for that ones who helping him.

    Please explain what problem do you have? does it's fails to compile or it's not working? Script is working but it's buggy ? The more information you provide, the faster you'll have your question / support thread solved.
    Cheers.

    Right now i can say that it's may not be working because of else tag is missing.

    Code:
    bool OnQuestComplete(Player* player, Creature* creature, Quest const* quest)
            {
                            if(quest->GetQuestId() != 26000)
                                    return false;
                            else
                            player->ResurrectPlayer(0.5f);
                            player->SpawnCorpseBones();
                            return true;
            }
    I added else tag, maybe that will fix your problem. that's my first thought on this.
    P.s in your place i would rather check if quest id is equal to that one you need, it's easier to understand and maintain the scripts like that.
    Last edited by Vitrex; 07-31-2016 at 11:28 AM.
    Achievements:
    Shopper Got a Sticky! 1 year registered Member Level XL Level C Referrer
    Awards:
    Raffle Winner Donator Member of Staff Pot Head
    I won't create anything for you, i can only guide you to right direction.
    Don't forget to read rules before posting.
    Forum Rules
    Need and assistance with your issue? use this section to ask for assistance !
    -----
    My Portfolio
    Wanna learn PHP ? check out my One-Page project


  3. The Following User Says Thank You to Vitrex For This Useful Post:


  4. #3
    Administrator
    Join Date
    May 2013
    Location
    yes
    Posts
    257
    XP
    1,838,387
    Level
    244
    Thanks
    6
    Thanked 110 Times in 67 Posts
    The reason nothing happens is because there is no hook called "OnQuestComplete".

    Use this hook instead and check if the status is equal to completed:

    Code:
    void OnQuestStatusChange(Player* /*player*/, uint32 /*questId*/, QuestStatus /*status*/)
    It should be a PlayerScript as well.

    Quote Originally Posted by Vitrex View Post
    Right now i can say that it's may not be working because of else tag is missing.
    The else statement is redundant.

  5. The Following User Says Thank You to Jpp For This Useful Post:


  6. #4
    Original Poster
    Enthusiast
    Join Date
    Feb 2015
    Posts
    23
    XP
    1,597
    Level
    11
    Thanks
    5
    Thanked 1 Time in 1 Post
    Thank you for you usefull advices, I really do appriciate it :-)
    Reworked it with OnQuestStatusChange, but it did not changed, it's still doing nothing upon completing quest. Quest itself has good id.
    Now script looks this way


    Code:
    class playerQuestRevive : public PlayerScript
    {
    public:
    	playerQuestRevive() : PlayerScript("playerQuestRevive") { }
    
    	void OnQuestStatusChange(Player* player, uint32 questId, QuestStatus questStatus)
    	{
    		if((questId==26000)&&(questStatus==1/*QUEST_STATUS_COMPLETE*/))
    		{
    			player->ResurrectPlayer(0.5f);
                            player->SpawnCorpseBones();
    		}
    
    	}
    };
    Last edited by madman1851; 07-31-2016 at 04:39 PM.
    Achievements:
    1 year registered Level X

  7. #5
    Founder <span style='color: #FF4500'>Tommy</span>'s Avatar
    Join Date
    Apr 2013
    Posts
    7,391
    XP
    3,449,104
    Level
    378
    Thanks
    889
    Thanked 1,856 Times in 1,119 Posts
    Quote Originally Posted by madman1851 View Post
    Thank you for you usefull advices, I really do appriciate it :-)
    Reworked it with OnQuestStatusChange, but it did not changed, it's still doing nothing upon completing quest. Quest itself has good id.
    Now script looks this way


    Code:
    class playerQuestRevive : public PlayerScript
    {
    public:
    	playerQuestRevive() : PlayerScript("playerQuestRevive") { }
    
    	void OnQuestStatusChange(Player* player, uint32 questId, QuestStatus questStatus)
    	{
    		if((questId==26000)&&(questStatus==1/*QUEST_STATUS_COMPLETE*/))
    		{
    			player->ResurrectPlayer(0.5f);
                            player->SpawnCorpseBones();
    		}
    
    	}
    };
    Are you even setting the script up in a script loader? The script itself doesn't have a setup function so I assume you aren't (but most people only link the class itself sometimes). Also, why use "1" instead of the enumerator type when checking questStatus? You are missing override for OnQuestStatusChange hook as well.

    I've corrected some mistakes below. Don't forget to set your script up in one of the script loaders. e.g. custom_script_loader.cpp

    Code:
    class playerQuestRevive : public PlayerScript
    {
    public:
        playerQuestRevive() : PlayerScript("playerQuestRevive") { }
    
        void OnQuestStatusChange(Player* player, uint32 questId, QuestStatus questStatus) override
        {
            if (questId == 26000 && questStatus == QUEST_STATUS_COMPLETE)
            {
                player->ResurrectPlayer(0.5f);
                player->SpawnCorpseBones();
            }
    
        }
    };
    
    void SetupPlayerRevive()
    {
        new playerQuestRevive;
    }

  8. The Following User Says Thank You to Tommy For This Useful Post:


  9. #6
    Original Poster
    Enthusiast
    Join Date
    Feb 2015
    Posts
    23
    XP
    1,597
    Level
    11
    Thanks
    5
    Thanked 1 Time in 1 Post
    Thank you for more of useful advices, i've reworked it...but it still does nothing.

    Script itself now:
    Code:
    #include "ScriptPCH.h"
    #include "ScriptMgr.h"
    #include "Player.h"
    
    class playerQuestRevive : public PlayerScript
    {
    public:
    	playerQuestRevive() : PlayerScript("playerQuestRevive") { }
    
    	void OnQuestStatusChange(Player* player, uint32 questId, QuestStatus questStatus) override
    	{
    	player->SetMoney(10);//test
    		if((questId==26000)&&(questStatus==QUEST_STATUS_COMPLETE))
    		{
    			player->ResurrectPlayer(0.5f,false);
    			player->SetFullHealth();
    			player->SetMoney(100);//test
                   		player->SpawnCorpseBones();
    		}
    
    	}
    };
    
    void AddSC_questRevive()
    {
    	new playerQuestRevive;
    }
    Script was and still is added in custom_script_loader:
    Code:
    // This is where scripts' loading functions should be declared:
    void AddSC_npc_scaler();
    void AddSC_questRevive();
    
    // The name of this function should match:
    // void Add${NameOfDirectory}Scripts()
    void AddCustomScripts()
    {
    	AddSC_npc_scaler();
    	AddSC_questRevive();
    }
    I've added it also on quest giver(but i think it's redundant).
    Once more, still, thank you a lot :-)

  10. #7
    Moderator / Eluna Dev <span style='color: #FF0000'><span class='glow_8B0000'>Rochet2</span></span>'s Avatar
    Join Date
    Apr 2013
    Location
    Finland
    Posts
    1,860
    XP
    13,487
    Level
    35
    Thanks
    95
    Thanked 591 Times in 418 Posts
    QUEST_STATUS_COMPLETE is probably wrong. Completing is when all objectives are complete.
    QUEST_STATUS_REWARDED is probably when a quest is "completed" and by that I mean returned to the questgiver and rewarded to the player.

    Does player->SetMoney(10);//test
    get called?
    Awards:
    Support LOL Scripter Facepalm! Raffle Winner
    rochet2.github.io - Home of great codes

  11. The Following User Says Thank You to Rochet2 For This Useful Post:


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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