Advertisement
Pinkishu

Untitled

Oct 19th, 2014
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.05 KB | None | 0 0
  1. /*
  2.  
  3. Usage:
  4. say /staffchat once added to player
  5.  
  6. messages arent saved through server restarts
  7.  
  8.  
  9. */
  10.  
  11. //findplayerbycommunityname("Inari").addweapon(this.name);
  12. function onCreated()
  13. {
  14. enum cmd
  15. {
  16. SEND_MESSAGE,
  17. RECEIVE_MESSAGE,
  18. LOAD_CHAT,
  19. LOGIN,
  20. LOGOUT
  21. }
  22. this.saveMessages = 30;
  23. this.users = {};
  24. this.chatMsgs = new[this.saveMessages];
  25.  
  26. }
  27.  
  28. function onPlayerLogout(obj,int)
  29. {
  30. if(obj != null)
  31. {
  32. logoutPlayer(obj);
  33. }
  34. }
  35.  
  36. function strreplace(input,search,replace)
  37. {
  38. temp.pos = input.positions(search);
  39. for(temp.i=temp.pos.size()-1;temp.i >= 0; temp.i--)
  40. {
  41. temp.posi = temp.pos[temp.i];
  42. input = input.substring(0,temp.posi) @ replace @ input.substring(temp.posi + search.length());
  43.  
  44. }
  45. return input;
  46. }
  47.  
  48. function sanitizeMsg(input)
  49. {
  50.  
  51. input = strreplace(input,"\\n"," ");
  52. input = strreplace(input,"\\r"," ");
  53. input = strreplace(input,"<","&lt;");
  54.  
  55. return input;
  56. }
  57.  
  58. function addMessage(nick,msg)
  59. {
  60. this.chatMsgs.insert(0,{nick,msg});
  61. this.chatMsgs.delete(30);
  62. sendToUsers(cmd.RECEIVE_MESSAGE,{player.communityname,temp.msg});
  63. }
  64.  
  65. function onActionServerSide(cmd,data)
  66. {
  67. if(!(findeapon(this.name) in player.weapons)) return;
  68. if( cmd == cmd.SEND_MESSAGE )
  69. {
  70. temp.msg = sanitizeMsg(data[0]);
  71.  
  72. addMessage(player.communityname,temp.msg);
  73.  
  74. }
  75. elseif( cmd == cmd.LOAD_CHAT )
  76. {
  77. loginPlayer();
  78. player.triggerClient("weapon", this.name, cmd.LOAD_CHAT,{this.chatMsgs,this.users});
  79. }
  80. elseif( cmd == cmd.LOGIN )
  81. {
  82. sendToUsers(cmd,data);
  83. }
  84. elseif( cmd == cmd.LOGOUT )
  85. {
  86. sendToUsers(cmd,data);
  87. }
  88. }
  89.  
  90. function sendToUsers(cmd,data)
  91. {
  92. for(temp.user: this.users)
  93. {
  94. findPlayer(temp.user[0]).triggerClient("weapon",this.name,cmd,data);
  95. }
  96. }
  97.  
  98. function loginPlayer(playerVar)
  99. {
  100. if( playerVar == null ) playerVar = player;
  101. sendToUsers(cmd.LOGIN,player.communityname);
  102.  
  103. temp.inIt = false;
  104. for(temp.user: this.users)
  105. {
  106. if(temp.user[0] == playerVar.account)
  107. {
  108. temp.inIt = true; break;
  109. }
  110. }
  111.  
  112. addMessage("System","<i>" @ playerVar.communityName @ " logged in</i>");
  113. if(!inIt) this.users.add({playerVar.account,playerVar.communityname});
  114. }
  115.  
  116. function logoutPlayer(playerVar)
  117. {
  118. if(playerVar == null ) playerVar = player;
  119. if(!(findeapon(this.name) in playerVar.weapons)) return;
  120.  
  121. temp.f = false;
  122. for(temp.i=0; temp.i < this.users.size(); temp.i++)
  123. {
  124. if(playerVar.account == this.users[temp.i][0])
  125. {
  126. temp.f = true;
  127. this.users.delete(temp.i); temp.i--;
  128. }
  129. }
  130. if( temp.f )
  131. {
  132. addMessage("System","<i>" @ playerVar.communityName @ " logged out</i>");
  133. sendToUsers(cmd.LOGOUT,playerVar.communityName);
  134. }
  135.  
  136. }
  137.  
  138. //#CLIENTSIDE
  139. function onCreated()
  140. {
  141. enum cmd
  142. {
  143. SEND_MESSAGE,
  144. RECEIVE_MESSAGE,
  145. LOAD_CHAT,
  146. LOGIN,
  147. LOGOUT
  148. }
  149.  
  150. this.saveMessages = 200;
  151. this.loaded = false;
  152.  
  153. createGUI();
  154.  
  155. }
  156.  
  157. function onPlayerChats()
  158. {
  159. if(player.chat == "/staffchat")
  160. {
  161. if(this.loaded) openGUI();
  162. else triggerServer("weapon",this.name,cmd.LOAD_CHAT);
  163.  
  164. }
  165. }
  166.  
  167. function onActionClientSide(cmd,data)
  168. {
  169. if( cmd == cmd.LOAD_CHAT )
  170. {
  171.  
  172. GUI_ChatUsers.clearRows();
  173. for(temp.userData: data[1])
  174. {
  175. GUI_ChatUsers.addRow(0,temp.userData[1]);
  176. }
  177.  
  178. GUI_Chat.text = "Welcome to the Staff Chat!";
  179. for(temp.chatMsg: data[0])
  180. {
  181. if( temp.chatMsg != null )
  182. GUI_Chat.text @= "\n<b>" @ temp.chatMsg[0] @ "</b>: " @ temp.chatMsg[1];
  183. }
  184.  
  185. openGUI();
  186. }
  187. elseif( cmd == cmd.RECEIVE_MESSAGE )
  188. {
  189.  
  190. GUI_Chat.text @= "\n<b>" @ data[0] @ "</b>: " @ data[1];
  191. }
  192. elseif( cmd == cmd.LOGIN )
  193. {
  194. if(GUI_ChatUsers.findtext(data[0]) == -1 )
  195. GUI_ChatUsers.addRow(0,data[0]);
  196. }
  197. elseif( cmd == cmd.LOGOUT )
  198. {
  199. GUI_ChatUsers.removerow(GUI_ChatUsers.findtext(data[0]));
  200. }
  201.  
  202. }
  203.  
  204. function openGUI()
  205. {
  206. if(GUI_ChatWindow == null ) createGUI();
  207. GUI_ChatWindow.visible = true;
  208. }
  209.  
  210. function createGUI()
  211. {
  212. GUI_ChatWindow.destroy();
  213. new GuiWindowCtrl("GUI_ChatWindow") {
  214. profile = GuiBlueWindowProfile;
  215. style = $pref::Video::defaultguistyle;
  216. clientrelative = true;
  217. clientextent = "645,307";
  218.  
  219. canmove = true;
  220. canresize = true;
  221. closequery = false;
  222. destroyonhide = false;
  223. visible = false;
  224. text = "Staff Chat";
  225. x = 346;
  226. y = 526;
  227.  
  228. new GuiScrollCtrl("GUI_Chat_Scroll") {
  229. profile = GuiBlueScrollProfile;
  230. childmargin = "8,8";
  231. height = 270;
  232. hscrollbar = "alwaysOff";
  233. vscrollbar = "dynamic";
  234. width = 500;
  235. x = 8;
  236. y = 6;
  237.  
  238. horizsizing = "width";
  239. vertsizing = "height";
  240.  
  241. new GuiMLTextCtrl("GUI_Chat") {
  242. profile = GuiBlueMLTextProfile;
  243. height = 68;
  244. horizsizing = "width";
  245. plaintext = "";
  246. text = "";
  247. width = 480;
  248. }
  249. }
  250. new GuiTextEditCtrl("GUI_ChatInput") {
  251. profile = GuiBlueTextEditProfile;
  252. height = 20;
  253. width = 450;
  254. x = 8;
  255. y = 281;
  256.  
  257. horizsizing = "width";
  258. vertsizing = "top";
  259. }
  260. new GuiButtonCtrl("GUI_ChatButton_Send") {
  261. profile = GuiBlueButtonProfile;
  262. height = 20;
  263. text = "Send";
  264. width = 49;
  265. x = 460;
  266. y = 279;
  267.  
  268. horizsizing = "left";
  269. vertsizing = "top";
  270. }
  271. new GuiScrollCtrl("GUI_ChatUsers_Scroll") {
  272. profile = GuiBlueScrollProfile;
  273. height = 295;
  274. hscrollbar = "alwaysOff";
  275. vscrollbar = "dynamic";
  276. width = 130;
  277. x = 510;
  278. y = 6;
  279. childmargin = "8,8";
  280.  
  281. horizsizing = "left";
  282. vertsizing = "height";
  283.  
  284. new GuiTextListCtrl("GUI_ChatUsers") {
  285. profile = GuiBlueTextListProfile;
  286. height = 34;
  287. horizsizing = "width";
  288. sortcolumn = 82557184;
  289. width = 126;
  290.  
  291. }
  292. }
  293. }
  294. }
  295.  
  296. function GUI_ChatButton_Send.onAction()
  297. {
  298. triggerServer("weapon",this.name,cmd.SEND_MESSAGE,GUI_ChatInput.text);
  299. GUI_ChatInput.text = "";
  300.  
  301. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement