Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.26 KB | None | 0 0
  1. #include <a_samp>
  2. #include <zcmd>
  3. #include <sscanf2>
  4. #include <streamer>
  5. #include <YSI\y_ini>
  6. #include <colors>
  7.  
  8. #define DIALOG_REGISTER 1
  9. #define DIALOG_LOGIN 2
  10. #define DIALOG_SUCCESS_1 3
  11. #define DIALOG_SUCCESS_2 4
  12.  
  13. #define PATH "/Users/%s.ini"
  14.  
  15. enum pInfo
  16. {
  17. pPass,
  18. pCash,
  19. pAdmin,
  20. pKills,
  21. pDeaths
  22. }
  23. new PlayerInfo[MAX_PLAYERS][pInfo];
  24.  
  25. forward LoadUser_data(playerid,name[],value[]);
  26. public LoadUser_data(playerid,name[],value[])
  27. {
  28. INI_String("Password",PlayerInfo[playerid][pPass], 128);
  29. INI_Int("Cash",PlayerInfo[playerid][pCash]);
  30. INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
  31. INI_Int("Kills",PlayerInfo[playerid][pKills]);
  32. INI_Int("Deaths",PlayerInfo[playerid][pDeaths]);
  33. return 1;
  34. }
  35.  
  36. stock UserPath(playerid)
  37. {
  38. new str[128],playername[MAX_PLAYER_NAME];
  39. GetPlayerName(playerid,playername,sizeof(playername));
  40. format(str,sizeof(str),PATH,playername);
  41. return str;
  42. }
  43.  
  44. main( ) { }
  45.  
  46. public OnGameModeInit()
  47. {
  48. print("Playground executed!");
  49. return 1;
  50. }
  51.  
  52. public OnPlayerConnect(playerid)
  53. {
  54. if(fexist(UserPath(playerid)))
  55. {
  56. INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
  57. ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"Login","Enter your password to gain access to your account.","Login","Exit");
  58. }
  59. else
  60. {
  61. 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");
  62. }
  63. return 1;
  64. }
  65.  
  66. public OnPlayerDisconnect(playerid, reason)
  67. {
  68. new INI:File = INI_Open(UserPath(playerid));
  69. INI_SetTag(File,"data");
  70. INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
  71. INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
  72. INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
  73. INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
  74. INI_Close(File);
  75. return 1;
  76. }
  77.  
  78. public OnPlayerDeath(playerid, killerid, reason)
  79. {
  80. PlayerInfo[killerid][pKills]++;
  81. PlayerInfo[playerid][pDeaths]++;
  82. return 1;
  83. }
  84.  
  85. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  86. {
  87. switch( dialogid )
  88. {
  89. case DIALOG_REGISTER:
  90. {
  91. if (!response) return Kick(playerid);
  92. if(response)
  93. {
  94. 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");
  95. new INI:File = INI_Open(UserPath(playerid));
  96. INI_SetTag(File,"data");
  97. INI_WriteString(File, "Password",(inputtext));
  98. INI_WriteInt(File,"Cash",0);
  99. INI_WriteInt(File,"Admin",0);
  100. INI_WriteInt(File,"Kills",0);
  101. INI_WriteInt(File,"Deaths",0);
  102. INI_Close(File);
  103.  
  104. SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0);
  105. SpawnPlayer(playerid);
  106. 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","");
  107. }
  108. }
  109.  
  110. case DIALOG_LOGIN:
  111. {
  112. if ( !response ) return Kick ( playerid );
  113. if( response )
  114. {
  115. if(!strcmp(PlayerInfo[playerid][pPass], inputtext))
  116. {
  117. printf("ww: %s", PlayerInfo[playerid][pPass]);
  118. INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
  119. GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
  120. ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX,"Success!","Welcome back to Playground.","Ok","");
  121. }
  122. else
  123. {
  124. ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"Login","Invalid password.\n""Enter your password to gain access to your account.","Login","Exit");
  125. }
  126. return 1;
  127. }
  128. }
  129. }
  130. return 1;
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement