Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //After
- int32_t LuaScriptInterface::popCallback(lua_State* L)
- {
- return luaL_ref(L, LUA_REGISTRYINDEX);
- }
- //Add this
- bool LuaScriptInterface::popBoolean(lua_State* L)
- {
- if (lua_gettop(L) == 0) {
- return false;
- }
- bool value = lua_toboolean(L, -1) != 0;
- lua_pop(L, 1);
- return value;
- }
- //After
- #define registerEnumIn(tableName, value) { std::string enumName = #value; registerVariable(tableName, enumName.substr(enumName.find_last_of(':') + 1), value); }
- //Add this
- int32_t LuaScriptInterface::luaDoPlayerSetCastPassword(lua_State* L)
- {
- //doPlayerSetCastPassword(cid, password)
- std::string str = popString(L);
- if (Player* player = g_game.getPlayerByID(popNumber<int32_t>(L)))
- {
- player->setCastPassword(str);
- lua_pushboolean(L, true);
- }
- else
- {
- reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND));
- lua_pushboolean(L, false);
- }
- return 1;
- }
- int32_t LuaScriptInterface::luaDoPlayerSetCastState(lua_State* L)
- {
- //doPlayerSetCastState(cid, bool)
- bool state = (bool)popBoolean(L);
- Player * p = g_game.getPlayerByID(popNumber<int32_t>(L));
- if (p)
- {
- if (state)
- {
- if (p->cast.mCastChannelId == -1)
- {
- ChatChannel * tmpchat = (g_chat.createChannel(*p, CHANNEL_CAST));
- if (!tmpchat)
- return 0;
- tmpchat->addUser(*p);
- p->cast.mCastChannelId = tmpchat->getId();
- }
- p->sendCreatePrivateChannel(p->cast.mCastChannelId, "Spectator Chat");
- }
- else
- {
- int id = p->cast.mCastChannelId;
- p->kickCastViewers();
- g_game.playerCloseChannel(p->id, id);
- }
- p->setCasting(state);
- lua_pushboolean(L, true);
- }
- return 1;
- }
- void LuaScriptInterface::setFieldBool(lua_State* L, const char* index, bool value)
- {
- lua_pushboolean(L, value);
- lua_setfield(L, -2, index);
- }
- int32_t LuaScriptInterface::luaGetPlayerCast(lua_State* L)
- {
- //getPlayerCast(cid)
- if (Player* player = g_game.getPlayerByID(popNumber<int32_t>(L)))
- {
- lua_newtable(L);
- setFieldBool(L, "status", player->getCastingState());
- setField(L, "password", player->getCastingPassword());
- }
- else
- {
- reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND));
- lua_pushboolean(L, false);
- }
- return 1;
- }
- //After
- //getPlayerFlagValue(cid, flag)
- lua_register(m_luaState, "getPlayerFlagValue", LuaScriptInterface::luaGetPlayerFlagValue);
- //Add this
- //doPlayerSetCastPassword(cid, password)
- lua_register(m_luaState, "doPlayerSetCastPassword", LuaScriptInterface::luaDoPlayerSetCastPassword);
- //doPlayerSetCastState(cid)
- lua_register(m_luaState, "doPlayerSetCastState", LuaScriptInterface::luaDoPlayerSetCastState);
- //getPlayerCast(cid)
- lua_register(m_luaState, "getPlayerCast", LuaScriptInterface::luaGetPlayerCast);
Advertisement
Add Comment
Please, Sign In to add comment