diff --git a/src/ElunaLuaEngine_SC.cpp b/src/ElunaLuaEngine_SC.cpp
index 8d1d257e76..bdf9cbb91c 100644
--- a/src/ElunaLuaEngine_SC.cpp
+++ b/src/ElunaLuaEngine_SC.cpp
@@ -736,6 +736,11 @@ class Eluna_PlayerScript : public PlayerScript
{
sEluna->OnLearnSpell(player, spellId);
}
+
+ void OnAchiComplete(Player* player, AchievementEntry const* achievement) override
+ {
+ sEluna->OnAchiComplete(player, achievement);
+ }
};
class Eluna_ServerScript : public ServerScript
diff --git a/src/LuaEngine/AchievementMethods.h b/src/LuaEngine/AchievementMethods.h
new file mode 100644
index 0000000000..a7d6559f5e
--- /dev/null
+++ b/src/LuaEngine/AchievementMethods.h
@@ -0,0 +1,23 @@
+/*
+* Copyright (C) 2010 - 2016 Eluna Lua Engine
+* This program is free software licensed under GPL version 3
+* Please see the included DOCS/LICENSE.md for more information
+*/
+
+#ifndef ACHIEVEMENTMETHODS_H
+#define ACHIEVEMENTMETHODS_H
+
+namespace LuaAchievement
+{
+ /**
+ * Returns the [Achievement]s ID
+ *
+ * @return uint32 id
+ */
+ int GetId(lua_State* L, AchievementEntry* const achievement)
+ {
+ Eluna::Push(L, achievement->ID);
+ return 1;
+ }
+};
+#endif
diff --git a/src/LuaEngine/GlobalMethods.h b/src/LuaEngine/GlobalMethods.h
index 2ec082cd13..52aceaec21 100644
--- a/src/LuaEngine/GlobalMethods.h
+++ b/src/LuaEngine/GlobalMethods.h
@@ -706,7 +706,8 @@ namespace LuaGlobalFunctions
* // UNUSED = 41, // (event, player)
* PLAYER_EVENT_ON_COMMAND = 42, // (event, player, command, chatHandler) - player is nil if command used from console. Can return false
* PLAYER_EVENT_ON_PET_ADDED_TO_WORLD = 43, // (event, player, pet)
- * * PLAYER_EVENT_ON_LEARN_SPELL = 44, // (event, player, spellId)
+ * PLAYER_EVENT_ON_LEARN_SPELL = 44, // (event, player, spellId)
+ * PLAYER_EVENT_ON_ACHIEVEMENT_COMPLETE = 45, // (event, player, achievement)
* };
*
*
diff --git a/src/LuaEngine/Hooks.h b/src/LuaEngine/Hooks.h
index 5beb8cb64b..0079e69d85 100644
--- a/src/LuaEngine/Hooks.h
+++ b/src/LuaEngine/Hooks.h
@@ -206,6 +206,7 @@ namespace Hooks
PLAYER_EVENT_ON_COMMAND = 42, // (event, player, command, chatHandler) - player is nil if command used from console. Can return false
PLAYER_EVENT_ON_PET_ADDED_TO_WORLD = 43, // (event, player, pet)
PLAYER_EVENT_ON_LEARN_SPELL = 44, // (event, player, spellId)
+ PLAYER_EVENT_ON_ACHIEVEMENT_COMPLETE = 45, // (event, player, achievement)
PLAYER_EVENT_COUNT
};
diff --git a/src/LuaEngine/LuaEngine.h b/src/LuaEngine/LuaEngine.h
index 517c0bdfcf..d435a64518 100644
--- a/src/LuaEngine/LuaEngine.h
+++ b/src/LuaEngine/LuaEngine.h
@@ -473,6 +473,7 @@ class ELUNA_GAME_API Eluna
void OnMapChanged(Player* pPlayer);
void HandleGossipSelectOption(Player* pPlayer, uint32 menuId, uint32 sender, uint32 action, const std::string& code);
void OnLearnSpell(Player* player, uint32 spellId);
+ void OnAchiComplete(Player* player, AchievementEntry const* achievement);
#ifndef CLASSIC
#ifndef TBC
diff --git a/src/LuaEngine/LuaFunctions.cpp b/src/LuaEngine/LuaFunctions.cpp
index bc2c865f1b..2ad242a9e3 100644
--- a/src/LuaEngine/LuaFunctions.cpp
+++ b/src/LuaEngine/LuaFunctions.cpp
@@ -37,6 +37,7 @@ extern "C"
#include "VehicleMethods.h"
#include "BattleGroundMethods.h"
#include "ChatHandlerMethods.h"
+#include "AchievementMethods.h"
luaL_Reg GlobalMethods[] =
{
@@ -1319,6 +1320,13 @@ ElunaRegister ChatHandlerMethods[] =
{ NULL, NULL }
};
+ElunaRegister AchievementMethods[] =
+{
+ { "GetId", &LuaAchievement::GetId },
+
+ { NULL, NULL }
+};
+
#if (!defined(TBC) && !defined(CLASSIC))
// fix compile error about accessing vehicle destructor
template<> int ElunaTemplate::CollectGarbage(lua_State* L)
@@ -1461,6 +1469,9 @@ void RegisterFunctions(Eluna* E)
ElunaTemplate::Register(E, "ElunaQuery", true);
ElunaTemplate::SetMethods(E, QueryMethods);
+ ElunaTemplate::Register(E, "AchievementEntry", true);
+ ElunaTemplate::SetMethods(E, AchievementMethods);
+
ElunaTemplate::Register(E, "long long", true);
ElunaTemplate::Register(E, "unsigned long long", true);
diff --git a/src/LuaEngine/PlayerHooks.cpp b/src/LuaEngine/PlayerHooks.cpp
index f556cb9245..005d603314 100644
--- a/src/LuaEngine/PlayerHooks.cpp
+++ b/src/LuaEngine/PlayerHooks.cpp
@@ -566,3 +566,11 @@ void Eluna::OnLearnSpell(Player* player, uint32 spellId)
Push(spellId);
CallAllFunctions(PlayerEventBindings, key);
}
+
+void Eluna::OnAchiComplete(Player* player, AchievementEntry const* achievement)
+{
+ START_HOOK(PLAYER_EVENT_ON_ACHIEVEMENT_COMPLETE);
+ Push(player);
+ Push(achievement);
+ CallAllFunctions(PlayerEventBindings, key);
+}