Advertisement
Guest User

Mitch

a guest
Dec 3rd, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.14 KB | None | 0 0
  1. //Sistema By Saullo English...
  2.  
  3. // - Includes
  4.  
  5. #include <a_samp>
  6. #include <a_mysql>
  7.  
  8. // - Variaveis
  9.  
  10. new connect;
  11. new Query[512];
  12.  
  13. // - Enum
  14.  
  15. enum aInfo
  16. {
  17. bool:Logado,
  18. Colete,
  19. Saldo bancario,
  20. Fome,
  21. Sede,
  22. Vida,
  23.  
  24. Dinheiro,
  25.  
  26. }
  27. new AccountInfo[MAX_PLAYERS][aInfo];
  28.  
  29. #define SQL_Host ""
  30. #define SQL_User ""
  31. #define SQL_DataBase ""
  32. #define SQL_Password ""
  33.  
  34. #define TableName "Accounts"
  35.  
  36. #define DIALOG_REGISTER 0
  37. #define DIALOG_LOGIN 1
  38.  
  39. // - Forward's
  40.  
  41. forward MySQL_CheckAccount(playerid);
  42. forward R_MySQL_CheckAccount(playerid);
  43.  
  44. forward MySQL_CheckAccountPass(playerid, password[]);
  45. forward R_MySQL_CheckAccountPass(playerid);
  46.  
  47. forward MySQL_LoadAccount(playerid);
  48. forward R_MySQL_LoadAccount(playerid);
  49.  
  50. forward MySQL_SaveAccount(playerid);
  51.  
  52. // - CallBacks
  53.  
  54. public OnFilterScriptInit()
  55. {
  56. connect = mysql_connect(SQL_Host, SQL_User, SQL_DataBase, SQL_Password);
  57. static x;
  58. x = -1;
  59. for(; ++x ^ 3;)
  60. {
  61. if(!connect)
  62. printf("MySQL connection attempt %d failed!", x);
  63. else break;
  64. }
  65. mysql_debug(1);
  66. return 1;
  67. }
  68.  
  69. public OnFilterScriptExit()
  70. return mysql_debug(0), mysql_close(connect);
  71.  
  72. public OnPlayerRequestSpawn(playerid)
  73. return (AccountInfo[playerid][Logged] ? 1 : 0);
  74.  
  75. public OnPlayerConnect(playerid)
  76. {
  77. AccountInfo[playerid][Colete] = 0;
  78. AccountInfo[playerid][Saldo Bancario] = 0;
  79. AccountInfo[playerid][Fome] = 0;
  80. AccountInfo[playerid][Sede] = 0;
  81. AccountInfo[playerid][Dinheiro] = 0;
  82. AccountInfo[playerid][Banco] = 0;
  83. return MySQL_CheckAccount(playerid);
  84. }
  85.  
  86. public OnPlayerDisconnect(playerid, reason)
  87. return MySQL_SaveAccount(playerid);
  88.  
  89. public MySQL_CheckAccount(playerid)
  90. {
  91. format(Query,sizeof(Query),"SELECT * FROM `%s` WHERE Nick='%s'", TableName, _@PlayerName(playerid));
  92. mysql_function_query(connect, Query, true, "R_@MySQL_CheckAccount", "d", playerid);
  93. return 1;
  94. }
  95.  
  96. public R_@MySQL_CheckAccount(playerid)
  97. {
  98. static rows,fields;
  99. cache_get_data(rows, fields, connect);
  100. if(rows)
  101. ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login",;
  102. else
  103. ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Registro",;
  104. return 1;
  105. }
  106.  
  107. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  108. {
  109. switch(dialogid)
  110. {
  111. case 0:
  112. {
  113. if(response)
  114. {
  115. if(!strlen(inputtext))
  116. {
  117. ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Registro",;
  118. }
  119.  
  120. format(Query, sizeof(Query), "INSERT INTO `Contas` VALUES ('%s','%s','%d','%d','0','1500','2000');", _@PlayerName(playerid), inputtext, AccountInfo[playerid][Killed], AccountInfo[playerid][Died]);
  121. mysql_function_query(connect, Query, false, "", "", "");
  122.  
  123. SendClientMessage(playerid, -1, "Registrado com sucesso!");
  124.  
  125. SetPlayerHealth(playerid, 100);
  126. ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login",;
  127. }
  128. else
  129. Kick(playerid);
  130. return 1;
  131. }
  132. case 1:
  133. {
  134. if(response)
  135. {
  136. if(!strlen(inputtext))
  137. {
  138. ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login",;
  139. SendClientMessage(playerid,0xFF0000AA,;
  140. }
  141. MySQL_CheckAccountPass(playerid, inputtext);
  142. }
  143. else
  144. Kick(playerid);
  145. return 1;
  146. }
  147. }
  148. return 1;
  149. }
  150.  
  151. public MySQL_CheckAccountPass(playerid, password[])
  152. {
  153. format(Query,sizeof(Query),"SELECT * FROM `%s` WHERE Nick='%s' and Pass='%s'", TableName, _@PlayerName(playerid), password);
  154. mysql_function_query(connect, Query, true, "R_@MySQL_CheckAccountPass", "d", playerid);
  155. return 1;
  156. }
  157.  
  158. public R_@MySQL_CheckAccountPass(playerid)
  159. {
  160. static rows,fields;
  161. cache_get_data(rows, fields, connect);
  162. if(rows)
  163. {
  164. MySQL_LoadAccount(playerid);
  165. AccountInfo[playerid][Connections]++;
  166. MySQL_SaveAccount(playerid);
  167. SendClientMessage(playerid, -1,;
  168. }
  169. else
  170. ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login",;
  171. return 1;
  172. }
  173.  
  174. public MySQL_LoadAccount(playerid)
  175. {
  176. format(Query,sizeof(Query),"SELECT * FROM `%s` WHERE Nick='%s'", TableName, _@PlayerName(playerid));
  177. mysql_function_query(connect,Query,true,"R_@MySQL_LoadAccount", "d", playerid);
  178. return 1;
  179. }
  180.  
  181. public R_@MySQL_LoadAccount(playerid)
  182. {
  183. static rows,fields;
  184. cache_get_data(rows,fields,connect);
  185. if(rows)
  186. {
  187. cache_get_field_content(0,"Dinheiro",Query,connect);
  188. AccountInfo[playerid][Dinnheiro] = strval(Query);
  189.  
  190. cache_get_field_content(0,"Banco",Query,connect);
  191. AccountInfo[playerid][Banco] = strval(Query);
  192.  
  193. cache_get_field_content(0,"Saldo Bancario",Query,connect);
  194. AccountInfo[playerid][Saldo Bancario] = strval(Query);
  195.  
  196. cache_get_field_content(0,"vida",Query,connect);
  197. AccountInfo[playerid][Vida] = strval(Query);
  198.  
  199. cache_get_field_content(0,"Fome",Query,connect);
  200. AccountInfo[playerid][Fome] = strval(Query)
  201.  
  202. cache_get_field_content(0,"Sede",Query,connect);
  203. AccountInfo[playerid][Sede] = strval(Query)
  204.  
  205. cache_get_field_content(0,"Colete",Query,connect);
  206. AccountInfo[playerid][Colete] = strval(Query)
  207. }
  208. return 1;
  209. }
  210.  
  211. public MySQL_SaveAccount(playerid)
  212. {
  213. format(Query,sizeof(Query),"UPDATE `%s` SET Dinheiro='%d', Banco='%d', Vida='%d', Sede='%d', Fome='%d', Colete='%d' nick='%s'", AccountInfo[playerid][Money], AccountInfo[playerid][Bank], AccountInfo[playerid][Killed], AccountInfo[playerid][Died], _@PlayerName(playerid));
  214. mysql_function_query(connect,Query,false,"","","");
  215. return 1;
  216. }
  217.  
  218. // - Stocks
  219.  
  220. _@PlayerName(playerid)
  221. {
  222. new _@pN[24];
  223. GetPlayerName(playerid, _@pN, sizeof(_@pN));
  224. return _@pN;
  225. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement