DayDun

[CoasterTown] Chat Commands

Jan 15th, 2019
3,243
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. global prefix = "!";
  2.  
  3. global ranks = Dynamic_Object();
  4. ranks["DayDun"] = 2; // Owner
  5. ranks["MeanDean"] = 1; // Trusted
  6.  
  7. def string::getRank() {
  8.     if (ranks.has_attr(this)) {
  9.         return ranks[this];
  10.     }
  11.     return 0;
  12. }
  13.  
  14. def parseSelector(player, selector) {
  15.     var out = [];
  16.     if (selector == "@a") {
  17.         for (var i=0; i<CountPlayers(); ++i) {
  18.             out.push_back(GetPlayerAtIndex(i));
  19.         }
  20.     } else if (selector == "@me") {
  21.         out.push_back(player);
  22.     } else {
  23.         out.push_back(selector);
  24.     }
  25.    
  26.     return out;
  27. }
  28.  
  29.  
  30. class Command {
  31.     var rank;
  32.     var usage;
  33.     var func;
  34.     def Command(rank, usage, func) {
  35.         this.rank = rank;
  36.         this.usage = usage;
  37.         this.func = func;
  38.     }
  39. }
  40.  
  41. global commands = Dynamic_Object();
  42. commands["help"] = Command(0, "!help (<cmd>)", fun(player, args) {
  43.     if (args.size() >= 1) {
  44.         if (!commands.has_attr(args[0])) {
  45.             return false;
  46.         }
  47.        
  48.         ConsoleMessage(player, "Usage: " + commands[args[0]].usage);
  49.     } else {
  50.         var cmds = [];
  51.         var range = commands.get_attrs().range();
  52.         while(!range.empty()) {
  53.             cmds.push_back(prefix + range.front().first());
  54.             range.pop_front();
  55.         }
  56.        
  57.         ConsoleMessage(player, cmds.join(", "));
  58.     }
  59.     return true;
  60. });
  61. commands["tint"] = Command(0, "!tint <selector> <color>", fun(player, args) {
  62.     if (args.size() != 2) {
  63.         return false;
  64.     }
  65.    
  66.     var players = parseSelector(player, args[0]);
  67.    
  68.     var color = to_int(args[1]);
  69.    
  70.     if (color < 0 || color > 9) {
  71.         return false;
  72.     }
  73.    
  74.     for (var i=0; i<players.size(); ++i) {
  75.         TintPlayer(players[i], color);
  76.     }
  77.     return true;
  78. });
  79. commands["gravity"] = Command(1, "!gravity <value>", fun(player, args) {
  80.     if (args.size() != 1) {
  81.         return false;
  82.     }
  83.    
  84.     var value = to_float(args[0]);
  85.    
  86.     if (value < 0.5 || value > 1.0) {
  87.         return false;
  88.     }
  89.    
  90.     Gravity(value);
  91.     return true;
  92. });
  93. commands["players"] = Command(0, "!players", fun(player, args) {
  94.     var out = [];
  95.     for (var i=0; i<CountPlayers(); ++i) {
  96.         var p = GetPlayerAtIndex(i);
  97.         out.push_back("^3${p} ^7[^1${GetPlayerHealth(p)}^7] (${GetPlayerX(p)}, ${GetPlayerY(p)})");
  98.     }
  99.     ConsoleMessage(player, out.join(", "));
  100.     return true;
  101. });
  102. commands["tp"] = Command(1, "!tp <selector> (<x> <y>|<player>)", fun(player, args) {
  103.     if (args.size() != 2 && args.size() != 3) {
  104.         return false;
  105.     }
  106.    
  107.     var players = parseSelector(player, args[0]);
  108.    
  109.     var x;
  110.     var y;
  111.    
  112.     if (args.size() == 2) {
  113.         x = GetPlayerX(args[1]);
  114.         y = GetPlayerY(args[1]);
  115.     } else {
  116.         x = to_int(args[1]);
  117.         y = to_int(args[2]);
  118.     }
  119.    
  120.     for (var i=0; i<players.size(); ++i) {
  121.         TeleportPlayer(players[i], x, y);
  122.     }
  123.     return true;
  124. });
  125. commands["big"] = Command(1, "!big <selector> <message>", fun(player, args) {
  126.     if (args.size() < 2) {
  127.         return false;
  128.     }
  129.    
  130.     var players = parseSelector(player, args[0]);
  131.     args.erase_at(0);
  132.    
  133.     var msg = args.join(" ");
  134.    
  135.     for (var i=0; i<players.size(); ++i) {
  136.         BigMessage(players[i], msg);
  137.     }
  138.     return true;
  139. });
  140. commands["console"] = Command(1, "!console <selector> <message>", fun(player, args) {
  141.     if (args.size() < 2) {
  142.         return false;
  143.     }
  144.    
  145.     var players = parseSelector(player, args[0]);
  146.     args.erase_at(0);
  147.    
  148.     var msg = args.join(" ");
  149.    
  150.     for (var i=0; i<players.size(); ++i) {
  151.         ConsoleMessage(players[i], msg);
  152.     }
  153.     return true;
  154. });
  155.  
  156. def string::split(delim) {
  157.     var out = [];
  158.     var delimSize = delim.size()
  159.     var i = 0;
  160.     while (true) {
  161.         var next = this.find(delim, i);
  162.         out.push_back(this.substr(i, next - i));
  163.         if (next == -1) {
  164.             break;
  165.         }
  166.         i = next + delimSize;
  167.     }
  168.     return out;
  169. }
  170.  
  171. def OnPlayerChat(player, input) {
  172.     if (input.find(prefix) == 0) {
  173.         var args = input.substr(1, input.size()).split(" ");
  174.        
  175.         if (commands.has_attr(args[0])) {
  176.             var cmd = commands[args[0]];
  177.             args.erase_at(0);
  178.            
  179.             var rank = player.getRank();
  180.            
  181.             if (rank >= cmd.rank) {
  182.                 var result := cmd.func(player, args);
  183.                 if (result != true) {
  184.                     var err = "^1Usage: " + cmd.usage;
  185.                     ConsoleMessage(player, err);
  186.                 }
  187.             } else {
  188.                 var err = "^1You are not permitted to use this command!";
  189.                 ConsoleMessage(player, err);
  190.             }
  191.         } else {
  192.             var err = "^1Unknown command! Type !help for help";
  193.             ConsoleMessage(player, err);
  194.         }
  195.     }
  196. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×