SAMP Gitlab CI Test
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

293 lines
7.7 KiB

  1. //
  2. //
  3. // SA-MP Roleplay style chat module for Grand Larceny
  4. // (c) 2012 SA-MP Team
  5. // All rights reserved
  6. //
  7. #include <a_samp>
  8. #include "../include/gl_common.inc"
  9. #include "../include/gl_messages.inc" // <- contains all the main text/messaging functions
  10. //---------------------------------------------
  11. stock ProcessChatText(playerid, text[])
  12. {
  13. new useindex=1;
  14. // Handle shouting prefix (!)
  15. if(text[0] == '!' && strlen(text) > 1) {
  16. if(text[1] == ' ') useindex++;
  17. TalkMessage(SHOUT_DISTANCE, playerid, "*shouts*", text[useindex]);
  18. return;
  19. }
  20. // Handle quiet prefix (#)
  21. if(text[0] == '#' && strlen(text) > 1) {
  22. if(text[1] == ' ') useindex++;
  23. TalkMessage(LOW_DISTANCE, playerid, "*quietly*", text[useindex]);
  24. return;
  25. }
  26. // Send to other players in range and fade
  27. TalkMessage(TALK_DISTANCE, playerid, "", text);
  28. }
  29. //---------------------------------------------
  30. stock ProcessActionText(playerid, message[], actiontype)
  31. {
  32. new ActionText[256+1];
  33. new ActionBubble[MAX_CHATBUBBLE_LENGTH+1];
  34. new PlayerName[MAX_PLAYER_NAME+1];
  35. GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
  36. if(actiontype == ACTION_DO) {
  37. format(ActionText, 256, "* %s ((%s))", message, PlayerName);
  38. format(ActionBubble, MAX_CHATBUBBLE_LENGTH, "* (( %s ))", message);
  39. } else {
  40. format(ActionText, 256, "* %s %s", PlayerName, message);
  41. format(ActionBubble, MAX_CHATBUBBLE_LENGTH, "* %s", message);
  42. }
  43. LocalMessage(ACTION_DISTANCE, playerid, ACTION_COLOR, ActionText);
  44. SetPlayerChatBubble(playerid, ActionBubble, ACTION_COLOR, ACTION_DISTANCE, CHAT_BUBBLE_TIME);
  45. }
  46. //---------------------------------------------
  47. new gOOCDisabled = false;
  48. stock GlobalOOCMessage(playerid, message[])
  49. {
  50. new msg[256+1];
  51. new PlayerName[MAX_PLAYER_NAME+1];
  52. if(gOOCDisabled) {
  53. CmdErrorMessage(playerid, "The OOC channel is not enabled right now");
  54. return;
  55. }
  56. GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
  57. format(msg, 256, "(( %s: %s ))", PlayerName, message);
  58. for(new i = 0; i < MAX_PLAYERS; i++) { // for every player
  59. if(IsPlayerConnected(i)) { // Todo: check if player accepts occ
  60. PlayerMessage(i, OOC_COLOR, msg);
  61. }
  62. }
  63. }
  64. //---------------------------------------------
  65. stock ToggleOOC(playerid)
  66. {
  67. if(IsPlayerAdmin(playerid)) {
  68. // toggle it
  69. if(gOOCDisabled) gOOCDisabled = false;
  70. else gOOCDisabled = true;
  71. if(!gOOCDisabled) {
  72. GlobalMessage(GENERAL_COLOR, "{D0D0D0}[ooc] channel is {80CC80}enabled");
  73. } else {
  74. GlobalMessage(GENERAL_COLOR, "{D0D0D0}[ooc] channel is {CC8080}disabled");
  75. }
  76. } else {
  77. CmdErrorMessage(playerid, "Your admin level isn't high enough to change this");
  78. }
  79. }
  80. //---------------------------------------------
  81. stock ProcessLocalOOC(playerid, message[])
  82. {
  83. new new_message[256+1];
  84. new PlayerName[MAX_PLAYER_NAME+1];
  85. GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
  86. format(new_message, 256, "%s (( %s ))", PlayerName, message);
  87. LocalMessage(TALK_DISTANCE, playerid, LOCAL_TALK_COLOR, new_message);
  88. }
  89. //---------------------------------------------
  90. stock ProcessMegaphone(playerid, message[])
  91. {
  92. // Todo: add permissions on megaphone usage
  93. new new_message[256+1];
  94. new PlayerName[MAX_PLAYER_NAME+1];
  95. GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
  96. format(new_message, 256, "(megaphone) %s >> %s", PlayerName, message);
  97. LocalMessage(MEGAPHONE_DISTANCE, playerid, MEGAPHONE_COLOR, new_message, 1);
  98. }
  99. //---------------------------------------------
  100. stock ProcessWhisper(playerid, toplayerid, message[])
  101. {
  102. new PlayerName[MAX_PLAYER_NAME+1];
  103. new ToPlayerName[MAX_PLAYER_NAME+1];
  104. new PmMessage[256+1];
  105. GetPlayerName(playerid,PlayerName,sizeof(PlayerName));
  106. GetPlayerName(toplayerid,ToPlayerName,sizeof(ToPlayerName));
  107. format(PmMessage, sizeof(PmMessage), ">> %s(%d): %s", ToPlayerName, toplayerid, message);
  108. PlayerMessage(playerid, WHISPER_COLOR, PmMessage);
  109. format(PmMessage, sizeof(PmMessage), "** %s(%d): %s", PlayerName, playerid, message);
  110. PlayerMessage(toplayerid, WHISPER_COLOR, PmMessage);
  111. PlayerPlaySound(toplayerid, 1085, 0.0, 0.0, 0.0);
  112. }
  113. //---------------------------------------------
  114. stock ProcessChatCommands(playerid, cmdtext[])
  115. {
  116. new cmd[256+1];
  117. new message[256+1];
  118. new tmp[256+1];
  119. new idx;
  120. cmd = strtok(cmdtext, idx);
  121. // Action commands
  122. if(!strcmp("/me", cmd, true))
  123. {
  124. message = strrest(cmdtext,idx);
  125. if(!strlen(message)) {
  126. CmdUsageMessage(playerid, "/me [action]");
  127. return 1;
  128. }
  129. ProcessActionText(playerid, message, ACTION_ME);
  130. return 1;
  131. }
  132. if(!strcmp("/do", cmd, true))
  133. {
  134. message = strrest(cmdtext,idx);
  135. if(!strlen(message)) {
  136. CmdUsageMessage(playerid, "/do [action]");
  137. return 1;
  138. }
  139. ProcessActionText(playerid, message, ACTION_DO);
  140. return 1;
  141. }
  142. // Talk commands
  143. // /low
  144. if(!strcmp("/l", cmd, true) || !strcmp("/low", cmd, true))
  145. {
  146. message = strrest(cmdtext,idx);
  147. if(!strlen(message)) {
  148. CmdUsageMessage(playerid, "(/l)ow [text]");
  149. return 1;
  150. }
  151. TalkMessage(LOW_DISTANCE, playerid, "*quietly*", message);
  152. return 1;
  153. }
  154. // /shout
  155. if(!strcmp("/s", cmd, true) || !strcmp("/shout", cmd, true))
  156. {
  157. message = strrest(cmdtext,idx);
  158. if(!strlen(message)) {
  159. CmdUsageMessage(playerid, "(/s)hout [text]");
  160. return 1;
  161. }
  162. TalkMessage(SHOUT_DISTANCE, playerid, "*shouts*", message);
  163. return 1;
  164. }
  165. // /b (local ooc)
  166. if(!strcmp("/b", cmd, true))
  167. {
  168. message = strrest(cmdtext,idx);
  169. if(!strlen(message)) {
  170. CmdUsageMessage(playerid, "/b [text]");
  171. return 1;
  172. }
  173. ProcessLocalOOC(playerid, message);
  174. return 1;
  175. }
  176. // /megaphone
  177. if(!strcmp("/m", cmd, true) || !strcmp("/megaphone", cmd, true))
  178. {
  179. message = strrest(cmdtext,idx);
  180. if(!strlen(message)) {
  181. CmdUsageMessage(playerid, "(/m)egaphone [text]");
  182. return 1;
  183. }
  184. ProcessMegaphone(playerid, message);
  185. return 1;
  186. }
  187. // Global OOC /o and /ooc
  188. if(!strcmp("/o", cmd, true) || !strcmp("/ooc", cmd, true))
  189. {
  190. message = strrest(cmdtext,idx);
  191. if(!strlen(message)) {
  192. CmdUsageMessage(playerid, "(/o)oc [text]");
  193. return 1;
  194. }
  195. GlobalOOCMessage(playerid, message);
  196. return 1;
  197. }
  198. // Toggle the OOC channel /togooc
  199. if(!strcmp("/togooc", cmd, true))
  200. {
  201. ToggleOOC(playerid);
  202. return 1;
  203. }
  204. // /whisper /pm
  205. if(!strcmp("/w", cmd, true) || !strcmp("/wisper", cmd, true) || !strcmp("/pm", cmd, true))
  206. {
  207. tmp = strtok(cmdtext,idx);
  208. if(!strlen(tmp)) {
  209. CmdUsageMessage(playerid, "(/w)isper [playerid/PartOfName] [whisper text]");
  210. return 1;
  211. }
  212. new toplayerid = ReturnUser(tmp);
  213. if(toplayerid == RETURN_USER_MULTIPLE) {
  214. CmdErrorMessage(playerid, "Multiple matches found for [name]. Please narrow the search.");
  215. return 1;
  216. }
  217. if(toplayerid == RETURN_USER_FAILURE || !IsPlayerConnected(toplayerid)) {
  218. CmdErrorMessage(playerid, "That player isn't connected right now.");
  219. return 1;
  220. }
  221. message = strrest(cmdtext,idx);
  222. if(!strlen(message)) {
  223. CmdUsageMessage(playerid, "(/w)isper [playerid/PartOfName] [whisper text]");
  224. return 1;
  225. }
  226. if(IsPlayerConnected(toplayerid)) {
  227. ProcessWhisper(playerid, toplayerid, message);
  228. }
  229. return 1;
  230. }
  231. return 0;
  232. }
  233. //---------------------------------------------
  234. public OnPlayerText(playerid, text[])
  235. {
  236. ProcessChatText(playerid, text);
  237. return 0;
  238. }
  239. //------------------------------------------------
  240. public OnPlayerCommandText(playerid, cmdtext[])
  241. {
  242. if(ProcessChatCommands(playerid,cmdtext)) {
  243. return 1;
  244. }
  245. return 0;
  246. }
  247. //---------------------------------------------