Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <a_mysqlr33>
- forward G_OnPlayerUpdate(playerid, type);
- forward G_OnPlayerMysqlFinish(playerid);
- forward G_OnPlayerLogin(playerid);
- forward KickPlayer(playerid);
- new ParolaGresita[MAX_PLAYERS] = 0,
- g_Logat[MAX_PLAYERS],
- SQL = -1;
- main()
- {}
- enum
- {
- DIALOG_LOGIN = 1,
- DIALOG_REGISTER,
- }
- enum pData
- {
- ORM:pORM_ID,
- pID,
- pNume[MAX_PLAYER_NAME],
- pParola[150],
- pNivel,
- pBani,
- pCoins,
- pAdmin,
- pOre,
- pMinute,
- pSecunde,
- }
- new G_PlayerInfo[MAX_PLAYERS][pData];
- public OnGameModeInit()
- {
- new Query[450];
- mysql_log();
- SendRconCommand("gamemodetext Inceput GameMode");
- SQL = mysql_connect("127.0.0.1", "root", "test", "");
- mysql_format(SQL, Query, sizeof Query, "CREATE TABLE IF NOT EXISTS `players` (\
- `ID` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,\
- `Nume` VARCHAR( 34 ) NOT NULL ,\
- `Parola` VARCHAR( 151 ) NOT NULL ,\
- `Nivel` INT( 3 ) NOT NULL ,\
- `Bani` INT( 7 ) NOT NULL ,\
- `Coins` INT( 9 ) NOT NULL ,\
- `Admin` INT( 2 ) NOT NULL ,\
- `Ore` INT( 10 ) NOT NULL ,\
- `Minute` INT( 2 ) NOT NULL ,\
- `Secunde` INT( 2 ) NOT NULL)");
- mysql_query(SQL, Query);
- AddPlayerClass(0, 1958.33, 1343.12, 15.36, 269.15, 26, 36, 28, 150, 0, 0);
- }
- public OnPlayerConnect(playerid)
- {
- SetPlayerCameraPos(playerid, 1969.8353, 1342.8879, 19.4200);
- SetPlayerCameraLookAt(playerid, 1968.8373, 1342.8861, 19.0650);
- SetVariableTo0(playerid);
- new playerQuery[100];
- mysql_format(SQL, playerQuery, sizeof(playerQuery), "SELECT * FROM `players` WHERE `Nume` = '%s'", pName(playerid));
- mysql_tquery(SQL, playerQuery, "G_OnPlayerMysqlFinish", "d", playerid);
- return 1;
- }
- public G_OnPlayerUpdate(playerid, type)
- {
- new playerQuery[87];
- switch(type)
- {
- case pParola: mysql_format(SQL, playerQuery, sizeof(playerQuery), "UPDATE `players` SET `Parola` = '%s' WHERE `Nume` = '%s'", G_PlayerInfo[playerid][pParola], pName(playerid));
- case pNivel: mysql_format(SQL, playerQuery, sizeof(playerQuery), "UPDATE `players` SET `Nivel` = %d WHERE `Nume` = '%s'", G_PlayerInfo[playerid][pNivel], pName(playerid));
- case pCoins: mysql_format(SQL, playerQuery, sizeof(playerQuery), "UPDATE `players` SET `Coins` = %d WHERE `Nume` = '%s'", G_PlayerInfo[playerid][pCoins], pName(playerid));
- case pAdmin: mysql_format(SQL, playerQuery, sizeof(playerQuery), "UPDATE `players` SET `Admin` = %d WHERE `Nume` = '%s'", G_PlayerInfo[playerid][pAdmin], pName(playerid));
- case pOre: mysql_format(SQL, playerQuery, sizeof(playerQuery), "UPDATE `players` SET `Ore` = %d WHERE `Nume` = '%s'", G_PlayerInfo[playerid][pOre], pName(playerid));
- case pMinute: mysql_format(SQL, playerQuery, sizeof(playerQuery), "UPDATE `players` SET `Minute` = %d WHERE `Nume` = '%s'", G_PlayerInfo[playerid][pMinute], pName(playerid));
- case pSecunde: mysql_format(SQL, playerQuery, sizeof(playerQuery), "UPDATE `players` SET `Secunde` = %d WHERE `Nume` = '%s'", G_PlayerInfo[playerid][pSecunde], pName(playerid));
- }
- mysql_tquery(SQL, playerQuery, "SendQuery", "");
- return 1;
- }
- forward SendQuery();
- public SendQuery()
- {
- return 1;
- }
- public G_OnPlayerMysqlFinish(playerid)
- {
- if(cache_num_rows())
- {
- if(g_Logat[playerid] == 0)
- {
- new rows, fields;
- cache_get_data(rows, fields, SQL);
- cache_get_row(0, 2, G_PlayerInfo[playerid][pParola], SQL, 151);
- ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "Te rugam introduti parola", "Login", "Abort");
- }
- }
- else if(!cache_num_rows())
- {
- if(g_Logat[playerid] == 0)
- {
- ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Register", "1Te rugam introduti parola", "Register", "Abort");
- }
- }
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[ ])
- {
- switch(dialogid)
- {
- case DIALOG_LOGIN:
- {
- if(response)
- {
- 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");
- if(strcmp(inputtext, G_PlayerInfo[playerid][pParola], true) == 0)
- {
- g_Logat[playerid] = 1;
- new playerQuery[100];
- mysql_format(SQL, playerQuery, sizeof(playerQuery), "SELECT * FROM `players` WHERE `Nume` = '%s'", pName(playerid));
- mysql_tquery(SQL, playerQuery, "G_OnPlayerLogin", "d", playerid);
- }
- else
- {
- if(ParolaGresita[playerid] == 3)
- {
- SendClientMessage(playerid, 0xFFFFFFFF, "Ai primit kick pentru parola gresita");
- KickEx(playerid);
- }
- ParolaGresita[playerid]++;
- ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "Te rugam introduti parola", "Login", "Exit");
- }
- }
- else
- {
- KickEx(playerid);
- }
- }
- case DIALOG_REGISTER:
- {
- if(response)
- {
- new playerQuery[200];
- 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");
- mysql_format(SQL, playerQuery, sizeof playerQuery, "INSERT INTO players (Nume, Parola, Nivel, Bani, Coins, Admin, Ore, Minute, Secunde) \
- VALUES('%s', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d');", pName(playerid), inputtext, 1, 10000, 10, 0, 0, 0, 1);
- mysql_query(SQL, playerQuery);
- SpawnPlayer(playerid);
- SendClientMessage(playerid, -1, "Te-ai inregistrat cu succesc");
- }
- else
- {
- KickEx(playerid);
- }
- }
- }
- return 0;
- }
- public G_OnPlayerLogin(playerid)
- {
- new rows, fields,string[86];
- cache_get_data(rows, fields, SQL);
- G_PlayerInfo[playerid][pID] = cache_get_row_int(0, 0, SQL);
- G_PlayerInfo[playerid][pNivel] = cache_get_row_int(0, 3, SQL);
- G_PlayerInfo[playerid][pBani] = cache_get_row_int(0, 4, SQL);
- G_PlayerInfo[playerid][pCoins] = cache_get_row_int(0, 5, SQL);
- G_PlayerInfo[playerid][pAdmin] = cache_get_row_int(0, 6, SQL);
- G_PlayerInfo[playerid][pOre] = cache_get_row_int(0, 7, SQL);
- G_PlayerInfo[playerid][pMinute] = cache_get_row_int(0, 8, SQL);
- G_PlayerInfo[playerid][pSecunde] = cache_get_row_int(0, 9, SQL);
- 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]);
- SendClientMessage(playerid, -1, string);
- SpawnPlayer(playerid);
- return 1;
- }
- stock KickEx(playerid)
- {
- SetTimerEx("KickPlayer", 2000, 0, "d", playerid);
- }
- public KickPlayer(playerid)
- {
- return Kick(playerid);
- }
- stock pName(playerid)
- {
- new nume[34];
- GetPlayerName(playerid, nume, sizeof(nume));
- return nume;
- }
- stock SetVariableTo0(playerid)
- {
- g_Logat[playerid] = 0;
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement