Advertisement
Guest User

Apenas um teste

a guest
Apr 14th, 2018
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.31 KB | None | 0 0
  1. #include <a_samp>
  2. #include <sscanf2>
  3. #include <a_mysql>
  4.  
  5.  
  6. // -------------------------------
  7. #define HOST "localhost"
  8. #define USER "root"
  9. #define SENHA ""
  10. #define DATABASE "samp"
  11.  
  12. new MySQL: MYSQLConnected;
  13. // -------------------------------
  14. #define DIALOG_LOGIN 1
  15. #define DIALOG_REGISTRO 2
  16. // -------------------------------
  17. #define TEMPO_LOGIN 30
  18.  
  19. #define DEFAULTPOSX 1139.4064
  20. #define DEFAULTPOSY -1761.9249
  21. #define DEFAULTPOSZ 13.5955
  22. #define DEFAULTPOSA 4.5833
  23. // -------------------------------
  24. enum E_PLAYERS{
  25. ID, // MYSQL ID, int
  26. Nome[MAX_PLAYER_NAME], // string
  27. Senha, // string
  28. Money, // int
  29. Skin, // int
  30. Score, // int
  31. Float: PosX, // float
  32. Float: PosY, // float
  33. Float: PosZ, // float
  34. Float: PosA, // float
  35. Interior, // int
  36. VirtualWorld, // int
  37.  
  38. bool: pLogado, // se o player estiver logado
  39. }
  40. new Player[MAX_PLAYERS][E_PLAYERS];
  41. // --------------------------------
  42.  
  43. main() {}
  44.  
  45. public OnGameModeInit()
  46. {
  47. MySQLConnect(); // Verifica se o banco de dados está ligado
  48. CriarTabela(); // Crias as tabelas
  49. return 1;
  50. }
  51.  
  52. public OnGameModeExit()
  53. {
  54. FecharServidor(); // Quando o servidor fechar todos os jogadores onlines vão sair como se fosse por contra propria
  55. return 1;
  56. }
  57.  
  58. public OnPlayerRequestClass(playerid, classid)
  59. {
  60. SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
  61. SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
  62. SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
  63. return 1;
  64. }
  65.  
  66. public OnPlayerConnect(playerid)
  67. {
  68. MYSQLConnected = mysql_connect(HOST, USER, SENHA, DATABASE);
  69. GetPlayerName(playerid, Player[playerid][Nome], 20);
  70.  
  71. new Query[90];
  72. mysql_format(MYSQLConnected, Query, sizeof(Query), "SELECT `ID`, `SENHA` FROM `Jogadores` WHERE `Player`='%s' ",Player[playerid][Nome]);
  73. mysql_tquery(MYSQLConnected, Query, "VerificarContas", "i", playerid);
  74.  
  75. return 1;
  76. }
  77.  
  78. public OnPlayerDisconnect(playerid, reason)
  79. {
  80. SalvarDados(playerid);
  81. return 1;
  82. }
  83.  
  84. public OnPlayerSpawn(playerid)
  85. {
  86. return 1;
  87. }
  88.  
  89. public OnPlayerDeath(playerid, killerid, reason)
  90. {
  91. return 1;
  92. }
  93.  
  94. public OnVehicleSpawn(vehicleid)
  95. {
  96. return 1;
  97. }
  98.  
  99. public OnVehicleDeath(vehicleid, killerid)
  100. {
  101. return 1;
  102. }
  103.  
  104. public OnPlayerText(playerid, text[])
  105. {
  106. return 1;
  107. }
  108.  
  109. public OnPlayerCommandText(playerid, cmdtext[])
  110. {
  111. if (strcmp("/mycommand", cmdtext, true, 10) == 0)
  112. {
  113. // Do something here
  114. return 1;
  115. }
  116. return 0;
  117. }
  118.  
  119. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  120. {
  121. return 1;
  122. }
  123.  
  124. public OnPlayerExitVehicle(playerid, vehicleid)
  125. {
  126. return 1;
  127. }
  128.  
  129. public OnPlayerStateChange(playerid, newstate, oldstate)
  130. {
  131. return 1;
  132. }
  133.  
  134. public OnPlayerEnterCheckpoint(playerid)
  135. {
  136. return 1;
  137. }
  138.  
  139. public OnPlayerLeaveCheckpoint(playerid)
  140. {
  141. return 1;
  142. }
  143.  
  144. public OnPlayerEnterRaceCheckpoint(playerid)
  145. {
  146. return 1;
  147. }
  148.  
  149. public OnPlayerLeaveRaceCheckpoint(playerid)
  150. {
  151. return 1;
  152. }
  153.  
  154. public OnRconCommand(cmd[])
  155. {
  156. return 1;
  157. }
  158.  
  159. public OnPlayerRequestSpawn(playerid)
  160. {
  161. return 1;
  162. }
  163.  
  164. public OnObjectMoved(objectid)
  165. {
  166. return 1;
  167. }
  168.  
  169. public OnPlayerObjectMoved(playerid, objectid)
  170. {
  171. return 1;
  172. }
  173.  
  174. public OnPlayerPickUpPickup(playerid, pickupid)
  175. {
  176. return 1;
  177. }
  178.  
  179. public OnVehicleMod(playerid, vehicleid, componentid)
  180. {
  181. return 1;
  182. }
  183.  
  184. public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
  185. {
  186. return 1;
  187. }
  188.  
  189. public OnVehicleRespray(playerid, vehicleid, color1, color2)
  190. {
  191. return 1;
  192. }
  193.  
  194. public OnPlayerSelectedMenuRow(playerid, row)
  195. {
  196. return 1;
  197. }
  198.  
  199. public OnPlayerExitedMenu(playerid)
  200. {
  201. return 1;
  202. }
  203.  
  204. public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
  205. {
  206. return 1;
  207. }
  208.  
  209. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  210. {
  211. return 1;
  212. }
  213.  
  214. public OnRconLoginAttempt(ip[], password[], success)
  215. {
  216. return 1;
  217. }
  218.  
  219. public OnPlayerUpdate(playerid)
  220. {
  221. return 1;
  222. }
  223.  
  224. public OnPlayerStreamIn(playerid, forplayerid)
  225. {
  226. return 1;
  227. }
  228.  
  229. public OnPlayerStreamOut(playerid, forplayerid)
  230. {
  231. return 1;
  232. }
  233.  
  234. public OnVehicleStreamIn(vehicleid, forplayerid)
  235. {
  236. return 1;
  237. }
  238.  
  239. public OnVehicleStreamOut(vehicleid, forplayerid)
  240. {
  241. return 1;
  242. }
  243.  
  244. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  245. {
  246. new Dialog[240];
  247.  
  248. if(dialogid == DIALOG_REGISTRO){
  249. if(!response) return Kick(playerid);
  250.  
  251. if(strlen(inputtext) < 4 || strlen(inputtext) > 20){
  252. SendClientMessage(playerid, -1,"{0xFF0000AA}[ERRO]Apenas entre 4 a 20 Caracteres");
  253.  
  254. format(Dialog, sizeof(Dialog), "{0xFFFFFFAA}%s\n{0x80FF00AA}STATUS: NÃO REGISTRADA", Player[playerid][Nome]);
  255. ShowPlayerDialog(playerid, DIALOG_REGISTRO, DIALOG_STYLE_INPUT, "Login", Dialog, "Confirmar", "Sair");
  256. }else{
  257.  
  258. new Query[100];
  259. mysql_format(MYSQLConnected, Query, sizeof(Query), "INSERT INTO `Jogadores`(`Player`.`Senha`), VALUES('%s','%s')", Player[playerid][Nome], inputtext);
  260. mysql_tquery(MYSQLConnected, Query, "DadosRegistrados", "i", playerid);
  261.  
  262. RegistrarDados(playerid);
  263. }
  264. }
  265.  
  266. if(dialogid == DIALOG_LOGIN){
  267.  
  268. if(!response) return Kick(playerid);
  269.  
  270. if(!strcmp(Player[playerid][Senha], inputtext, true, 20)){
  271. new Query[70];
  272. mysql_format(MYSQLConnected, Query, sizeof(Query), "SELECT * FROM `Jogadores` Nome='%s'", Player[playerid][Nome]);
  273. mysql_tquery(MYSQLConnected, Query, "CarregarContas", "d", playerid);
  274. }else{
  275. SendClientMessage(playerid, -1,"{0xFF0000AA}[ERRO]Senha incorreta");
  276. format(Dialog, sizeof(Dialog), "{0xFFFFFFAA}%s\n{0xFF0000AA}STATUS: Registrado", Player[playerid][Nome]);
  277. ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", Dialog, "Confirmar", "Sair");
  278. }
  279. }
  280.  
  281. // == //
  282. return 1;
  283. }
  284.  
  285. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  286. {
  287. return 1;
  288. }
  289.  
  290. //=========================
  291. forward MySQLConnect();
  292. public MySQLConnect(){
  293.  
  294.  
  295. MYSQLConnected = mysql_connect(HOST, USER, SENHA, DATABASE);
  296. if (MYSQLConnected == MYSQL_INVALID_HANDLE || mysql_errno(MYSQLConnected) != 0){
  297. printf("[MySQL]Conexão com o banco de dados falhou");
  298. SendRconCommand("exit");
  299. }else{
  300. printf("[MySQL]Conectado ao banco de dados com sucesso");
  301. }
  302. return 1;
  303. }
  304.  
  305. // --------------------------
  306. forward FecharServidor();
  307. public FecharServidor(){
  308.  
  309. for (new i = 0, j = GetPlayerPoolSize(); i <= j; i++){
  310. if (IsPlayerConnected(i)){
  311. OnPlayerDisconnect(i, 1);
  312. }
  313. }
  314. mysql_close(MYSQLConnected);
  315. return 1;
  316. }
  317. // -------------------------
  318. forward CriarTabela();
  319. public CriarTabela(){
  320. MYSQLConnected = mysql_connect(HOST, USER, SENHA, DATABASE);
  321. mysql_query(MYSQLConnected ,"CREATE TABLE IF NOT EXISTS Jogadores(ID INT AUTO_INCREMENT PRIMARY KEY,Player INT(20),Senha VARCHAR(15), Dinheiro INT(20), Skin INT(20), Score INT(20), PosX FLOAT(20), PosY FLOAT(20), PosZ FLOAT(20), PosA FLOAT(20), Interior INT(10), VirtualWorld INT(10))");
  322. return 1;
  323. }
  324. // -------------------------
  325. forward VerificarContas(playerid);
  326. public VerificarContas(playerid){
  327. new Dialog[240];
  328.  
  329. if(cache_num_rows() > 0){
  330. cache_get_value(0, "Senha", Player[playerid][Senha]);
  331. format(Dialog, sizeof(Dialog), "{0xFFFFFFAA}%s\n{0xFF0000AA}STATUS: Registrado", Player[playerid][Nome]);
  332. ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", Dialog, "Confirmar", "Sair");
  333. }else{
  334. format(Dialog, sizeof(Dialog), "{0xFFFFFFAA}%s\n{0x80FF00AA}STATUS: NÃO REGISTRADA", Player[playerid][Nome]);
  335. ShowPlayerDialog(playerid, DIALOG_REGISTRO, DIALOG_STYLE_INPUT, "Login", Dialog, "Confirmar", "Sair");
  336. }
  337. return 1;
  338. }
  339. // --------------------------
  340. forward DadosRegistrados(playerid);
  341. public DadosRegistrados(playerid){
  342. Player[playerid][ID] = cache_insert_id();
  343. printf("CONTA ID %d REGISTRADA", Player[playerid][ID]);
  344. return 1;
  345. }
  346. // --------------------------
  347. forward CarregarContas(playerid);
  348. public CarregarContas(playerid){
  349. cache_get_value_int(0, "ID", Player[playerid][ID]);
  350. cache_get_value_int(0, "Skin", Player[playerid][Skin]);
  351. cache_get_value_int(0, "Score", Player[playerid][Score]);
  352. cache_get_value_int(0, "Dinheiro", Player[playerid][Money]);
  353. cache_get_value_int(0, "Interior", Player[playerid][Interior]);
  354. cache_get_value_int(0, "VirtualWorld", Player[playerid][VirtualWorld]);
  355.  
  356. cache_get_value_float(0, "PosX", Player[playerid][PosX]);
  357. cache_get_value_float(0, "PosY", Player[playerid][PosY]);
  358. cache_get_value_float(0, "PosZ", Player[playerid][PosZ]);
  359. cache_get_value_float(0, "PosA", Player[playerid][PosA]);
  360.  
  361. CarregarDados(playerid);
  362. return 1;
  363. }
  364. // ----------------------------
  365. stock RegistrarDados(playerid){
  366. Player[playerid][Skin] = 23;
  367. Player[playerid][Score] = 0;
  368. Player[playerid][Money] = 1500;
  369. Player[playerid][Interior] = 0;
  370. Player[playerid][VirtualWorld] = 0;
  371.  
  372. Player[playerid][PosX] = DEFAULTPOSX;
  373. Player[playerid][PosY] = DEFAULTPOSY;
  374. Player[playerid][PosZ] = DEFAULTPOSZ;
  375. Player[playerid][PosA] = DEFAULTPOSA;
  376. CarregarDados(playerid);
  377. return 1;
  378. }
  379. // -----------------------------
  380. stock CarregarDados(playerid){
  381. Player[playerid][pLogado] = true;
  382. SetPlayerScore(playerid, Player[playerid][Score]);
  383. GivePlayerMoney(playerid, Player[playerid][Money]);
  384. SetPlayerInterior(playerid, Player[playerid][Interior]);
  385. SetPlayerVirtualWorld(playerid, Player[playerid][VirtualWorld]);
  386.  
  387. SetSpawnInfo(playerid, 0, Player[playerid][Skin], Player[playerid][PosX], Player[playerid][PosY], Player[playerid][PosZ], Player[playerid][PosA], 0, 0, 0, 0, 0, 0);
  388. return 1;
  389. }
  390. // ------------------------------
  391. stock SalvarDados(playerid){
  392. Player[playerid][Score] = GetPlayerScore(playerid);
  393. Player[playerid][Skin] = GetPlayerSkin(playerid);
  394. Player[playerid][Money] = GetPlayerMoney(playerid);
  395. Player[playerid][Interior] = GetPlayerInterior(playerid);
  396. Player[playerid][VirtualWorld] = GetPlayerVirtualWorld(playerid);
  397.  
  398. GetPlayerPos(playerid ,Player[playerid][PosX], Player[playerid][PosY], Player[playerid][PosZ]);
  399. GetPlayerFacingAngle(playerid, Player[playerid][PosA]);
  400.  
  401. new Query[350];
  402. mysql_format(MYSQLConnected, Query, sizeof(Query), "UPDATE `Jogadores` SET `Player`='%s', `Dinheiro`='%d', `Skin`='%d', `Score`='%d', `PosY`='%f',`PosZ`='%f',`PosX`='%f',`PosA`='%f', `Interior`='%d', `VirtualWorld`='%d' WHERE `ID`='%d'",
  403. Player[playerid][Nome],
  404. Player[playerid][Money],
  405. Player[playerid][Skin],
  406. Player[playerid][Score],
  407. Player[playerid][PosX],
  408. Player[playerid][PosY],
  409. Player[playerid][PosZ],
  410. Player[playerid][PosA],
  411. Player[playerid][Interior],
  412. Player[playerid][VirtualWorld],
  413. Player[playerid][ID]);
  414.  
  415. mysql_tquery(MYSQLConnected, Query, "DadosSalvos", "d", playerid);
  416.  
  417. Player[playerid][Money] = 0;
  418. Player[playerid][Score] = 0;
  419. Player[playerid][Skin] = 0;
  420. Player[playerid][PosX] = 0;
  421. Player[playerid][PosY] = 0;
  422. Player[playerid][PosZ] = 0;
  423. Player[playerid][PosA] = 0;
  424. Player[playerid][Interior] = 0;
  425. Player[playerid][VirtualWorld] = 0;
  426. Player[playerid][pLogado] = false;
  427. return 1;
  428.  
  429. }
  430. // --------------------------------------------------
  431. forward DadosSalvos(playerid);
  432. public DadosSalvos(playerid) return printf("-> Conta salva ID: %d", Player[playerid][ID]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement