Advertisement
Kevick

TV SYSTEM

May 25th, 2016
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.89 KB | None | 0 0
  1. Vá em luascript.cpp e procure:
  2. int32_t LuaScriptInterface::luaGetTopCreature(lua_State* L)
  3. {
  4. //getTopCreature(pos)
  5. PositionEx pos;
  6. popPosition(L, pos);
  7.  
  8.  
  9. ScriptEnviroment* env = getEnv();
  10. Tile* tile = g_game.getTile(pos);
  11. if(!tile)
  12. {
  13. pushThing(L, NULL, 0);
  14. return 1;
  15. }
  16.  
  17.  
  18. Thing* thing = tile->getTopCreature();
  19. if(!thing || !thing->getCreature())
  20. {
  21. pushThing(L, NULL, 0);
  22. return 1;
  23. }
  24.  
  25.  
  26. pushThing(L, thing, env->addThing(thing));
  27. return 1;
  28. }
  29. E coloque embaixo:
  30. int32_t LuaScriptInterface::luaGetAllsTvs(lua_State* L)
  31. {
  32. //getAllsTvs(cid)
  33. ScriptEnviroment* env = getEnv();
  34. Player* player = env->getPlayerByUID(popNumber(L));
  35.  
  36.  
  37. if (!player) {
  38. errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
  39. lua_pushboolean(L, false);
  40. return 1;
  41. }
  42.  
  43.  
  44. Tvlist::iterator it;
  45. it = player->tv.begin();
  46. lua_newtable(L);
  47. uint32_t tableplayers = 1;
  48. for(uint32_t i = 1; it != player->tv.end(); ++it, ++i)
  49. {
  50. Player* players = env->getPlayerByUID(*it);
  51. if (players) {
  52. lua_pushnumber(L, tableplayers);
  53. lua_pushnumber(L, env->addThing(players));
  54. pushTable(L);
  55. tableplayers = tableplayers+1;
  56. }
  57. }
  58.  
  59.  
  60. return 1;
  61. }
  62.  
  63. int32_t LuaScriptInterface::luaSetPlayerTv(lua_State* L)
  64. {
  65. ScriptEnviroment* env = getEnv();
  66.  
  67.  
  68. Player* player_tv = env->getPlayerByUID(popNumber(L));
  69. Creature* creature = env->getCreatureByUID(popNumber(L));
  70.  
  71.  
  72. if (!creature) {
  73. errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
  74. lua_pushboolean(L, false);
  75. }
  76.  
  77.  
  78. Player* player = creature->getPlayer();
  79.  
  80.  
  81. if (!player) {
  82. errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
  83. lua_pushboolean(L, false);
  84. return 1;
  85. }
  86.  
  87.  
  88. if (!player_tv) {
  89. errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
  90. lua_pushboolean(L, false);
  91. return 1;
  92. }
  93.  
  94.  
  95. player_tv->tv.push_back(player->getID());
  96.  
  97.  
  98. SpectatorVec::iterator it;
  99. SpectatorVec list = g_game.getSpectators(player->getPosition());
  100. Player* tmpPlayer = NULL;
  101.  
  102.  
  103. Condition* condition = NULL;
  104.  
  105.  
  106. if((condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_GAMEMASTER, -1, 0, false, GAMEMASTER_INVISIBLE)))
  107. {
  108. creature->setHideName(false);
  109. player->addCondition(condition);
  110. g_game.internalCreatureChangeVisible(creature, VISIBLE_GHOST_DISAPPEAR);
  111. for(it = list.begin(); it != list.end(); ++it)
  112. {
  113. if((tmpPlayer = (*it)->getPlayer()) && !tmpPlayer->canSeeCreature(player))
  114. tmpPlayer->sendMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  115. }
  116.  
  117.  
  118. for(AutoList<Player>::iterator pit = Player::autoList.begin(); pit != Player::autoList.end(); ++pit)
  119. {
  120. if(!pit->second->canSeeCreature(player))
  121. pit->second->notifyLogOut(player);
  122. }
  123.  
  124.  
  125. IOLoginData::getInstance()->updateOnlineStatus(player->getGUID(), false);
  126. if(player->isTrading())
  127. g_game.internalCloseTrade(player);
  128.  
  129.  
  130. player->clearPartyInvitations();
  131.  
  132.  
  133. if(player->getParty())
  134. player->getParty()->leave(player);
  135.  
  136.  
  137. g_game.internalTeleport(player, player_tv->getPosition(), true);
  138.  
  139. }
  140.  
  141. lua_pushboolean(L, true);
  142. }
  143.  
  144. int32_t LuaScriptInterface::luaDoSendChannelsTv(lua_State* L)
  145. {
  146. ScriptEnviroment* env = getEnv();
  147. Player* player = env->getPlayerByUID(popNumber(L));
  148.  
  149.  
  150. if (!player) {
  151. errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
  152. lua_pushboolean(L, false);
  153. return 1;
  154. }
  155.  
  156.  
  157. player->sendChannelsDialog(true);
  158. lua_pushboolean(L, true);
  159. return 1;
  160. }
  161.  
  162.  
  163. int32_t LuaScriptInterface::luaDoRemovePlayerTv(lua_State* L)
  164. {
  165. ScriptEnviroment* env = getEnv();
  166. Player* player = env->getPlayerByUID(popNumber(L));
  167. Player* creature = env->getPlayerByUID(popNumber(L));
  168. if (!player) {
  169. errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
  170. lua_pushboolean(L, false);
  171. return 1;
  172. }
  173.  
  174.  
  175. for(std::list<uint32_t>::iterator it = player->tv.begin(); it != player->tv.end(); ++it)
  176. {
  177. if ((*it) == creature->getID()) {
  178. Tvlist tv = player->tv;
  179.  
  180.  
  181. if (!creature) {
  182. errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
  183. lua_pushboolean(L, false);
  184. return 1;
  185. }
  186.  
  187. Player* player_tv = creature->getPlayer();
  188. if (!player) {
  189. return 1;
  190. }
  191. SpectatorVec::iterator its;
  192. SpectatorVec list = g_game.getSpectators(player_tv->getPosition());
  193. Player* tmpPlayer = NULL;
  194.  
  195.  
  196. Condition* condition = NULL;
  197.  
  198.  
  199. creature->setHideName(false);
  200. if((condition = player_tv->getCondition(CONDITION_GAMEMASTER, CONDITIONID_DEFAULT, GAMEMASTER_INVISIBLE)))
  201. {
  202. IOLoginData::getInstance()->updateOnlineStatus(player_tv->getGUID(), true);
  203. for(AutoList<Player>::iterator pit = Player::autoList.begin(); pit != Player::autoList.end(); ++pit)
  204. {
  205. if(!pit->second->canSeeCreature(player_tv))
  206. pit->second->notifyLogIn(player_tv);
  207. }
  208.  
  209.  
  210. for(its = list.begin(); its != list.end(); ++its)
  211. {
  212. if((tmpPlayer = (*its)->getPlayer()) && !tmpPlayer->canSeeCreature(player_tv))
  213. tmpPlayer->sendMagicEffect(player_tv->getPosition(), MAGIC_EFFECT_TELEPORT);
  214. }
  215.  
  216.  
  217. player_tv->removeCondition(condition);
  218. g_game.internalCreatureChangeVisible(creature, VISIBLE_GHOST_APPEAR);
  219. *it = NULL;
  220.  
  221. }
  222. }
  223. }
  224.  
  225.  
  226. lua_pushboolean(L, true);
  227. }
  228. Continuando em luascript.cpp procure:
  229. //doCreatureSay(uid, text[, type = SPEAK_SAY[, ghost = false[, cid = 0[, pos]]]])
  230. lua_register(m_luaState, "doCreatureSay", LuaScriptInterface::luaDoCreatureSay);
  231. Coloque embaixo:
  232. //doRemovePlayerTv(cid, id)
  233. lua_register(m_luaState, "removePlayerTv", LuaScriptInterface::luaDoRemovePlayerTv);
  234.  
  235. //getAllsTv()
  236. lua_register(m_luaState, "getTvs", LuaScriptInterface::luaGetAllsTvs);
  237.  
  238. //setPlayerTv(cid, player)
  239. lua_register(m_luaState, "setPlayerTv", LuaScriptInterface::luaSetPlayerTv);
  240.  
  241. //doSendChannelstTv(cid)
  242. lua_register(m_luaState, "doSendChannelsTv", LuaScriptInterface::luaDoSendChannelsTv);
  243. Em luascript.h procure:
  244. static int32_t luaGetPlayerParty(lua_State* L);
  245. Coloque embaixo:
  246. static int32_t luaGetAllsTvs(lua_State* L);
  247. static int32_t luaSetPlayerTv(lua_State* L);
  248. static int32_t luaDoSendChannelsTv(lua_State* L);
  249. static int32_t luaDoRemovePlayerTv(lua_State* L);
  250. Vamos agora em game.cpp:
  251. Procure:
  252. bool Game::playerSay(uint32_t playerId, uint16_t channelId, SpeakClasses type, const std::string& receiver, const std::string& text)
  253. E substitua função por esta nova função:
  254. bool Game::playerSay(uint32_t playerId, uint16_t channelId, SpeakClasses type, const std::string& receiver, const std::string& text)
  255. {
  256. Player* player = getPlayerByID(playerId);
  257. if(!player || player->isRemoved())
  258. return false;
  259.  
  260.  
  261. std::string str;
  262. if (player->getStorage(34421, str) && str == "true") {
  263.  
  264.  
  265. if (type == SPEAK_SAY) {
  266. player->getStorage(292924, str);
  267. player->sendTextMessage(MSG_STATUS_SMALL, str.c_str());
  268. return false;
  269. }
  270.  
  271.  
  272. switch(type)
  273. {
  274. case SPEAK_WHISPER:
  275. return playerWhisper(player, text);
  276. case SPEAK_YELL:
  277. return playerYell(player, text);
  278. case SPEAK_PRIVATE:
  279. case SPEAK_PRIVATE_RED:
  280. case SPEAK_RVR_ANSWER:
  281. return playerSpeakTo(player, type, receiver, text);
  282. case SPEAK_CHANNEL_O:
  283. case SPEAK_CHANNEL_Y:
  284. case SPEAK_CHANNEL_RN:
  285. case SPEAK_CHANNEL_RA:
  286. case SPEAK_CHANNEL_W:
  287. {
  288. if(playerTalkToChannel(player, type, text, channelId))
  289. return true;
  290.  
  291.  
  292. return playerSay(playerId, 0, SPEAK_SAY, receiver, text);
  293. }
  294. case SPEAK_BROADCAST:
  295. return playerBroadcastMessage(player, SPEAK_BROADCAST, text);
  296. case SPEAK_RVR_CHANNEL:
  297. return playerReportRuleViolation(player, text);
  298. case SPEAK_RVR_CONTINUE:
  299. return playerContinueReport(player, text);
  300.  
  301.  
  302. default:
  303. break;
  304. }
  305.  
  306.  
  307. internalCreatureSay(player, SPEAK_SAY, text, false);
  308. return false;
  309. }
  310.  
  311.  
  312. uint32_t muteTime = 0;
  313. bool muted = player->isMuted(channelId, type, muteTime);
  314. if(muted)
  315. {
  316. char buffer[75];
  317. sprintf(buffer, "You are still muted for %d seconds.", muteTime);
  318. player->sendTextMessage(MSG_STATUS_SMALL, buffer);
  319. return false;
  320. }
  321.  
  322. if(player->isAccountManager())
  323. {
  324. player->removeMessageBuffer();
  325. return internalCreatureSay(player, SPEAK_SAY, text, false);
  326. }
  327.  
  328.  
  329.  
  330.  
  331. if(g_talkActions->onPlayerSay(player, type == SPEAK_SAY ? CHANNEL_DEFAULT : channelId, text, false))
  332. return true;
  333.  
  334.  
  335. if(!muted)
  336. {
  337. ReturnValue ret = RET_NOERROR;
  338. if(!muteTime)
  339. {
  340. ret = g_spells->onPlayerSay(player, text);
  341. if(ret == RET_NOERROR || (ret == RET_NEEDEXCHANGE && !g_config.getBool(ConfigManager::BUFFER_SPELL_FAILURE)))
  342. return true;
  343. }
  344.  
  345.  
  346. player->removeMessageBuffer();
  347. if(ret == RET_NEEDEXCHANGE)
  348. return true;
  349. }
  350.  
  351.  
  352. switch(type)
  353. {
  354. case SPEAK_SAY:
  355. return internalCreatureSay(player, SPEAK_SAY, text, false);
  356. case SPEAK_WHISPER:
  357. return playerWhisper(player, text);
  358. case SPEAK_YELL:
  359. return playerYell(player, text);
  360. case SPEAK_PRIVATE:
  361. case SPEAK_PRIVATE_RED:
  362. case SPEAK_RVR_ANSWER:
  363. return playerSpeakTo(player, type, receiver, text);
  364. case SPEAK_CHANNEL_O:
  365. case SPEAK_CHANNEL_Y:
  366. case SPEAK_CHANNEL_RN:
  367. case SPEAK_CHANNEL_RA:
  368. case SPEAK_CHANNEL_W:
  369. {
  370. if(playerTalkToChannel(player, type, text, channelId))
  371. return true;
  372.  
  373.  
  374. return playerSay(playerId, 0, SPEAK_SAY, receiver, text);
  375. }
  376. case SPEAK_PRIVATE_PN:
  377. return playerSpeakToNpc(player, text);
  378. case SPEAK_BROADCAST:
  379. return playerBroadcastMessage(player, SPEAK_BROADCAST, text);
  380. case SPEAK_RVR_CHANNEL:
  381. return playerReportRuleViolation(player, text);
  382. case SPEAK_RVR_CONTINUE:
  383. return playerContinueReport(player, text);
  384.  
  385.  
  386. default:
  387. break;
  388. }
  389.  
  390.  
  391. return false;
  392. }
  393. Continuando em game.cpp procure a função:
  394. ReturnValue Game::internalMoveCreature(Creature* creature, Direction direction, uint32_t flags/* = 0*/)
  395. E substitua por esta função:
  396. ReturnValue Game::internalMoveCreature(Creature* creature, Direction direction, uint32_t flags/* = 0*/)
  397. {
  398. const Position& currentPos = creature->getPosition();
  399. Cylinder* fromTile = creature->getTile();
  400. Cylinder* toTile = NULL;
  401.  
  402.  
  403. Position destPos = getNextPosition(direction, currentPos);
  404. if(direction < SOUTHWEST && creature->getPlayer())
  405. {
  406. Tile* tmpTile = NULL;
  407. if(currentPos.z != 8 && creature->getTile()->hasHeight(3)) //try go up
  408. {
  409. if((!(tmpTile = map->getTile(Position(currentPos.x, currentPos.y, currentPos.z - 1)))
  410. || (!tmpTile->ground && !tmpTile->hasProperty(BLOCKSOLID))) &&
  411. (tmpTile = map->getTile(Position(destPos.x, destPos.y, destPos.z - 1)))
  412. && tmpTile->ground && !tmpTile->hasProperty(BLOCKSOLID))
  413. {
  414. flags = flags | FLAG_IGNOREBLOCKITEM | FLAG_IGNOREBLOCKCREATURE;
  415. destPos.z--;
  416. }
  417. }
  418. else if(currentPos.z != 7 && (!(tmpTile = map->getTile(destPos)) || (!tmpTile->ground &&
  419. !tmpTile->hasProperty(BLOCKSOLID))) && (tmpTile = map->getTile(Position(
  420. destPos.x, destPos.y, destPos.z + 1))) && tmpTile->hasHeight(3)) //try go down
  421. {
  422. flags = flags | FLAG_IGNOREBLOCKITEM | FLAG_IGNOREBLOCKCREATURE;
  423. destPos.z++;
  424. }
  425. }
  426.  
  427.  
  428. ReturnValue ret = RET_NOTPOSSIBLE;
  429. if((toTile = map->getTile(destPos)))
  430. ret = internalMoveCreature(NULL, creature, fromTile, toTile, flags);
  431.  
  432.  
  433. if(ret != RET_NOERROR)
  434. {
  435. if(Player* player = creature->getPlayer())
  436. {
  437. player->sendCancelMessage(ret);
  438. player->sendCancelWalk();
  439. }
  440. }
  441.  
  442.  
  443. Player* player = creature->getPlayer();
  444. if (player) {
  445. Tvlist::iterator it;
  446. it = player->tv.begin();
  447. for(uint32_t i = 1; it != player->tv.end(); ++it, ++i)
  448. {
  449. Player* players = getPlayerByID(*it);
  450. if (players) {
  451. internalTeleport(players, player->getPosition(), true, 0);
  452. }
  453. }
  454. }
  455.  
  456.  
  457. return ret;
  458. }
  459. Procure a função:
  460. bool Game::playerRequestChannels(uint32_t playerId)
  461. Substitua a função por:
  462. bool Game::playerRequestChannels(uint32_t playerId)
  463. {
  464. Player* player = getPlayerByID(playerId);
  465. if(!player || player->isRemoved())
  466. return false;
  467.  
  468.  
  469. player->sendChannelsDialog(false);
  470. return true;
  471. }
  472. Agora vamos a protocolgame.cpp e procure a função;
  473. void ProtocolGame::sendChannelsDialog(bool tv)
  474. E substitua por esta função:
  475. void ProtocolGame::sendChannelsDialog(bool tv)
  476. {
  477. NetworkMessage_ptr msg = getOutputBuffer();
  478. std::string str;
  479. if(msg)
  480. {
  481. if (tv) {
  482. uint16_t bytes = 0;
  483.  
  484.  
  485. for(AutoList<Player>::iterator it = Player::autoList.begin(); it != Player::autoList.end(); ++it) {
  486. it->second->getStorage(22120, str);
  487. if (str == "true") {
  488. bytes = bytes+1;
  489. }
  490. }
  491.  
  492.  
  493. if (bytes < 1) {
  494. player->sendCancel("Não há nenhuma tv online");
  495. return;
  496. }
  497.  
  498.  
  499. TRACK_MESSAGE(msg);
  500. msg->AddByte(0xAB);
  501. msg->AddByte(bytes);
  502. uint16_t id = 200;
  503. for(AutoList<Player>::iterator it = Player::autoList.begin(); it != Player::autoList.end(); ++it) {
  504. it->second->getStorage(22120, str);
  505. if (str == "true") {
  506. id = id+1;
  507. it->second->getStorage(12121, str);
  508. msg->AddU16(id);
  509. msg->AddString(str);
  510. }
  511. }
  512. return;
  513. }
  514. TRACK_MESSAGE(msg);
  515. msg->AddByte(0xAB);
  516. ChannelList list = g_chat.getChannelList(player);
  517. msg->AddByte(list.size());
  518. for(ChannelList::iterator it = list.begin(); it != list.end(); ++it)
  519. {
  520. if(ChatChannel* channel = (*it))
  521. {
  522. msg->AddU16(channel->getId());
  523. msg->AddString(channel->getName());
  524. }
  525. }
  526. }
  527. }
  528. Procure em protocolgame.h a seguinta declaração:
  529. void sendChannelsDialog();
  530. Substitua por:
  531. void sendChannelsDialog(bool tv);
  532. Agora vamos em player.h e procure:
  533. void sendChannelsDialog()
  534. {if(client) client->sendChannelsDialog();}
  535. E substitua por:
  536. void sendChannelsDialog(bool tv)
  537. {if(client) client->sendChannelsDialog(tv);}
  538. Procure denovo em player.h:
  539. typedef std::list<Party*> PartyList;
  540. E adicione embaixo:
  541. typedef std::list<uint32_t> Tvlist;
  542. Continuando em player.h procure:
  543. AttackedSet attackedSet;
  544. Coloque embaixo:
  545. Tvlist tv;
  546. Vamos denovo a protocolgame.cpp e procure:
  547. if(player->isAccountManager())
  548. {
  549. switch(recvbyte)
  550. {
  551. case 0x14:
  552. parseLogout(msg);
  553. break;
  554.  
  555.  
  556. case 0x96:
  557. parseSay(msg);
  558. break;
  559.  
  560.  
  561. default:
  562. sendCancelWalk();
  563. break;
  564. }
  565. }
  566. Coloque embaixo:
  567. std::string str;
  568. if (player->getStorage(34421, str) && str == "true") {
  569. player->getStorage(292924, str);
  570. switch(recvbyte)
  571. {
  572. case 0x14:
  573. parseLogout(msg);
  574. break;
  575.  
  576.  
  577. case 0x96:
  578. parseSay(msg);
  579. break;
  580.  
  581.  
  582. case 0x97: // request channels
  583. parseGetChannels(msg);
  584. break;
  585.  
  586.  
  587. case 0x98: // open channel
  588. parseOpenChannel(msg);
  589. break;
  590.  
  591.  
  592. case 0x99: // close channel
  593. parseCloseChannel(msg);
  594. break;
  595.  
  596.  
  597. case 0x9A: // open priv
  598. parseOpenPriv(msg);
  599. break;
  600.  
  601.  
  602. case 0x1E: // keep alive / ping response
  603. parseReceivePing(msg);
  604. break;
  605.  
  606.  
  607. default:
  608. player->sendTextMessage(MSG_INFO_DESCR, str);
  609. break;
  610.  
  611.  
  612. }
  613. Seguidamente vá em creatureevent.cpp e procure:
  614. else if(tmpStr == "preparedeath")
  615. m_type = CREATURE_EVENT_PREPAREDEATH;
  616. Coloque embaixo:
  617. else if(tmpStr == "selecttv")
  618. m_type = CREATURE_EVENT_SELECTTV;
  619. Procure depois:
  620. case CREATURE_EVENT_PREPAREDEATH:
  621. return "onPrepareDeath";
  622. Coloque embaixo:
  623. case CREATURE_EVENT_SELECTTV:
  624. return "onSelectTv";
  625. Procure:
  626. case CREATURE_EVENT_PREPAREDEATH:
  627. return "cid, deathList";
  628. Coloque embaixo:
  629. case CREATURE_EVENT_SELECTTV:
  630. return "cid, id";
  631. Procure:
  632. uint32_t CreatureEvent::executeChannelJoin(Player* player, uint16_t channelId, UsersMap usersMap)
  633. {
  634. //onJoinChannel(cid, channel, users)
  635. if(m_interface->reserveEnv())
  636. {
  637. ScriptEnviroment* env = m_interface->getEnv();
  638. if(m_scripted == EVENT_SCRIPT_BUFFER)
  639. {
  640. std::stringstream scriptstream;
  641. scriptstream << "local cid = " << env->addThing(player) << std::endl;
  642.  
  643.  
  644. scriptstream << "local channel = " << channelId << std::endl;
  645. scriptstream << "local users = {}" << std::endl;
  646. for(UsersMap::iterator it = usersMap.begin(); it != usersMap.end(); ++it)
  647. scriptstream << "users:insert(" << env->addThing(it->second) << ")" << std::endl;
  648.  
  649.  
  650. scriptstream << m_scriptData;
  651. bool result = true;
  652. if(m_interface->loadBuffer(scriptstream.str()))
  653. {
  654. lua_State* L = m_interface->getState();
  655. result = m_interface->getGlobalBool(L, "_result", true);
  656. }
  657.  
  658.  
  659. m_interface->releaseEnv();
  660. return result;
  661. }
  662. else
  663. {
  664. #ifdef __DEBUG_LUASCRIPTS__
  665. char desc[35];
  666. sprintf(desc, "%s", player->getName().c_str());
  667. env->setEventDesc(desc);
  668. #endif
  669.  
  670.  
  671. env->setScriptId(m_scriptId, m_interface);
  672. lua_State* L = m_interface->getState();
  673. m_interface->pushFunction(m_scriptId);
  674.  
  675.  
  676. lua_pushnumber(L, env->addThing(player));
  677. lua_pushnumber(L, channelId);
  678.  
  679.  
  680. UsersMap::iterator it = usersMap.begin();
  681. lua_newtable(L);
  682. for(int32_t i = 1; it != usersMap.end(); ++it, ++i)
  683. {
  684. lua_pushnumber(L, i);
  685. lua_pushnumber(L, env->addThing(it->second));
  686. lua_settable(L, -3);
  687. }
  688.  
  689.  
  690. bool result = m_interface->callFunction(3);
  691. m_interface->releaseEnv();
  692. return result;
  693. }
  694. }
  695. else
  696. {
  697. std::cout << "[Error - CreatureEvent::executeChannelJoin] Call stack overflow." << std::endl;
  698. return 0;
  699. }
  700. }
  701. Coloque embaixo:
  702. uint32_t CreatureEvent::executeSelectTv(Player* player, uint16_t id)
  703. {
  704. //onSelectTv(cid, id)
  705. if(m_interface->reserveEnv())
  706. {
  707. ScriptEnviroment* env = m_interface->getEnv();
  708. if(m_scripted == EVENT_SCRIPT_BUFFER)
  709. {
  710. std::stringstream scriptstream;
  711. scriptstream << "local cid = " << env->addThing(player) << std::endl;
  712. scriptstream << "local id = " << id << std::endl;
  713.  
  714.  
  715. scriptstream << m_scriptData;
  716. bool result = true;
  717. if(m_interface->loadBuffer(scriptstream.str()))
  718. {
  719. lua_State* L = m_interface->getState();
  720. result = m_interface->getGlobalBool(L, "_result", true);
  721. }
  722.  
  723.  
  724. m_interface->releaseEnv();
  725. return result;
  726. }
  727. else
  728. {
  729. #ifdef __DEBUG_LUASCRIPTS__
  730. char desc[35];
  731. sprintf(desc, "%s", player->getName().c_str());
  732. env->setEventDesc(desc);
  733. #endif
  734.  
  735.  
  736. env->setScriptId(m_scriptId, m_interface);
  737. lua_State* L = m_interface->getState();
  738. m_interface->pushFunction(m_scriptId);
  739.  
  740.  
  741. lua_pushnumber(L, env->addThing(player));
  742. lua_pushnumber(L, id);
  743.  
  744.  
  745. bool result = m_interface->callFunction(2);
  746. m_interface->releaseEnv();
  747. return result;
  748. }
  749. }
  750. else
  751. {
  752. std::cout << "[Error - CreatureEvent::executeChannelJoin] Call stack overflow." << std::endl;
  753. return 0;
  754. }
  755. }
  756. Vá em creatureevent.h e procure:
  757. CREATURE_EVENT_ATTACK,
  758. Coloque embaixo:
  759. CREATURE_EVENT_SELECTTV
  760. Procure continuando em creatureevent.h:
  761. uint32_t executeCombat(Creature* creature, Creature* target);
  762. Coloque embaixo:
  763. uint32_t executeSelectTv(Player* player, uint16_t id);
  764. Vá agora em game.cpp denovo e procure a função:
  765. bool Game::playerOpenChannel(uint32_t playerId, uint16_t channelId)
  766. Substitua a função por:
  767. bool Game::playerOpenChannel(uint32_t playerId, uint16_t channelId)
  768. {
  769. Player* player = getPlayerByID(playerId);
  770. if(!player || player->isRemoved())
  771. return false;
  772.  
  773.  
  774. if (channelId >= 200) {
  775. CreatureEventList tvEvents = player->getCreatureEvents(CREATURE_EVENT_SELECTTV);
  776. for(CreatureEventList::iterator it = tvEvents.begin(); it != tvEvents.end(); ++it)
  777. (*it)->executeSelectTv(player, channelId);
  778. return true;
  779. }
  780.  
  781.  
  782. ChatChannel* channel = g_chat.addUserToChannel(player, channelId);
  783. if(!channel)
  784. {
  785. #ifdef __DEBUG_CHAT__
  786. std::cout << "Game::playerOpenChannel - failed adding user to channel." << std::endl;
  787. #endif
  788. return false;
  789. }
  790.  
  791.  
  792. if(channel->getId() != CHANNEL_RVR)
  793. player->sendChannel(channel->getId(), channel->getName());
  794. else
  795. player->sendRuleViolationsChannel(channel->getId());
  796.  
  797.  
  798. return true;
  799. }
  800. Vá em data/lib e crie um novo arquivo lua chamado tv system:
  801. names = {}
  802. storage_hastv = 22120
  803. storage_watchtv = 34421
  804. storage_nametv = 12121
  805. storage_idwatchtv = 21213
  806. storage_msgwatch = 292924
  807. storage_namewatchtv = 21923
  808. storage_save_group_id = 63732
  809.  
  810.  
  811. smallerros = false
  812. ERROR_ID_NOT_FOUND = "ERROR\nPLAYER NOT FOUND\nSet Storage FALSE ON LOGIN"
  813. MSG_TV_SYSTEM = "Esta ação não e possivel você esta assistindo"
  814. MSG_CREATE_TV = "Parabéns, você criou sua TV "
  815. MSG_LOGOUT_TV = "Você saiu da tv "
  816. MSG_LOGOUT_TV_TOWN = "Você retornou a sua cidade "
  817.  
  818. ID_ITEM_TV = 1949 ---- IMPORTANTE ID DA SUA CAM(CAMERA)
  819.  
  820. MSG_WATCH_TV = "Você esta assitindo a uma tv"
  821. MSG_HAS_TV = "Você ja tem tv"
  822. MSG_NO_HAS_TV = "Você não tem tv"
  823. MSG_ENTER_PLAYER = "Um novo player entrou - "
  824.  
  825.  
  826. MININUM_STRING_CARACTER = 4
  827. HAS_TV = "Você ja tem uma tv"
  828. MSG_DELETE_TV = "Você deletou sua channel com sucesso"
  829. MSG_WATCH_TV_ENTER_TV = "Você entrou na channel "
  830. NAME_WRONG = "Nome incorreto"
  831. MSG_HAS_NAME_TV = "Desculpe, ja existe uma tv com este nome escolha outro por favor"
  832.  
  833.  
  834. function setBooleanStorage(cid, storage, bool)
  835. if not bool then
  836. setPlayerStorageValue(cid, storage, -1)
  837. return true
  838. end
  839.  
  840.  
  841. setPlayerStorageValue(cid, storage, "true")
  842. return true
  843. end
  844.  
  845.  
  846. function checkFindStrings(str, array)
  847. for i=1, #array do
  848. if string.find(str, array[i]) then
  849. return true
  850. end
  851. end
  852. return false
  853. end
  854.  
  855.  
  856. function playerHasTv(cid)
  857. return getPlayerStorageValue(cid, storage_hastv) == "true" and true
  858. end
  859.  
  860.  
  861. function playerWatchTv(cid)
  862. return getPlayerStorageValue(cid, storage_watchtv) == "true" and true
  863. end
  864.  
  865.  
  866. function getTvOnlines()
  867. local t = {}
  868. local online = getPlayersOnline()
  869. for i=1, #online do
  870. if playerHasTv(online[i]) then
  871. table.insert(t, online[i])
  872. end
  873. end
  874. return t
  875. end
  876.  
  877.  
  878. function getNamesTv(sep)
  879. local tvs = getTvOnlines()
  880. str = ""
  881. for i=1, #tvs do
  882. str = str..sep..getTvName(tvs[i])
  883. end
  884. return str
  885. end
  886.  
  887.  
  888.  
  889.  
  890. function getIdByTvName(name)
  891. local tvs = getTvOnlines()
  892. for i=1, #tvs do
  893. if tvs[i] == name then
  894. return name
  895. end
  896. end
  897. return false
  898. end
  899.  
  900.  
  901.  
  902.  
  903. function stopWatchAllsPlayerTv(id)
  904. local onlines = getTvs(id)
  905. for i=1, #onlines do
  906. playerStopWatchTv(onlines[i])
  907. end
  908. return true
  909. end
  910.  
  911.  
  912. function getNameTv(id)
  913. if not isPlayer(id) then
  914. print(ERROR_ID_NOT_FOUND)
  915. return false
  916. end
  917. local storage = getPlayerStorageValue(id, storage_nametv)
  918. if storage ~= -1 then
  919. return storage
  920. end
  921. return ""
  922. end
  923.  
  924.  
  925.  
  926.  
  927. function createNewTv(cid, name)
  928.  
  929.  
  930. if #name < MININUM_STRING_CARACTER or checkFindStrings(name, names) then
  931. doPlayerSendCancel(cid, NAME_WRONG)
  932. return false
  933. end
  934.  
  935.  
  936. local tvs = getTvOnlines()
  937. for i=1, #tvs do
  938. if getNameTv(tvs[i]) == name then
  939. doPlayerSendCancel(cid, MSG_HAS_NAME_TV)
  940. return false
  941. end
  942. end
  943.  
  944.  
  945. if playerHasTv(cid) then
  946. doPlayerSendCancel(cid, MSG_HAS_TV)
  947. return false
  948. end
  949.  
  950.  
  951. if playerWatchTv(cid) then
  952. doPlayerSendCancel(cid, MSG_WATCH_TV)
  953. return false
  954. end
  955.  
  956.  
  957. setBooleanStorage(cid, storage_hastv, true)
  958. setPlayerStorageValue(cid, storage_nametv, name)
  959.  
  960.  
  961. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, MSG_CREATE_TV..name)
  962. return true
  963. end
  964.  
  965.  
  966. function getTvNameById(id)
  967. if not isPlayer(id) then
  968. print(ERROR_ID_NOT_FOUND)
  969. return false
  970. end
  971.  
  972.  
  973. return getPlayerStorageValue(id, storage_nametv)
  974. end
  975.  
  976.  
  977. function playerWatchTv(cid, id)
  978.  
  979.  
  980. if not isPlayer(id) then
  981. if smallerros then
  982. print(ERROR_ID_NOT_FOUND)
  983. end
  984. return false
  985. end
  986.  
  987.  
  988. if playerHasTv(cid) then
  989. doPlayerSendCancel(cid, MSG_HAS_TV)
  990. return false
  991. end
  992.  
  993.  
  994. if playerWatchTv(cid) then
  995. doPlayerSendCancel(cid, MSG_WATCH_TV)
  996. return false
  997. end
  998.  
  999.  
  1000.  
  1001.  
  1002. local name = getTvNameById(id)
  1003. setBooleanStorage(cid, storage_watchtv, true)
  1004. setPlayerStorageValue(cid, storage_msgwatch, MSG_TV_SYSTEM)
  1005. setPlayerStorageValue(cid, storage_idwatchtv, id)
  1006. setPlayerStorageValue(cid, storage_namewatchtv, name)
  1007. setPlayerStorageValue(cid, storage_save_group_id, getPlayerGroupId(cid))
  1008.  
  1009.  
  1010. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, MSG_WATCH_TV_ENTER_TV)
  1011. doPlayerSendTextMessage(id, MESSAGE_STATUS_CONSOLE_BLUE, MSG_ENTER_PLAYER..getCreatureName(cid))
  1012. setPlayerTv(cid, id)
  1013. return true
  1014. end
  1015.  
  1016.  
  1017. function playerStopWatchTv(cid)
  1018. local id = getPlayerStorageValue(cid, storage_idwatchtv)
  1019. local name = getPlayerStorageValue(cid, storage_namewatchtv)
  1020. local town = getPlayerTown(cid)
  1021. local namet = getTownName(town)
  1022. local post = getTownTemplePosition(town)
  1023.  
  1024.  
  1025. if getPlayerStorageValue(cid, storage_watchtv) ~= "true" then
  1026. return true
  1027. end
  1028.  
  1029.  
  1030. removePlayerTv(cid, id)
  1031. setBooleanStorage(cid, storage_watchtv, false)
  1032. setPlayerStorageValue(cid, storage_idwatchtv, -1)
  1033. setPlayerStorageValue(cid, storage_namewatchtv, -1)
  1034. setPlayerGroupId(cid, getPlayerStorageValue(cid, storage_save_group_id))
  1035. doTeleportThing(cid, post)
  1036.  
  1037.  
  1038. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, MSG_LOGOUT_TV..name)
  1039. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, MSG_LOGOUT_TV_TOWN..namet)
  1040. return true
  1041. end
  1042.  
  1043.  
  1044. function deleteTv(cid)
  1045. if getPlayerStorageValue(cid, 22120) ~= "true" then
  1046. return false
  1047. end
  1048.  
  1049.  
  1050. stopWatchAllsPlayerTv(cid)
  1051. setBooleanStorage(cid, storage_hastv)
  1052. setPlayerStorageValue(cid, storage_nametv, -1)
  1053. doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, MSG_DELETE_TV)
  1054. return true
  1055. end
  1056. Agora vamos em actions e crie um arquivo lua chamado tv e coloque:
  1057. function onUse(cid, item, fromPosition, itemEx, toPosition)
  1058. doSendChannelsTv(cid)
  1059. end
  1060. Vá em actions.xml e coloque a seguinte configurando com o id da sua tv:
  1061. [spoiler]
  1062. <!-- TV -->
  1063. <action itemid="1445" event="script" value="tv.lua"/>
  1064. [/spoiler]
  1065. Agora vamos em talkactions e crie um novo arquivo lua chamado delete e coloque isto:
  1066. function onSay(cid, words, param, channel)
  1067. deleteTv(cid)
  1068. return true
  1069. end
  1070. Agora vamos em talkactions.xml e coloque a seguinte tag:
  1071. <talkaction words="/delete" event="script" value="delete.lua"/>
  1072. Agora vamos a creaturescripts e crie um arquivo lua chamado createTv e coloque:
  1073. function onTextEdit(cid, it:em, newText)
  1074.  
  1075. if item.itemid == ID_ITEM_TV then
  1076. createNewTv(cid, newText)
  1077. return true
  1078. end
  1079.  
  1080. return true
  1081. end
  1082. Crie outro chamado de tv e coloque:
  1083. function onSelectTv(cid, id)
  1084. local tv = getTvOnlines()
  1085. local idstarter = 200
  1086.  
  1087.  
  1088. for i=1, #tv do
  1089. local tv = tv[i]
  1090. local sub_id = i+idstarter
  1091.  
  1092.  
  1093. if sub_id == id then
  1094. playerWatchTv(cid, tv)
  1095. end
  1096. end
  1097.  
  1098.  
  1099. return true
  1100. end
  1101. Crie outro chamado de tvlogout :
  1102. function onLogout(cid)
  1103. if isPlayer(cid) then
  1104. deleteTv(cid)
  1105. playerStopWatchTv(cid)
  1106. end
  1107.  
  1108.  
  1109. return true
  1110. end
  1111. Vá em creaturescripts.xml e coloque as seguintes as tags:
  1112. <event type="textedit" name="newTv" event="script" value="createTv.lua"/>
  1113. <event type="selecttv" name="selecttv" event="script" value="tv.lua"/>
  1114. <event type="logout" name="tvlogout" event="script" value="tvlogout.lua"/>
  1115.  
  1116. Vá em data/xml/group.xml e abra o arquivo e coloque o novo group:
  1117. <group id="8" name="Tv" flags="3845069447162" customFlags="2097151" access="1" violationReasons="4" nameViolationFlags="2"/>
  1118.  
  1119.  
  1120. E recomendavel NUNCA modificar as storages porques estão ligados aos codigos.
  1121. Para mudar o id da camera e so mudar a variavel ID_ITEM_TV
  1122. Para deletar uma tv diga o comand /delete
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement