-
-
Save Rochet2/d6212b5a2289eeac2d56 to your computer and use it in GitHub Desktop.
Stops the default behavior of the spell and uses the spell's data to make a permanent spawn. Tested and works with http://www.wowhead.com/spell=62743/undercity-banner and similar spells.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
REPLACE INTO `spell_script_names` (`spell_id`, `ScriptName`) VALUES (62743, 'spell_save_object'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ScriptPCH.h" | |
class spell_save_object : public SpellScriptLoader | |
{ | |
public: | |
spell_save_object() : SpellScriptLoader("spell_save_object") { } | |
class spell_save_object_spellscript : public SpellScript | |
{ | |
PrepareSpellScript(spell_save_object_spellscript); | |
private: | |
static bool SpawnObject(Player* player, uint32 objectId, const WorldLocation* summonPos) | |
{ | |
const GameObjectTemplate* objectInfo = sObjectMgr->GetGameObjectTemplate(objectId); | |
if (!objectInfo) | |
return false; | |
if (objectInfo->displayId && !sGameObjectDisplayInfoStore.LookupEntry(objectInfo->displayId)) | |
return false; | |
float x, y, z, o; | |
summonPos->GetPosition(x, y, z, o); | |
o = player->GetOrientation(); | |
Map* map = player->GetMap(); | |
GameObject* object = new GameObject; | |
uint32 guidLow = sObjectMgr->GenerateLowGuid(HIGHGUID_GAMEOBJECT); | |
if (!object->Create(guidLow, objectInfo->entry, map, player->GetPhaseMaskForSpawn(), x, y, z, o, 0.0f, 0.0f, 0.0f, 0.0f, 0, GO_STATE_READY)) | |
{ | |
delete object; | |
return false; | |
} | |
// fill the gameobject data and save to the db | |
object->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), player->GetPhaseMaskForSpawn()); | |
// this will generate a new guid if the object is in an instance | |
if (!object->LoadGameObjectFromDB(guidLow, map)) | |
{ | |
delete object; | |
return false; | |
} | |
sObjectMgr->AddGameobjectToGrid(guidLow, sObjectMgr->GetGOData(guidLow)); | |
return true; | |
} | |
void SaveObject(SpellEffIndex effIndex) | |
{ | |
PreventHitDefaultEffect(effIndex); | |
const WorldLocation* summonPos = GetExplTargetDest(); | |
Player* player = GetCaster()->ToPlayer(); | |
if (!summonPos || !player) | |
return; | |
SpawnObject(player, GetSpellInfo()->Effects[effIndex].MiscValue, summonPos); | |
} | |
void Register() override | |
{ | |
// OnCast += SpellCastFn(spell_save_object_spellscript::SaveObject); | |
OnEffectHit += SpellEffectFn(spell_save_object_spellscript::SaveObject, EFFECT_0, SPELL_EFFECT_TRANS_DOOR); | |
} | |
uint32 _targetCount; | |
}; | |
SpellScript* GetSpellScript() const override | |
{ | |
return new spell_save_object_spellscript(); | |
} | |
}; | |
void AddSC_spell_save_object() | |
{ | |
new spell_save_object(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment