Well instead of making a guide I decided to post a blizzlike fix I made for a quest:
- OK first you need to run Visual Studio and compile this somewhere in one of your scripts projects.
Code:
//Whitebark's Memory Quest 10166
bool Whitebark_Memory(uint32 i, Spell* pSpell)
{
Player *pPlayer = (Player*)pSpell->u_caster;
if(!pPlayer)
return true;
if(!pSpell->u_caster->IsPlayer())
return true;
QuestLogEntry *qle = pPlayer->GetQuestLogForEntry(10166);
Creature * Whitebark = NULL;
Whitebark = pPlayer->GetMapMgr()->GetInterface()->GetCreatureNearestCoords(8187.786f, -6337.986f, 64.51f, 19456);
if(qle == NULL)
return true;
pPlayer->GetMapMgr()->GetInterface()->SpawnCreature(19456, 8187.786, -6337.986, 64.51, 3.369, true, false, 0,0)->Despawn(180000, 0);
Creature * pCreature = NULL;
pCreature = pPlayer->GetMapMgr()->GetInterface()->GetCreatureNearestCoords(8187.786f, -6337.986f, 64.51f, 19456);
pCreature->SetUInt32Value(UNIT_NPC_FLAGS, 0);
pCreature->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE, 91);
return true;
};
void SetupQuestScripts(ScriptMgr * mgr) // change this to whatever name the functions are registered
{
mgr->register_dummy_spell(33980, &Whitebark_Memory);
}
Compile and put the file in your script_bin folder
- Next come a little lua scripting for the second part (sorry I couldnt make it through C++, guess I need to learn more)
Code:
-- Quest 10166 Whitebark Memory
function Whitebark_onDefeat(Unit, event, miscunit, misc)
if Unit:GetHealthPct() < 30 then
Unit:RemoveEvents()
Unit:SendChatMessage(12, 0, "Very well...I admit defeat")
Unit:SetNPCFlags(2)
Unit:SetFaction(35)
Unit:SetCombatCapable(1)
Unit:Despawn(30000, 0)
else
end
end
function Whitebark_OnEnterCombat(Unit, event, miscunit, misc)
Unit:SendChatMessage(12, 0, "Haven't you done enough?")
Unit:RegisterEvent("Whitebark_onDefeat", 1000, 0)
end
function Whitebark_OnLeaveCombat(Unit, event, miscunit, misc)
Unit:RemoveEvents()
end
RegisterUnitEvent(19456, 1,"Whitebark_OnEnterCombat")
RegisterUnitEvent(19456, 2,"Whitebark_OnLeaveCombat")
Save the following in a .lua file and put in your scripts folder.
Tested and working with ascent based emus and 2.4.3 patch
Basically if you can understand the code you can easily fix tons of other quest that have the same mechanism, well any comment or code optimization is welcome.
Another fix for the Quest 437 The Dead Fields
Code:
//The Dead Fields Quest 437 Rote Hide
class Nightslash_Spawned_A : public CreatureAIScript
{
public:
ADD_CREATURE_FACTORY_FUNCTION(Nightslash_Spawned_A);
Nightslash_Spawned_A(Creature* pCreature) : CreatureAIScript(pCreature) {}
void OnDied(Unit *mKiller)
{
if(!mKiller->IsPlayer())
return;
Player *plr = (Player*)mKiller;
QuestLogEntry *qle = plr->GetQuestLogForEntry(437);
if(qle == NULL)
return;
uint8 chance = (uint8)RandomUInt(5);
uint32 spawn = 0;
switch(chance)
{
case 3:
spawn = 1983;
}
Creature *creat = sEAS.SpawnCreature(plr, spawn, 1077.445f, 1542.687f, 28.858f, 1*60*1000);
if(spawn != 1983)
return;
creat->SendChatMessage(CHAT_MSG_MONSTER_SAY, LANG_UNIVERSAL, "Who dares to kill my minions?");
}
};
//The Dead Fields Quest 437 Rote Hide Mystic
class Nightslash_Spawned_B : public CreatureAIScript
{
public:
ADD_CREATURE_FACTORY_FUNCTION(Nightslash_Spawned_B);
Nightslash_Spawned_B(Creature* pCreature) : CreatureAIScript(pCreature) {}
void OnDied(Unit *mKiller)
{
if(!mKiller->IsPlayer())
return;
Player *plr = (Player*)mKiller;
QuestLogEntry *qle = plr->GetQuestLogForEntry(437);
if(qle == NULL)
return;
uint8 chance = (uint8)RandomUInt(5);
uint32 spawn = 0;
switch(chance)
{
case 5:
spawn = 1983;
}
Creature *creat = sEAS.SpawnCreature(plr, spawn, 1077.445f, 1542.687f, 28.858f, 1*60*1000);
if(spawn != 1983)
return;
creat->SendChatMessage(CHAT_MSG_MONSTER_SAY, LANG_UNIVERSAL, "You will pay for what you did!");
}
};
And put these these two lines to register the functions
Code:
mgr->register_creature_script(1772, &Nightslash_Spawned_A::Create);
mgr->register_creature_script(1773, &Nightslash_Spawned_B::Create);