Advertisement
Guest User

Plugin::CallPlayerHook()

a guest
Apr 1st, 2010
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.70 KB | None | 0 0
  1. bool Plugin::CallPlayerHook(const char *hook, Player *playerObj) {
  2.     std::list<Hook*>::iterator iter;
  3.     try {
  4.         for(iter = Hooks.begin(); iter != Hooks.end(); ++iter) {
  5.             if(strcmp((*iter)->eventName, hook))
  6.                 continue;
  7.             if(lua_gettop(Lua))
  8.                 return false;
  9.             try {
  10.                 lua_getfield(Lua, LUA_GLOBALSINDEX, "PLUGINS");
  11.                 lua_pushnumber(Lua, this->id);
  12.                 lua_gettable(Lua, -2);
  13.                 lua_getfield(Lua, -1, (*iter)->functionName);
  14.             } catch(...) {
  15.                 Console::PrintText("Exception with getting function for hook '%s' and plugin '%s'", hook, this->Name);
  16.                 lua_settop(Lua, 0);
  17.                 return false;
  18.             }
  19.             try {
  20.                 this->SetEnv();
  21.             } catch(...) {
  22.                 Console::PrintText("Exception with SetEnv() for hook '%s' and plugin '%s'", hook, this->Name);
  23.                 lua_settop(Lua, 0);
  24.                 return false;
  25.             }
  26.             try {
  27.                 if (playerObj != NULL) {
  28.                     tolua_pushusertype(Lua, playerObj, "Player");
  29.                 } else {
  30.                     Console::PrintText("Player is NULL for hook '%s' and plugin '%s'", hook, this->Name);
  31.                     lua_settop(Lua, 0);
  32.                     return false;
  33.                 }
  34.             } catch(...) {
  35.                 Console::PrintText("Exception with pushing params for hook '%s' and plugin '%s'", hook, this->Name);
  36.                 lua_settop(Lua, 0);
  37.                 return false;
  38.             }
  39.             try {
  40.                 if(lua_pcall(Lua, 1, 0, 0)) {
  41.                     Console::PrintText("LUA ERROR: %s", lua_tostring(Lua, -1));
  42.                     lua_pop(Lua, 1);
  43.                 }
  44.             } catch(...) {
  45.                 Console::PrintText("Exception with hook pcall for hook '%s' and plugin '%s'", hook, this->Name);
  46.                 lua_settop(Lua, 0);
  47.                 return false;
  48.             }
  49.             lua_settop(Lua, 0);
  50.         }
  51.     } catch(...) {
  52.         Console::PrintText("CallHook failed at '%s'. Retrying.", hook);
  53.         lua_settop(Lua, 0);
  54.         return false;
  55.     }
  56.     return true;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement