Guest User

Neil's Reputation System

a guest
Apr 3rd, 2013
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.97 KB | None | 0 0
  1. #define FILTERSCRIPT
  2.  
  3. #include <a_samp>
  4. #include <a_mysql>
  5. #include <sscanf2>
  6. #include <zcmd>
  7.  
  8.  
  9. /*
  10. ---------------------------Functions List----------------------------------------
  11. GetRepPoints(playerid) > Will get the total rep points of the 'playerid'
  12. AddNewUser(playerid) > This will add a new user to the table 'repinfo' with 0 reputation points
  13. SetRep(playerid, rep) > Sets the total reputation points to 'rep'
  14. GiveRep(playerid, rep) > Will get the rep points of the playerid and add the 'rep'
  15. */
  16.  
  17.  
  18.  
  19. //Your MySQL Setup
  20. #define host "localhost"
  21. #define user "root"
  22. #define db "testpurpose"
  23. #define password ""
  24.  
  25.  
  26.  
  27. // Time to wait before a player can rep again. (In Milliseconds, default is set to 30 mins)
  28. #define TimetoWait 1800000
  29.  
  30.  
  31. #define First.RequiredScore 50 // When a player has less than 50 score and does /rep other players, he's gonna give them,
  32. #define FirstRepPoints 1 // 1 Reputation Point
  33.  
  34. #define Second.RequiredScore 120 // When a players score is < 120 but >= 50 and does /rep other players, he's gonna give them,
  35. #define SecondRepPoints 2 // 2 Reputation Point
  36.  
  37. #define Third.RequiredScore 200
  38. #define ThirdRepPoints 3 // You get the point here
  39.  
  40. #define Fourth.RequiredScore 330
  41. #define FourthRepPoints 4 // Change all values of the defines to your preference
  42.  
  43. #define Fifth.RequiredScore 400
  44. #define FifthRepPoints 5
  45.  
  46.  
  47.  
  48.  
  49. new query[256];
  50. new msg[128];
  51. new time[MAX_PLAYERS];
  52. new bool:USEonPlayerClickPlayer = true;
  53.  
  54.  
  55.  
  56. public OnFilterScriptInit()
  57. {
  58. mysql_connect(host, user, db, password);
  59. if(mysql_ping() >= 1) {
  60. print("Connected to the database\n"); }
  61. else print("Cannot connect to the database\n");
  62.  
  63. mysql_debug(1);
  64. SetupTable();
  65. print("=============================================================");
  66. print("============== Neil's Reputation System Loaded ==============");
  67. print("=============================================================");
  68. return 1;
  69. }
  70.  
  71.  
  72.  
  73. public OnPlayerConnect(playerid)
  74. {
  75. format(query,sizeof(query), "SELECT `username` FROM `repinfo` WHERE `username` = '%s'", escpname(playerid));
  76. mysql_query(query);
  77. mysql_store_result();
  78. new rows = mysql_num_rows();
  79. if(!rows)
  80. {
  81. AddNewUser(playerid);
  82. }
  83. mysql_free_result();
  84. return 1;
  85. }
  86.  
  87. public OnPlayerDisconnect(playerid, reason)
  88. {
  89. time[playerid] = 0;
  90. return 1;
  91. }
  92.  
  93.  
  94. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  95. {
  96. if(USEonPlayerClickPlayer == true)
  97. {
  98. if(clickedplayerid == playerid)
  99. {
  100. format(msg,sizeof(msg), "Your reputation point(s): %d", GetRepPoints(playerid));
  101. ShowPlayerDialog(playerid, 0, DIALOG_STYLE_MSGBOX, "{FF0000}Rep Points", msg, "Close", "");
  102. }
  103. else
  104. {
  105. format(msg,sizeof(msg), "%s's(%d) reputation point(s): %d", GetRepPoints(clickedplayerid));
  106. ShowPlayerDialog(playerid, 1, DIALOG_STYLE_MSGBOX, "{FFFF00}Rep Points", msg, "Close", "");
  107. }
  108. }
  109. else return 1;
  110. return 1;
  111. }
  112. //---------------------------------------------CMD-------------------------------
  113.  
  114.  
  115. CMD:rep(playerid, params[])
  116. {
  117. new target, points, reason[30], targetname[24], playeridname[24], newtime;
  118. points = HowManyReps(playerid);
  119. newtime = GetTickCount() - time[playerid];
  120. if(newtime < TimetoWait) return SendClientMessage(playerid, -1, "You just gave someone a reputation.");
  121. if(sscanf(params, "us[30]", target, reason)) return SendClientMessage(playerid, -1, "[USAGE]: /rep [playerid] [reason]");
  122. if(target == playerid) return SendClientMessage(playerid, 0xFF0000AA, "You cannot reputate yourself");
  123. if(target == INVALID_PLAYER_ID) return SendClientMessage(playerid, 0xFF0000AA, "Player is not online");
  124. {
  125. GetPlayerName(playerid, playeridname, 24);
  126. GiveRep(target, points);
  127. format(msg,sizeof(msg), "** %s(%d) has given you {FF0000}%d{FFFFFF} reputation points due to %s **", playeridname, playerid, HowManyReps(playerid), reason);
  128. SendClientMessage(target, -1, msg);
  129. format(msg,sizeof(msg), "You now have {00FF00}%d {FFFFFF}Total Rep Points", GetRepPoints(target));
  130. SendClientMessage(target, -1, msg);
  131. GetPlayerName(target, targetname, 24);
  132. format(msg,sizeof(msg), "You have given %s(%d) %d reputation points. He now has %d reputation points.", targetname, target, HowManyReps(playerid), GetRepPoints(target));
  133. SendClientMessage(playerid, -1, msg);
  134. time[playerid] = GetTickCount();
  135. }
  136. return 1;
  137. }
  138.  
  139. CMD:checkrep(playerid, params[]) return cmd_checkreps(playerid, params);
  140. CMD:checkreps(playerid, params[])
  141. {
  142. new target;
  143. if(sscanf(params, "u", target)) return SendClientMessage(playerid, -1, "[USAGE]: /checkrep [playerid]");
  144. {
  145. new name[MAX_PLAYER_NAME];
  146. GetPlayerName(target, name, sizeof(name));
  147. format(msg,sizeof(msg), "%s's(%d) current rep: %d", name, target, GetRepPoints(target));
  148. SendClientMessage(playerid, -1, msg);
  149. }
  150. return 1;
  151. }
  152.  
  153. CMD:myreps(playerid, params[]) return cmd_myrep(playerid, params);
  154. CMD:myrep(playerid, params[])
  155. {
  156. format(msg,sizeof(msg), "Your current reputation point(s) is: %d", GetRepPoints(playerid));
  157. SendClientMessage(playerid, -1, msg);
  158. return 1;
  159. }
  160.  
  161.  
  162. //-------------------------------------------------------------------------------
  163.  
  164.  
  165. public HowManyReps(playerid)
  166. {
  167. new repped;
  168. new score;
  169. score = GetPlayerScore(playerid);
  170. if(score < First.RequiredScore) return repped = FirstRepPoints;
  171. else if(score < Second.RequiredScore && score >= First.RequiredScore) return repped = SecondRepPoints;
  172. else if(score < Third.RequiredScore && score >= Second.RequiredScore) return repped = ThirdRepPoints;
  173. else if(score < Fourth.RequiredScore && score >= Third.RequiredScore) return repped = FourthRepPoints;
  174. else if(score < Fifth.RequiredScore && score >= Fourth.RequiredScore) return repped = FifthRepPoints;
  175. return repped;
  176. }
  177.  
  178.  
  179. public SetRep(playerid, rep)
  180. {
  181. format(query,sizeof(query), "UPDATE `repinfo` SET `reps` = '%d' WHERE `username` = '%s'", rep, escpname(playerid));
  182. mysql_query(query);
  183. return 1;
  184. }
  185. public GiveRep(playerid, rep)
  186. {
  187. new total;
  188. total = GetRepPoints(playerid) + rep;
  189. format(query,sizeof(query), "UPDATE `repinfo` SET `reps` = '%d' WHERE `username` = '%s'", total, escpname(playerid));
  190. mysql_query(query);
  191. return 1;
  192. }
  193.  
  194. public GetRepPoints(playerid)
  195. {
  196. new value[10];
  197. format(query,sizeof(query), "SELECT `reps` FROM `repinfo` WHERE `username` = '%s'", escpname(playerid));
  198. mysql_query(query);
  199. mysql_store_result();
  200. mysql_fetch_row_format(query, "|");
  201. {
  202. format(value, sizeof(value), "%s", query);
  203. }
  204. new reps = strval(value);
  205. mysql_free_result();
  206. return reps;
  207. }
  208. public AddNewUser(playerid)
  209. {
  210. format(query,sizeof(query), "INSERT INTO `repinfo` (`username`, `reps`) VALUES ('%s', 0)", escpname(playerid));
  211. mysql_query(query);
  212. return 1;
  213. }
  214.  
  215.  
  216. SetupTable()
  217. {
  218. return mysql_query("CREATE TABLE IF NOT EXISTS `repinfo`(`username` VARCHAR(30), `reps` INT(7))");
  219. }
  220.  
  221. //----------------------------------STOCK----------------------------------------
  222.  
  223. stock escpname(playerid)
  224. {
  225. new Pname[MAX_PLAYER_NAME];
  226. new escname[24];
  227. GetPlayerName(playerid, Pname, sizeof(Pname));
  228. mysql_real_escape_string(Pname, escname);
  229. return escname;
  230. }
  231.  
  232. //-------------------------------------------------------------------------------
  233.  
  234.  
  235. //---------------------------------FORWARDS--------------------------------------
  236. forward HowManyReps(playerid);
  237. forward GetRepPoints(playerid);
  238. forward AddNewUser(playerid);
  239. forward SetRep(playerid, rep);
  240. forward GiveRep(playerid, rep);
  241. //-------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment