Advertisement
Guest User

CFeedBack

a guest
Nov 13th, 2014
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.87 KB | None | 0 0
  1. //                      **NOTICE**
  2. //You may re-distribute the filterscript or alter its contents
  3. //without the consent of Capua, the creator of this filterscript.
  4. //However it is appreciated if you mention the creator if re-distributed.
  5.  
  6. #define FILTERSCRIPT
  7.  
  8. #include <a_samp>
  9. #include <a_mysql>
  10. #include <sscanf2>
  11. #include <zcmd>
  12.  
  13. #define     SQL_HOST            "changeme"
  14. #define     SQL_USER            "changeme"
  15. #define     SQL_PASS            "changeme"
  16. #define     SQL_DB              "changeme"
  17.  
  18. enum PLAYER_INFO
  19. {
  20.     pName[MAX_PLAYER_NAME],
  21. };
  22.  
  23. new gPlayerInfo[MAX_PLAYERS][PLAYER_INFO];
  24. new NoFeedBackSpam[MAX_PLAYERS];
  25.  
  26. public OnFilterScriptInit()
  27. {
  28.     print("\n--------------------------------------");
  29.     print(" Feedback FS by Capua");
  30.     print("--------------------------------------\n");
  31.    
  32.     mySQL_init();
  33.     return 1;
  34. }
  35.  
  36. new gHandle;
  37.  
  38. stock mySQL_init()
  39. {
  40.     mysql_debug(1); //mysql debug enabled so we can spot errors etc.'
  41.     gHandle = mysql_connect(SQL_HOST, SQL_USER, SQL_DB, SQL_PASS);
  42.     //we'll create a table named 'feedback' with 3 columns: 'feedback id'...
  43.     //...which can be used to detect how many feedbacks has been sent.
  44.     //then we have sender column just to show who sent the feedback.
  45.     //and message obviously shows the message sent by the sender
  46.     mysql_function_query(gHandle, "CREATE TABLE IF NOT EXISTS `feedback` ( \
  47.         `feedback id` int(11) NOT NULL AUTO_INCREMENT, \
  48.         `sender` varchar(24) NOT NULL, \
  49.         `message` varchar(129) NOT NULL, \
  50.         PRIMARY KEY (`feedback id`) \
  51.     )", false, "SendQuery", "");
  52.        
  53.     return 1;
  54. }
  55.  
  56. forward SendQuery();
  57. public SendQuery()
  58. {
  59.     // callback for queries that don't fetch data
  60.     return 1;
  61. }
  62.  
  63. public OnPlayerConnect(playerid)
  64. {
  65.     GetPlayerName(playerid,gPlayerInfo[playerid][pName],MAX_PLAYER_NAME);
  66.     return 1;
  67. }
  68.  
  69. CMD:feedback(playerid, params[])
  70. {
  71.     if(NoFeedBackSpam[playerid] == 1)
  72.         return SendClientMessage(playerid, -1, "Do not spam the feedback function!");
  73.     new feedback[128]; //feedback variable is set to 128 because that's max characters in sa-mp
  74.     if (sscanf(params,"s[128]",feedback))
  75.         return SendClientMessage(playerid,-1,"USAGE: /feedback [text]");
  76.     new query[240];
  77.     //now we'll send the written text into the database
  78.     format(query, sizeof(query), "INSERT INTO feedback (sender,message) VALUES ('%s', '%s')", gPlayerInfo[playerid][pName], feedback);
  79.     mysql_function_query(gHandle, query, false, "OnFeedBackInsert", "");
  80.     SendClientMessage(playerid, -1, "Feedback dispatched! Thank you.");
  81.     NoFeedBackSpam[playerid] = 1;
  82.     //10 seconds until the player can send another feedback
  83.     SetTimer("FeedBackTimer", 10000, 0);
  84.     return 1;
  85. }
  86.  
  87. forward FeedBackTimer();
  88. public FeedBackTimer()
  89. {
  90.     new playerid;
  91.     NoFeedBackSpam[playerid] = 0;
  92.     return 1;
  93. }
  94.  
  95. forward OnFeedBackInsert(playerid);
  96. public OnFeedBackInsert(playerid)
  97. {
  98.     //and the last thing is to assign an ID for the feedback comment!
  99.     mysql_insert_id();
  100.     return 1;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement