Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <gBank>
- main(){}
- #define SQL_HOST "localhost"
- #define SQL_USER "root"
- #define SQL_PASS "..."
- #define SQL_DB "test"
- public OnGameModeInit()
- {
- mysql_connect(SQL_HOST, SQL_USER, SQL_DB, SQL_PASS);
- if(mysql_ping())
- {
- printf("[MYSQL]: Se ha podido conectar a la Base de Datos (%s)", SQL_DB);
- BankSystemInit(); // Necesario para crear la base de datos, caso contrario habría que crearla a mano.
- printf("Cuentas Totales: %d", GetTotalAccounts());
- }
- else printf("[MYSQL]: No se ha podido conectar a la Base de Datos (%s)", SQL_DB);
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- if(IsPlayerLoggedInAnyAccount(playerid)) ResetPlayerLogged(playerid); // Resetear la variable de login de cuenta.
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- new cmd[128], idx, nombre[MAX_PLAYER_NAME+1], string[128];
- cmd = strtok(cmdtext, idx);
- if(!strcmp(cmd, "/registrar", true))
- {
- if(IsPlayerConnected(playerid))
- {
- cmd = strrest(cmdtext, idx);
- if(!strlen(cmd))
- {
- SendClientMessage(playerid, -1, "Utiliza: /registrar [contraseña]");
- return 1;
- }
- GetPlayerName(playerid, nombre, sizeof(nombre));
- SendClientMessage(playerid, -1, " Has recibido $1000 de bonificación por crear una cuenta en nuestro banco.");
- format(string, sizeof(string), "Tu número de cuenta es %d", CreateBankAccount(nombre, cmd, 1000));
- }
- return 1;
- }
- if(!strcmp(cmd, "/ingresar", true))
- {
- if(IsPlayerConnected(playerid))
- {
- cmd = strtok(cmdtext, idx);
- if(!strlen(cmd))
- {
- SendClientMessage(playerid, -1, "Utiliza: /ingresar [cuenta] [contraseña]");
- return 1;
- }
- new cuenta = strval(cmd);
- cmd = strrest(cmdtext, idx);
- if(!strlen(cmd))
- {
- SendClientMessage(playerid, -1, "Utiliza: /ingresar [cuenta] [contraseña]");
- return 1;
- }
- PlayerLoggedInAccount(playerid, cuenta, cmd);
- }
- return 1;
- }
- if(!strcmp(cmd, "/balance", true))
- {
- if(IsPlayerConnected(playerid))
- {
- if(IsPlayerLoggedInAnyAccount(playerid))
- {
- format(string, sizeof(string), " Tu balance es de $%d", GetAccountBalance(GetPlayerAccountLogged(playerid)));
- SendClientMessage(playerid, -1, string);
- }
- else SendClientMessage(playerid, -1, " No has ingresado a ninguna cuenta bancaria.");
- }
- return 1;
- }
- if(!strcmp(cmd, "/salir", true))
- {
- if(IsPlayerConnected(playerid))
- {
- if(IsPlayerLoggedInAnyAccount(playerid))
- {
- PlayerLogoutOfAccount(playerid);
- }
- else SendClientMessage(playerid, -1, " No has ingresado a ninguna cuenta bancaria.");
- }
- return 1;
- }
- return 1;
- }
- public OnPlayerLoginAccount(playerid, account, success)
- {
- if(success)
- {
- SendClientMessage(playerid, -1, " Has recibido $100 de bonificación por ingresar a tu cuenta.");
- DepositBankMoney(account, 100);
- }
- else SendClientMessage(playerid, -1, " No has podido ingresar a la cuenta bancaria.");
- return 1;
- }
- public OnPlayerLogoutAccount(playerid, account)
- {
- new string[50];
- format(string, sizeof(string), "Has salido de la cuenta bancaria %d", account);
- SendClientMessage(playerid, -1, string);
- return 1;
- }
- strtok(const string[], &index)
- {
- new length = strlen(string);
- while ((index < length) && (string[index] <= ' ')) index++;
- new offset = index, result[20];
- while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
- {
- result[index - offset] = string[index];
- index++;
- }
- result[index - offset] = EOS;
- return result;
- }
- strrest(const string[], &index)
- {
- new length = strlen(string);
- while ((index < length) && (string[index] <= ' '))
- {
- index++;
- }
- new offset = index;
- new result[128];
- while ((index < length) && ((index - offset) < (sizeof(result) - 1)))
- {
- result[index - offset] = string[index];
- index++;
- }
- result[index - offset] = EOS;
- return result;
- }
Add Comment
Please, Sign In to add comment