Guest User

Untitled

a guest
Nov 19th, 2014
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. //After
  2.  
  3. int32_t LuaScriptInterface::popCallback(lua_State* L)
  4. {
  5. return luaL_ref(L, LUA_REGISTRYINDEX);
  6. }
  7.  
  8. //Add this
  9.  
  10. bool LuaScriptInterface::popBoolean(lua_State* L)
  11. {
  12. if (lua_gettop(L) == 0) {
  13. return false;
  14. }
  15.  
  16. bool value = lua_toboolean(L, -1) != 0;
  17. lua_pop(L, 1);
  18. return value;
  19. }
  20.  
  21. //After
  22.  
  23. #define registerEnumIn(tableName, value) { std::string enumName = #value; registerVariable(tableName, enumName.substr(enumName.find_last_of(':') + 1), value); }
  24.  
  25. //Add this
  26.  
  27. int32_t LuaScriptInterface::luaDoPlayerSetCastPassword(lua_State* L)
  28. {
  29. //doPlayerSetCastPassword(cid, password)
  30. std::string str = popString(L);
  31. if (Player* player = g_game.getPlayerByID(popNumber<int32_t>(L)))
  32. {
  33. player->setCastPassword(str);
  34. lua_pushboolean(L, true);
  35. }
  36. else
  37. {
  38. reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND));
  39. lua_pushboolean(L, false);
  40. }
  41.  
  42. return 1;
  43. }
  44.  
  45. int32_t LuaScriptInterface::luaDoPlayerSetCastState(lua_State* L)
  46. {
  47. //doPlayerSetCastState(cid, bool)
  48. bool state = (bool)popBoolean(L);
  49. Player * p = g_game.getPlayerByID(popNumber<int32_t>(L));
  50. if (p)
  51. {
  52. if (state)
  53. {
  54. if (p->cast.mCastChannelId == -1)
  55. {
  56. ChatChannel * tmpchat = (g_chat.createChannel(*p, CHANNEL_CAST));
  57. if (!tmpchat)
  58. return 0;
  59.  
  60. tmpchat->addUser(*p);
  61. p->cast.mCastChannelId = tmpchat->getId();
  62.  
  63. }
  64. p->sendCreatePrivateChannel(p->cast.mCastChannelId, "Spectator Chat");
  65. }
  66. else
  67. {
  68. int id = p->cast.mCastChannelId;
  69.  
  70. p->kickCastViewers();
  71. g_game.playerCloseChannel(p->id, id);
  72.  
  73. }
  74. p->setCasting(state);
  75. lua_pushboolean(L, true);
  76.  
  77. }
  78.  
  79. return 1;
  80. }
  81.  
  82. void LuaScriptInterface::setFieldBool(lua_State* L, const char* index, bool value)
  83. {
  84. lua_pushboolean(L, value);
  85. lua_setfield(L, -2, index);
  86. }
  87.  
  88. int32_t LuaScriptInterface::luaGetPlayerCast(lua_State* L)
  89. {
  90. //getPlayerCast(cid)
  91.  
  92. if (Player* player = g_game.getPlayerByID(popNumber<int32_t>(L)))
  93. {
  94. lua_newtable(L);
  95. setFieldBool(L, "status", player->getCastingState());
  96. setField(L, "password", player->getCastingPassword());
  97. }
  98. else
  99. {
  100. reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND));
  101. lua_pushboolean(L, false);
  102. }
  103.  
  104. return 1;
  105. }
  106.  
  107. //After
  108.  
  109. //getPlayerFlagValue(cid, flag)
  110. lua_register(m_luaState, "getPlayerFlagValue", LuaScriptInterface::luaGetPlayerFlagValue);
  111.  
  112. //Add this
  113.  
  114. //doPlayerSetCastPassword(cid, password)
  115. lua_register(m_luaState, "doPlayerSetCastPassword", LuaScriptInterface::luaDoPlayerSetCastPassword);
  116.  
  117. //doPlayerSetCastState(cid)
  118. lua_register(m_luaState, "doPlayerSetCastState", LuaScriptInterface::luaDoPlayerSetCastState);
  119.  
  120. //getPlayerCast(cid)
  121. lua_register(m_luaState, "getPlayerCast", LuaScriptInterface::luaGetPlayerCast);
Advertisement
Add Comment
Please, Sign In to add comment