MuhammadZeeshan

ban func and cmd

Dec 2nd, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. else if ( cmd == "ban")
  2. {
  3. if ( status[ player.ID ].Registered == false ) ErrorMessage( "[#FFFFFF]You need to be a part of our community to use this command.", player );
  4. else if ( status[ player.ID ].Logged == false ) ErrorMessage( "[#FFFFFF]You need to be identified to use this command.", player );
  5. else if ( GetLevel( player ) < 5 ) MessagePlayer("[Error] You don't have access to use this Command.", player );
  6. else if ( !text ) ErrorMessage( "Syntax: /" + cmd + " <playername> <h/d/m> <Reason>", player );
  7. else
  8. {
  9. local args = split( text, " " );
  10. local plr = GetPlayer(args[0]), duration = args[1], reason = GetTok( text, " ", 3, NumTok( text, " " ) );
  11. if ( !plr ) ErrorMessage( "Invalid player", player );
  12. else if (!duration) ErrorMessage( "Syntax: /" + cmd + " <playername> <h/d/m> <Reason> ", player );
  13. else if(!reason) ErrorMessage( "Syntax: /" + cmd + " <playername> <h/d/m> <Reason> ", player );
  14. else
  15. {
  16. Ban( plr, duration, reason, player );
  17. }
  18. }
  19. }
  20.  
  21.  
  22. function Ban( plr, duration, reason, player )
  23. {
  24. local g_bantime, duration_type;
  25. switch( duration.len() )
  26. {
  27. case 2: //this is for slicing the type of 1d
  28. g_bantime = duration.slice(0,1);
  29. duration_type = duration.slice(1,2);
  30. break;
  31.  
  32. case 3: //this is for slicing the type of 10d,10h,10m
  33. g_bantime = duration.slice(0,2);
  34. duration_type = duration.slice(2,3);
  35. break;
  36. }
  37.  
  38. local g_bantime_, g_duration_type_;
  39. switch( duration_type )
  40. {
  41. case "d":
  42. g_bantime_ = g_bantime.tointeger() * 86400;
  43. g_duration_type_ = "day(s)";
  44. break;
  45.  
  46. case "m":
  47. g_bantime_ = g_bantime.tointeger() * 2678400;
  48. g_duration_type_ = "month(s)";
  49. break;
  50.  
  51. case "h":
  52. g_bantime_ = g_bantime.tointeger() * 3600;
  53. g_duration_type_ = "hour(s)";
  54. break;
  55.  
  56. default:
  57. SendMessage( "Invalid format, the format you typed is wrong", player );
  58. }
  59. local dur = g_bantime + " " + g_duration_type_;
  60. ServerMessage( "Admin:[ " + player + " ] Banned: [ "+ plr +" ], for Reason: [ " + reason+ " ], Duration: [ " + dur + " ]" );
  61. EchoMessage( "[BAN] - "+ICOL_RED+"Admin:[ " + player + " ] Banned: [ "+ plr +" ], for Reason: [ " + reason+ " ], Duration: [ " + dur + " ]" );
  62. EchoMessage1( "[BAN] - "+ICOL_RED+"Admin:[ " + player + " ] Banned: [ "+ plr +" ], for Reason: [ " + reason+ " ], Duration: [ " + dur + " ]" );
  63. QuerySQL(db, "INSERT INTO Bans ( Name, g_bantime, g_banexp, Reason, Admin, UID, IP ) VALUES ( '"+plr+"', '"+time()+"', '"+g_bantime_+"', '"+reason+"', '"+player+"', '"+plr.UniqueID+"', '"+plr.IP+"' )" );
  64. plr.Kick();
  65. }
Add Comment
Please, Sign In to add comment