Guest User

Untitled

a guest
Jul 31st, 2011
15,963
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Credits to Y_Less, Dracoblue and Kush.
  2.  
  3. #include <a_samp>
  4. #include <YSI\y_ini>
  5.  
  6. #define DIALOG_REGISTER 1
  7. #define DIALOG_LOGIN 2
  8. #define DIALOG_SUCCESS_1 3
  9. #define DIALOG_SUCCESS_2 4
  10.  
  11. #define PATH "/Users/%s.ini"
  12.  
  13. #define COL_WHITE "{FFFFFF}"
  14. #define COL_RED "{F81414}"
  15. #define COL_GREEN "{00FF22}"
  16. #define COL_LIGHTBLUE "{00CED1}"
  17.  
  18. enum pInfo
  19. {
  20. pPass,
  21. pCash,
  22. pAdmin,
  23. pKills,
  24. pDeaths
  25. }
  26. new PlayerInfo[MAX_PLAYERS][pInfo];
  27.  
  28. forward LoadUser_data(playerid,name[],value[]);
  29. public LoadUser_data(playerid,name[],value[])
  30. {
  31. INI_Int("Password",PlayerInfo[playerid][pPass]);
  32. INI_Int("Cash",PlayerInfo[playerid][pCash]);
  33. INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
  34. INI_Int("Kills",PlayerInfo[playerid][pKills]);
  35. INI_Int("Deaths",PlayerInfo[playerid][pDeaths]);
  36. return 1;
  37. }
  38.  
  39. stock UserPath(playerid)
  40. {
  41. new string[128],playername[MAX_PLAYER_NAME];
  42. GetPlayerName(playerid,playername,sizeof(playername));
  43. format(string,sizeof(string),PATH,playername);
  44. return string;
  45. }
  46.  
  47. /*Credits to Dracoblue*/
  48. stock udb_hash(buf[]) {
  49. new length=strlen(buf);
  50. new s1 = 1;
  51. new s2 = 0;
  52. new n;
  53. for (n=0; n<length; n++)
  54. {
  55. s1 = (s1 + buf[n]) % 65521;
  56. s2 = (s2 + s1) % 65521;
  57. }
  58. return (s2 << 16) + s1;
  59. }
  60.  
  61. main()
  62. {
  63. print("\n----------------------------------");
  64. print(" Blank Gamemode by your name here");
  65. print("----------------------------------\n");
  66. }
  67.  
  68. public OnGameModeInit()
  69. {
  70. SetGameModeText("Blank Script");
  71. return 1;
  72. }
  73.  
  74. public OnGameModeExit()
  75. {
  76. return 1;
  77. }
  78.  
  79. public OnPlayerRequestClass(playerid, classid)
  80. {
  81. return 1;
  82. }
  83.  
  84. public OnPlayerConnect(playerid)
  85. {
  86. if(fexist(UserPath(playerid)))
  87. {
  88. INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
  89. ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Login",""COL_WHITE"Type your password below to login.","Login","Quit");
  90. }
  91. else
  92. {
  93. ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,""COL_WHITE"Registering...",""COL_WHITE"Type your password below to register a new account.","Register","Quit");
  94. }
  95. return 1;
  96. }
  97.  
  98. public OnPlayerDisconnect(playerid, reason)
  99. {
  100. new INI:File = INI_Open(UserPath(playerid));
  101. INI_SetTag(File,"data");
  102. INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
  103. INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
  104. INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
  105. INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
  106. INI_Close(File);
  107. return 1;
  108. }
  109.  
  110. public OnPlayerSpawn(playerid)
  111. {
  112. return 1;
  113. }
  114.  
  115. public OnPlayerDeath(playerid, killerid, reason)
  116. {
  117. PlayerInfo[killerid][pKills]++;
  118. PlayerInfo[playerid][pDeaths]++;
  119. return 1;
  120. }
  121.  
  122. public OnVehicleSpawn(vehicleid)
  123. {
  124. return 1;
  125. }
  126.  
  127. public OnVehicleDeath(vehicleid, killerid)
  128. {
  129. return 1;
  130. }
  131.  
  132. public OnPlayerText(playerid, text[])
  133. {
  134. return 1;
  135. }
  136.  
  137. public OnPlayerCommandText(playerid, cmdtext[])
  138. {
  139. if (strcmp("/mycommand", cmdtext, true, 10) == 0)
  140. {
  141. // Do something here
  142. return 1;
  143. }
  144. return 0;
  145. }
  146.  
  147. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  148. {
  149. return 1;
  150. }
  151.  
  152. public OnPlayerExitVehicle(playerid, vehicleid)
  153. {
  154. return 1;
  155. }
  156.  
  157. public OnPlayerStateChange(playerid, newstate, oldstate)
  158. {
  159. return 1;
  160. }
  161.  
  162. public OnPlayerEnterCheckpoint(playerid)
  163. {
  164. return 1;
  165. }
  166.  
  167. public OnPlayerLeaveCheckpoint(playerid)
  168. {
  169. return 1;
  170. }
  171.  
  172. public OnPlayerEnterRaceCheckpoint(playerid)
  173. {
  174. return 1;
  175. }
  176.  
  177. public OnPlayerLeaveRaceCheckpoint(playerid)
  178. {
  179. return 1;
  180. }
  181.  
  182. public OnRconCommand(cmd[])
  183. {
  184. return 1;
  185. }
  186.  
  187. public OnPlayerRequestSpawn(playerid)
  188. {
  189. return 1;
  190. }
  191.  
  192. public OnObjectMoved(objectid)
  193. {
  194. return 1;
  195. }
  196.  
  197. public OnPlayerObjectMoved(playerid, objectid)
  198. {
  199. return 1;
  200. }
  201.  
  202. public OnPlayerPickUpPickup(playerid, pickupid)
  203. {
  204. return 1;
  205. }
  206.  
  207. public OnVehicleMod(playerid, vehicleid, componentid)
  208. {
  209. return 1;
  210. }
  211.  
  212. public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
  213. {
  214. return 1;
  215. }
  216.  
  217. public OnVehicleRespray(playerid, vehicleid, color1, color2)
  218. {
  219. return 1;
  220. }
  221.  
  222. public OnPlayerSelectedMenuRow(playerid, row)
  223. {
  224. return 1;
  225. }
  226.  
  227. public OnPlayerExitedMenu(playerid)
  228. {
  229. return 1;
  230. }
  231.  
  232. public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
  233. {
  234. return 1;
  235. }
  236.  
  237. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  238. {
  239. return 1;
  240. }
  241.  
  242. public OnRconLoginAttempt(ip[], password[], success)
  243. {
  244. return 1;
  245. }
  246.  
  247. public OnPlayerUpdate(playerid)
  248. {
  249. return 1;
  250. }
  251.  
  252. public OnPlayerStreamIn(playerid, forplayerid)
  253. {
  254. return 1;
  255. }
  256.  
  257. public OnPlayerStreamOut(playerid, forplayerid)
  258. {
  259. return 1;
  260. }
  261.  
  262. public OnVehicleStreamIn(vehicleid, forplayerid)
  263. {
  264. return 1;
  265. }
  266.  
  267. public OnVehicleStreamOut(vehicleid, forplayerid)
  268. {
  269. return 1;
  270. }
  271.  
  272. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  273. {
  274. switch( dialogid )
  275. {
  276. case DIALOG_REGISTER:
  277. {
  278. if (!response) return Kick(playerid);
  279. if(response)
  280. {
  281. if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""COL_WHITE"Registering...",""COL_RED"You have entered an invalid password.\n"COL_WHITE"Type your password below to register a new account.","Register","Quit");
  282. new INI:File = INI_Open(UserPath(playerid));
  283. INI_SetTag(File,"data");
  284. INI_WriteInt(File,"Password",udb_hash(inputtext));
  285. INI_WriteInt(File,"Cash",0);
  286. INI_WriteInt(File,"Admin",0);
  287. INI_WriteInt(File,"Kills",0);
  288. INI_WriteInt(File,"Deaths",0);
  289. INI_Close(File);
  290.  
  291. SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0);
  292. SpawnPlayer(playerid);
  293. ShowPlayerDialog(playerid, DIALOG_SUCCESS_1, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"Great! Your Y_INI system works perfectly. Relog to save your stats!","Ok","");
  294. }
  295. }
  296.  
  297. case DIALOG_LOGIN:
  298. {
  299. if ( !response ) return Kick ( playerid );
  300. if( response )
  301. {
  302. if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])
  303. {
  304. INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
  305. GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
  306. ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"You have successfully logged in!","Ok","");
  307. }
  308. else
  309. {
  310. ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Login",""COL_RED"You have entered an incorrect password.\n"COL_WHITE"Type your password below to login.","Login","Quit");
  311. }
  312. return 1;
  313. }
  314. }
  315. }
  316. return 1;
  317. }
  318.  
  319. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  320. {
  321. return 1;
  322. }
RAW Paste Data