Guest User

Pawno crash script code

a guest
May 6th, 2013
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.43 KB | None | 0 0
  1. /*
  2. Includes
  3. */
  4. #include <a_samp>
  5. #include <zcmd>
  6. #include <sscanf>
  7. #include <mysql>
  8. #include <data>
  9. #include <YSI\y_ini>
  10. /*
  11. Defines
  12. */
  13. #define COLOR_BLACK 0x000000AA
  14. #define COLOR_GREEN 0xFF0000
  15. #define COLOR_RED 0xFF0000AA
  16. #define COLOR_WHITE 0xFFFFFFAA
  17. #define COLOR_LIGHTBLUE 0x33CCFFAA
  18. #define notadmin "You are not authorised to use that command!"
  19. #define mysql_host "localhost" //your destination server
  20. #define mysql_user "root" //default user name of wampserver
  21. #define mysql_password "seanom" //wampserver has no default password unless you have set one.
  22. #define mysql_database "sa-mpsql"//the name of your database
  23. #define MAX_ADMIN_LEVEL 7
  24. #define SETLEVEL_ADMIN 7
  25.  
  26. /*
  27. DIALOG DEFINES
  28. */
  29. #define DIALOG_UPDATES 3
  30. #define DIALOG_ACMDS 4
  31. #define DIALOG_RULES 5
  32. /*
  33. SCRIPT BEGIN
  34. */
  35. new MySQL:mysql;
  36. new field[128];
  37.  
  38. #define mysql_fetch_float(%0,%1) mysql_fetch_field(%0,field); \
  39. %1=floatstr(field)
  40. #define mysql_fetch_string(%0,%1) mysql_fetch_field(%0,%1)
  41. #define mysql_fetch_int(%0,%1) mysql_fetch_field(%0,field); \
  42. %1=strval(field)
  43.  
  44.  
  45.  
  46. main()
  47. {
  48. print("\n----------------------------------");
  49. print(" Instant Roleplay by Mahony ");
  50. print("----------------------------------\n");
  51. }
  52.  
  53.  
  54. // ENUM FOR SQL SYSTEM
  55. enum PlayerInfo
  56. {
  57. ID, // id of the player
  58. Nick[24], // name of the player
  59. pAdmin, // admin level of the player
  60. pMoney, //money of the player
  61. pKills, // Kills of the player
  62. pDeaths, // deaths of the player
  63. pScore, // score of the player
  64. IP[16], // Storing the ip of the player
  65. Logged, // Players logged in or not variable
  66. IsRegistered //checks if the player is registered or not.
  67. };
  68. new pInfo[MAX_PLAYERS][PlayerInfo];
  69.  
  70. // END OF ENUM
  71. public OnGameModeInit()
  72. {
  73. SetGameModeText("Instant Roleplay");
  74. AddPlayerClass(0,1481.3726,-1765.3018,18.7958,1.6393,0,0,0,0,0,0);
  75. mysql = mysql_init(LOG_ALL); // Tells sql to log all mysql features used in the script
  76. new Connection = mysql_connect(mysql_host, mysql_user, mysql_password, mysql_database, mysql); // connects with the mysql database
  77. if(Connection) //checks if the database is successfully connected
  78. {
  79. new dest[200];
  80. mysql_stat(dest); // display the mysql database statistics.
  81. printf(dest);
  82. printf(">> MySQL connection successfully initialized"); // if it is connected it will display this line, if not then it wont display anything.
  83. }
  84. return 1;
  85. }
  86.  
  87. public OnGameModeExit()
  88. {
  89. return 1;
  90. }
  91.  
  92. public OnPlayerRequestClass(playerid, classid)
  93. {
  94. SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
  95. SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
  96. SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
  97. return 1;
  98. }
  99.  
  100. public OnPlayerConnect(playerid)
  101. {
  102. new Query[500];
  103. GetPlayerName(playerid, pInfo[playerid][Nick], 24); //gets the player's name and stores it to to your enum pInfo[playerid][Nick]
  104. GetPlayerIp(playerid, pInfo[playerid][IP], 16); //Gets the IP of the player and stores it to pInfo[playerid][IP]
  105. mysql_real_escape_string(pInfo[playerid][Nick], pInfo[playerid][Nick]); // now we have to escape the name inorder to escape any mysql injections. ([url]http://en.wikipedia.org/wiki/SQL_injection[/url])
  106. format(Query, 500, "SELECT `nick` FROM `playerdata` WHERE `nick` COLLATE latin1_general_cs = '%s' LIMIT 1", pInfo[playerid][Nick]); // here we are selecting the name of the player who logged in from the database.
  107. mysql_query(Query); // we query the statement above
  108. mysql_store_result(); // next we store the result inorder for it to be used further ahead.
  109. if(mysql_num_rows() > 0) // if the database has more then one table with the given name
  110. {//then
  111. ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PASSWORD, "Login", "This account is registered! Please log in:", "Login", ""); // show the login dialog and tell the player to login.
  112. }
  113. else // else if the database found no tables with the given name
  114. { // then
  115. ShowPlayerDialog(playerid, 2, DIALOG_STYLE_PASSWORD, "Register", "This account not registered yet! Please register:", "Register", "");// show the register dialog and tell the player to register
  116. }
  117. mysql_free_result(); // here we free the result we stored in the beginning as we do not need it anymore.
  118. //You must always free the mysql result to avoid
  119. //there being massive memory usage.
  120. return 1;
  121. }
  122.  
  123. public OnPlayerDisconnect(playerid, reason)
  124. {
  125. SavePlayer(playerid);
  126. return 1;
  127. }
  128.  
  129. public OnPlayerSpawn(playerid)
  130. {
  131. ShowPlayerDialog(playerid, DIALOG_RULES, DIALOG_STYLE_MSGBOX, "Server Rules", "- No Cheating\n- No Spamming\n- Respect Admins\n\nDo you agree to these rules?", "Yes", "No");
  132. return 1;
  133. }
  134.  
  135. public OnPlayerDeath(playerid, killerid, reason)
  136. {
  137. pInfo[killerid][pKills]++;
  138. pInfo[playerid][pDeaths]++;
  139. return 1;
  140. }
  141.  
  142.  
  143. /*
  144.  
  145. DIALOGS ***WARNING VERY LONG***
  146. */
  147. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  148. {
  149. if(dialogid == 5)
  150. {
  151. if(response) // If they clicked 'Yes' or pressed enter
  152. {
  153. SendClientMessage(playerid, COLOR_GREEN, "Thank you for agreeing to the server rules!");
  154. }
  155. else // Pressed ESC or clicked cancel
  156. {
  157. SendClientMessage(playerid, COLOR_RED, "You MUST agree to the server rules to play here.");
  158. //For info & code of this function please refer to the bottom of this article.
  159. }
  160. }
  161. if(dialogid == 2) //If Dialog is our register dialog
  162. {
  163. if(response) //If they click the button register
  164. {
  165. if(!strlen(inputtext) || strlen(inputtext) > 68) //checks if password is more then 68 characters or nothing.
  166. {
  167. SendClientMessage(playerid, 0xFF0000, "You must insert a password between 1-68 characters!");
  168. ShowPlayerDialog(playerid, 2, DIALOG_STYLE_PASSWORD, "Register", "This account not registered yet! Please register:", "Register", "");// show the register dialog again.
  169. }
  170. else if(strlen(inputtext) > 0 && strlen(inputtext) < 68) // if the password is in between 1 - 68 characters
  171. {
  172. new escpass[100];
  173. mysql_real_escape_string(inputtext, escpass); // here we escape the data again to avoid any mysql injection,
  174. //remember to always to do this when SELECT'ing or INSERT'ing any data in the database
  175. MySQL_Register(playerid, escpass); // Here we are going to another function to register the player.
  176. }
  177. }
  178. if(!response)
  179. {
  180. SendClientMessage(playerid, 0xFF0000, "You must register before you can login!");
  181. ShowPlayerDialog(playerid, 2, DIALOG_STYLE_PASSWORD, "Register", "This account not registered yet! Please register:", "Register", "");// show the register dialog again.
  182. }
  183. }
  184. if(dialogid == 1) //Dialog login
  185. {
  186. if(!response) //If they click the cancel button
  187. {
  188. SendClientMessage(playerid, 0xFF0000, "You must login before you spawn!"); //Sends the client a error message
  189. Kick(playerid); // and kicks him. ( you can change it to show the player the login dialog again by uncommenting the bottem line and commenting this one.
  190. //ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PASSWORD, "Login", "This account is registered! Please log in:", "Login", "");
  191. }
  192. if(response) //If the player clicked login
  193. {
  194. if(!strlen(inputtext) || strlen(inputtext) > 68) //if the password is not 1 to 100 characters
  195. {
  196. SendClientMessage(playerid, 0xFF0000, "You must insert a password between 1-68 characters!"); //Sends the client a error message
  197. ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PASSWORD, "Login","Your user is registered! Please login with your password below!\n{FF0000} Please enter a password between 0 and 68 characters","Login","Cancel");
  198. return 1;
  199. }
  200. mysql_real_escape_string(inputtext, inputtext); //Here we escape the inputtext to avoid SQL injections as stated above.
  201. mysql_real_escape_string(pInfo[playerid][Nick], pInfo[playerid][Nick]); // escapeing ^^
  202. new Query[500];
  203. format(Query, 500, "SELECT * FROM `playerdata` WHERE `nick` COLLATE latin1_general_cs = '%s' AND `password` = '%d'", pInfo[playerid][Nick], udb_hash(inputtext)); // now here check the database if the player has given the proper password.HTTP
  204. mysql_query(Query);
  205. mysql_store_result();
  206. if(mysql_num_rows() > 0) { // if the password the player provided is correct and matches the database
  207. MySQL_Login(playerid); // we will call this function and log the player in.
  208. } else {
  209. //other wise this means that the password that the player
  210. //typed was incorrect and we will resend the dialog.
  211. ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PASSWORD, "Login","Your user is registered! Please login with your password below!\n The password you typed was incorrect!","Login","Cancel"); //Shows our login dialog again.
  212. }
  213. mysql_free_result(); //Remember to always free a result if you stored one!
  214. }
  215. }
  216. return 1;
  217. }
  218.  
  219. /*
  220.  
  221.  
  222. STOCKS///FUCTIONS
  223.  
  224. */
  225.  
  226. forward KickPublic(playerid);
  227. public KickPublic(playerid) { Kick(playerid); }
  228.  
  229. stock KickWithMessage(playerid, color, message[])
  230. {
  231. SendClientMessage(playerid, color, message);
  232. SetTimerEx("KickPublic", 1000, 0, "d", playerid); //Delay of 1 second before kicking the player so he recieves the message
  233. }
  234.  
  235.  
  236. stock MySQL_Register(playerid, passwordstring[])
  237. {
  238. new Query[300];
  239. mysql_real_escape_string(pInfo[playerid][Nick], pInfo[playerid][Nick]);
  240. // escaping the name of the player to avoid sql_injections.
  241. mysql_real_escape_string(pInfo[playerid][IP], pInfo[playerid][IP]);
  242. // escaping the IP of the player to avoid sql_injections.
  243. // as you might've seen we haven't escaped the password here because it was already escaped in our register dialog
  244. format(Query, sizeof(Query), "INSERT INTO `playerdata` (`nick`, `password`, `ip`) VALUES('%s', '%d', '%s')", pInfo[playerid][Nick], udb_hash(passwordstring), pInfo[playerid][IP]); // Here we use the INSERT option and insert the name, password, and ip of the player in the database.
  245. // we don't insert the score, admin, or any other variable because its automatically 0.
  246. mysql_query(Query);
  247. // here we do not need to mysql_store_result or mysql_free_result
  248. // because we are only inserting data in the database not selecting it
  249. //next we set the players logged variable to 1.
  250. //and the isregistered variable to 1 aswell.
  251. SendClientMessage(playerid, -1, "You have now been successfully registered on this server! Click 'Spawn' to begin playing!");
  252. pInfo[playerid][Logged] = 1; //Sets the login variable to 1, meaning logged in.
  253. pInfo[playerid][IsRegistered] = 1; // sets the registered variable to 1. meaning registered.
  254. return 1;
  255. }
  256.  
  257. stock MySQL_Login(playerid)
  258. {
  259. new Query[500];
  260. mysql_real_escape_string(pInfo[playerid][Nick], pInfo[playerid][Nick]); // escaping the name of the player to avoid sql_injections.
  261. format(Query, sizeof(Query), "SELECT * FROM `playerdata` WHERE `nick` COLLATE latin1_general_cs = '%s' LIMIT 1", pInfo[playerid][Nick]);
  262. mysql_query(Query);
  263. // here we select all of the user's data in the database and store it
  264. mysql_store_result();
  265. while(mysql_fetch_row(Query))
  266. // here after the server has selected the user
  267. //from the database and stored its data we extract that data onto our enums.
  268. {
  269. mysql_fetch_int("id", pInfo[playerid][ID]);
  270. // the special identifier of a user called "id"
  271. mysql_fetch_int("admin", pInfo[playerid][pAdmin]);
  272. // the admin level of the player
  273. mysql_fetch_int("score", pInfo[playerid][pScore]); SetPlayerScore(playerid, pInfo[playerid][pScore]);
  274. // here we fetch the score and save it to the enum and also save it to the server by using setplayerscore
  275. mysql_fetch_int("money", pInfo[playerid][pMoney]); GivePlayerMoney(playerid, pInfo[playerid][pMoney]);
  276. // here we fetch the score and save it to the enum and also save it to the server by using setplayerscore
  277. mysql_fetch_int("kills", pInfo[playerid][pKills]);
  278. // the amount of kills a player has
  279. mysql_fetch_int("deaths", pInfo[playerid][pDeaths]);
  280. // the amount of deaths a player has
  281. //
  282. // the way to fetch a users stats from the database is:
  283. //mysql_fetch_int("table_name", variable_to_store_in); remember the "table_name" is case sensitive!
  284. }
  285. mysql_free_result();
  286. // here we free our result and end the SELECT process. Remember this is very important otherwise you may receive high amount of lag in your server!
  287. SendClientMessage(playerid, -1, "You have now been successfully logged into this server! Click 'Spawn' to begin playing!");
  288. pInfo[playerid][Logged] = 1; // sets the logged variable to 1 meaning logged in.
  289. return 1;
  290. }
  291.  
  292. SavePlayer(playerid)
  293. {
  294. if(pInfo[playerid][Logged] == 1)
  295. // checks if the player is logged
  296. {
  297. new Query[500];
  298. format(Query, 500, "UPDATE `playerdata` SET `admin` = '%d', `score` = '%d', `money` = '%d', `kills` = '%d', `deaths` = '%d' WHERE `id` = '%d' LIMIT 1",
  299. pInfo[playerid][pAdmin],
  300. pInfo[playerid][pScore],
  301. pInfo[playerid][pMoney],
  302. pInfo[playerid][pKills],
  303. pInfo[playerid][pDeaths],
  304. pInfo[playerid][ID]);
  305. mysql_query(Query);
  306. //this basically gets the variables and stores it to the players special identifier called "ID".
  307. }
  308. }
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337. /*
  338. Command section
  339. This is where all the commands are
  340. */
  341.  
  342. CMD:help(playerid, params[])
  343. {
  344. SendClientMessage(playerid, COLOR_BLACK, "********************************************************************************");
  345. SendClientMessage(playerid, COLOR_WHITE, "/help - Help commands /updates - Latest updates");
  346. SendClientMessage(playerid, COLOR_WHITE, "/heal - Heal another player /kill - Kill another player ");
  347. SendClientMessage(playerid, COLOR_WHITE, "/feedback - Rate the script!, /bugreport - Report a bug");
  348. SendClientMessage(playerid, COLOR_BLACK, "********************************************************************************");
  349. return 1;
  350. }
  351. CMD:kill(playerid, params[])
  352. {
  353.  
  354. new killplayer;
  355. if(sscanf(params, "u", killplayer)) return SendClientMessage(playerid, COLOR_WHITE, "SYNTAX: /kill [playerid/name]");
  356. else if(!IsPlayerConnected(killplayer)) return SendClientMessage(playerid, COLOR_RED, "This player is not connected");
  357. else
  358. {
  359. if (IsPlayerAdmin(playerid)) SetPlayerHealth(killplayer, 0);
  360. if (IsPlayerAdmin(playerid)) SendClientMessage(killplayer, COLOR_RED, "An Admin Has Killed you!");
  361. else SendClientMessage(playerid, COLOR_RED, notadmin);
  362. }
  363. return 1;
  364. }
  365. CMD:heal(playerid, params[])
  366. {
  367. new healplayer;
  368. if(sscanf(params, "u", healplayer)) return SendClientMessage(playerid, COLOR_WHITE, "SYNTAX: /heal [playerid/name]");
  369. else if(!IsPlayerConnected(healplayer)) return SendClientMessage(playerid, COLOR_RED, "This player is not connected");
  370. else
  371. {
  372. if (IsPlayerAdmin(playerid)) SetPlayerHealth(healplayer, 100);
  373. if (IsPlayerAdmin(playerid)) SendClientMessage(healplayer, COLOR_RED, "An Admin Has Healed you!");
  374. else SendClientMessage(playerid, COLOR_RED, notadmin);
  375. }
  376. return 1;
  377. }
  378. CMD:updates(playerid,params[])
  379. {
  380.  
  381. ShowPlayerDialog(playerid, DIALOG_UPDATES, DIALOG_STYLE_LIST, "Server Updates", "UPDATES: UPDATED 4/5/2013, VERSION 0.5\n- Added: MySQL Admin system\n- Added: Updates dialog\n-Added: New admin commands\n- Bug Fix: Reportbug and feedback has been officially fixed.\n- Removed: /hi command, it was only a test.", "Close", "");
  382. return 1;
  383. }
  384.  
  385. CMD:feedback(playerid,params[])
  386. {
  387. if (isnull(params)) return SendClientMessage(playerid,-1,#"SYNTAX: /feedback <feedback> " );//This is if the player does not type any feedback and only does /feedback
  388. new
  389. _msg[ 128 ],
  390. _msg2[ 128 ],
  391. player_name[ MAX_PLAYER_NAME ];
  392. GetPlayerName(playerid, player_name, MAX_PLAYER_NAME);
  393. SendClientMessage(playerid,COLOR_WHITE,"The feedback you have given has been sent to the database, We will improve it as soon as possible.");//This is to tell the player that there feedback has gone through
  394. format( _msg, sizeof ( _msg ), "Name: %s\r\n", player_name);
  395. format( _msg2, sizeof( _msg2), "Feedback: %s\r\n",params);
  396. new File: fileToWrite = fopen("Feedback.txt", io_append);//Feedback.txt is were all the feedback will go from your players.(It could get spammed -_-)
  397. fwrite(fileToWrite,"[New Feedback]\r\n");//Everytime a player types a new suggestion it will type [New Feedback] Underneath the other feedback.
  398. fwrite(fileToWrite, _msg);
  399. fwrite(fileToWrite, _msg2);
  400. fclose(fileToWrite);
  401. return 1;
  402. }
  403. CMD:reportbug(playerid,params[])
  404. {
  405. if (isnull(params)) return SendClientMessage(playerid,-1,"SYNTAX: /bugreport <bug>" );
  406. new
  407. _bug[ 128 ],
  408. player_name[ MAX_PLAYER_NAME ];
  409. GetPlayerName(playerid, player_name, MAX_PLAYER_NAME);
  410. SendClientMessage(playerid,COLOR_WHITE,"The bug you reported has been sent through to the database, We will investigate it as soon as possible.");
  411. format( _bug, sizeof( _bug ), "Bug: %s\r\n", params);
  412. new File: fileToWrite = fopen("bugreports.txt", io_append);
  413. fwrite(fileToWrite,"[New Bug Report]\r\n");
  414. fwrite(fileToWrite, _bug);
  415. fclose(fileToWrite);
  416. return 1;
  417.  
  418. }
  419.  
  420. CMD:gmx(playerid, params[])
  421. {
  422. if (IsPlayerAdmin(playerid)) SendRconCommand("gmx");
  423. else SendClientMessage(playerid, COLOR_RED, notadmin);
  424. return 1;
  425. }
  426. CMD:kick(playerid, params[])
  427. {
  428. new id, reason[128];
  429. if(!IsPlayerAdmin(playerid))return SendClientMessage(playerid, COLOR_RED, notadmin);
  430. else if(sscanf(params, "us", id, reason))SendClientMessage(playerid, COLOR_WHITE, "Usage: /kick [id/name][reason]");
  431. else if(id==playerid)SendClientMessage(playerid,COLOR_RED,"Error: You can not kick yourself!");
  432. else if(IsPlayerAdmin(id))SendClientMessage(playerid,COLOR_RED,"Error: You can not kick another admin!");
  433. else if (id==INVALID_PLAYER_ID)SendClientMessage(playerid,COLOR_RED,"Error: Player is not connected!");
  434. else {
  435. new Name[MAX_PLAYER_NAME], KickMessage[128];
  436. new Name2[MAX_PLAYER_NAME];
  437. GetPlayerName(playerid, Name, sizeof(Name));
  438. GetPlayerName(id, Name2, sizeof(Name2));
  439. format(KickMessage, sizeof(KickMessage), "%s(%d) has kicked player %s(%d). Reason: %s", Name, playerid, Name2, id);
  440. SendClientMessageToAll(COLOR_WHITE, KickMessage);
  441. Kick(id);
  442. }
  443. return 1;
  444. }
  445. CMD:ban(playerid, params[])
  446. {
  447. new id, reason[128];
  448. if(!IsPlayerAdmin(playerid) || pInfo[playerid][pAdmin] <= SETLEVEL_ADMIN )return SendClientMessage(playerid, COLOR_RED, notadmin);
  449. else if(sscanf(params, "us", id, reason))SendClientMessage(playerid, COLOR_WHITE, "Usage: /ban [id/name][reason]");
  450. else if(id==playerid)SendClientMessage(playerid,COLOR_RED,"Error: You can not ban yourself!");
  451. else if(IsPlayerAdmin(id))SendClientMessage(playerid,COLOR_RED,"Error: You can not ban another admin!");
  452. else if (id==INVALID_PLAYER_ID)SendClientMessage(playerid,COLOR_RED,"Error: Player is not connected!");
  453. else {
  454. new Name[MAX_PLAYER_NAME], banmessage[128];
  455. new Name2[MAX_PLAYER_NAME];
  456. GetPlayerName(playerid, Name, sizeof(Name));
  457. GetPlayerName(id, Name2, sizeof(Name2));
  458. format(banmessage, sizeof(banmessage), "%s(%d) has banned player %s(%d). Reason: %s", Name, playerid, Name2, id);
  459. SendClientMessageToAll(COLOR_WHITE, banmessage);
  460. Ban(id);
  461. }
  462. return 1;
  463. }
  464.  
  465. CMD:acmds(playerid,params[])
  466. {
  467. if(!IsPlayerAdmin(playerid) || pInfo[playerid][pAdmin] <= 0 )return SendClientMessage(playerid, COLOR_RED, notadmin);
  468. else ShowPlayerDialog(playerid, DIALOG_ACMDS, DIALOG_STYLE_MSGBOX, "Admin Commands", "/ban(playerid)(reason) - ban a player /kick(playerid)(reason) - Kick a player\n/heal(playerid) - heal a player /kill(playerid) - kill a player\n/gmx - Restart the server(rcon admins only)", "Close", "");
  469. return 1;
  470. }
  471. /*SendClientMessageToAll()
  472.  
  473. ====================================
  474.  
  475. SET LEVEL COMMAND
  476.  
  477. ====================================
  478.  
  479. VERY LONG
  480.  
  481. ====================================
  482.  
  483. ====================================
  484.  
  485. */
  486. CMD:setlevel(playerid, params[])
  487. {
  488. if(IsPlayerAdmin(playerid) || pInfo[playerid][pAdmin] >= SETLEVEL_ADMIN)
  489. // if the player is an rcon admin or the players admin level is greater or equal
  490. // to the defined admin level of that command
  491. {//then
  492. new level, target;
  493. //here we create 2 variable which we will use
  494. if(sscanf(params, "ui", target, level)) return SendClientMessage(playerid, red, "[*] Usage: /setlevel [playerid/name] [level]");
  495. //if the player hasnt entered a target id or level then it will return that msg
  496. if(target == INVALID_PLAYER_ID) return SendClientMessage(playerid, red, "[*] Enter a valid player ID/name!");
  497. // if the target player is not a valid player then it will return that msg
  498. new string[128], Query[500], str2[50];
  499. if(level < 0 || level > MAX_ADMIN_LEVEL) // here we check if the level the player entered is more then the max admin level defined or 0
  500. {
  501. format(string, sizeof(string), "Enter a level between 0 and %d!", MAX_ADMIN_LEVEL);
  502. SendClientMessage(playerid, red,string); // if it is then we send the message and stop the command from processing
  503. return 1;
  504. }
  505. format(Query, 500, "UPDATE `playerdata` SET `admin` = '%d' WHERE `id` = '%d' LIMIT 1", level, pInfo[target][ID]); //Format the query
  506. mysql_query(Query);
  507. // here we use the UPDATE option again and tell the database to update the player we specified's admin level to what we have set.
  508. pInfo[target][pAdmin] = level;
  509. // here we set the target's var to what we defined
  510. format(string, 256, "You have set %s[%d]'s admin level to %d.", pInfo[target][Nick], target, level);
  511. SendClientMessage(playerid, green, string);
  512. format(string, 256, "Admin %s has set your admin level to %d.", pInfo[playerid][Nick], level);
  513. SendClientMessage(target, yellow, string);
  514. for (new i=0; i<MAX_PLAYERS; i++)
  515. {
  516. if(pInfo[i][Logged] == 1 && pInfo[i][pAdmin])
  517. {
  518. format(str2, sizeof(str2), "Admin %s[%d] has used the following command: Setlevel", pInfo[playerid][Nick], playerid);
  519. SendClientMessage(i,COLOR_SPRINGGREEN,string);
  520. }
  521. }
  522. // here we send the message to the admins
  523. PlayerPlaySound(target,1057,0.0,0.0,0.0);
  524. // play the sound for the target notifying him of this command.
  525. }
  526. else return notadmin(playerid); // if it wasnt a rcon admin or his admin level wasnt greater then the max level
  527. //then we send the error message
  528. return 1;
  529. }
  530.  
  531. /*
  532. ======================================
  533.  
  534. SETADMIN END
  535.  
  536. ======================================
  537. */
Advertisement
Add Comment
Please, Sign In to add comment