Guest User

Untitled

a guest
Feb 26th, 2015
521
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.78 KB | None | 0 0
  1. // Includes
  2. #include <a_samp>
  3. #include <YSI\y_ini>
  4. #include <YSI\y_commands>
  5.  
  6. // Save locations
  7. #define PATH "/Files/Accounts/%s.ini"
  8.  
  9. // Dialogs
  10. #define DIALOG_REGISTER 0
  11. #define DIALOG_LOGIN 1
  12. #define DIALOG_CLASS 2
  13.  
  14. // Enum for player data
  15. enum TPlayerData
  16. {
  17. pPass,
  18. pAdmin,
  19. pCash,
  20. pScore
  21. }
  22. new APlayerData[MAX_PLAYERS][TPlayerData];
  23.  
  24. forward LoadUser_data(playerid,name[],value[]);
  25. public LoadUser_data(playerid,name[],value[])
  26. {
  27. INI_Int("Password",APlayerData[playerid][pPass]);
  28. INI_Int("Admin",APlayerData[playerid][pAdmin]);
  29. INI_Int("Cash",APlayerData[playerid][pCash]);
  30. INI_Int("Score",APlayerData[playerid][pScore]);
  31. return 1;
  32. }
  33.  
  34. stock UserPath(playerid)
  35. {
  36. new string[128],playername[MAX_PLAYER_NAME];
  37. GetPlayerName(playerid,playername,sizeof(playername));
  38. format(string,sizeof(string),PATH,playername);
  39. return string;
  40. }
  41.  
  42. stock udb_hash(buf[])
  43. {
  44. new length=strlen(buf);
  45. new s1 = 1;
  46. new s2 = 0;
  47. new n;
  48. for (n=0; n<length; n++)
  49. {
  50. s1 = (s1 + buf[n]) % 65521;
  51. s2 = (s2 + s1) % 65521;
  52. }
  53. return (s2 << 16) + s1;
  54. }
  55.  
  56. main()
  57. {
  58. print("\n----------------------------------");
  59. print(" Blank Gamemode by your name here");
  60. print("----------------------------------\n");
  61. }
  62.  
  63. public OnGameModeInit()
  64. {
  65. SetGameModeText("Blank Script");
  66. return 1;
  67. }
  68.  
  69. public OnPlayerRequestClass(playerid, classid)
  70. {
  71. SetPlayerPos(playerid, 2527.9763,-1666.6794,15.1682);
  72. SetPlayerCameraPos(playerid, 2522.4639,-1667.2499,15.0358);
  73. SetPlayerCameraLookAt(playerid, 2527.9763,-1666.6794,15.1682);
  74.  
  75. return ShowPlayerDialog(playerid, DIALOG_CLASS, DIALOG_STYLE_LIST, "Choose your class:", "Class 1\nClass 2\nClass 3", "Choose", "");
  76. }
  77.  
  78. public OnPlayerConnect(playerid)
  79. {
  80. if(fexist(UserPath(playerid)))
  81. {
  82. INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
  83. ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "Type your password below to login.", "Login", "Quit");
  84. }
  85. else
  86. {
  87. ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Registering","Type your password below to register a new account.", "Register", "Quit");
  88. }
  89. return 1;
  90. }
  91.  
  92. public OnPlayerDisconnect(playerid, reason)
  93. {
  94. new INI:File = INI_Open(UserPath(playerid));
  95. INI_SetTag(File,"data");
  96. INI_WriteInt(File,"Admin",APlayerData[playerid][pAdmin]);
  97. INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
  98. INI_WriteInt(File,"Score",GetPlayerScore(playerid));
  99. INI_Close(File);
  100. return 1;
  101. }
  102.  
  103. public OnPlayerRequestSpawn(playerid)
  104. {
  105. return 0;
  106. }
  107.  
  108. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  109. {
  110. switch( dialogid )
  111. {
  112. case DIALOG_REGISTER:
  113. {
  114. if (!response) return Kick(playerid);
  115. if(response)
  116. {
  117. if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Registering","You have entered an invalid password.\nType your password below to register a new account.","Register","Quit");
  118. new INI:File = INI_Open(UserPath(playerid));
  119. INI_SetTag(File,"data");
  120. INI_WriteInt(File,"Password",udb_hash(inputtext));
  121. INI_WriteInt(File,"Admin",0);
  122. INI_WriteInt(File,"Cash",0);
  123. INI_WriteInt(File,"Score",0);
  124. INI_Close(File);
  125. }
  126. }
  127. case DIALOG_LOGIN:
  128. {
  129. if ( !response ) return Kick ( playerid );
  130. if( response )
  131. {
  132. if(udb_hash(inputtext) == APlayerData[playerid][pPass])
  133. {
  134. INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
  135. GivePlayerMoney(playerid, APlayerData[playerid][pCash]);
  136. SetPlayerScore(playerid, APlayerData[playerid][pScore]);
  137. }
  138. else
  139. {
  140. ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"Login","You have entered an incorrect password.\nType your password below to login.","Login","Quit");
  141. }
  142. return 1;
  143. }
  144. }
  145. case DIALOG_CLASS:
  146. {
  147. switch(listitem)
  148. {
  149. case 0: // Class 1
  150. {
  151. SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0);
  152. SpawnPlayer(playerid);
  153. }
  154. case 1: // Class 2
  155. {
  156. SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0);
  157. SpawnPlayer(playerid);
  158. }
  159. case 2: // Class 3
  160. {
  161. SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0);
  162. SpawnPlayer(playerid);
  163. }
  164. }
  165. }
  166. }
  167. return 1;
  168. }
Advertisement
Add Comment
Please, Sign In to add comment