设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 2774|回复: 13
打印 上一主题 下一主题

[有事请教] 用了Online_Chat.js网络插件聊天白屏

[复制链接]

Lv3.寻梦者

梦石
0
星屑
1409
在线时间
200 小时
注册时间
2021-8-19
帖子
43
跳转到指定楼层
1
发表于 2021-10-12 10:54:04 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
20星屑
用了这种Online_Chat.js网络插件,可以同屏,但是别人在打怪界面,我发消息打怪的就会白屏卡死,怎么解决啊,具体就是我在聊天框发个消息,别的处于待机的玩家没事,别的处于打怪界面的玩家集体白屏卡死

QQ截图20211012105121.png (33.99 KB, 下载次数: 24)

QQ截图20211012105121.png

Lv4.逐梦者

梦石
0
星屑
7253
在线时间
1372 小时
注册时间
2018-12-16
帖子
1952
2
发表于 2021-10-12 11:30:25 | 只看该作者
01. Online_Chat.js 你要發出來不然我們怎麼幫你看?
02. 不然發個範例工程來看.
03. 不然要有個連結可以看.
回复

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1409
在线时间
200 小时
注册时间
2021-8-19
帖子
43
3
 楼主| 发表于 2021-10-12 11:50:02 | 只看该作者
  1. var Imported = Imported || {};
  2. Imported.Online_Chat = true;

  3. (function () {
  4. var Nasty = Nasty || {};
  5. //=============================================================================
  6. // Online Chat
  7. // Version: 1.0.5 - Allows for chat to be retained on map transfer/menu/battle
  8. // Version: 1.0.4 - Add function to enable/disable chat and chat by leader name
  9. //=============================================================================

  10. //=============================================================================
  11. /*:
  12. * @plugindesc Online Chat for Neldersons Online Core
  13. * <Online_Chat>
  14. * @author Nelderson
  15. *
  16. * @param Chat Key Code
  17. * @desc Key code to toggle the chat on/off (Default F1 - 112)
  18. * @default 112
  19. *
  20. * @param Chat with Username or Character Name
  21. * @desc 0=Username 1=Character Name (Leader of party)
  22. * @default 0
  23. *
  24. * @param Input Character limit
  25. * @desc Limit the amount of characters per message
  26. * @default 80
  27. *
  28. * @param Room Name by Map
  29. * @desc Change the room name by map that you are on?
  30. * @default false
  31. *
  32. * @param Recall Message Limit
  33. * @desc Recalls this many messages when switching maps/battles/etc
  34. * @default 20
  35. *
  36. * @param Chat Username Color
  37. * @desc Color of usernames in chat window
  38. * @default #c92cac
  39. *
  40. * @param Chat Text Color
  41. * @desc Color of chat text in chat window
  42. * @default #000000
  43. *
  44. * @param Chat Text Window Width
  45. * @desc Chat Window width
  46. * @default 800
  47. *
  48. * @param Chat Text Window Height
  49. * @desc Chat Window Height
  50. * @default 500
  51. *
  52. * @param Chat Text Window Offset X
  53. * @desc Offset X Poisition of Chat Text Window from CENTER
  54. * @default 0
  55. *
  56. * @param Chat Text Window Offset Y
  57. * @desc Offset Y Poisition of Chat Text Window from CENTER
  58. * @default 0
  59. *
  60. * @param Chat Text Font
  61. * @desc Font for Chat Text (Defaults to game default)
  62. * @default
  63. *
  64. * @param Chat Text Font Size
  65. * @desc Font size for Chat Text
  66. * @default 15
  67. *
  68. * @param Chat Text Background Color
  69. * @desc Background color and transparency for Chat Window
  70. * @default rgba(255,255,255,0.7)
  71. *
  72. * @param Chat Text Background Picture
  73. * @desc Background Pic from img/pictures folder instead of Background Color
  74. * @default
  75. *
  76. * @param Chat Input Window Width
  77. * @desc Chat Input Window width
  78. * @default 600
  79. *
  80. * @param Chat Input Window Height
  81. * @desc Chat Input Window Height
  82. * @default 40
  83. *
  84. * @param Chat Input Window Offset X
  85. * @desc Offset X Poisition of Chat Input Window from CENTER
  86. * @default 0
  87. *
  88. * @param Chat Input Window Offset Y
  89. * @desc Offset Y Poisition of Chat Input Window from CENTER
  90. * @default 564
  91. *
  92. * @param Input Text Font
  93. * @desc Font for Input Text (Defaults to game default)
  94. * @default
  95. *
  96. * @param Input Text Font Size
  97. * @desc Font size for Input Text
  98. * @default 15
  99. *
  100. * @param Input Text Background Color
  101. * @desc Background color and transparency for Input Window
  102. * @default rgba(255,255,255,0.7)
  103. *
  104. * @param Input Text Background Picture
  105. * @desc Background Pic from img/pictures folder instead of Background Color
  106. * @default #FFFFFF
  107. *
  108. * @help
  109. * ============================================================================
  110. * Introduction and Instructions
  111. * ============================================================================
  112. * This plugin allows you to chat with other players.
  113. *
  114. * There are two ways to access the chat windows.  Either by plugin
  115. * command or the Key Code from the parameters(Default F1).
  116. *
  117. * The only thing that is overwritten are the defaults for the SPACEBAR
  118. * and Z key within the Input Keymapper so that they will not interfere
  119. * with typing in the chat input window
  120. *
  121. * =====================
  122. * ===Plugin Commands===
  123. * =====================
  124. *
  125. * ToggleChat - Turns Chat Windows On/Off
  126. * SendChatMessage - Sends the message in the chat input window.
  127. * EnableChat - Enables chat to be opened
  128. * DisableChat - Disables chat to be opened
  129. *
  130. */
  131. //=============================================================================
  132. var socket = null;
  133. var chatHistory = [];
  134. Nasty.Parameters = $plugins.filter(function(p)
  135.          { return p.description.contains('<Online_Chat>');})[0].parameters;

  136.   //Chat text window
  137.   var textWinWidth = Nasty.Parameters['Chat Text Window Width'];
  138.   var textWinHeight = Nasty.Parameters['Chat Text Window Height'];
  139.   var textWinOffsetX = Nasty.Parameters['Chat Text Window Offset X'];
  140.   var textWinOffsetY = Nasty.Parameters['Chat Text Window Offset Y'];
  141.   var textWinFont = Nasty.Parameters['Chat Text Font'];
  142.   var textWinFontSize = Nasty.Parameters['Chat Text Font Size'];
  143.   var textWinBack = Nasty.Parameters['Chat Text Background Color'];
  144.   var textWinBackPic = Nasty.Parameters['Chat Text Background Picture'];

  145.   //Chat input window
  146.   var inputWinWidth = Nasty.Parameters['Chat Input Window Width'];
  147.   var inputWinHeight = Nasty.Parameters['Chat Input Window Height'];
  148.   var inputWinOffsetX = Nasty.Parameters['Chat Input Window Offset X'];
  149.   var inputWinOffsetY = Nasty.Parameters['Chat Input Window Offset Y'];
  150.   var inputWinFont = Nasty.Parameters['Input Text Font'];
  151.   var inputWinFontSize = Nasty.Parameters['Input Text Font Size'];
  152.   var inputWinBack = Nasty.Parameters['Input Text Background Color'];
  153.   var inputWinBackPic = Nasty.Parameters['Input Text Background Picture'];
  154.   var inputCharLimit = Nasty.Parameters['Input Character limit'];

  155.   var chatKeyCode = Nasty.Parameters['Chat Key Code'];
  156.   var chatUserColor = Nasty.Parameters['Chat Username Color'];
  157.   var chatTextColor = Nasty.Parameters['Chat Text Color'];
  158.   var roomMapNameFlag = Nasty.Parameters['Room Name by Map'];
  159.   var NetPlayerChatNameType = Number(Nasty.Parameters['Chat with Username or Character Name']);
  160.   var recallMessageLimit = Number(Nasty.Parameters['Recall Message Limit']);

  161.   var networkName = '';

  162. var OnlineMV_ChatSystem_SocketConn_Alias = Game_Network.prototype.connectSocketsAfterLogin;
  163. Game_Network.prototype.connectSocketsAfterLogin = function(){
  164.   OnlineMV_ChatSystem_SocketConn_Alias.call(this);

  165.   $gameNetwork.connectSocket('chat','/chat',false);
  166.   socket = $gameNetwork._socket.chat;
  167.   Nasty.chatEnabled = true;

  168.   socket.on('MyID',function(data){
  169.     networkName = data.name;
  170.         });

  171.   socket.on('messageServer', function(data){
  172.     var chat = document.getElementById('txtarea');
  173.     var message = document.createElement('div');
  174.     var user = document.createElement('span');
  175.     var chatText = document.createElement('span');
  176.     //Combine user/text spans to div container
  177.     user.style.color = chatUserColor;
  178.     chatText.style.color = chatTextColor;
  179.     user.textContent = data.id+ ': ';
  180.     chatText.textContent = data.message;
  181.     message.appendChild(user);
  182.     message.appendChild(chatText);
  183.     chatHistory.push([user, chatText]);
  184.     //Append to chat text div
  185.     chat.appendChild(message);
  186.     chat.scrollTop = chat.scrollHeight;
  187.   });
  188. };

  189. //=============================================================================
  190. //  GAME CHAT code
  191. //=============================================================================

  192.   var OnlineChat_createDisplayObj_Scene_Map = Scene_Map.prototype.createDisplayObjects;
  193.   Scene_Map.prototype.createDisplayObjects = function() {
  194.     OnlineChat_createDisplayObj_Scene_Map.call(this);
  195.     this.createChatDOMElements();
  196.     this.appendChatHistory();
  197.   };

  198.   Scene_Map.prototype.appendChatHistory = function(){
  199.   var diff = chatHistory.length - recallMessageLimit;
  200.   if (diff>0) chatHistory.splice(0,diff);
  201.   var chat = document.getElementById('txtarea');
  202.     for (var i=0;i<chatHistory.length;i++){
  203.       var message = document.createElement('div');
  204.       message.appendChild(chatHistory[i][0]);
  205.       message.appendChild(chatHistory[i][1]);
  206.       chat.appendChild(message);
  207.     }
  208.   };

  209.    Scene_Map.prototype.createChatDOMElements = function(){
  210.      //Chat Bar for Inputing messages
  211.      this.chatinput = document.createElement('INPUT');
  212.      this.chatinput.id = 'chatInput';
  213.      this.chatinput.maxLength = inputCharLimit;
  214.      this.chatinput.style.fontSize = inputWinFont + 'px';
  215.      this.chatinput.style.fontStyle = inputWinFont;
  216.      this.chatinput.style.color = '#ffffff';
  217.      this.chatinput.style.fontStyle = '';
  218.      this.chatinput.style.position = 'absolute';
  219.      this.chatinput.style.textIndent = '15px';
  220.      this.chatinput.style.zIndex = 100;
  221.      this.chatinput.placeholder = '世界频道';
  222.      this.chatinput.style.color = '#FFFFFF';
  223.      this.chatinput.style.border = 'none';
  224.      this.chatinput.style.visibility = 'visible';
  225.      if (inputWinBackPic===''){
  226.        this.chatinput.style.background = inputWinBack;
  227.      }else{
  228.        this.chatinput.style.backgroundImage = "url('img/pictures/"+inputWinBackPic+".png')";
  229.      }
  230.      //Chat Message area
  231.      this.txtarea = document.createElement('div');
  232.      this.txtarea.id = 'txtarea';
  233.      this.txtarea.style.padding = '15px';
  234.      this.txtarea.style.fontSize = textWinFontSize + 'px';
  235.      this.txtarea.style.fontStyle = textWinFont;
  236.      this.txtarea.style.position = 'absolute';
  237.      this.txtarea.style.overflowY = 'auto';
  238.      this.txtarea.style.width = textWinWidth + 'px';
  239.      this.txtarea.style.height = textWinHeight + 'px';
  240.      this.txtarea.style.zIndex = 99;
  241.      this.txtarea.style.visibility = 'visible';
  242.      if (textWinBackPic===''){
  243.        this.txtarea.style.background = textWinBack;
  244.      }else{
  245.        this.txtarea.style.backgroundImage = "url('img/pictures/"+textWinBackPic+".png')";
  246.      }
  247.      //Add and adjust both DOM elements
  248.      document.body.appendChild(this.txtarea);
  249.      document.body.appendChild(this.chatinput);
  250.      //--Mobile fix for input--
  251.      $("#chatInput").tap(function(){$("#chatInput").focus();});
  252.      //-------------------------
  253.      Graphics._centerElement(this.chatinput);
  254.      Graphics._centerElement(this.txtarea);
  255.      this.chatinput.style.width = inputWinWidth +'px';
  256.      this.chatinput.style.height = inputWinHeight + 'px';
  257.      this.chatinput.style.top = inputWinOffsetY +'px';
  258.      this.chatinput.style.left = inputWinOffsetX +'px';
  259.      this.txtarea.style.left = textWinOffsetX + 'px';
  260.      this.txtarea.style.top = textWinOffsetY + 'px';

  261.      var that = this;
  262.      $("#chatInput").keypress(function(e){
  263.                         if (e.which == 13) { //enter
  264.                                 that.sendChatMessage();
  265.                         }
  266.                 });
  267.    };

  268.    var Online_Chat_SceneMap_isMenuCalled_alias = Scene_Map.prototype.isMenuCalled;
  269.    Scene_Map.prototype.isMenuCalled = function() {
  270.     if (document.activeElement===document.getElementById('chatInput')) return false;
  271.     return Online_Chat_SceneMap_isMenuCalled_alias.call(this);
  272.    };

  273.    var Online_Chat_SceneMap_ProcessTouch_alias = Scene_Map.prototype.processMapTouch;
  274.    Scene_Map.prototype.processMapTouch = function() {
  275.      if (document.activeElement!==document.getElementById('chatInput')){
  276.        Online_Chat_SceneMap_ProcessTouch_alias.call(this);
  277.      }
  278.    };

  279.    var Chat_Online_sceneMap_updtSceneAlias = Scene_Map.prototype.updateScene;
  280.    Scene_Map.prototype.updateScene = function() {
  281.      Chat_Online_sceneMap_updtSceneAlias.call(this);
  282.        if (!SceneManager.isSceneChanging()) {
  283.            this.updateChat();
  284.        }
  285.    };

  286.    Scene_Map.prototype.updateChat = function(){
  287.      if (document.activeElement===document.getElementById('chatInput')){
  288.        if (Input.isTriggered('ok')){
  289.          this.sendChatMessage();
  290.        }
  291.      }
  292.      //Toggle Chat Windows On/Off
  293.      if (Input.isTriggered('chat')){
  294.        this.toggleChat();
  295.      }
  296.    };

  297.    Scene_Map.prototype.sendChatMessage = function(){
  298.    if (NetPlayerChatNameType===1) networkName=$gameParty.leader()._name;
  299.      var value = document.getElementById('chatInput').value;
  300.      value = value.trim();
  301.      if (value==='') return;
  302.      //Emit message to server
  303.        socket.emit('clientMessage',{
  304.          id: networkName,
  305.          message: value
  306.        });
  307.      document.getElementById('chatInput').value = '';
  308.    };

  309.    Scene_Map.prototype.toggleChat = function(){
  310.      if (!Nasty.chatEnabled) {
  311.       document.getElementById('txtarea').style.visibility = 'hidden';
  312.       document.getElementById('chatInput').style.visibility = 'hidden';
  313.       return;
  314.      }
  315.      if (document.getElementById('txtarea').style.visibility ==='hidden'){
  316.        document.getElementById('txtarea').style.visibility = 'visible';
  317.        document.getElementById('chatInput').style.visibility = 'visible';
  318.        $("#chatInput").focus();
  319.      }else{
  320.        document.getElementById('txtarea').style.visibility = 'hidden';
  321.        document.getElementById('chatInput').style.visibility = 'hidden';
  322.      }
  323.    };

  324.    var NastySceneMapChat_Terminate = Scene_Map.prototype.terminate;
  325.    Scene_Map.prototype.terminate = function() {
  326.        NastySceneMapChat_Terminate.call(this);
  327.        document.body.removeChild(this.txtarea);
  328.        document.body.removeChild(this.chatinput);
  329.    };

  330.    var OnlineChat_gamePlayer_canMoveAlias = Game_Player.prototype.canMove;
  331.    Game_Player.prototype.canMove = function() {
  332.      if (document.activeElement===document.getElementById('chatInput')){
  333.        return false;
  334.      }
  335.      return OnlineChat_gamePlayer_canMoveAlias.call(this);
  336.    };

  337.    var Nel_OnlineChat_pluginCommands_alias = Game_Interpreter.prototype.pluginCommand;
  338.    Game_Interpreter.prototype.pluginCommand = function(command, args) {
  339.        Nel_OnlineChat_pluginCommands_alias.call(this, command, args);
  340.        if (command.toUpperCase() === 'TOGGLECHAT'){
  341.          if (SceneManager._scene instanceof Scene_Map){
  342.            SceneManager._scene.toggleChat();
  343.          }
  344.        }
  345.        if (command.toUpperCase() === 'SENDCHATMESSAGE'){
  346.          if (SceneManager._scene instanceof Scene_Map){
  347.            SceneManager._scene.sendChatMessage();
  348.          }
  349.        }
  350.        if (command.toUpperCase() === 'ENABLECHAT'){
  351.           Nasty.chatEnabled = true;
  352.        }
  353.        if (command.toUpperCase() === 'DISABLECHAT'){
  354.           Nasty.chatEnabled = false;
  355.           if (SceneManager._scene instanceof Scene_Map){
  356.             SceneManager._scene.toggleChat();
  357.           }
  358.        }
  359.      };

  360.   //Re-Map Input Keys
  361.   Input.keyMapper[chatKeyCode] = 'chat';
  362.   Input.keyMapper['90'] = 'none'; // Z
  363.   Input.keyMapper['32'] = 'none'; // SpaceBar
  364. })();
复制代码
回复

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1409
在线时间
200 小时
注册时间
2021-8-19
帖子
43
4
 楼主| 发表于 2021-10-12 11:56:38 | 只看该作者
play337 发表于 2021-10-12 11:30
01. Online_Chat.js 你要發出來不然我們怎麼幫你看?
02. 不然發個範例工程來看.
03. 不然要有個連結可以看. ...

大佬,代码在楼下,太多了,就如我说的那样,我发个聊天消息,其他在战斗界面的玩家立马白屏卡死,
回复

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
7253
在线时间
1372 小时
注册时间
2018-12-16
帖子
1952
5
发表于 2021-10-12 13:10:25 | 只看该作者
本帖最后由 play337 于 2021-10-12 13:12 编辑

這個我之前有裝阿!
https://forums.rpgmakerweb.com/i ... -online-core.79938/

你要先裝他要求的環境吧...
01.有很多插件要裝
02.最重要的是 你那個伺服環境要用起來
03.我測試的時候.發訊息不會當機阿. 我開兩個瀏覽器測試.都不會當機阿

所以程式應該是沒有問題的...
你有開瀏覽器測試嗎?

還是有另一種可能. 你在瀏覽器測試沒有問題. 但是其他人測試有問題...

是怎麼樣的情況呢?

對了! 測試的時候 你要用 http://localhost/
這樣下去測試...你可不能用RPG MAKER MV 的測試去測試...這樣是沒有網路連線環境的...你懂吧.... ^_^
回复

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1409
在线时间
200 小时
注册时间
2021-8-19
帖子
43
6
 楼主| 发表于 2021-10-12 13:33:13 | 只看该作者
play337 发表于 2021-10-12 13:10
這個我之前有裝阿!
https://forums.rpgmakerweb.com/index.php?threads/neldersons-mv-online-core.79938/
...

我什么都部署好了,包括服务器上面测试,本地测试,这套插件我也装了很久了,一直没什么问题,直到昨天,我一个客服端在战斗界面,另一个客服端发送消息才发现这个问题,后面开三个窗口,反复测试,就是只要有人发消息,在战斗界面的人会白屏卡死,其他没问题,然后我又把别人装这套插件的范例工程拿来测试,同样是这个问题

点评

我記得當時我每天都在作者的discord上面掛著...後來作者跟他們的好朋友說要放棄這個插件了...我想這後來也沒希望了...一堆BUG不會有人解...就棄坑了  发表于 2021-10-12 14:23
回复

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1409
在线时间
200 小时
注册时间
2021-8-19
帖子
43
7
 楼主| 发表于 2021-10-12 15:14:52 | 只看该作者
