Advertisement
OG_LOC

Untitled

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