Guest User

Untitled

a guest
Feb 24th, 2014
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <a_samp>
  2. #include <YSI\y_ini>
  3.  
  4. native WP_Hash(buffer[],len,const str[]);
  5.  
  6. #define dregister 2011
  7. #define dlogin 2012
  8. #define UserPath "Users/%s.ini"
  9.  
  10. enum PlayerInfo
  11. {
  12.     Pass[129],
  13.     Adminlevel,
  14.     VIPlevel,
  15.     TrustedPlayerlevel,
  16.     Money,
  17.     Scores,
  18.     Kills,
  19.     Deaths
  20. }
  21. new pInfo[MAX_PLAYERS][PlayerInfo];
  22.  
  23. main()
  24. {
  25.     print("\n----------------------------------");
  26.     print(" Cops and Robbers by Brad Nunchr,AKA. Mriss");
  27.     print("----------------------------------\n");
  28. }
  29.  
  30. public OnGameModeInit()
  31. {
  32.     // Don't use these lines if it's a filterscript
  33.     SetGameModeText("Cops and Robbers[0.3z]");
  34.     AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
  35.     return 1;
  36. }
  37.  
  38. public OnGameModeExit()
  39. {
  40.     return 1;
  41. }
  42.  
  43. public OnPlayerRequestClass(playerid, classid)
  44. {
  45.     SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
  46.     SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
  47.     SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
  48.     return 1;
  49. }
  50.  
  51. public OnPlayerConnect(playerid)
  52. {
  53.     new name[MAX_PLAYER_NAME];
  54.     GetPlayerName(playerid,name,sizeof(name));
  55.     if(fexist(Path(playerid)))
  56.     {
  57.         INI_ParseFile(Path(playerid),"loadaccount_%s", .bExtra = true, .extra = playerid);
  58.         ShowPlayerDialog(playerid,dlogin,DIALOG_STYLE_INPUT,"Login","Welcome back. This account is registered. \nInsert your password to login to your account","Login","Quit");/*A dialog with input style will appear so you can insert your password to login.*/
  59.     }
  60.     else
  61.     {
  62.         ShowPlayerDialog(playerid,dregister,DIALOG_STYLE_INPUT,"Register","Welcome! This account is not registered.\nEnter your own password to create a new account.","Register","Quit");
  63.         return 1;
  64.     }
  65.     return 1;
  66. }
  67.  
  68. public OnPlayerDisconnect(playerid, reason)
  69. {
  70.     new INI:file = INI_Open(Path(playerid));
  71.     INI_SetTag(file,"Data");
  72.     INI_WriteInt(file,"AdminLevel",pInfo[playerid][Adminlevel]);
  73.     INI_WriteInt(file,"VIPLevel",pInfo[playerid][VIPlevel]);
  74.     INI_WriteInt(file,"TrustedPlayerLevel",pInfo[playerid][TrustedPlayerlevel]);
  75.     INI_WriteInt(file,"Money",GetPlayerMoney(playerid));
  76.     INI_WriteInt(file,"Scores",GetPlayerScore(playerid));
  77.     INI_WriteInt(file,"Kills",pInfo[playerid][Kills]);
  78.     INI_WriteInt(file,"Deaths",pInfo[playerid][Deaths]);
  79.     INI_Close(file);
  80.     return 1;
  81. }
  82.  
  83. public OnPlayerSpawn(playerid)
  84. {
  85.     return 1;
  86. }
  87.  
  88. public OnPlayerDeath(playerid, killerid, reason)
  89. {
  90.     SendDeathMessage(killerid, playerid, reason);
  91.     pInfo[killerid][Kills]++;
  92.     pInfo[playerid][Deaths]++;
  93.     return 1;
  94. }
  95.  
  96. public OnVehicleSpawn(vehicleid)
  97. {
  98.     return 1;
  99. }
  100.  
  101. public OnVehicleDeath(vehicleid, killerid)
  102. {
  103.     return 1;
  104. }
  105.  
  106. public OnPlayerText(playerid, text[])
  107. {
  108.     return 1;
  109. }
  110.  
  111. public OnPlayerCommandText(playerid, cmdtext[])
  112. {
  113.     if (strcmp("/mycommand", cmdtext, true, 10) == 0)
  114.     {
  115.         // Do something here
  116.         return 1;
  117.     }
  118.     return 0;
  119. }
  120.  
  121. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  122. {
  123.     return 1;
  124. }
  125.  
  126. public OnPlayerExitVehicle(playerid, vehicleid)
  127. {
  128.     return 1;
  129. }
  130.  
  131. public OnPlayerStateChange(playerid, newstate, oldstate)
  132. {
  133.     return 1;
  134. }
  135.  
  136. public OnPlayerEnterCheckpoint(playerid)
  137. {
  138.     return 1;
  139. }
  140.  
  141. public OnPlayerLeaveCheckpoint(playerid)
  142. {
  143.     return 1;
  144. }
  145.  
  146. public OnPlayerEnterRaceCheckpoint(playerid)
  147. {
  148.     return 1;
  149. }
  150.  
  151. public OnPlayerLeaveRaceCheckpoint(playerid)
  152. {
  153.     return 1;
  154. }
  155.  
  156. public OnRconCommand(cmd[])
  157. {
  158.     return 1;
  159. }
  160.  
  161. public OnPlayerRequestSpawn(playerid)
  162. {
  163.     return 1;
  164. }
  165.  
  166. public OnObjectMoved(objectid)
  167. {
  168.     return 1;
  169. }
  170.  
  171. public OnPlayerObjectMoved(playerid, objectid)
  172. {
  173.     return 1;
  174. }
  175.  
  176. public OnPlayerPickUpPickup(playerid, pickupid)
  177. {
  178.     return 1;
  179. }
  180.  
  181. public OnVehicleMod(playerid, vehicleid, componentid)
  182. {
  183.     return 1;
  184. }
  185.  
  186. public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
  187. {
  188.     return 1;
  189. }
  190.  
  191. public OnVehicleRespray(playerid, vehicleid, color1, color2)
  192. {
  193.     return 1;
  194. }
  195.  
  196. public OnPlayerSelectedMenuRow(playerid, row)
  197. {
  198.     return 1;
  199. }
  200.  
  201. public OnPlayerExitedMenu(playerid)
  202. {
  203.     return 1;
  204. }
  205.  
  206. public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
  207. {
  208.     return 1;
  209. }
  210.  
  211. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  212. {
  213.     return 1;
  214. }
  215.  
  216. public OnRconLoginAttempt(ip[], password[], success)
  217. {
  218.     return 1;
  219. }
  220.  
  221. public OnPlayerUpdate(playerid)
  222. {
  223.     return 1;
  224. }
  225.  
  226. public OnPlayerStreamIn(playerid, forplayerid)
  227. {
  228.     return 1;
  229. }
  230.  
  231. public OnPlayerStreamOut(playerid, forplayerid)
  232. {
  233.     return 1;
  234. }
  235.  
  236. public OnVehicleStreamIn(vehicleid, forplayerid)
  237. {
  238.     return 1;
  239. }
  240.  
  241. public OnVehicleStreamOut(vehicleid, forplayerid)
  242. {
  243.     return 1;
  244. }
  245.  
  246. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  247. {
  248.     if(dialogid == dregister)
  249.     {
  250.         if(!response) return Kick(playerid);
  251.         if(response)
  252.         {
  253.             if(!strlen(inputtext))
  254.             {
  255.                 ShowPlayerDialog(playerid,dregister,DIALOG_STYLE_INPUT,"Register","Welcome! This account is not registered.\nEnter your own password to create a new account.\nPlease enter the password!","Register","Quit");
  256.                 return 1;
  257.             }
  258.             new hashpass[129];
  259.             WP_Hash(hashpass,sizeof(hashpass),inputtext);
  260.             new INI:file = INI_Open(Path(playerid));
  261.             INI_SetTag(file,"Data");
  262.             INI_WriteString(file,"Password",hashpass);
  263.             INI_WriteInt(file,"AdminLevel",0);
  264.             INI_WriteInt(file,"VIPLevel",0);
  265.             INI_WriteInt(file,"TrustedPlayerLevel",0);
  266.             INI_WriteInt(file,"Money",0);
  267.             INI_WriteInt(file,"Scores",0);
  268.             INI_WriteInt(file,"Kills",0);
  269.             INI_WriteInt(file,"Deaths",0);
  270.             INI_Close(file);
  271.             SendClientMessage(playerid,-1,"Thank you for registering,/n Success!");
  272.             return 1;
  273.         }
  274.     }
  275.     if(dialogid == dlogin)
  276.     {//then
  277.         if(!response) return Kick(playerid);
  278.         if(response)
  279.         {
  280.             new hashpass[129];
  281.             WP_Hash(hashpass,sizeof(hashpass),inputtext);
  282.             if(!strcmp(hashpass, pInfo[playerid][Pass], false))
  283.             {//then
  284.                 INI_ParseFile(Path(playerid),"loadaccount_%s",.bExtra = true, .extra = playerid);
  285.                 SetPlayerScore(playerid,pInfo[playerid][Scores]);
  286.                 GivePlayerMoney(playerid,pInfo[playerid][Money]);
  287.                 SendClientMessage(playerid,-1,"Welcome back! You have successfully logged in");//Tell them that they've successfully logged in
  288.             }
  289.             else
  290.             {
  291.                 ShowPlayerDialog(playerid,dlogin,DIALOG_STYLE_INPUT,"Login","Welcome back. This account is registered. \nInsert your password to login to your account.\nIncorrect password!","Login","Quit");//We will tell to them that they've entered an incorrect password
  292.                 return 1;
  293.             }
  294.         }
  295.     }
  296.     return 1;
  297. }
  298.  
  299. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  300. {
  301.     return 1;
  302. }
  303.  
  304. stock Path(playerid) //Will create a new stock so we can easily use it later to load/save user's data in user's path
  305. {
  306.     new str[128],name[MAX_PLAYER_NAME];
  307.     GetPlayerName(playerid,name,sizeof(name));
  308.     format(str,sizeof(str),UserPath,name);
  309.     return str;
  310. }
  311.  
  312. forward loadaccount_user(playerid, name[], value[]);
  313. public loadaccount_user(playerid, name[], value[])
  314. {
  315.     INI_String("Password", pInfo[playerid][Pass],129);
  316.     INI_Int("AdminLevel",pInfo[playerid][Adminlevel]);
  317.     INI_Int("VIPLevel",pInfo[playerid][VIPlevel]);
  318.     INI_Int("TrustedPlayerlevel",pInfo[playerid][TrustedPlayerlevel]);
  319.     INI_Int("Money",pInfo[playerid][Money]);
  320.     INI_Int("Scores",pInfo[playerid][Scores]);
  321.     INI_Int("Kills",pInfo[playerid][Kills]);
  322.     INI_Int("Deaths",pInfo[playerid][Deaths]);
  323.     return 1;
  324. }
Advertisement
Add Comment
Please, Sign In to add comment