Advertisement
Guest User

Ban System SQLITE by Pain Nagato

a guest
Aug 14th, 2016
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.36 KB | None | 0 0
  1. #include <a_samp>
  2. // configuração
  3. new DB:Banidos;
  4.  
  5. forward KickEx(playerid);
  6.  
  7. public OnGameModeInit()
  8. {
  9. Banidos = db_open("Banidos.db");
  10. db_query(Banidos, "CREATE TABLE IF NOT EXISTS `Banidos` (`Admin`,`Banido`,`Dias`,`Motivo`,`Data`)");
  11. print("\n-------------------------------------------------\n");
  12. print("Ban Syssstem Carregado com sucesso! versão 0.2 By: Pain Nagato");
  13. print("\n-------------------------------------------------\n");
  14. return 1;
  15. }
  16.  
  17. #if defined _ALS_OnGameModeInit
  18. #undef OnGameModeInit
  19. #else
  20. #define _ALS_OnGameModeInit
  21. #endif
  22. #define OnGameModeInit PainNagato_OnGameModeInit
  23. #if defined PainNagato_OnGameModeInit
  24. forward PainNagato_OnGameModeInit();
  25. #endif
  26. public OnPlayerConnect(playerid)
  27. {
  28. return OnPlayerCheckBan(playerid);
  29. }
  30. #if defined _ALS_OnPlayerConnect
  31. #undef OnPlayerConnect
  32. #else
  33. #define _ALS_OnPlayerConnect
  34. #endif
  35. #define OnPlayerConnect PainNagato_OnPlayerConnect
  36. #if defined PainNagato_OnPlayerConnect
  37. forward PainNagato_OnPlayerConnect(playerid);
  38. #endif
  39. stock SetBanPlayerEx(adminban, banid , days, const reason[]) // banir o player com parametros a mais
  40. {
  41. new file2[50], Query[300] , a, m , d , h , mi , s;
  42. getdate(a,m,d);
  43. gettime(h,mi,s);
  44. format(file2, sizeof(file2), "%02d/%02d/%d - %02d:%02d:%02d", d , m , a , h , mi , s);
  45. format(Query, sizeof(Query), "INSERT INTO `Banidos` (`Admin`,`Banido`,`Dias`,`Motivo`,`Data`) VALUES ('%s','%s','%d','%s','%s')", GetNameId(adminban), GetNameId(banid), days * 86400 + gettime() , reason , file2);
  46. db_free_result(db_query(Banidos, Query));
  47. GameTextForPlayer(banid, "~r~BANIDO" , 5000 , 5);
  48. SetTimerEx("KickEx" , 200 , false , "i" , banid);
  49. return 1;
  50. }
  51.  
  52. stock SetBanPlayer(banid, days, const reason[]) // banir o player
  53. {
  54. new Query[300] , file2[50] , a, m , d , h , mi , s;
  55. getdate(a,m,d);
  56. gettime(h,mi,s);
  57. format(file2, sizeof(file2), "%02d/%02d/%d - %02d:%02d:%02d", d , m , a , h , mi , s);
  58. format(Query, sizeof(Query), "INSERT INTO `Banidos` (`Admin`,`Banido`,`Dias`,`Motivo`,`Data`) VALUES ('BOT-ADMIN','%s','%d','%s','%s')", GetNameId(banid), days * 86400 + gettime(), reason , file2);
  59. db_free_result(db_query(Banidos, Query));
  60. GameTextForPlayer(banid, "~r~BANIDO" , 5000 , 5);
  61. SetTimerEx("KickEx" , 200 , false , "i" , banid);
  62. return 1;
  63. }
  64.  
  65. stock GetNameId(playerid)
  66. {
  67. new name[MAX_PLAYER_NAME+1];
  68. GetPlayerName(playerid, name , MAX_PLAYER_NAME+1);
  69. return name;
  70. }
  71.  
  72. stock ConverterNumeros(n) // by DanDRT
  73. {
  74. new dia, hr, mn, seg, resto;
  75. resto = n;
  76. seg = resto % 60;
  77. resto /= 60;
  78. mn = resto % 60;
  79. resto /= 60;
  80. hr = resto % 24;
  81. resto /= 24;
  82. dia = resto;
  83. new str[50];
  84. format(str, sizeof(str), "%ddias, %02dh %02dm %02ds", dia, hr, mn, seg);
  85. return str;
  86. }
  87.  
  88. stock OnPlayerCheckBan(playerid) // checar se está banido
  89. {
  90. new query[300] , DBResult:result;
  91.  
  92. format(query, sizeof(query) , "SELECT * FROM `Banidos` WHERE `Banido` = '%s'" , GetNameId(playerid));
  93.  
  94. result = db_query(Banidos, query);
  95.  
  96. if(db_num_rows(result) == 0) print("Não existe nenhuma conta ");
  97.  
  98. new AdminBan[25] , Days , Data[50] , Motivo[64] , string[200];
  99.  
  100. new Field[100];
  101.  
  102. db_get_field_assoc(result, "Admin", Field, sizeof(Field));
  103. format(AdminBan, sizeof(AdminBan) , Field);
  104.  
  105. db_get_field_assoc(result, "Dias", Field, sizeof(Field));
  106. Days = strval(Field);
  107.  
  108. db_get_field_assoc(result, "Data", Field, sizeof(Field));
  109. format(Data, sizeof(Data) , Field);
  110.  
  111. db_get_field_assoc(result, "Motivo", Field, sizeof(Field));
  112. format(Motivo, sizeof(Motivo) , Field);
  113.  
  114. if(Days < gettime())
  115. {
  116.  
  117. format(query, sizeof query , "DELETE FROM `Banidos` WHERE `Banido` = '%s'" , GetNameId(playerid));
  118. db_query(Banidos, query);
  119. }
  120.  
  121. else
  122. {
  123.  
  124. format(string, sizeof(string), "{FFFF00}Admin: {FFFFFF}%s\n{FFFF00}Conta Banida: {FFFFFF}%s\n{FFFF00}Dias Restante: {FFFFFF}%s\n{FFFF00}Data: {FFFFFF}%s\n{FFFF00}Motivo: {FFFFFF}%s", AdminBan , GetNameId(playerid), ConverterNumeros(Days - gettime()) , Data , Motivo);
  125. ShowPlayerDialog(playerid, 9898 , DIALOG_STYLE_MSGBOX , "{FFFFFF}Conta {FF0000}Banida", string , "Fechar" , "");
  126. SetTimerEx("KickEx", 500 , false , "i" , playerid);
  127.  
  128. }
  129. return 1;
  130. }
  131.  
  132. stock RemoveBanPlayer(const bannick[]) // remover o ban
  133. {
  134. new query[300] , DBResult:result;
  135.  
  136. format(query, sizeof query , "SELECT * FROM `Banidos` WHERE `Banido` = '%s'" , bannick);
  137.  
  138. result = db_query(Banidos, query);
  139.  
  140. if(db_num_rows(result) == 0) printf("Essa conta %s não está banida", bannick);
  141.  
  142. format(query, sizeof query , "DELETE FROM `Banidos` WHERE `Banido` = '%s'", bannick);
  143. db_query(Banidos, query);
  144. return 1;
  145. }
  146.  
  147. stock EditBanPlayer(const bannick[] , days , const reason[]) // editar o ban
  148. {
  149. new query[300] , DBResult:result;
  150.  
  151. format(query, sizeof query , "SELECT * FROM `Banidos` WHERE `Banido` = '%s'" , bannick);
  152.  
  153. result = db_query(Banidos, query);
  154.  
  155. if(db_num_rows(result) == 0) return false;
  156.  
  157. format(query, sizeof query , "UPDATE `Banidos` SET `Banido` = '%s' WHERE `Dias` = '%d' WHERE `Motivo` = '%s'" , bannick , days * 86400 + gettime() , reason);
  158.  
  159. db_query(Banidos, query);
  160. return 1;
  161. }
  162.  
  163. stock ScheduleBanPlayer(adminban, const bannick[] , days , const reason[]) // agendar ban
  164. {
  165. new query[300] , file2[50] , a, m , d , h , mi , s;
  166. getdate(a,m,d);
  167. gettime(h,mi,s);
  168. format(file2, sizeof(file2), "%02d/%02d/%d - %02d:%02d:%02d", d , m , a , h , mi , s);
  169. format(query, sizeof(query) , "INSERT INTO `Banidos` (`Admin`,`Banido`,`Dias`,`Data`,`Motivo`) VALUES('%s','%s','%d','%s','%s')", GetNameId(adminban), bannick , days * 86400 + gettime() , file2 , reason);
  170. db_query(Banidos, query);
  171. return 1;
  172. }
  173.  
  174. public KickEx(playerid) return Kick(playerid);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement