porsamp

Discord

May 23rd, 2021 (edited)
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.38 KB | None | 0 0
  1. /*
  2.  
  3.     Welcome to another OUTWARDLY EXPERIENCE!!!
  4.     In this we will learn how to control a discord command to affect ingame activities like banning, kicking or sending a message to a player!
  5.     Let's GO!
  6.  
  7. */
  8.  
  9. #include <a_samp>
  10. #include <sscanf2>
  11. #include <discord-connector> // Including the include of the plugin //
  12.  
  13. /*
  14.  
  15.     Welcome to another OUTWARDLY EXPERIENCE!!!
  16.     In this we will learn how to control a discord command to affect ingame activities like banning, kicking or sending a message to a player!
  17.     Let's GO!
  18.  
  19. */
  20.  
  21. #include <a_samp>
  22. #include <sscanf2>
  23. #include <discord-connector> // ปลักอิน //
  24.  
  25. static DCC_Channel:commandChannel;
  26. static DCC_Guild:guildName;
  27. static DCC_Role:adminRole;
  28.  
  29. public OnGameModeInit(){
  30.     commandChannel = DCC_FindChannelById("651471342180368394"); // ห้องดิษคอส
  31.     guildName = DCC_FindGuildById("651471013850382337");  // ชื่อเซิฟเวอร์ดิษคอส
  32.     adminRole = DCC_FindRoleById("651471401408135180");  // ยศดิษดิษคอส
  33.  
  34.     // DCC_Channel ได้เปลี่ยนเป็น commandChannel //
  35.     return 1;
  36. }
  37.  
  38. public OnGameModeExit(){
  39.     return 1;
  40. }
  41.  
  42. // ~~~~~~~~~~~~~~~~~~~ DISCORD COMMANDS SECTION ~~~~~~~~~~~~~~~~ //
  43.  
  44. public DCC_OnMessageCreate(DCC_Message:message){ // Callback เชื่อมต่อ Discord กับ Serevr
  45.  
  46.     new DCC_Channel:channel;
  47.  
  48.     DCC_GetMessageChannel(message, channel);
  49.  
  50.     // ถ้า ห้องที่ใช้คำสั่ง ไม่ตรงกับ ห้องที่เรากำหนดไว้ให้ใช้คำสั่ง เซิฟเวอร์จะตีกลับ
  51.     if(channel != commandChannel)
  52.         return 1;
  53.  
  54.     //ค้นหาคนออกคำสั่งว่าเป็นใคร
  55.     new DCC_User:author;
  56.     DCC_GetMessageAuthor(message, author);
  57.  
  58.     //เอาคนที่ใช้คำสั่งมาตรวจสอบว่าเป็นคนหรอบอท
  59.     new bool:isBot;
  60.     DCC_IsUserBot(author, isBot);
  61.  
  62.     if(isBot) return 1;
  63.        
  64.     //  ตรวจสอบคนใช้คำสั่งว่ามียศถึงที่ทางเซิฟเวอร์กำหนดหรอป่าว ? //
  65.     new bool:hasRole;
  66.     DCC_HasGuildMemberRole(guildName, author, adminRole, hasRole);
  67.  
  68.     // หากคนใช้คำสั่งมียศไม่ถึงที่กำหนดส่งกลับ
  69.     if(!hasRole){
  70.         DCC_SendChannelMessage(commandChannel, "You do not have the role required");
  71.         return 1;
  72.     }
  73.  
  74.     new str[256];
  75.     new command[32], params[128];
  76.  
  77.     DCC_GetMessageContent(message, str); // ข้อความที่ส่งมาจาก Discord จะถุกจัดเก็บไว้ภายใน Str
  78.  
  79.     // แยกคำสั่ง และ จำนวน ออกจากกัน //
  80.  
  81.     sscanf(str, "s[32]s[128]", command, params);
  82.  
  83.     // ตรวจสอบว่าใช้คำสั่งถุกหรอป่าว
  84.  
  85.     if(!strcmp(command, "&chat", true))
  86.     {
  87.         new playerID, _message[128];
  88.  
  89.         sscanf(params, "us[128]", playerID, _message); // แยกไอดีผู้เล่นและข้อความ //
  90.  
  91.         if(!IsPlayerConnected(playerID))
  92.             return DCC_SendChannelMessage(channel, "The player is not online!");
  93.  
  94.         SendClientMessage(playerID, -1, _message);
  95.     }
  96.     return 1;
  97. }
Add Comment
Please, Sign In to add comment