萌新一个人 发表于 2021-10-12 13:33
我什么都部署好了,包括服务器上面测试,本地测试,这套插件我也装了很久了,一直没什么问题,直到昨天, ...

谢谢,如果是这样就证实了是插件BUG,不是我设置的问题了,那问一下有办法加个开关吗?具体就是在传送到有怪的地图前关闭这个聊天的功能,这样在刷怪的时候,别人发信息就没有影响了,能实现吗?
回复

使用道具 举报

Lv6.析梦学徒

老鹰

梦石
40
星屑
33604
在线时间
6576 小时
注册时间
2012-5-26
帖子
3186

极短24评委极短23参与极短22参与极短21评委老司机慢点开短篇十吟唱者组别冠军开拓者剧作品鉴家

8
发表于 2021-10-12 15:38:28 | 只看该作者
* =====================
* ===Plugin Commands===
* =====================
*
* ToggleChat - Turns Chat Windows On/Off
* SendChatMessage - Sends the message in the chat input window.
* EnableChat - Enables chat to be opened
* DisableChat - Disables chat to be opened

插件指令 DisableChat 没法关闭这个功能吗
回复

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1409
在线时间
200 小时
注册时间
2021-8-19
帖子
43
9
 楼主| 发表于 2021-10-12 16:06:59 | 只看该作者
百里_飞柳 发表于 2021-10-12 15:38
* =====================
* ===Plugin Commands===
* =====================

这个我试过了,不行。我也不懂代码,这个应该是禁用聊天窗口,所以别人发信息我这里还是能接收的,只是不显示了,所以还是白屏
回复

使用道具 举报

Lv6.析梦学徒

老鹰

梦石
40
星屑
33604
在线时间
6576 小时
注册时间
2012-5-26
帖子
3186

极短24评委极短23参与极短22参与极短21评委老司机慢点开短篇十吟唱者组别冠军开拓者剧作品鉴家

10
发表于 2021-10-12 17:24:14 | 只看该作者
我觉得报错原因是 Scene_Battle 里面没有这个聊天框
但是它是实时接收更新聊天文本的
导致182行提取的chat对象不存在

具体怎么改我就不知道了,可能可以:如果chat不存在,就先把接收到的data存起来,回到地图上时再更新;直接扔掉
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-6-15 07:00

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表