Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <a_mysql>
- #define DIALOG_REGISTER 1
- #define DIALOG_LOGIN 2
- forward LoadPlayerAccount_DBData(playerid);
- enum pInfo
- {
- Password[128],
- Score,
- Money,
- bool:IsLogged
- }
- new QueryString[500]; // We need a string to format queries. I always put it at the top so I do not need to recreate it all the time
- new PlayerInfo[MAX_PLAYERS][pInfo];
- main()
- {
- print("Loaded the best deathmatch script ever");
- }
- stock PlayerName(playerid)
- {
- new name[MAX_PLAYER_NAME];
- GetPlayerName(playerid,name,sizeof(name));
- return name;
- }
- public OnGameModeInit()
- {
- mysql_connect("fr1.volt-host.com","7959_kol","7959_kol","hallo5",3306); // Connect to the MySQL Database. "Host - Database - User - Password - Port (always 3306)
- SetGameModeText("Best DM ever");
- AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- mysql_format(1,QueryString,"SELECT * FROM `PlayerInfo` WHERE `PlayerName` = '%s' LIMIT 1",PlayerName(playerid)); // Select TABLE PlayerInfo, FIELD PlayerName and only the ONE that matches to your name
- mysql_function_query(1,QueryString,true,"LoadPlayerAccount_DBData","i",playerid); // The 1 is connection handle (dunno what it means). The "True" comes from cache. We want to use the cache functions, otherwise we could also use the easy R6 if we didnt =D
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- if(dialogid == DIALOG_LOGIN)
- {
- if(!strcmp(inputtext,PlayerInfo[playerid][Password],false))
- {
- SendClientMessage(playerid,-1,"Congratulations, you have successfully logged in! Welcome back!");
- PlayerInfo[playerid][IsLogged] = true;
- }
- else
- {
- printf("%s does not match to %s",inputtext,PlayerInfo[playerid][Password]);
- SendClientMessage(playerid,-1,"Lozur, you failed to login! Cya =D");
- Kick(playerid);
- return 1;
- }
- }
- else if(dialogid == DIALOG_REGISTER)
- {
- mysql_format(1,QueryString,"INSERT INTO `PlayerInfo` (`PlayerName`, `Password`, `Money`, `Score`) VALUES ('%s', '%s', %d, %d)",PlayerName(playerid),inputtext,5000,0); // suppose 5000 is start cash
- mysql_function_query(1,QueryString,false,"SomeNotExistingCallback","",""); // You dont have to call a callback when you UPDATE or INSERT
- PlayerInfo[playerid][IsLogged] = true;
- PlayerInfo[playerid][Money] = 5000;
- format(PlayerInfo[playerid][Password],128,"%s",inputtext);
- SendClientMessage(playerid,-1,"Congratulations, you have successfully registered a cool account at this shit server!");
- return 1;
- }
- return 1;
- }
- public LoadPlayerAccount_DBData(playerid)
- {
- new rows, fields;
- cache_get_data(rows,fields); // Get the amount of rows & fields matching to the query, i.o.w if rows is 1, there is one row having the field 'PlayerName' filled with your nick
- if(rows)
- {
- new temp[10];
- ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Login","Welcome back, pass plz.","Login","Quit");
- cache_get_field_content(0,"Password",PlayerInfo[playerid][Password]);
- cache_get_field_content(0,"Money",temp);
- PlayerInfo[playerid][Money] = strval(temp);
- cache_get_field_content(0,"Score",temp);
- PlayerInfo[playerid][Score] = strval(temp);
- return 1;
- }
- else return ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_PASSWORD,"Register","Welcome, plz insert pass to make acc","Register","Quit");
- }
Advertisement
Add Comment
Please, Sign In to add comment