Advertisement
Gireada

G_Base

Apr 19th, 2014
687
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 6.70 KB | None | 0 0
  1. #include <a_samp>
  2. #include <a_mysqlr33>
  3.  
  4. forward G_OnPlayerUpdate(playerid, type);  
  5. forward G_OnPlayerMysqlFinish(playerid);
  6. forward G_OnPlayerLogin(playerid);
  7. forward KickPlayer(playerid);
  8.  
  9. new ParolaGresita[MAX_PLAYERS] = 0,
  10. g_Logat[MAX_PLAYERS],
  11. SQL = -1;
  12.  
  13. main()
  14. {}
  15.  
  16. enum
  17. {
  18.     DIALOG_LOGIN = 1,
  19.     DIALOG_REGISTER,
  20. }  
  21.  
  22. enum pData
  23. {
  24.     ORM:pORM_ID,
  25.     pID,
  26.     pNume[MAX_PLAYER_NAME],
  27.     pParola[150],
  28.     pNivel,
  29.     pBani,
  30.     pCoins,
  31.     pAdmin,
  32.     pOre,
  33.     pMinute,
  34.     pSecunde,
  35. }
  36. new G_PlayerInfo[MAX_PLAYERS][pData];
  37.  
  38. public OnGameModeInit()
  39. {
  40.     new Query[450];
  41.     mysql_log();
  42.     SendRconCommand("gamemodetext Inceput GameMode");
  43.     SQL = mysql_connect("127.0.0.1", "root", "test", "");
  44.    
  45.     mysql_format(SQL, Query, sizeof Query, "CREATE TABLE IF NOT EXISTS  `players` (\
  46.     `ID` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,\
  47.     `Nume` VARCHAR( 34 ) NOT NULL ,\
  48.     `Parola` VARCHAR( 151 ) NOT NULL ,\
  49.     `Nivel` INT( 3 ) NOT NULL ,\
  50.     `Bani` INT( 7 ) NOT NULL ,\
  51.     `Coins` INT( 9 ) NOT NULL ,\
  52.     `Admin` INT( 2 ) NOT NULL ,\
  53.     `Ore` INT( 10 ) NOT NULL ,\
  54.     `Minute` INT( 2 ) NOT NULL ,\
  55.     `Secunde` INT( 2 ) NOT NULL)");
  56.     mysql_query(SQL, Query);
  57.     AddPlayerClass(0, 1958.33, 1343.12, 15.36, 269.15, 26, 36, 28, 150, 0, 0);
  58. }
  59.  
  60. public OnPlayerConnect(playerid)
  61. {  
  62.     SetPlayerCameraPos(playerid, 1969.8353, 1342.8879, 19.4200);
  63.     SetPlayerCameraLookAt(playerid, 1968.8373, 1342.8861, 19.0650);
  64.     SetVariableTo0(playerid);
  65.     new playerQuery[100];
  66.     mysql_format(SQL, playerQuery, sizeof(playerQuery), "SELECT * FROM `players` WHERE `Nume` = '%s'", pName(playerid));
  67.     mysql_tquery(SQL, playerQuery, "G_OnPlayerMysqlFinish", "d", playerid);
  68.     return 1;
  69. }
  70.  
  71. public G_OnPlayerUpdate(playerid, type)
  72. {
  73.     new playerQuery[87];
  74.     switch(type)
  75.     {
  76.         case pParola: mysql_format(SQL, playerQuery, sizeof(playerQuery), "UPDATE `players` SET `Parola` = '%s' WHERE `Nume` = '%s'", G_PlayerInfo[playerid][pParola], pName(playerid));
  77.         case pNivel: mysql_format(SQL, playerQuery, sizeof(playerQuery), "UPDATE `players` SET `Nivel` = %d WHERE `Nume` = '%s'", G_PlayerInfo[playerid][pNivel], pName(playerid));
  78.         case pCoins: mysql_format(SQL, playerQuery, sizeof(playerQuery), "UPDATE `players` SET `Coins` = %d WHERE `Nume` = '%s'", G_PlayerInfo[playerid][pCoins], pName(playerid));
  79.         case pAdmin: mysql_format(SQL, playerQuery, sizeof(playerQuery), "UPDATE `players` SET `Admin` = %d WHERE `Nume` = '%s'", G_PlayerInfo[playerid][pAdmin], pName(playerid));
  80.         case pOre: mysql_format(SQL, playerQuery, sizeof(playerQuery), "UPDATE `players` SET `Ore` = %d WHERE `Nume` = '%s'", G_PlayerInfo[playerid][pOre], pName(playerid));
  81.         case pMinute: mysql_format(SQL, playerQuery, sizeof(playerQuery), "UPDATE `players` SET `Minute` = %d WHERE `Nume` = '%s'", G_PlayerInfo[playerid][pMinute], pName(playerid));
  82.         case pSecunde: mysql_format(SQL, playerQuery, sizeof(playerQuery), "UPDATE `players` SET `Secunde` = %d WHERE `Nume` = '%s'", G_PlayerInfo[playerid][pSecunde], pName(playerid));
  83.     }  
  84.     mysql_tquery(SQL, playerQuery, "SendQuery", "");
  85.     return 1;
  86. }
  87.  
  88. forward SendQuery();
  89. public SendQuery()
  90. {
  91.     return 1;
  92. }
  93.  
  94. public G_OnPlayerMysqlFinish(playerid)
  95. {
  96.     if(cache_num_rows())
  97.     {
  98.         if(g_Logat[playerid] == 0)
  99.         {
  100.             new rows, fields;
  101.             cache_get_data(rows, fields, SQL);
  102.             cache_get_row(0, 2, G_PlayerInfo[playerid][pParola], SQL, 151);
  103.             ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "Te rugam introduti parola", "Login", "Abort");
  104.         }  
  105.     }
  106.     else if(!cache_num_rows())
  107.     {
  108.         if(g_Logat[playerid] == 0)
  109.         {
  110.             ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Register", "1Te rugam introduti parola", "Register", "Abort");
  111.         }  
  112.     }
  113.     return 1;
  114. }
  115.  
  116. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[ ])
  117. {
  118.     switch(dialogid)
  119.     {
  120.         case DIALOG_LOGIN:
  121.         {  
  122.             if(response)
  123.             {
  124.                 if(strlen(inputtext) < 6) return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "Parola trebuei sa aibai minim 6 caractere\nTe rugam introduti parola", "Login", "Exit");
  125.                 if(strcmp(inputtext, G_PlayerInfo[playerid][pParola], true) == 0)
  126.                 {
  127.                     g_Logat[playerid] = 1;
  128.                     new playerQuery[100];
  129.                     mysql_format(SQL, playerQuery, sizeof(playerQuery), "SELECT * FROM `players` WHERE `Nume` = '%s'", pName(playerid));
  130.                     mysql_tquery(SQL, playerQuery, "G_OnPlayerLogin", "d", playerid);
  131.                 }
  132.                 else
  133.                 {
  134.                     if(ParolaGresita[playerid] == 3)
  135.                     {
  136.                         SendClientMessage(playerid, 0xFFFFFFFF, "Ai primit kick pentru parola gresita");
  137.                         KickEx(playerid);
  138.                     }  
  139.                     ParolaGresita[playerid]++;
  140.                     ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "Te rugam introduti parola", "Login", "Exit");
  141.                 }
  142.             }
  143.             else
  144.             {
  145.                 KickEx(playerid);
  146.             }  
  147.         }
  148.         case DIALOG_REGISTER:
  149.         {  
  150.             if(response)
  151.             {
  152.                 new playerQuery[200];
  153.                 if(strlen(inputtext) < 6) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Register", "Parola trebuei sa aibai minim 6 caractere\nTe rugam introduti parola", "Register", "Exit");
  154.                 mysql_format(SQL, playerQuery, sizeof playerQuery, "INSERT INTO players (Nume, Parola, Nivel, Bani, Coins, Admin, Ore, Minute, Secunde) \
  155.                 VALUES('%s', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d');", pName(playerid), inputtext, 1, 10000, 10, 0, 0, 0, 1);
  156.                 mysql_query(SQL, playerQuery);
  157.                 SpawnPlayer(playerid);
  158.                 SendClientMessage(playerid, -1, "Te-ai inregistrat cu succesc");
  159.             }
  160.             else
  161.             {  
  162.                 KickEx(playerid);
  163.             }  
  164.         }  
  165.     }  
  166.     return 0;
  167. }
  168.  
  169. public G_OnPlayerLogin(playerid)
  170. {
  171.     new rows, fields,string[86];
  172.     cache_get_data(rows, fields, SQL);
  173.     G_PlayerInfo[playerid][pID] = cache_get_row_int(0, 0, SQL);
  174.     G_PlayerInfo[playerid][pNivel] = cache_get_row_int(0, 3, SQL);
  175.     G_PlayerInfo[playerid][pBani] = cache_get_row_int(0, 4, SQL);
  176.     G_PlayerInfo[playerid][pCoins] = cache_get_row_int(0, 5, SQL);
  177.     G_PlayerInfo[playerid][pAdmin] = cache_get_row_int(0, 6, SQL);
  178.     G_PlayerInfo[playerid][pOre] = cache_get_row_int(0, 7, SQL);
  179.     G_PlayerInfo[playerid][pMinute] = cache_get_row_int(0, 8, SQL);
  180.     G_PlayerInfo[playerid][pSecunde] = cache_get_row_int(0, 9, SQL);
  181.     format(string, sizeof(string), "Te-ai logat cu succes %s. Ai %d ore %d minute %d secunde",pName(playerid),G_PlayerInfo[playerid][pOre],G_PlayerInfo[playerid][pMinute],G_PlayerInfo[playerid][pSecunde]);
  182.     SendClientMessage(playerid, -1, string);
  183.     SpawnPlayer(playerid);
  184.     return 1;
  185. }  
  186.  
  187.    
  188. stock KickEx(playerid)
  189. {
  190.     SetTimerEx("KickPlayer", 2000, 0, "d", playerid);
  191. }
  192.    
  193. public KickPlayer(playerid)
  194. {
  195.     return Kick(playerid);
  196. }  
  197.  
  198. stock pName(playerid)
  199. {
  200.     new nume[34];
  201.     GetPlayerName(playerid, nume, sizeof(nume));
  202.     return nume;
  203. }  
  204.  
  205. stock SetVariableTo0(playerid)
  206. {
  207.     g_Logat[playerid] = 0;
  208.     return 1;
  209. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement