Tamyy

ChatPanel.inc by Tamy

Jan 31st, 2016
690
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. //Written by Tamy
  2.  
  3. #define MAX_LINES 10
  4.  
  5. new Text:ChatLine[MAX_LINES];
  6. new ChatText[MAX_LINES][128];
  7.  
  8. stock createChatPanel()
  9. {
  10. new y=330;
  11. for(new i=0; i<MAX_LINES; i++)
  12. {
  13. if(!strlen(ChatText[i])) ChatText[i][0] = ' ';
  14. ChatLine[i] = TextDrawCreate(500, y, ChatText[i]);
  15. TextDrawAlignment(ChatLine[i], 2);
  16. TextDrawSetOutline(ChatLine[i], 1);
  17. TextDrawLetterSize(ChatLine[i], 0.2, 1.0);
  18. y += 10;
  19. }
  20. }
  21.  
  22. stock updateChatPanel()
  23. {
  24. for(new i=0; i<MAX_LINES; i++)
  25. {
  26. if(!strlen(ChatText[i])) ChatText[i][0] = ' ';
  27. else TextDrawSetString(ChatLine[i], ChatText[i]);
  28. }
  29. }
  30.  
  31. stock hidePlayerChatPanel(playerid)
  32. {
  33. for(new i=0; i<MAX_LINES; i++)
  34. {
  35. TextDrawHideForPlayer(playerid, ChatLine[i]);
  36. }
  37. }
  38.  
  39. stock showPlayerChatPanel(playerid)
  40. {
  41. for(new i=0; i<MAX_LINES; i++)
  42. {
  43. TextDrawShowForPlayer(playerid, ChatLine[i]);
  44. }
  45. }
  46.  
  47. stock addChatMessage(msgstr[], pancolor[]="white")
  48. {
  49. new f=0;
  50. if(isValidPanelColor(pancolor) == 0) return print("Invalid color entered.");
  51. if(checkChatStr(msgstr) == 0) return print("Failed to write the message in the box due to invalid characters/string lenth.");
  52. for(new i=0; i<MAX_LINES; i++)
  53. {
  54. if(!strlen(ChatText[i]) || ChatText[i][0] == ' ')
  55. {
  56. format(ChatText[i], 128, "%s%s", panelColor(pancolor), msgstr);
  57. TextDrawSetString(ChatLine[i], ChatText[i]);
  58. f=1;
  59. return 1;
  60. }
  61. }
  62. if(!f)
  63. {
  64. for(new i=0; i<MAX_LINES; i++)
  65. {
  66. if(i == 9) {format(ChatText[i], 128, "%s%s", panelColor(pancolor), msgstr); TextDrawSetString(ChatLine[i], ChatText[i]); return 1;}
  67. if(strlen(ChatText[i]) && ChatText[i][0] != ' ')
  68. {
  69. format(ChatText[i], 128, ChatText[i+1]);
  70. TextDrawSetString(ChatLine[i], ChatText[i]);
  71. }
  72.  
  73. }
  74. }
  75. return 0;
  76. }
  77.  
  78.  
  79. stock panelColor(pancol[])
  80. {
  81. new str[128];
  82. format(str, 128, "~w~");
  83. if(!strcmp(pancol, "red", true)) format(str, 128, "~r~");
  84. else if(!strcmp(pancol, "blue", true)) format(str, 128, "~b~");
  85. else if(!strcmp(pancol, "yellow", true)) format(str, 128, "~y~");
  86. else if(!strcmp(pancol, "green", true)) format(str, 128, "~g~");
  87. return str;
  88. }
  89.  
  90. stock isValidPanelColor(pancol[])
  91. {
  92. if(!strcmp(pancol, "white", true) || !strcmp(pancol, "red", true) || !strcmp(pancol, "blue", true) || !strcmp(pancol, "yellow", true) || !strcmp(pancol, "green", true)) return 1;
  93. return 0;
  94. }
  95.  
  96. stock checkChatStr(str[])
  97. {
  98. new len=strlen(str);
  99. if(len < 1 || len > 64) return 0;
  100. if(str[len] == ' ') return 0;
  101. if(strfind(str, "~ ", true) != -1 || strfind(str, "\n ", true) != -1 || strfind(str, "|", true) != -1 || strfind(str, "%", true) != -1) return 0;
  102. return 1;
  103. }
  104.  
  105. stock destroyChatPanel()
  106. {
  107. for(new i=0; i<MAX_LINES; i++)
  108. {
  109. TextDrawDestroy(ChatLine[i]);
  110. }
  111. }
Add Comment
Please, Sign In to add comment