Advertisement
YanLiima

[C++] getOtsysTime() + getPlayerPing(cid)...

Dec 28th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.30 KB | None | 0 0
  1. EM luascript.cpp:
  2.  
  3. //doPlayerSendPing(cid)
  4.     lua_register(m_luaState, "doPlayerSendPing", LuaInterface::luaDoPlayerSendPing);
  5.     //getPlayerLastPing(cid)
  6.     lua_register(m_luaState, "getPlayerLastPing", LuaInterface::luaGetPlayerLastPing);
  7.     //getPlayerLastPong(cid)
  8.     lua_register(m_luaState, "getPlayerLastPong", LuaInterface::luaGetPlayerLastPong);
  9.     //getOtsysTime(cid)
  10.     lua_register(m_luaState, "getOtsysTime", LuaInterface::luaGetOtsysTime);
  11.  
  12. AINDA EM luascript.cpp ADICIONE LA NO FINAL:
  13.  
  14. int32_t LuaInterface::luaDoPlayerSendPing(lua_State* L) // Adaptado by Yan Liima(Night for tibiaking.com)
  15. {
  16.     //doPlayerSendPing(cid)
  17.     ScriptEnviroment* env = getEnv();
  18.     Player* player = env->getPlayerByUID(popNumber(L));
  19.     if(!player)
  20.     {
  21.         lua_pushboolean(L, false);
  22.         return 1;
  23.     }
  24.     int64_t timeNow = OTSYS_TIME();
  25.     player->lastPing = timeNow;
  26.     if(player->client)
  27.     {
  28.             void sendPing();
  29.             lua_pushboolean(L, true);
  30.     }else{
  31.           lua_pushboolean(L, false);        
  32.           }
  33.     lua_pushboolean(L, true);
  34.  
  35.     return 1;
  36. }
  37. int32_t LuaInterface::luaGetOtsysTime(lua_State* L)
  38. {
  39.     //getOtsysTime()
  40.     lua_pushnumber(L, OTSYS_TIME());
  41.     return 1;
  42. }
  43. int32_t LuaInterface::luaGetPlayerLastPing(lua_State* L)
  44. {
  45.     //getPlayerLastPing(cid)
  46.     ScriptEnviroment* env = getEnv();
  47.     Player* player = env->getPlayerByUID(popNumber(L));
  48.     if(!player)
  49.     {
  50.         errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
  51.          lua_pushboolean(L, false);
  52.         return 1;
  53.     }
  54.     int64_t timeNow = OTSYS_TIME();
  55.     lua_pushnumber(L, player->lastPing);
  56.     return 1;
  57. }
  58. int32_t LuaInterface::luaGetPlayerLastPong(lua_State* L)
  59. {
  60.     //getPlayerLastPong(cid)
  61.     ScriptEnviroment* env = getEnv();
  62.     Player* player = env->getPlayerByUID(popNumber(L));
  63.     if(!player)
  64.     {
  65.         errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
  66.          lua_pushboolean(L, false);
  67.         return 1;
  68.     }
  69.     lua_pushnumber(L, player->lastPong);
  70.     return 1;
  71. }
  72.  
  73. EM luascript.h ADICIONE:
  74.  
  75. //Ping
  76.         static int32_t luaDoPlayerSendPing(lua_State* L);
  77.         static int32_t luaGetPlayerLastPing(lua_State* L);
  78.         static int32_t luaGetPlayerLastPong(lua_State* L);
  79.         static int32_t luaGetOtsysTime(lua_State* L);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement