Guest User

Discord Real Time chatting SA-MP

a guest
Jul 7th, 2018
3,398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.45 KB | None | 0 0
  1. #define FILTERSCRIPT
  2. #include <a_samp>
  3. #define CHANNEL_ID "464114891645517834" // Change this to your channel id
  4. #include <discord-connector>
  5. #include <zcmd>
  6. #include <sscanf2>
  7. #include <YSI\y_va>
  8.  
  9. //////////////////////////////////////////
  10. #define COLOR_WHITE 0xFFFFFFAA
  11. #define COLOR_RED 0xAA3333AA
  12.  
  13. /////////////////////////////////////////
  14.  
  15.  
  16. new DCC_Channel:BotChannel;
  17. new DiscordStats[MAX_PLAYERS];
  18. new Spawned[MAX_PLAYERS];
  19.  
  20. #if defined FILTERSCRIPT
  21.  
  22. public OnFilterScriptInit()
  23. {
  24. print("\n--------------------------------------");
  25. print(" Discord Connector Filterscript ~ Inferno");
  26. print("--------------------------------------\n");
  27. return 1;
  28. }
  29.  
  30. public OnFilterScriptExit()
  31. {
  32. return 1;
  33. }
  34.  
  35. #else
  36.  
  37. main()
  38.  
  39.  
  40. #endif
  41.  
  42.  
  43. forward DCC_OnChannelMessage(DCC_Channel:channel, DCC_User:author, const message[]);
  44. forward SendDC(channel[], const fmat[], va_args<>);
  45.  
  46. public OnGameModeInit()
  47. {
  48. return 1;
  49. }
  50.  
  51. public OnGameModeExit()
  52. {
  53. return 1;
  54. }
  55.  
  56. public OnPlayerConnect(playerid)
  57. {
  58. Spawned[playerid] = 0;
  59. return 1;
  60. }
  61.  
  62. public SendDC(channel[], const fmat[], va_args<>)
  63. {
  64. new str[145];
  65. va_format(str, sizeof (str), fmat, va_start<2>);
  66. BotChannel = DCC_FindChannelById(channel);
  67. return DCC_SendChannelMessage(BotChannel, str);
  68. }
  69.  
  70. public OnPlayerSpawn(playerid)
  71. {
  72. Spawned[playerid] = 1;
  73. return 1;
  74. }
  75.  
  76. public DCC_OnChannelMessage(DCC_Channel:channel, DCC_User:author, const message[])
  77. {
  78. new channel_name[100 + 1];
  79. if(!DCC_GetChannelName(channel, channel_name))
  80. return 0;
  81.  
  82. new user_name[32 + 1];
  83. if (!DCC_GetUserName(author, user_name))
  84. return 0;
  85.  
  86. if(channel != BotChannel) return 0;
  87. new str[145];
  88. format(str, sizeof str, "{667aca}[Discord/%s] %s:{ffffff} %s", channel_name, user_name, message);
  89. for(new i = 0; i < MAX_PLAYERS; i++) {
  90. if (DiscordStats[i]==0) continue;
  91. SendClientMessage(i, -1, str); }
  92.  
  93. return 1;
  94. }
  95.  
  96. CMD:dchat(playerid, params[])
  97. {
  98. new tmp[512], name[MAX_PLAYER_NAME];
  99. GetPlayerName(playerid, name, MAX_PLAYER_NAME);
  100. if (Spawned[playerid] == 0) return SendClientMessage(playerid, COLOR_WHITE, "Server: You must be spawned to use this command!");
  101. if (DiscordStats[playerid]==0) return SendClientMessage(playerid, COLOR_WHITE, "Server: Turn on Discord Chat using /dchaton.");
  102. if (sscanf(params, "s[512]", tmp)) return SendClientMessage(playerid, COLOR_WHITE, "Usage: /dchat [message]");
  103. SendDC(CHANNEL_ID, "[chat]%s: %s ", name, tmp);
  104. return 1;
  105. }
  106.  
  107. CMD:dchaton(playerid, params[])
  108. {
  109. new playername[MAX_PLAYER_NAME];
  110. GetPlayerName(playerid, playername, MAX_PLAYER_NAME);
  111. if (Spawned[playerid] == 0) return SendClientMessage(playerid, COLOR_WHITE, "Server: You must be spawned to use this command!");
  112. if (DiscordStats[playerid]==1) return SendClientMessage(playerid, COLOR_WHITE, "Server: Discord Chat is already switched on!");
  113. DiscordStats[playerid]=1;
  114. SendClientMessage(playerid, COLOR_WHITE, "Server: Discord Chat turned on.");
  115. return 1;
  116. }
  117.  
  118. CMD:dchatoff(playerid, params[])
  119. {
  120. new name[MAX_PLAYER_NAME];
  121. GetPlayerName(playerid, name, MAX_PLAYER_NAME);
  122. if (Spawned[playerid] == 0) return SendClientMessage(playerid, COLOR_WHITE, "Server: You must be spawned to use this command!");
  123. if (DiscordStats[playerid]==0) return SendClientMessage(playerid, COLOR_WHITE, "Server: Discord Chat is already switched off!");
  124. DiscordStats[playerid]=0;
  125. SendClientMessage(playerid, COLOR_WHITE, "Server: Discord Chat turned off.");
  126. return 1;
  127. }
Add Comment
Please, Sign In to add comment