player.inc 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. @Author: dy1zan / Golden
  3. @Command: !newb
  4. This callback is invoked whenever someone types !newb in Discord.
  5. This will send an a new message in-game command /newb
  6. */
  7. DiscordResponse:newb(data[]) {
  8. //Convert string into JSON object so we can extract data e.g sender, message
  9. new JSONNode:jsonData = json_parse_string(data);
  10. new sender[MAX_PLAYER_NAME+1], message[110], channel[30];
  11. json_get_string(jsonData, channel, sizeof channel, "channel");
  12. //Get the 'sender'/'message' contained within the JSON object
  13. json_get_string(jsonData, sender, sizeof sender, "sender");
  14. json_get_string(jsonData, message, sizeof message, "message");
  15. //Output the data
  16. new string[144];
  17. format(string, sizeof string, "** [Discord] %s: %s **", sender, message);
  18. printf(string);
  19. OOCNewbie(NEWBIE_COLOR, string);
  20. return 1;
  21. }
  22. /*
  23. Some util
  24. */
  25. stock Discord:GetHelperRank(playerid) {
  26. new name[32];
  27. new level = PlayerInfo[playerid][pHelper];
  28. switch(level) {
  29. case 0: name = "None";
  30. case 1: name = "Trial Helper";
  31. case 2: name = "Helper";
  32. case 3: name = "Senior Helper";
  33. case 4: name = "Head Helper";
  34. case 5: name = "Director of The Helpers Team";
  35. default: name = "?";
  36. }
  37. return name;
  38. }
  39. DiscordResponse:id(data[]) {
  40. //Convert string into JSON object so we can extract data e.g sender, message
  41. new JSONNode:jsonData = json_parse_string(data);
  42. new pattern[110], channel[30], string[128], string2[128], count;
  43. json_get_string(jsonData, channel, sizeof channel, "channel");
  44. json_get_string(jsonData, pattern, sizeof pattern, "pattern");
  45. if(IsNumeric(pattern))
  46. {
  47. new player;
  48. sscanf(pattern, "u", player);
  49. if(IsPlayerConnected(player))
  50. {
  51. new name2[24], status[10];
  52. strmid(name2, str_replace('_', ' ', PlayerName(player)), 0, MAX_PLAYER_NAME);
  53. if(PlayerPaused[player] == 1)
  54. status = "tabbed";
  55. else
  56. status = "untabbed";
  57. format(string, sizeof(string), "Name: %s, ID: %d, Level: %d, Ping: %d, Status: %s", name2, player, PlayerInfo[player][pLevel], GetPlayerPing(player), status);
  58. Discord:sendBasicRequest(channel, "Players found", string, DISCORD_COLOR_INFO);
  59. }
  60. return 1;
  61. }
  62. else
  63. {
  64. foreach( new i: Player )
  65. {
  66. if(strfind(PlayerName(i), pattern, true) != -1)
  67. {
  68. new name2[24], status[10];
  69. strmid(name2, str_replace('_', ' ', PlayerName(i)), 0, MAX_PLAYER_NAME);
  70. if(PlayerPaused[i] == 1)
  71. status = "tabbed";
  72. else
  73. status = "untabbed";
  74. if( count > 1 )
  75. {
  76. format(string2, sizeof(string2), "Name: %s, ID: %d, Level: %d, Ping: %d, Status: %s\n", name2, i, PlayerInfo[i][pLevel], GetPlayerPing(i), status);
  77. strins(string, string2, 0);
  78. }
  79. else
  80. {
  81. format(string, sizeof(string), "Name: %s, ID: %d, Level: %d, Ping: %d, Status: %s", name2, i, PlayerInfo[i][pLevel], GetPlayerPing(i), status);
  82. count++;
  83. }
  84. Discord:sendBasicRequest(channel, "Players found", string, DISCORD_COLOR_INFO);
  85. }
  86. }
  87. }
  88. return 1;
  89. }
  90. DiscordResponse:time(data[])
  91. {
  92. new JSONNode:jsonData = json_parse_string(data);
  93. new channel[30];
  94. json_get_string(jsonData, channel, sizeof channel, "channel");
  95. new year, month, day;
  96. getdate(year, month, day);
  97. new hour, minute, second;
  98. gettime(hour, minute, second);
  99. hour = FixHour(hour);
  100. new string[128];
  101. format(string, sizeof(string), "%02d %s %02d:%02d:%02d", day, GetMonthFromInt(month), hour, minute, second);
  102. Discord:sendBasicRequest(channel, "Server time", string, DISCORD_COLOR_INFO);
  103. return 1;
  104. }
  105. DiscordResponse:admins(data[]) {
  106. //Get the channel the command was sent from
  107. new JSONNode:jsonData = json_parse_string(data);
  108. new channel[30];
  109. json_get_string(jsonData, channel, sizeof channel, "channel");
  110. //Get online admins as a string
  111. new string[144];
  112. foreach(new i : Player) {
  113. if(PlayerInfo[i][pAdmin] >= 1 && PlayerInfo[i][pStealthed] == 0) {
  114. if(strlen(string) > 1) {
  115. format(string, sizeof string, "%s, %s", string, PlayerICName(i));
  116. }
  117. else {
  118. format(string, sizeof string, "%s", PlayerICName(i));
  119. }
  120. }
  121. }
  122. if(strlen(string) < 1) {
  123. format(string, sizeof string, "There are no administrators online.");
  124. }
  125. //Send the list to Discord
  126. Discord:sendBasicRequest(channel, "Server administrators", string, DISCORD_COLOR_INFO);
  127. }