From 943dcaea14c7530eecca57af015f1007b3b9630f Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Sat, 22 Jun 2013 19:08:34 +0000 Subject: Plugins can modify message in the OnChat() hook handler. FS #376 git-svn-id: http://mc-server.googlecode.com/svn/trunk@1622 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/Plugin_NewLua.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'source/Plugin_NewLua.cpp') diff --git a/source/Plugin_NewLua.cpp b/source/Plugin_NewLua.cpp index 885184c12..335ac000a 100644 --- a/source/Plugin_NewLua.cpp +++ b/source/Plugin_NewLua.cpp @@ -228,7 +228,7 @@ bool cPlugin_NewLua::OnBlockToPickups(cWorld * a_World, cEntity * a_Digger, int -bool cPlugin_NewLua::OnChat(cPlayer * a_Player, const AString & a_Message) +bool cPlugin_NewLua::OnChat(cPlayer * a_Player, AString & a_Message) { cCSLock Lock(m_CriticalSection); const char * FnName = GetHookFnName(cPluginManager::HOOK_CHAT); @@ -241,13 +241,17 @@ bool cPlugin_NewLua::OnChat(cPlayer * a_Player, const AString & a_Message) tolua_pushusertype(m_LuaState, a_Player, "cPlayer"); tolua_pushstring (m_LuaState, a_Message.c_str()); - if (!CallFunction(2, 1, FnName)) + if (!CallFunction(2, 2, FnName)) { return false; } - bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0); - lua_pop(m_LuaState, 1); + bool bRetVal = (tolua_toboolean(m_LuaState, -2, 0) > 0); + if (lua_isstring(m_LuaState, -1)) + { + a_Message = tolua_tostring(m_LuaState, -1, ""); + } + lua_pop(m_LuaState, 2); return bRetVal; } -- cgit v1.2.3