• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

TrinityCore 3.3.5 [C++]Script for revive

madman1851

Enthusiast
[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:

Vitrex

Moderator
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;
                        [U]else[/U]
                        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:

Jpp

Administrator
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.

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

The else statement is redundant.
 

madman1851

Enthusiast
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:

Tommy

Founder
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;
}
 

madman1851

Enthusiast
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 :)
 

Rochet2

Moderator / Eluna Dev
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?
 

Tommy

Founder
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?

Oh, forgot about the QUEST_STATUS_REWARDED data type logic. Not sure if SetMoney gets called, but "ModifyMoney(val)" is the method he should probably be using.
 

madman1851

Enthusiast
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?

Tested it with QUEST_STATUS_REWARDED. SetMoney or ModifyMoney is not called. Nothing happened. Still, thank you for your posts, really appriciate it :)
EDIT:I've recompiled whole server, now command ModifyMoney is working.
EDIT2:Well, this is intresting. I've pulled player->RessurectPlayer(0.5f,false); before if statement and now compiler gives this error:‘class Player’ has no member named ‘RessurectPlayer’
Any ideas?
EDIT3:Well, i was really stupid :D Error was couse of mispelling :D Now it's fully working :)
 
Last edited:
Top