Advertisement
Guest User

tAdmin - By Thour57

a guest
Jan 10th, 2013
624
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.56 KB | None | 0 0
  1. //tAdmin - V1.1
  2. // By Thour57
  3. // Thanks for using it.
  4. // Dont remove credits, it wont be shown in Game.
  5.  
  6. #include <a_samp>
  7. #include <YSI\y_ini>
  8. #include <aColors>
  9. #include <zcmd>
  10. #include <sscanf2>
  11.  
  12. native WP_Hash(buffer[],len,const str[]);
  13.  
  14. #define register 1 //Defining register dialog so it won't mixed up with the other dialogs
  15. #define login 2 //Defining login dialog so it won't mixed up with the other dialogs
  16. #define UserPath "tAdmin/Users/%s.ini"
  17.  
  18. enum PlayerInfo
  19. {
  20. Pass[129], //User's password
  21. Adminlevel, //User's admin level
  22. VIPlevel, //User's vip level
  23. Money, //User's money
  24. Scores, //User's scores
  25. Kills, //User's kills
  26. Deaths //User's deaths
  27. }
  28. new pInfo[MAX_PLAYERS][PlayerInfo];
  29.  
  30. 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
  31. {
  32. new str[128],name[MAX_PLAYER_NAME];
  33. GetPlayerName(playerid,name,sizeof(name));
  34. format(str,sizeof(str),UserPath,name);
  35. return str;
  36. }
  37.  
  38. forward loadaccount_user(playerid, name[], value[]);
  39. public loadaccount_user(playerid, name[], value[])
  40. {
  41. INI_String("Password", pInfo[playerid][Pass],129); /*we will use INI_String to load user's password.
  42. ("Password",.. will load user's password inside of user's path. 'pInfo[playerid][Pass]',...We have defined our user's variable above called, pInfo. Now it's time to use it here to load user's password. '129',... 129 is a length of a hashed user's password. Whirlpool will hash 128 characters + NULL*/
  43. INI_Int("AdminLevel",pInfo[playerid][Adminlevel]);/*We will use INI_Int to load user's admin level. INI_Int stands for INI_Integer. This load an admin level. */
  44. INI_Int("VIPLevel",pInfo[playerid][VIPlevel]);//As explained above
  45. INI_Int("Money",pInfo[playerid][Money]); //As explained above
  46. INI_Int("Scores",pInfo[playerid][Scores]);//As explained above
  47. INI_Int("Kills",pInfo[playerid][Kills]);//As explained above
  48. INI_Int("Deaths",pInfo[playerid][Deaths]);//As explained above
  49. return 1;
  50. }
  51.  
  52. public OnFilterScriptInit()
  53. {
  54. print("\n--------------------------------------");
  55. print(" tAdmin - By thour57 ");
  56. print("--------------------------------------\n");
  57. return 1;
  58. }
  59.  
  60. public OnPlayerConnect(playerid)
  61. {
  62. new name[MAX_PLAYER_NAME]; //Making a new variable called 'name'. name[MAX_PLAYER_NAME] is created so we can use it to get player's name.
  63. GetPlayerName(playerid,name,sizeof(name)); //Get player's name
  64. if(fexist(Path(playerid))) /* Check if the connected user is registered or not. fexist stands for file exist. So if file exist in the files(Path(playerid)),*/
  65. {// then
  66. INI_ParseFile(Path(playerid),"loadaccount_%s", .bExtra = true, .extra = playerid); //Will load user's data using INI_Parsefile.
  67. ShowPlayerDialog(playerid,login,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.*/
  68. }
  69. else //If the connected user is not registered,
  70. {//then we will 'force' him to register :)
  71. ShowPlayerDialog(playerid,register,DIALOG_STYLE_INPUT,"Register","Welcome! This account is not registered.\nEnter your own password to create a new account.","Register","Quit");
  72. return 1;
  73. }
  74. new string[64], pName[MAX_PLAYER_NAME];
  75. GetPlayerName(playerid,pName,MAX_PLAYER_NAME);
  76. format(string,sizeof string,"..::%s Has Joined the Server::..",pName);
  77. SendClientMessageToAll(COLOR_CYAN,string);
  78. return 1;
  79. }
  80.  
  81. public OnPlayerDisconnect(playerid, reason)
  82. {
  83. new INI:file = INI_Open(Path(playerid)); //will open their file
  84. INI_SetTag(file,"Player's Data");//We will set a tag inside of user's account called "Player's Data"
  85. INI_WriteInt(file,"AdminLevel",pInfo[playerid][Adminlevel]); //If you've set his/her admin level, then his/her admin level will be saved inside of his/her account
  86. INI_WriteInt(file,"VIPLevel",pInfo[playerid][VIPlevel]);//As explained above
  87. INI_WriteInt(file,"Money",GetPlayerMoney(playerid));//We will save his money inside of his account
  88. INI_WriteInt(file,"Scores",GetPlayerScore(playerid));//We will save his score inside of his account
  89. INI_WriteInt(file,"Kills",pInfo[playerid][Kills]);//As explained above
  90. INI_WriteInt(file,"Deaths",pInfo[playerid][Deaths]);//As explained above
  91. INI_Close(file);
  92. new
  93. string[64],
  94. name[MAX_PLAYER_NAME];
  95. GetPlayerName(playerid,name,MAX_PLAYER_NAME);
  96. switch(reason)
  97. {
  98. case 0: format(string,sizeof string,"..::%s left the server. (Timed out)::..",name);
  99. case 1: format(string,sizeof string,"..::%s left the server. (Leaving)::..",name);
  100. case 2: format(string,sizeof string,"..::%s left the server. (Kicked/Banned)::..",name);
  101. }
  102. SendClientMessageToAll(COLOR_CYAN,string);
  103. return 1;
  104. }
  105.  
  106. public OnPlayerDeath(playerid, killerid, reason)
  107. {
  108. pInfo[killerid][Kills]++;
  109. pInfo[playerid][Deaths]++;
  110. SendDeathMessage(killerid, playerid, reason);
  111. return 1;
  112. }
  113.  
  114. ////////////////////////////////////////////////////////////////////////////////Common Commands
  115. stock PlayerName(playerid)
  116. {
  117. new Name[MAX_PLAYER_NAME];
  118. GetPlayerName(playerid, Name, sizeof(Name));
  119. return Name;
  120. }
  121.  
  122. CMD:report(playerid, params[])
  123. {
  124. new string[128];
  125. if(!isnull(params))
  126. {
  127. SendClientMessage(playerid, COLOR_YELLOW, "Your report was sent to the Admin Teams.");
  128. format(string, sizeof(string), "Your Report : %s", params); // Proof to the reporter, that the command worked.
  129. SendClientMessage(playerid, COLOR_YELLOW, string);
  130. for(new i=0; i<MAX_PLAYERS; i++)
  131. {
  132. if(pInfo[playerid][Adminlevel] >= 1)
  133. {
  134. format(string, sizeof(string), "Report from %s[%d]: %s", PlayerName(playerid), playerid, params);
  135. SendClientMessage(i, COLOR_ORANGE, string); // Send's the format to the online Rcon'ly Logged in Admins.
  136. }
  137. }
  138. }
  139. else
  140. {
  141. SendClientMessage(playerid, COLOR_RED, "USAGE: /Report [Text]"); // Show's the player the Usage.
  142. }
  143. return 1;
  144. }
  145.  
  146. CMD:ask(playerid, params[])
  147. {
  148. new string[128];
  149. if(!isnull(params))
  150. {
  151. SendClientMessage(playerid, COLOR_YELLOW, "Your Question was sent to the Admin Teams.");
  152. format(string, sizeof(string), "You Asked :%s", params); // Proof to the reporter, that the command worked.
  153. SendClientMessage(playerid, COLOR_YELLOW, string);
  154. for(new i=0; i<MAX_PLAYERS; i++)
  155. {
  156. if(pInfo[playerid][Adminlevel] >= 1)
  157. {
  158. format(string, sizeof(string), "Question from %s[%d]: %s", PlayerName(playerid), playerid, params);
  159. SendClientMessage(i, COLOR_ORANGE, string); // Send's the format to the online Rcon'ly Logged in Admins.
  160. }
  161. }
  162. }
  163. else
  164. {
  165. SendClientMessage(playerid, COLOR_RED, "USAGE: /Ask [Text]"); // Show's the player the Usage.
  166. }
  167. return 1;
  168. }
  169.  
  170. CMD:admins(playerid,params[])
  171. {
  172. new Count, string[128],n[MAX_PLAYER_NAME];
  173. new i;
  174. SendClientMessage(playerid, COLOR_LIGHTBLUE, "__________|Admins|__________");
  175. {
  176. if(pInfo[i][Adminlevel] ==1) {
  177. GetPlayerName(i,n,sizeof(n));
  178. format(string,sizeof(string),"Global Moderator (Level 1) : %s(%d)",n, playerid);
  179. SendClientMessage(playerid,COLOR_LIGHTBLUE,string);
  180. Count++;
  181. }
  182. if(pInfo[i][Adminlevel] ==2) {
  183. GetPlayerName(i,n,sizeof(n));
  184. format(string,sizeof(string),"Moderator (Level 2) : %s(%d)",n, playerid);
  185. SendClientMessage(playerid,COLOR_LIGHTBLUE,string);
  186. Count++;
  187. }
  188. if(pInfo[i][Adminlevel] ==3) {
  189. GetPlayerName(i,n,sizeof(n));
  190. format(string,sizeof(string),"Administrator (Level 3) : %s(%d)",n, playerid);
  191. SendClientMessage(playerid,COLOR_LIGHTBLUE,string);
  192. Count++;
  193. }
  194. if(pInfo[i][Adminlevel] ==4) {
  195. GetPlayerName(i,n,sizeof(n));
  196. format(string,sizeof(string),"Head Administrator (Level 4) : %s(%d)",n, playerid);
  197. SendClientMessage(playerid,COLOR_LIGHTBLUE,string);
  198. Count++;
  199. }
  200. if(pInfo[i][Adminlevel] ==5) {
  201. GetPlayerName(i,n,sizeof(n));
  202. format(string,sizeof(string),"Server Owner (Level 5) : %s(%d)",n, playerid);
  203. SendClientMessage(playerid,COLOR_LIGHTBLUE,string);
  204. Count++;
  205. }
  206. }
  207. if(Count == 0) SendClientMessage(playerid, COLOR_LIGHTBLUE, "No Admins Online");
  208. SendClientMessage(playerid, COLOR_LIGHTBLUE, "____________________________");
  209. return 1;
  210. }
  211.  
  212. CMD:vips(playerid,params[])
  213. {
  214. new Count, string[128],n[MAX_PLAYER_NAME];
  215. new i;
  216. SendClientMessage(playerid, COLOR_LIGHTBLUE, "__________|VIPS|__________");
  217. {
  218. if(pInfo[i][VIPlevel] ==1) {
  219. GetPlayerName(i,n,sizeof(n));
  220. format(string,sizeof(string),"VIP : %s(%d)",n, playerid);
  221. SendClientMessage(playerid,COLOR_LIGHTBLUE,string);
  222. Count++;
  223. }
  224. }
  225. if(Count == 0) SendClientMessage(playerid, COLOR_LIGHTBLUE, "No VIP Online");
  226. SendClientMessage(playerid, COLOR_LIGHTBLUE, "____________________________");
  227. return 1;
  228. }
  229.  
  230. CMD:pm(playerid, params[])
  231. {
  232. new str[256], str2[256], id, Name1[MAX_PLAYER_NAME], Name2[MAX_PLAYER_NAME];
  233. if(sscanf(params, "us", id, str2))
  234. {
  235. SendClientMessage(playerid, 0xFF0000FF, "Usage: /pm <id> <message>");
  236. return 1;
  237. }
  238. if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: Player not connected");
  239. if(playerid == id) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: You cannot pm yourself!");
  240. {
  241. GetPlayerName(playerid, Name1, sizeof(Name1));
  242. GetPlayerName(id, Name2, sizeof(Name2));
  243. format(str, sizeof(str), "PM To %s(ID %d): %s", Name2, id, str2);
  244. SendClientMessage(playerid, 0xFF0000FF, str);
  245. format(str, sizeof(str), "PM From %s(ID %d): %s", Name1, playerid, str2);
  246. SendClientMessage(id, COLOR_PINK, str);
  247. }
  248. return 1;
  249. }
  250.  
  251. /// Vip Commands.
  252. CMD:vskin(playerid, params[])
  253. {
  254. if(pInfo[playerid][VIPlevel] < 1) return SendClientMessage(playerid, COLOR_RED,"Only VIP's Can use this Command.");
  255. {
  256. SetPlayerSkin(playerid, 101);
  257. SendClientMessage(playerid, COLOR_LIGHTBLUE,"Skin Changed.");
  258. }
  259. return 1;
  260. }
  261.  
  262. ///Admin Commands:
  263. CMD:makeadmin(playerid, params[])
  264. {
  265. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "You need to be Admin to use this command");
  266. new targetid, level;
  267. if(sscanf(params, "ui", targetid, level)) return SendClientMessage(playerid, COLOR_RED, "Usage /makeadmin [playerid/part of name] [admin level]");
  268. if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_RED, "Player is not connected!");
  269. pInfo[targetid][Adminlevel] = level;
  270. return 1;
  271. }
  272.  
  273. CMD:makevip(playerid, params[])
  274. {
  275. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "You need to be Admin to use this command");
  276. new targetid, level;
  277. if(sscanf(params, "ui", targetid, level)) return SendClientMessage(playerid, COLOR_RED, "Usage /makevip [playerid/part of name] [vip level]");
  278. if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_RED, "Player is not connected!");
  279. pInfo[targetid][VIPlevel] = level;
  280. return 1;
  281. }
  282.  
  283. CMD:kick(playerid, params[])
  284. {
  285. new targetid;
  286. new reason[64]; //the reason, put into a string
  287. new str[128]; //a new message string
  288. new Playername[MAX_PLAYER_NAME], Adminname[MAX_PLAYER_NAME];
  289. if(pInfo[playerid][Adminlevel] < 1) return SendClientMessage(playerid, -1, "You need to be admin to use this command");
  290. if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, -1, "USAGE /kick [playerid/part of name]");
  291. if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_RED, "Player is not connected!");
  292. format(str, sizeof(str), "'%s' has been Kicked by administrator '%s'. Reason: %s ", Playername, Adminname, reason); //format the string we've defined to send the message, playername and adminname are used to receive the information about the names
  293. SendClientMessageToAll(COLOR_RED, str); //send that message to all
  294. Kick(targetid);
  295. return 1;
  296. }
  297.  
  298. CMD:ban(playerid, params[])
  299. {
  300. if(pInfo[playerid][Adminlevel] < 3) return SendClientMessage(playerid, COLOR_GREY, "You have to be Admin to use that command!"); //return this message
  301. new PID; //define the playerid we wanna ban
  302. new reason[64]; //the reason, put into a string
  303. new str[128]; //a new message string
  304. new Playername[MAX_PLAYER_NAME], Adminname[MAX_PLAYER_NAME]; //defines the function with the playername we wanna get
  305. GetPlayerName(playerid, Adminname, sizeof(Adminname)); //defines the function with the adminname we wanna get
  306. GetPlayerName(PID, Playername, sizeof(Playername));
  307. if(sscanf(params, "us[64]", PID,reason)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /ban [playerid] [reason]"); //tell sscanf if the parameters/the syntax is written wrong to return a message (PID and the reason used here)
  308. if(!IsPlayerConnected(PID)) return SendClientMessage(playerid, COLOR_RED, "Player is not connected!");
  309. format(str, sizeof(str), "'%s' has been banned by administrator '%s'. Reason: %s ", Playername, Adminname, reason); //format the string we've defined to send the message, playername and adminname are used to receive the information about the names
  310. SendClientMessageToAll(COLOR_RED, str); //send that message to all
  311. Ban(PID); //Ban the playerid we've defined
  312. return 1;
  313. }
  314.  
  315. CMD:clearchat(playerid,params[])
  316. {
  317. if(pInfo[playerid][Adminlevel] < 1 ) return SendClientMessage(playerid, COLOR_RED, "You must be Admin to use this command!" );
  318. {
  319. for( new i = 0; i <= 100; i ++ ) SendClientMessageToAll( COLOR_WHITE, "" );
  320. }
  321. return 1;
  322. }
  323.  
  324. CMD:askin(playerid, params[])
  325. {
  326. if(pInfo[playerid][Adminlevel] < 1 ) return SendClientMessage(playerid, COLOR_RED, "You must be Admin to use this command!" );
  327. {
  328. SetPlayerSkin(playerid, 217);
  329. SendClientMessage(playerid, COLOR_RED, "Skin Changed.");
  330. }
  331. return 1;
  332. }
  333.  
  334. CMD:goto(playerid, params[])
  335. {
  336. new ID;//creates a new something idk what we call it :P but it is defined later on or used in something this 1 is used in next line
  337. if(sscanf(params, "u", ID)) SendClientMessage(playerid, 0xFF0000FF, "USAGE: /goto [id]");//checks if you have written something after /goto if no it sends error
  338. else if(!IsPlayerConnected(ID) || ID == playerid) return SendClientMessage(playerid, 0xFF0000FF, "This player is offline or it is yourself");//checks if the player you are teleporting to is connected or if it is yourself if yes then comes an error
  339. else if(pInfo[playerid][Adminlevel] < 1 ) return SendClientMessage(playerid, COLOR_RED, "You must be Admin to use this command!" );
  340. else//ELSE what will happen if no errors
  341. {
  342. new Float:x, Float:y, Float:z;//creates new floats
  343. GetPlayerPos(ID, x, y, z);//gets the player id(which we have entered after /goto position and like saves them into x,y,z defined above as floats
  344. SetPlayerPos(playerid, x+1, y+1, z);//sets the player position the id of that player +1 in x +1 in y and z remains same as it defines height
  345. }
  346. return 1;
  347. }
  348.  
  349. CMD:gethere(playerid,params[])
  350. {
  351. new ID;
  352. new targetid, Float:x, Float:y, Float:z;//defines floats and [U]targetid(same which we did as id above)[/U]
  353. if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /gethere [id]");//checks if there is something written after /gethere if no sends the usage error
  354. if(!IsPlayerConnected(ID) || ID == playerid) return SendClientMessage(playerid, 0xFF0000FF, "This player is offline or it is yourself");//checks if the player is conneted or not and also checks that we are not teleporting ourselves to our self :P if we are it sends error
  355. else if(pInfo[playerid][Adminlevel] < 1 ) return SendClientMessage(playerid, COLOR_RED, "You must be Admin to use this command!" );
  356. GetPlayerPos(playerid, x, y, z);//gets player pos PLAYER POS not targetid
  357. SetPlayerPos(targetid, x+1, y+1, z);//gets the TARGETID player to the PLAYERID x+1,y+1 and z remains same as it defines height
  358. return 1;
  359. }
  360.  
  361. CMD:akill(playerid, params[])
  362. {
  363. new targetid;
  364. new ID;
  365. if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /akill [id]");
  366. if(!IsPlayerConnected(ID) || ID == playerid) return SendClientMessage(playerid, 0xFF0000FF, "This player is offline or it is yourself");
  367. else if(pInfo[playerid][Adminlevel] < 1 ) return SendClientMessage(playerid, COLOR_RED, "You must be Admin to use this command!" );
  368. SetPlayerHealth(ID, 0.00);
  369. SpawnPlayer(ID);
  370. SendClientMessage(ID, COLOR_RED, "You Have Been Killed by An Admin.");
  371. return 1;
  372. }
  373.  
  374. CMD:aspawn(playerid, params[])
  375. {
  376. new targetid;
  377. new ID;
  378. if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /aspawn [id]");
  379. if(!IsPlayerConnected(ID) || ID == playerid) return SendClientMessage(playerid, 0xFF0000FF, "This player is offline or it is yourself");
  380. else if(pInfo[playerid][Adminlevel] < 1 ) return SendClientMessage(playerid, COLOR_RED, "You must be Admin to use this command!" );
  381. SetPlayerHealth(ID, 0.00);
  382. SpawnPlayer(ID);
  383. SendClientMessage(ID, COLOR_RED, "You Have Been Spawned by An Admin.");
  384. return 1;
  385. }
  386.  
  387. CMD:aheal(playerid, params[])
  388. {
  389. new targetid;
  390. new ID;
  391. if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /aheal [id]");
  392. if(!IsPlayerConnected(ID) || ID == playerid) return SendClientMessage(playerid, 0xFF0000FF, "This player is offline or it is yourself");
  393. else if(pInfo[playerid][Adminlevel] < 1 ) return SendClientMessage(playerid, COLOR_RED, "You must be Admin to use this command!" );
  394. SetPlayerHealth(ID, 100.00);
  395. SendClientMessage(ID, COLOR_RED, "You Have Been Healed by An Admin.");
  396. return 1;
  397. }
  398.  
  399. CMD:aarmour(playerid, params[])
  400. {
  401. new targetid;
  402. new ID;
  403. if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /aarmour [id]");
  404. if(!IsPlayerConnected(ID) || ID == playerid) return SendClientMessage(playerid, 0xFF0000FF, "This player is offline or it is yourself");
  405. else if(pInfo[playerid][Adminlevel] < 1 ) return SendClientMessage(playerid, COLOR_RED, "You must be Admin to use this command!" );
  406. SetPlayerArmour(ID, 100.00);
  407. SendClientMessage(ID, COLOR_RED, "You Have Been Armoured by An Admin.");
  408. return 1;
  409. }
  410.  
  411. CMD:ahelp(playerid, params[])
  412. {
  413. if(pInfo[playerid][Adminlevel] < 1) return SendClientMessage(playerid, COLOR_RED,"Only Admin's Can use this Command.");
  414. {
  415. SendClientMessage(playerid, COLOR_LIGHTGREEN, "Level 1 Commands :\n/kick\n/clearchat\n/askin\n/goto\n/gethere\n/akill\n/aarmour\n/aheal\n/aspawn");
  416. SendClientMessage(playerid, COLOR_LIGHTGREEN, "Level 2 Commands :\n/kick\n/clearchat\n/askin\n/goto\n/gethere\n/akill\n/aarmour\n/aheal\n/aspawn");
  417. SendClientMessage(playerid, COLOR_LIGHTGREEN, "Level 3 Commands :\n/ban\n/kick\n/clearchat\n/askin\n/goto\n/gethere\n/akill\n/aarmour\n/aheal\n/aspawn");
  418. SendClientMessage(playerid, COLOR_LIGHTGREEN, "Level 4 Commands :\n/ban\n/kick\n/clearchat\n/askin\n/goto\n/gethere\n/akill\n/aarmour\n/aheal\n/aspawn");
  419. SendClientMessage(playerid, COLOR_LIGHTGREEN, "Level 5 Commands :\n/ban\n/kick\n/clearchat\n/askin\n/goto\n/gethere\n/akill\n/aarmour\n/aheal\n/aspawn\n/makeadmin\n/makevip");
  420. }
  421. return 1;
  422. }
  423.  
  424. ///////////////////////////////////////////////////////////////////////////////////
  425.  
  426. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  427. {
  428. if(dialogid == register) //If dialog id is a register dialog
  429. {//then
  430. if(!response) return Kick(playerid); //If they clicked the second button "Quit", we will kick them.
  431. if(response) //if they clicked the first button "Register"
  432. {//then
  433. if(!strlen(inputtext)) //If they didn't enter any password
  434. {// then we will tell to them to enter the password to register
  435. ShowPlayerDialog(playerid,register,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");
  436. return 1;
  437. }
  438. //If they have entered a correct password for his/her account...
  439. new hashpass[129]; //Now we will create a new variable to hash his/her password
  440. WP_Hash(hashpass,sizeof(hashpass),inputtext);//We will use whirlpool to hash their inputted text
  441. new INI:file = INI_Open(Path(playerid)); // we will open a new file for them to save their account inside of Scriptfiles/Users folder
  442. INI_SetTag(file,"Player's Data");//We will set a tag inside of user's account called "Player's Data"
  443. INI_WriteString(file,"Password",hashpass);//This will write a hashed password into user's account
  444. INI_WriteInt(file,"AdminLevel",0); //Write an integer inside of user's account called "AdminLevel". We will set his level to 0 after he registered.
  445. INI_WriteInt(file,"VIPLevel",0);//As explained above
  446. INI_WriteInt(file,"Money",0);//Write an integer inside of user's account called "Money". We will set their money to 0 after he registered
  447. INI_WriteInt(file,"Scores",0);//Write an integer inside of user's account called "Scores". We will set their score to 0 after he registered
  448. INI_WriteInt(file,"Kills",0);//As explained above
  449. INI_WriteInt(file,"Deaths",0);//As explained above
  450. INI_Close(file);//Now after we've done saving their data, we now need to close the file
  451. SendClientMessage(playerid,-1,"You have been successfully registered");//Tell to them that they have successfully registered a new account
  452. return 1;
  453. }
  454. }
  455. if(dialogid == login) //If dialog id is a login dialog
  456. {//then
  457. if(!response) return Kick(playerid); //If they clicked the second button "Quit", we will kick them.
  458. if(response) //if they clicked the first button "Register"
  459. {//then
  460. new hashpass[129]; //Will create a new variable to hash his/her password
  461. WP_Hash(hashpass,sizeof(hashpass),inputtext); //Will hash inputted password
  462. if(!strcmp(hashpass,pInfo[playerid][Pass])) //If they have insert their correct password
  463. {//then
  464. INI_ParseFile(Path(playerid),"loadaccount_user",.bExtra = true, .extra = playerid);//We will load his account's data from user's path
  465. SetPlayerScore(playerid,pInfo[playerid][Scores]);//We will get their score inside of his user's account and we will set it here
  466. GivePlayerMoney(playerid,pInfo[playerid][Money]);//As explained above
  467. SendClientMessage(playerid,-1,"Welcome back! You have successfully logged in");//Tell them that they've successfully logged in
  468. }
  469. else //If they've entered an incorrect password
  470. {//then
  471. ShowPlayerDialog(playerid,login,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
  472. return 1;
  473. }
  474. }
  475. }
  476. return 1;
  477. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement