Julian90

FS de ejemplo. gBank

May 26th, 2012
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.93 KB | None | 0 0
  1. #include <a_samp>
  2. #include <gBank>
  3.  
  4. main(){}
  5.  
  6. #define SQL_HOST    "localhost"
  7. #define SQL_USER    "root"
  8. #define SQL_PASS    "..."
  9. #define SQL_DB      "test"
  10.  
  11. public OnGameModeInit()
  12. {
  13.     mysql_connect(SQL_HOST, SQL_USER, SQL_DB, SQL_PASS);
  14.     if(mysql_ping())
  15.     {
  16.         printf("[MYSQL]: Se ha podido conectar a la Base de Datos (%s)", SQL_DB);
  17.         BankSystemInit(); // Necesario para crear la base de datos, caso contrario habría que crearla a mano.
  18.         printf("Cuentas Totales: %d", GetTotalAccounts());
  19.     }
  20.     else printf("[MYSQL]: No se ha podido conectar a la Base de Datos (%s)", SQL_DB);
  21.     return 1;
  22. }
  23.  
  24. public OnPlayerConnect(playerid)
  25. {
  26.     if(IsPlayerLoggedInAnyAccount(playerid)) ResetPlayerLogged(playerid); // Resetear la variable de login de cuenta.
  27.     return 1;
  28. }
  29.  
  30. public OnPlayerCommandText(playerid, cmdtext[])
  31. {
  32.     new cmd[128], idx, nombre[MAX_PLAYER_NAME+1], string[128];
  33.     cmd = strtok(cmdtext, idx);
  34.    
  35.     if(!strcmp(cmd, "/registrar", true))
  36.     {
  37.         if(IsPlayerConnected(playerid))
  38.         {
  39.             cmd = strrest(cmdtext, idx);
  40.             if(!strlen(cmd))
  41.             {
  42.                 SendClientMessage(playerid, -1, "Utiliza: /registrar [contraseña]");
  43.                 return 1;
  44.             }
  45.             GetPlayerName(playerid, nombre, sizeof(nombre));
  46.             SendClientMessage(playerid, -1, "   Has recibido $1000 de bonificación por crear una cuenta en nuestro banco.");
  47.             format(string, sizeof(string), "Tu número de cuenta es %d", CreateBankAccount(nombre, cmd, 1000));
  48.         }
  49.         return 1;
  50.     }
  51.  
  52.     if(!strcmp(cmd, "/ingresar", true))
  53.     {
  54.         if(IsPlayerConnected(playerid))
  55.         {
  56.             cmd = strtok(cmdtext, idx);
  57.             if(!strlen(cmd))
  58.             {
  59.                 SendClientMessage(playerid, -1, "Utiliza: /ingresar [cuenta] [contraseña]");
  60.                 return 1;
  61.             }
  62.             new cuenta = strval(cmd);
  63.             cmd = strrest(cmdtext, idx);
  64.             if(!strlen(cmd))
  65.             {
  66.                 SendClientMessage(playerid, -1, "Utiliza: /ingresar [cuenta] [contraseña]");
  67.                 return 1;
  68.             }
  69.             PlayerLoggedInAccount(playerid, cuenta, cmd);
  70.         }
  71.         return 1;
  72.     }
  73.    
  74.     if(!strcmp(cmd, "/balance", true))
  75.     {
  76.         if(IsPlayerConnected(playerid))
  77.         {
  78.             if(IsPlayerLoggedInAnyAccount(playerid))
  79.             {
  80.                 format(string, sizeof(string), "    Tu balance es de $%d", GetAccountBalance(GetPlayerAccountLogged(playerid)));
  81.                 SendClientMessage(playerid, -1, string);
  82.             }
  83.             else SendClientMessage(playerid, -1, "  No has ingresado a ninguna cuenta bancaria.");
  84.            
  85.         }
  86.         return 1;
  87.     }
  88.  
  89.     if(!strcmp(cmd, "/salir", true))
  90.     {
  91.         if(IsPlayerConnected(playerid))
  92.         {
  93.             if(IsPlayerLoggedInAnyAccount(playerid))
  94.             {
  95.                 PlayerLogoutOfAccount(playerid);
  96.             }
  97.             else SendClientMessage(playerid, -1, "  No has ingresado a ninguna cuenta bancaria.");
  98.         }
  99.         return 1;
  100.     }
  101.  
  102.     return 1;
  103. }
  104.  
  105. public OnPlayerLoginAccount(playerid, account, success)
  106. {
  107.     if(success)
  108.     {
  109.         SendClientMessage(playerid, -1, "   Has recibido $100 de bonificación por ingresar a tu cuenta.");
  110.         DepositBankMoney(account, 100);
  111.     }
  112.     else SendClientMessage(playerid, -1, "  No has podido ingresar a la cuenta bancaria.");
  113.     return 1;
  114. }
  115.  
  116. public OnPlayerLogoutAccount(playerid, account)
  117. {
  118.     new string[50];
  119.     format(string, sizeof(string), "Has salido de la cuenta bancaria %d", account);
  120.     SendClientMessage(playerid, -1, string);
  121.     return 1;
  122. }
  123.  
  124. strtok(const string[], &index)
  125. {
  126.     new length = strlen(string);
  127.     while ((index < length) && (string[index] <= ' ')) index++;
  128.     new offset = index, result[20];
  129.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  130.     {
  131.         result[index - offset] = string[index];
  132.         index++;
  133.     }
  134.     result[index - offset] = EOS;
  135.     return result;
  136. }
  137.  
  138. strrest(const string[], &index)
  139. {
  140.     new length = strlen(string);
  141.     while ((index < length) && (string[index] <= ' '))
  142.     {
  143.         index++;
  144.     }
  145.     new offset = index;
  146.     new result[128];
  147.     while ((index < length) && ((index - offset) < (sizeof(result) - 1)))
  148.     {
  149.         result[index - offset] = string[index];
  150.         index++;
  151.     }
  152.     result[index - offset] = EOS;
  153.     return result;
  154. }
Add Comment
Please, Sign In to add comment