Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <zcmd>
- #include <sscanf2>
- #include <streamer>
- #include <YSI\y_ini>
- #include <colors>
- #define DIALOG_REGISTER 1
- #define DIALOG_LOGIN 2
- #define DIALOG_SUCCESS_1 3
- #define DIALOG_SUCCESS_2 4
- #define PATH "/Users/%s.ini"
- enum pInfo
- {
- pPass,
- pCash,
- pAdmin,
- pKills,
- pDeaths
- }
- new PlayerInfo[MAX_PLAYERS][pInfo];
- forward LoadUser_data(playerid,name[],value[]);
- public LoadUser_data(playerid,name[],value[])
- {
- INI_String("Password",PlayerInfo[playerid][pPass], 128);
- INI_Int("Cash",PlayerInfo[playerid][pCash]);
- INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
- INI_Int("Kills",PlayerInfo[playerid][pKills]);
- INI_Int("Deaths",PlayerInfo[playerid][pDeaths]);
- return 1;
- }
- stock UserPath(playerid)
- {
- new str[128],playername[MAX_PLAYER_NAME];
- GetPlayerName(playerid,playername,sizeof(playername));
- format(str,sizeof(str),PATH,playername);
- return str;
- }
- main( ) { }
- public OnGameModeInit()
- {
- print("Playground executed!");
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- if(fexist(UserPath(playerid)))
- {
- INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
- ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"Login","Enter your password to gain access to your account.","Login","Exit");
- }
- else
- {
- ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,"Register","Enter a password below to register your new account. You will not be prompted again to validate it, so avoid errors.","Register","Exit");
- }
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- new INI:File = INI_Open(UserPath(playerid));
- INI_SetTag(File,"data");
- INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
- INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
- INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
- INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
- INI_Close(File);
- return 1;
- }
- public OnPlayerDeath(playerid, killerid, reason)
- {
- PlayerInfo[killerid][pKills]++;
- PlayerInfo[playerid][pDeaths]++;
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- switch( dialogid )
- {
- case DIALOG_REGISTER:
- {
- if (!response) return Kick(playerid);
- if(response)
- {
- if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Register","Invalid password.\n""Enter a password below to register your new account. You will not be prompted again to validate it, so avoid errors.","Register","Exit");
- new INI:File = INI_Open(UserPath(playerid));
- INI_SetTag(File,"data");
- INI_WriteString(File, "Password",(inputtext));
- INI_WriteInt(File,"Cash",0);
- INI_WriteInt(File,"Admin",0);
- INI_WriteInt(File,"Kills",0);
- INI_WriteInt(File,"Deaths",0);
- INI_Close(File);
- SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0);
- SpawnPlayer(playerid);
- ShowPlayerDialog(playerid, DIALOG_SUCCESS_1, DIALOG_STYLE_MSGBOX,"Account registered","We hope you enjoy your stay. By pressing the OK button you agree to our rules and regulations.","Ok","");
- }
- }
- case DIALOG_LOGIN:
- {
- if ( !response ) return Kick ( playerid );
- if( response )
- {
- if(!strcmp(PlayerInfo[playerid][pPass], inputtext))
- {
- printf("ww: %s", PlayerInfo[playerid][pPass]);
- INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
- GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
- ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX,"Success!","Welcome back to Playground.","Ok","");
- }
- else
- {
- ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"Login","Invalid password.\n""Enter your password to gain access to your account.","Login","Exit");
- }
- return 1;
- }
- }
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement