Guest User

Untitled

a guest
Mar 5th, 2016
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.53 KB | None | 0 0
  1. #include <a_samp>
  2. #pragma tabsize 0
  3. #include <YSI\y_ini>
  4. #include <zcmd>
  5. #include <sscanf2>
  6.  
  7. #define dregister 2011
  8. #define dlogin 2012
  9. #define acmds 2013
  10. #define UserPath "Users/%s.ini"
  11.  
  12. //COLORS
  13. #define COLOR_GREY 0xAFAFAFAA
  14. #define COLOR_GREEN 0x33AA33AA
  15. #define COLOR_RED 0xFF0000AA
  16. #define COLOR_YELLOW 0xFFFF00AA
  17. #define COLOR_WHITE 0xFFFFFFAA
  18. #define COLOR_VIOLETBLUE 0x8A2BE2AA
  19. #define COLOR_DEADCONNECT 0x808080AA
  20. #define COLOR_BLUE 0x0000FFAA
  21. #define COLOR_FORESTGREEN 0x228B22AA
  22. #define COLOR_DODGERBLUE 0x1E90FFAA
  23. #define COLOR_DARKOLIVEGREEN 0x556B2FAA
  24. #define COLOR_ORANGE 0xFFA500AA
  25. #define COLOR_PURPLE 0x800080AA
  26. #define COLOR_ROYALBLUE 0x4169FFAA
  27. #define COLOR_ERROR 0xD2691EAA
  28. #define COLOR_PINK 0xFF0080FF
  29. #define COLOR_SEXYGREEN 0x00FF00FF
  30. #define COLOR_LIGHTBLUE 0x33CCFFAA
  31. #define COLOR_LIME 0x10F441AA
  32. #define COLOR_ADMIN 0x10F441AA
  33. #define COLOR_CYAN 0x40FFFFFF
  34. #define COLOR_ORANGERED 0xFF4500AA
  35. #define COLOR_NAVY 0x000080AA
  36. #define COLOR_LIME 0x10F441AA
  37.  
  38. forward GivePlayerScore(targetid,Value);
  39.  
  40. native WP_Hash(buffer[],len,const str[]);
  41.  
  42.  
  43. enum PlayerInfo
  44. {
  45. Pass[129],
  46. Adminlevel,
  47. VIPlevel,
  48. Regularlevel,
  49. Money,
  50. Scores,
  51. Kills,
  52. Deaths
  53. }
  54. new pInfo[MAX_PLAYERS][PlayerInfo];
  55.  
  56. new WarnTimes[MAX_PLAYERS];
  57.  
  58. stock Path(playerid)
  59. {
  60. new str[128],name[MAX_PLAYER_NAME];
  61. GetPlayerName(playerid,name,sizeof(name));
  62. format(str,sizeof(str),UserPath,name);
  63. return str;
  64. }
  65.  
  66. forward loadaccount_user(playerid, name[], value[]);
  67.  
  68. public loadaccount_user(playerid, name[], value[])
  69. {
  70. INI_String("Password", pInfo[playerid][Pass],129);
  71. INI_Int("AdminLevel",pInfo[playerid][Adminlevel]);
  72. INI_Int("VIPLevel",pInfo[playerid][VIPlevel]);
  73. INI_Int("RegularPlayerLevel",pInfo[playerid][Regularlevel]);
  74. INI_Int("Money",pInfo[playerid][Money]);
  75. INI_Int("Scores",pInfo[playerid][Scores]);
  76. INI_Int("Kills",pInfo[playerid][Kills]);
  77. INI_Int("Deaths",pInfo[playerid][Deaths]);
  78. return 1;
  79. }
  80. public OnPlayerConnect(playerid)
  81. {
  82. new name[MAX_PLAYER_NAME];
  83. GetPlayerName(playerid,name,sizeof(name)); //Get player's name
  84. if(fexist(Path(playerid)))
  85. {
  86. INI_ParseFile(Path(playerid),"loadaccount_%s", .bExtra = true, .extra = playerid); //Will load user's data using INI_Parsefile.
  87. 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.*/
  88. }
  89. else
  90. {
  91. ShowPlayerDialog(playerid,dregister,DIALOG_STYLE_INPUT,"Register","Welcome! This account is not registered.\nEnter your own password to create a new account.","Register","Quit");
  92. return 1;
  93. }
  94. return 1;
  95. }
  96.  
  97. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  98. {
  99. if(dialogid == dregister) //If dialog id is a register dialog
  100. {//then
  101. if(!response) return Kick(playerid); //If they clicked the second button "Quit", we will kick them.
  102. if(response) //if they clicked the first button "Register"
  103. {//then
  104. if(!strlen(inputtext)) //If they didn't enter any password
  105. {// then we will tell to them to enter the password to register
  106. 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");
  107. return 1;
  108. }
  109. //If they have entered a correct password for his/her account...
  110. new hashpass[129]; //Now we will create a new variable to hash his/her password
  111. WP_Hash(hashpass,sizeof(hashpass),inputtext);//We will use whirlpool to hash their inputted text
  112. new INI:file = INI_Open(Path(playerid)); // we will open a new file for them to save their account inside of Scriptfiles/Users folder
  113. INI_SetTag(file,"Player's Data");//We will set a tag inside of user's account called "Player's Data"
  114. INI_WriteString(file,"Password",hashpass);//This will write a hashed password into user's account
  115. 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.
  116. INI_WriteInt(file,"VIPLevel",0);//As explained above
  117. INI_WriteInt(file,"RegularPlayerLevel",0);
  118. 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
  119. 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
  120. INI_WriteInt(file,"Kills",0);//As explained above
  121. INI_WriteInt(file,"Deaths",0);//As explained above
  122. INI_Close(file);//Now after we've done saving their data, we now need to close the file
  123. SendClientMessage(playerid,-1,"You have been successfully registered");//Tell to them that they have successfully registered a new account
  124. return 1;
  125. }
  126. }
  127. if(dialogid == dlogin) //If dialog id is a login dialog
  128. {//then
  129. if(!response) return Kick(playerid); //If they clicked the second button "Quit", we will kick them.
  130. if(response) //if they clicked the first button "Register"
  131. {//then
  132. new hashpass[129]; //Will create a new variable to hash his/her password
  133. WP_Hash(hashpass,sizeof(hashpass),inputtext); //Will hash inputted password
  134. if(!strcmp(hashpass,pInfo[playerid][Pass])) //If they have insert their correct password
  135. {//then
  136. INI_ParseFile(Path(playerid),"loadaccount_%s",.bExtra = true, .extra = playerid);//We will load his account's data from user's path
  137. SetPlayerScore(playerid,pInfo[playerid][Scores]);//We will get their score inside of his user's account and we will set it here
  138. GivePlayerMoney(playerid,pInfo[playerid][Money]);//As explained above
  139. SendClientMessage(playerid,-1,"Welcome back! You have successfully logged in");//Tell them that they've successfully logged in
  140. }
  141. else //If they've entered an incorrect password
  142. {//then
  143. 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
  144. return 1;
  145. }
  146. }
  147. }
  148. if(dialogid == acmds)
  149. {
  150.  
  151. {
  152. if(response)
  153. {
  154.  
  155. switch(listitem)
  156. {
  157.  
  158. case 0: ShowPlayerDialog(playerid,22778,DIALOG_STYLE_MSGBOX,"level 1 commands","/clearchat /goto /warn /asay","Exit","Back");
  159. case 1: ShowPlayerDialog(playerid,22778,DIALOG_STYLE_MSGBOX,"level 2 commands","/sethp /setarmour /kick","Exit","Back");
  160. case 2: ShowPlayerDialog(playerid,22778,DIALOG_STYLE_MSGBOX,"level 3 commands","/ban /unbanip","Exit","Back");
  161. case 3: ShowPlayerDialog(playerid,22778,DIALOG_STYLE_MSGBOX,"level 4 commands","/setscore /givemoney","Exit","Back");
  162. case 4: ShowPlayerDialog(playerid,22778,DIALOG_STYLE_MSGBOX,"level 5 commands","/makeadmin /fly","Exit","Back");
  163.  
  164. }
  165.  
  166. }
  167. }
  168.  
  169. }
  170.  
  171. return 1;
  172. }
  173.  
  174. public OnPlayerDisconnect(playerid, reason)
  175. {
  176. //Same as OnDialogResponse, we will save their stats inside of their user's account
  177. new INI:file = INI_Open(Path(playerid)); //will open their file
  178. INI_SetTag(file,"Player's Data");//We will set a tag inside of user's account called "Player's Data"
  179. 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
  180. INI_WriteInt(file,"VIPLevel",pInfo[playerid][VIPlevel]);//As explained above
  181. INI_WriteInt(file,"RegularPlayerLevel",pInfo[playerid][Regularlevel]);//Regular Player Level
  182. INI_WriteInt(file,"Money",GetPlayerMoney(playerid));//We will save his money inside of his account
  183. INI_WriteInt(file,"Scores",GetPlayerScore(playerid));//We will save his score inside of his account
  184. INI_WriteInt(file,"Kills",pInfo[playerid][Kills]);//As explained above
  185. INI_WriteInt(file,"Deaths",pInfo[playerid][Deaths]);//As explained above
  186. INI_Close(file);//Now after we've done saving their data, we now need to close the file
  187. return 1;
  188. }
  189.  
  190. public OnPlayerDeath(playerid, killerid, reason)
  191. {
  192. pInfo[killerid][Kills]++;//Will give 1 kill to killer and it will be saved inside of his/her account
  193. pInfo[playerid][Deaths]++;//Will give 1 death each time they die and it will be saved inside of his/her account
  194. return 1;
  195. }
  196.  
  197. COMMAND:acmds(playerid,params[])
  198. {
  199. if(pInfo[playerid][Adminlevel] >= 1) return SendClientMessage(playerid, 0xFF0000AA, "Unknown Command.");
  200. ShowPlayerDialog(playerid,acmds,DIALOG_STYLE_LIST,"Admin commands","Level 1\nLevel 2\nLevel 3\nLevel 4\nLevel 5","Go","Exit");
  201. return 1;
  202. }
  203.  
  204. COMMAND:goto(playerid,params[])
  205. {
  206. if(pInfo[playerid][Adminlevel] >= 2) return SendClientMessage(playerid, 0xFF0000AA, "Unknown Command.");
  207. {
  208. new Float:x,Float:y,Float:z,id;
  209. if(sscanf(params,"u",id)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /goto [playerid]");
  210. if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "This id isnt logged in!");
  211. GetPlayerPos(id,x,y,z);
  212. SetPlayerPos(playerid,x,y,z);
  213. SendClientMessage(playerid, 0x33AA33AA, "[ADMIN] You have succesfully telported to the player!");
  214. }
  215. return 1;
  216. }
  217.  
  218.  
  219. COMMAND:clearchat(playerid,params[])
  220. {
  221. if(pInfo[playerid][Adminlevel] >= 1) return SendClientMessage(playerid, 0xFF0000AA, "Unknown Command.");
  222. for(new i = 0; i < 250; i++) SendClientMessageToAll(0xFFC800," An administrator has cleared the chat ");
  223.  
  224. return 1;
  225. }
  226.  
  227.  
  228. COMMAND:kick(playerid,params[])
  229. {
  230. if(pInfo[playerid][Adminlevel] >= 2) return SendClientMessage(playerid, 0xFF0000AA, "Unknown Command.");
  231. {
  232. new id;
  233. new reason;
  234. if(sscanf(params,"u",id,reason)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /kick [playerid] [reason]");
  235. if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "This id isnt online!");
  236. if(pInfo[playerid][Adminlevel] < pInfo[id][Adminlevel]) return SendClientMessage(playerid,COLOR_RED,"You can't kick a higher admin level than you");
  237. Kick(id);
  238. SendClientMessage(playerid, 0x33AA33AA, "[ADMIN] You have succesfully kicked the player!");
  239. }
  240. return 1;
  241. }
  242.  
  243.  
  244. COMMAND:makeadmin(playerid,params[])
  245. {
  246. if(pInfo[playerid][Adminlevel] >= 5) return SendClientMessage(playerid, 0xFF0000AA, "Unknown Command.");
  247. {
  248. new id,level,string[128];
  249. if(sscanf(params,"ui",id,level)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /makeadmin [playerid] [level 1-5]");
  250. if(level < 1 && level > 5) return SendClientMessage(playerid,COLOR_RED,"[ERROR] Level not found.");
  251. format(string,sizeof(string),"You has been PROMOTED to admin level %i",level);
  252. SendClientMessage(id,COLOR_RED,string);
  253. pInfo[id][Adminlevel] = level;
  254. SendClientMessage(playerid, 0x33AA33AA, "[ADMIN] You have succesfully used /makeadmin command!");
  255. }
  256.  
  257. return 1;
  258. }
  259.  
  260. COMMAND:sethp(playerid,params[])
  261. {
  262. if(pInfo[playerid][Adminlevel] >= 3) return SendClientMessage(playerid, 0xFF0000AA, "Unknown Command.");
  263. {
  264. new id,Float:health;
  265. if(sscanf(params,"uf",id,health)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /sethp [playerid] [hp]");
  266. if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid,COLOR_RED,"Player not found!");
  267. if(pInfo[id][Adminlevel] > pInfo[playerid][Adminlevel]) return SendClientMessage(playerid,COLOR_RED,"You cannot use this command on another admin high level than you");
  268. SetPlayerHealth(id,health);
  269. SendClientMessage(id, 0xFFC800, "[GIFT] An administrator has healed you");
  270. }
  271. return 1;
  272. }
  273. COMMAND:setarmour(playerid,params[])
  274. {
  275. if(pInfo[playerid][Adminlevel] >= 3) return SendClientMessage(playerid, 0xFF0000AA, "Unknown Command.");
  276. {
  277. new id,Float:ar;
  278. if(sscanf(params,"uf",id,ar)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /setarmor [playerid] [armour]");
  279. if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid,COLOR_RED,"Player not found!");
  280. if(pInfo[id][Adminlevel] > pInfo[playerid][Adminlevel]) return SendClientMessage(playerid,COLOR_RED,"You can't use this command on a nother admin high level than you");
  281. SetPlayerArmour(id,ar);
  282. SendClientMessage(id, 0xFFC800, "[GIFT] An administrator has given you armour");
  283. }
  284. return 1;
  285. }
  286.  
  287. COMMAND:givemoney(playerid,params[])
  288. {
  289. if(pInfo[playerid][Adminlevel] >= 4) return SendClientMessage(playerid, 0xFF0000AA, "Unknown Command.");
  290. {
  291. new id,money;
  292. if(sscanf(params,"ui",id,money)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /givemoney [playerid] [ammount]");
  293. if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid,COLOR_RED,"Player not found!");
  294. GivePlayerMoney(id,money);
  295. SendClientMessage(id, 0xFFC800, "[GIFT] An administrator has given you money");
  296. SendClientMessage(playerid, 0x33AA33AA, "You have succesfully used /givemoney!");
  297. }
  298. return 1;
  299. }
  300.  
  301. command(warn, playerid, params[])
  302. {
  303. if(pInfo[playerid][Adminlevel] >= 1) return SendClientMessage(playerid, 0xFF0000AA, "Unknown Command.");
  304. {
  305. new i, reason[50];
  306. new name[50];
  307. new string[250];
  308. if(sscanf(params, "us[50]", i, reason)) SendClientMessage(playerid, COLOR_RED, "USAGE: /warn [id] [reason]");
  309. else if(i == INVALID_PLAYER_ID) SendClientMessage(playerid, COLOR_RED, "Player is not connected!");
  310. else
  311. {
  312. GetPlayerName(i, name, sizeof(name));
  313. if(playerid!=i)
  314. {
  315. if(WarnTimes[i]>=2)
  316. {
  317. format(string, 128,"[AUTO-KICK]: %s[%d] Has Been Kicked From The Server, [3/3 Warnings]", name, i);
  318. SendClientMessageToAll(0xFFC800, string);
  319. SetPlayerHealth(i, 999999999);
  320. SetPlayerInterior(i, 10);
  321. SetPlayerPos(i,226.9807,111.1730,999.0156);
  322. format(string, sizeof(string), "~W~You Have Been ~R~Kicked ~W~From The Server");
  323. GameTextForPlayer(i ,string, 99999999999999999999999, 3);
  324. Kick(i);
  325. }
  326. else
  327. {
  328. WarnTimes[i]+=1;
  329. if(WarnTimes[i]==1)
  330. {
  331. format(string, 128,"[ADMIN-WARN]: You Have Received A Warning, Reason: %s, [1/3 Warnings]", reason);
  332. SendClientMessage(i, 0xFFC800, string);
  333. }
  334. else if(WarnTimes[i]==2)
  335. {
  336. format(string, 128,"[ADMIN-WARN]: You Have Received A Warning, Reason: %s, [2/3 Warnings]", reason);
  337. SendClientMessage(i,0xFFC800, string);
  338. }
  339. format(string, 128,"[ADMIN-WARN]: %s[%d] Has Received A Warning, Reason: %s", name, i, reason);
  340. SendClientMessageToAll(0xFFC800, string);
  341. GameTextForPlayer(i,"~W~You Have Received A ~n~ ~R~Warning",5000,3);
  342. }
  343. }
  344. else SendClientMessage(playerid, COLOR_RED, "You Cannot Warn Yourself");
  345. }
  346. }
  347. return 1;
  348. }
  349.  
  350. CMD:ban(playerid, params[])
  351. {
  352. new id, reason[50], string[128], banned[MAX_PLAYER_NAME];
  353. if(pInfo[playerid][Adminlevel] >= 3) return SendClientMessage(playerid, 0xFF0000AA, "Unknown Command.");
  354. if(sscanf(params, "uz", id, reason))return SendClientMessage(playerid, -1, "USAGE: /ban [playerid] [reason(optional)]");
  355. GetPlayerName(id, banned, sizeof(banned));
  356. format(string, sizeof(string), "AdmCmd: %s has been banned by %s. reason: %s", banned, GetName(playerid), reason);
  357. SendClientMessageToAll(COLOR_RED, string);
  358. BanEx(id, reason);
  359. return 1;
  360. }
  361.  
  362. CMD:fly(playerid, params[])
  363. {
  364. if(pInfo[playerid][Adminlevel] >= 5) return SendClientMessage(playerid, 0xFF0000AA, "Unknown Command.");
  365. SetPlayerSpecialAction(playerid, SPECIAL_ACTION_USEJETPACK);
  366. return 1;
  367. }
  368.  
  369. stock GetName(playerid)
  370. {
  371. new
  372. pName[MAX_PLAYER_NAME];
  373.  
  374. GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
  375. return pName;
  376. }
  377.  
  378. CMD:unbanip(playerid,params[])
  379. {
  380. new ip[32], dformat[64];
  381. if(pInfo[playerid][Adminlevel] >= 3) return SendClientMessage(playerid, 0xFF0000AA, "Unknown Command.");
  382. if(sscanf(params,"s[32]",ip)) return SendClientMessage(playerid,0xff0000ff,"USAGE: /unban [ip]");
  383. format(dformat,sizeof dformat,"unbanip %s",ip);
  384. SendRconCommand(dformat);
  385. return 1;
  386. }
  387. CMD:setscore(playerid, params[]) {
  388. new id; // "defines" the targets id.
  389. new score; // Gets the targets score ( was added to prevent an error.)
  390. new name[MAX_PLAYER_NAME+1], string[24+MAX_PLAYER_NAME+1];
  391. GetPlayerName(playerid, name, sizeof(name));
  392. if(pInfo[playerid][Adminlevel] >= 4) return SendClientMessage(playerid, 0xFF0000AA, "Unknown Command.");
  393. if(sscanf(params, "ui", id, score)) return SendClientMessage(playerid, COLOR_NAVY, "USAGE: /setscore [ID] [SCORE]"); //If there aren't enough params typed in(ex - /setscore ID)
  394. if(score < 1) return SendClientMessage(playerid, COLOR_ORANGE, "You need to give more than 1 score."); //This isn't really needed, but it "forces" the admin to give the player more than 1 score.
  395. if(!IsPlayerConnected(id)) return SendClientMessage(playerid, COLOR_ORANGE, "Target is not online."); //If the targets id isn't "valid", the admin will receive this "error" message, cause there was no ID found.
  396. SetPlayerScore(id, score); //Sets the targets score.
  397. format(string, sizeof(string), "Administrator %s has given you some score!", name); //Target receives this message.
  398. SendClientMessage(id, COLOR_ORANGE, string);
  399. return 1;
  400. }
  401. CMD:asay(playerid,params[])
  402. {
  403. if(pInfo[playerid][Adminlevel] >= 1) return SendClientMessage(playerid, 0xFF0000AA, "Unknown Command.");
  404. if (isnull(params)) return SendClientMessage(playerid,COLOR_GREY, "Usage : /asay <text>");
  405. new string[256];
  406. format(string, sizeof(string), "ADMIN: %s",params);
  407. SendClientMessageToAll(0xFF0000FF, string);
  408. printf("%s",params);
  409. return 1;
  410. }
Advertisement
Add Comment
Please, Sign In to add comment