Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Handy eval command by DayDun.
- */
- def string::slice(start) {
- var out = "";
- for (var i=start; i<this.size(); ++i) {
- out += to_string(this[i]);
- }
- return out;
- }
- def broadcast(message) {
- for (var i=0; i<CountPlayers(); ++i) {
- var player = GetPlayerAtIndex(i);
- ConsoleMessage(player, message);
- }
- }
- def stringify(value) {
- var numColor = "^6";
- var boolColor = "^2";
- var strColor = "^9";
- var voidColor = "^0";
- var vectorColor = "^7";
- var mapColor = "^7";
- var mapPairColor = "^3";
- var errorColor = "^1";
- var unknownColor = "^7";
- var type = type_name(value);
- var out;
- if (type == "double") {
- var str = to_string(value);
- if (str.find(".") == -1) {
- str += ".0";
- }
- out = "${numColor}${str}";
- } else if (type == "float") {
- var str = to_string(value);
- if (str.find(".") == -1) {
- str += ".0";
- }
- out = "${numColor}${str}f";
- } else if (type == "long_double") {
- var str = to_string(value);
- if (str.find(".") == -1) {
- str += ".0";
- }
- out = "${numColor}${str}l";
- } else if (type == "int") {
- out = "${numColor}${to_string(value)}";
- } else if (type == "size_t") {
- out = "${numColor}${to_string(value)}u";
- } else if (type == "unsigned_long") {
- out = "${numColor}${to_string(value)}ul";
- } else if (type == "uint64_t") {
- out = "${numColor}${to_string(value)}ull";
- } else if (type == "bool") {
- out = "${boolColor}${to_string(value)}";
- } else if (type == "string") {
- out = "${strColor}\"${value}\"";
- } else if (type == "void") {
- out = "${voidColor}void";
- } else if (type == "Vector") {
- out = "${vectorColor}[";
- for (var i=0; i<value.size(); ++i) {
- out += stringify(value[i]);
- if (i != value.size() - 1) {
- out += "${vectorColor}, ";
- }
- }
- out += "${vectorColor}]";
- } else if (type == "Map") {
- out = "${mapColor}[";
- var range = value.range();
- while(true) {
- out += stringify(range.front());
- range.pop_front();
- if (range.empty()) {
- break;
- }
- out += "${mapColor}, ";
- }
- out += "${mapColor}]";
- } else if (type == "Map_Pair") {
- out = "${mapPairColor}<";
- out += stringify(value.first());
- out += "${mapPairColor}: ";
- out += stringify(value.second());
- out += "${mapPairColor}>";
- } else if (type == "eval_error") {
- out = "${errorColor}${value.reason}";
- } else {
- out = "${unknownColor}[${type}]";
- }
- return out;
- }
- def OnPlayerChat(player, text) {
- if (text.find("!eval ") != 0) {
- return;
- }
- text = text.slice(6);
- var value;
- try {
- value := eval(text);
- } catch(e) {
- value := e;
- }
- broadcast("> " + stringify(value));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement