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.

165 lines
4.7 KiB

5 years ago
  1. //
  2. //
  3. // SA-MP Roleplay style chat module for SA-MP 0.3
  4. // (c) 2012 SA-MP Team
  5. // All rights reserved
  6. //
  7. #define GENERAL_COLOR 0xEEEEEEFF
  8. #define LOCAL_TALK_COLOR 0xD0D0D0FF
  9. #define SPEECH_BUBBLE_COLOR 0xEEEEEEFF
  10. #define ACTION_COLOR 0xC2A2DAAA
  11. #define CMD_USAGE_COLOR 0xBFC0C2FF
  12. #define MEGAPHONE_COLOR 0xFFFF00AA
  13. #define WHISPER_COLOR 0xFFFF00AA
  14. #define OOC_COLOR 0xE0FFFFAA
  15. #define ADMIN_ACTION_COLOR 0xDAA2ACAA
  16. #define TALK_DISTANCE 30.0
  17. #define SHOUT_DISTANCE 60.0
  18. #define LOW_DISTANCE 5.0
  19. #define ACTION_DISTANCE 30.0
  20. #define MEGAPHONE_DISTANCE 70.0
  21. #define CHAT_BUBBLE_TIME 6000
  22. #define ACTION_ME 1
  23. #define ACTION_DO 2
  24. //---------------------------------------------
  25. // Send a chat message to this player
  26. stock PlayerMessage(playerid, color, message[])
  27. {
  28. SendClientMessage(playerid, color, message);
  29. }
  30. //---------------------------------------------
  31. // Send a chat message to all players
  32. stock GlobalMessage(color, message[])
  33. {
  34. SendClientMessageToAll(color, message);
  35. }
  36. //---------------------------------------------
  37. stock CmdUsageMessage(playerid, message[])
  38. {
  39. new msg[256+1];
  40. format(msg,256,"[{BFC0C2}usage{EEEEEE}] %s", message);
  41. SendClientMessage(playerid, GENERAL_COLOR, msg);
  42. }
  43. //---------------------------------------------
  44. stock CmdErrorMessage(playerid, message[])
  45. {
  46. new msg[256+1];
  47. format(msg,256,"[{E0C0C0}error{EEEEEE}] %s", message);
  48. SendClientMessage(playerid, GENERAL_COLOR, msg);
  49. }
  50. //---------------------------------------------
  51. stock CmdAdminMessage(playerid, message[])
  52. {
  53. new msg[256+1];
  54. format(msg,256,"[{5050EE}admin{EEEEEE}] %s", message);
  55. SendClientMessage(playerid, GENERAL_COLOR, msg);
  56. }
  57. //---------------------------------------------
  58. stock AdminActionMessage(playerid, message[])
  59. {
  60. PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
  61. SendClientMessage(playerid, ADMIN_ACTION_COLOR, message);
  62. }
  63. //---------------------------------------------
  64. // Send a chat message to players in distance of playerid
  65. // This includes the origin player.
  66. stock LocalMessage(Float:dist, playerid, color, message[], chatbubble=0)
  67. {
  68. if(!strlen(message)) return;
  69. if(IsPlayerConnected(playerid))
  70. {
  71. new Float:fPlayerX, Float:fPlayerY, Float:fPlayerZ;
  72. new Float:fPlayerToPlayerDist;
  73. // send to the origin player
  74. PlayerMessage(playerid, color, message);
  75. // if it requires a chat bubble, show it.
  76. if(chatbubble) {
  77. SetPlayerChatBubble(playerid, message, color, dist, CHAT_BUBBLE_TIME);
  78. }
  79. GetPlayerPos(playerid, fPlayerX, fPlayerY, fPlayerZ);
  80. for(new i = 0; i < MAX_PLAYERS; i++) { // for every player
  81. if(IsPlayerConnected(i) && (i != playerid) && IsPlayerStreamedIn(playerid,i)) {
  82. fPlayerToPlayerDist = GetPlayerDistanceFromPoint(i, fPlayerX, fPlayerY, fPlayerZ);
  83. if(fPlayerToPlayerDist < dist) { // receiving player is within the specified distance
  84. PlayerMessage(i, color, message);
  85. }
  86. }
  87. }
  88. }
  89. }
  90. //---------------------------------------------
  91. // This will send a local talk message and automatically grey-fade it.
  92. // This includes the origin player.
  93. stock TalkMessage(Float:dist, playerid, prefix[], message[])
  94. {
  95. new PlayerName[MAX_PLAYER_NAME+1];
  96. new Msg[256+1];
  97. new MsgWithName[256+1];
  98. if(!strlen(message)) return;
  99. if(IsPlayerConnected(playerid))
  100. {
  101. new Float:fPlayerX, Float:fPlayerY, Float:fPlayerZ;
  102. new Float:fPlayerToPlayerDist;
  103. new Float:fNormDistance;
  104. new ColorScale;
  105. new ColorValue;
  106. GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
  107. if(strlen(prefix)) {
  108. format(Msg, sizeof(Msg), "%s %s", prefix, message);
  109. } else {
  110. format(Msg, sizeof(Msg), "%s", message);
  111. }
  112. format(MsgWithName, sizeof(MsgWithName), "%s: %s", PlayerName, Msg);
  113. SetPlayerChatBubble(playerid, Msg, SPEECH_BUBBLE_COLOR, dist, CHAT_BUBBLE_TIME);
  114. // Send to originating player
  115. PlayerMessage(playerid, LOCAL_TALK_COLOR, MsgWithName);
  116. GetPlayerPos(playerid, fPlayerX, fPlayerY, fPlayerZ);
  117. for(new i = 0; i < MAX_PLAYERS; i++) { // for every player
  118. if(IsPlayerConnected(i) && (i != playerid) && IsPlayerStreamedIn(playerid,i)) {
  119. fPlayerToPlayerDist = GetPlayerDistanceFromPoint(i, fPlayerX, fPlayerY, fPlayerZ);
  120. if(fPlayerToPlayerDist < dist) { // receiving player is within the specified distance
  121. // get normalized distance to create a fade.
  122. fNormDistance = 1.0 - (fPlayerToPlayerDist / dist);
  123. if(fNormDistance > 0.75) ColorScale = 220;
  124. else ColorScale = floatround(96.0 + (128.0 * fNormDistance));
  125. ColorValue = 0x000000FF | ColorScale << 24 | ColorScale << 16 | ColorScale << 8;
  126. PlayerMessage(i, ColorValue, MsgWithName);
  127. }
  128. }
  129. }
  130. }
  131. }
  132. //---------------------------------------------