Skip to content

Commit 09ac3c6

Browse files
committed
Fix unique creature event registry
1 parent afb2992 commit 09ac3c6

File tree

2 files changed

+28
-27
lines changed

2 files changed

+28
-27
lines changed

LuaEngine.cpp

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -766,36 +766,37 @@ int Eluna::Register(uint8 regtype, uint32 entry, ObjectGuid guid, uint32 instanc
766766
case Hooks::REGTYPE_CREATURE:
767767
if (event_id < Hooks::CREATURE_EVENT_COUNT)
768768
{
769-
if (entry != 0)
769+
if (!eObjectMgr->GetCreatureTemplate(entry))
770770
{
771-
if (!eObjectMgr->GetCreatureTemplate(entry))
772-
{
773-
luaL_unref(L, LUA_REGISTRYINDEX, functionRef);
774-
luaL_error(L, "Couldn't find a creature with (ID: %d)!", entry);
775-
return 0; // Stack: (empty)
776-
}
777-
778-
typedef EntryKey<Hooks::CreatureEvents> Key;
779-
auto binding = GetBinding<Key>(regtype);
780-
auto key = Key((Hooks::CreatureEvents)event_id, entry);
781-
bindingID = binding->Insert(key, functionRef, shots);
782-
createCancelCallback(this, bindingID, binding);
771+
luaL_unref(L, LUA_REGISTRYINDEX, functionRef);
772+
luaL_error(L, "Couldn't find a creature with (ID: %d)!", entry);
773+
return 0; // Stack: (empty)
783774
}
784-
else
775+
776+
typedef EntryKey<Hooks::CreatureEvents> Key;
777+
auto binding = GetBinding<Key>(regtype);
778+
auto key = Key((Hooks::CreatureEvents)event_id, entry);
779+
bindingID = binding->Insert(key, functionRef, shots);
780+
createCancelCallback(this, bindingID, binding);
781+
return 1; // Stack: callback
782+
}
783+
break;
784+
785+
case Hooks::REGTYPE_CREATURE_UNIQUE:
786+
if (event_id < Hooks::CREATURE_EVENT_COUNT)
787+
{
788+
if (guid.IsEmpty())
785789
{
786-
if (guid.IsEmpty())
787-
{
788-
luaL_unref(L, LUA_REGISTRYINDEX, functionRef);
789-
luaL_error(L, "guid was 0!");
790-
return 0; // Stack: (empty)
791-
}
792-
793-
typedef UniqueObjectKey<Hooks::CreatureEvents> Key;
794-
auto binding = GetBinding<Key>(regtype);
795-
auto key = Key((Hooks::CreatureEvents)event_id, guid, instanceId);
796-
bindingID = binding->Insert(key, functionRef, shots);
797-
createCancelCallback(this, bindingID, binding);
790+
luaL_unref(L, LUA_REGISTRYINDEX, functionRef);
791+
luaL_error(L, "guid was 0!");
792+
return 0; // Stack: (empty)
798793
}
794+
795+
typedef UniqueObjectKey<Hooks::CreatureEvents> Key;
796+
auto binding = GetBinding<Key>(regtype);
797+
auto key = Key((Hooks::CreatureEvents)event_id, guid, instanceId);
798+
bindingID = binding->Insert(key, functionRef, shots);
799+
createCancelCallback(this, bindingID, binding);
799800
return 1; // Stack: callback
800801
}
801802
break;

methods/TrinityCore/GlobalMethods.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,7 @@ namespace LuaGlobalFunctions
11571157
*/
11581158
int RegisterUniqueCreatureEvent(Eluna* E)
11591159
{
1160-
return RegisterUniqueHelper(E, Hooks::REGTYPE_CREATURE);
1160+
return RegisterUniqueHelper(E, Hooks::REGTYPE_CREATURE_UNIQUE);
11611161
}
11621162

11631163
/**

0 commit comments

Comments
 (0)