Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Sistema By Saullo English...
- // - Includes
- #include <a_samp>
- #include <a_mysql>
- // - Variaveis
- new connect;
- new Query[512];
- // - Enum
- enum aInfo
- {
- bool:Logado,
- Colete,
- Saldo bancario,
- Fome,
- Sede,
- Vida,
- Dinheiro,
- }
- new AccountInfo[MAX_PLAYERS][aInfo];
- #define SQL_Host ""
- #define SQL_User ""
- #define SQL_DataBase ""
- #define SQL_Password ""
- #define TableName "Accounts"
- #define DIALOG_REGISTER 0
- #define DIALOG_LOGIN 1
- // - Forward's
- forward MySQL_CheckAccount(playerid);
- forward R_MySQL_CheckAccount(playerid);
- forward MySQL_CheckAccountPass(playerid, password[]);
- forward R_MySQL_CheckAccountPass(playerid);
- forward MySQL_LoadAccount(playerid);
- forward R_MySQL_LoadAccount(playerid);
- forward MySQL_SaveAccount(playerid);
- // - CallBacks
- public OnFilterScriptInit()
- {
- connect = mysql_connect(SQL_Host, SQL_User, SQL_DataBase, SQL_Password);
- static x;
- x = -1;
- for(; ++x ^ 3;)
- {
- if(!connect)
- printf("MySQL connection attempt %d failed!", x);
- else break;
- }
- mysql_debug(1);
- return 1;
- }
- public OnFilterScriptExit()
- return mysql_debug(0), mysql_close(connect);
- public OnPlayerRequestSpawn(playerid)
- return (AccountInfo[playerid][Logged] ? 1 : 0);
- public OnPlayerConnect(playerid)
- {
- AccountInfo[playerid][Colete] = 0;
- AccountInfo[playerid][Saldo Bancario] = 0;
- AccountInfo[playerid][Fome] = 0;
- AccountInfo[playerid][Sede] = 0;
- AccountInfo[playerid][Dinheiro] = 0;
- AccountInfo[playerid][Banco] = 0;
- return MySQL_CheckAccount(playerid);
- }
- public OnPlayerDisconnect(playerid, reason)
- return MySQL_SaveAccount(playerid);
- public MySQL_CheckAccount(playerid)
- {
- format(Query,sizeof(Query),"SELECT * FROM `%s` WHERE Nick='%s'", TableName, _@PlayerName(playerid));
- mysql_function_query(connect, Query, true, "R_@MySQL_CheckAccount", "d", playerid);
- return 1;
- }
- public R_@MySQL_CheckAccount(playerid)
- {
- static rows,fields;
- cache_get_data(rows, fields, connect);
- if(rows)
- ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login",;
- else
- ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Registro",;
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- switch(dialogid)
- {
- case 0:
- {
- if(response)
- {
- if(!strlen(inputtext))
- {
- ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Registro",;
- }
- format(Query, sizeof(Query), "INSERT INTO `Contas` VALUES ('%s','%s','%d','%d','0','1500','2000');", _@PlayerName(playerid), inputtext, AccountInfo[playerid][Killed], AccountInfo[playerid][Died]);
- mysql_function_query(connect, Query, false, "", "", "");
- SendClientMessage(playerid, -1, "Registrado com sucesso!");
- SetPlayerHealth(playerid, 100);
- ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login",;
- }
- else
- Kick(playerid);
- return 1;
- }
- case 1:
- {
- if(response)
- {
- if(!strlen(inputtext))
- {
- ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login",;
- SendClientMessage(playerid,0xFF0000AA,;
- }
- MySQL_CheckAccountPass(playerid, inputtext);
- }
- else
- Kick(playerid);
- return 1;
- }
- }
- return 1;
- }
- public MySQL_CheckAccountPass(playerid, password[])
- {
- format(Query,sizeof(Query),"SELECT * FROM `%s` WHERE Nick='%s' and Pass='%s'", TableName, _@PlayerName(playerid), password);
- mysql_function_query(connect, Query, true, "R_@MySQL_CheckAccountPass", "d", playerid);
- return 1;
- }
- public R_@MySQL_CheckAccountPass(playerid)
- {
- static rows,fields;
- cache_get_data(rows, fields, connect);
- if(rows)
- {
- MySQL_LoadAccount(playerid);
- AccountInfo[playerid][Connections]++;
- MySQL_SaveAccount(playerid);
- SendClientMessage(playerid, -1,;
- }
- else
- ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login",;
- return 1;
- }
- public MySQL_LoadAccount(playerid)
- {
- format(Query,sizeof(Query),"SELECT * FROM `%s` WHERE Nick='%s'", TableName, _@PlayerName(playerid));
- mysql_function_query(connect,Query,true,"R_@MySQL_LoadAccount", "d", playerid);
- return 1;
- }
- public R_@MySQL_LoadAccount(playerid)
- {
- static rows,fields;
- cache_get_data(rows,fields,connect);
- if(rows)
- {
- cache_get_field_content(0,"Dinheiro",Query,connect);
- AccountInfo[playerid][Dinnheiro] = strval(Query);
- cache_get_field_content(0,"Banco",Query,connect);
- AccountInfo[playerid][Banco] = strval(Query);
- cache_get_field_content(0,"Saldo Bancario",Query,connect);
- AccountInfo[playerid][Saldo Bancario] = strval(Query);
- cache_get_field_content(0,"vida",Query,connect);
- AccountInfo[playerid][Vida] = strval(Query);
- cache_get_field_content(0,"Fome",Query,connect);
- AccountInfo[playerid][Fome] = strval(Query)
- cache_get_field_content(0,"Sede",Query,connect);
- AccountInfo[playerid][Sede] = strval(Query)
- cache_get_field_content(0,"Colete",Query,connect);
- AccountInfo[playerid][Colete] = strval(Query)
- }
- return 1;
- }
- public MySQL_SaveAccount(playerid)
- {
- 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));
- mysql_function_query(connect,Query,false,"","","");
- return 1;
- }
- // - Stocks
- _@PlayerName(playerid)
- {
- new _@pN[24];
- GetPlayerName(playerid, _@pN, sizeof(_@pN));
- return _@pN;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement