diff --git a/config/scripts.cfg b/config/scripts.cfg index 26b40d3f..cb7c9c27 100644 --- a/config/scripts.cfg +++ b/config/scripts.cfg @@ -242,7 +242,7 @@ const sbconnect [ ] // answer last PM -const quickanswer [ if (>= $lastpm 0) [ saycommand (concat "/pm" $lastpm []); ] [ saycommand (concat "/pm" []); ] ] +const quickanswer [ if (>= $lastpm 0) [ saycommand (concat "/pm" $lastpm []) ] [ saycommand (concat "/pm" []) ] ] // For those players who use IRC too much... const join [ connect $arg1 $arg2 $arg3 ] @@ -364,7 +364,7 @@ const cleanshot [ disablehud; sleep 200 [ screenshot ]; sleep 500 [ enablehud ] // highestcn - Returns the highest valid client number available. const highestcn [ hcn = -1 - if $connected [ nl = (+ $MAX_CLIENTS 1) ] [ nl = 100 ] + if $connected [ nl = (+ $MAX_CLIENTS 1) ] [ if (curmodeattr bot) [ nl = 100 ] [ nl = 1 ] ] loop h $nl [ if (isclient $h) [ hcn = $h ] ] @@ -387,14 +387,14 @@ const ignoreteam [ if (curmodeattr team) [ _arg1 = (toupper $arg1) if (|| (strcmp $_arg1 CLA) (strcmp $_arg1 RVSF)) [ - loop itl 21 [ + loop itl (+ (highestcn) 1) [ if (isclient $itl) [ if (= (player $itl team) (at [0 1] (strcmp $_arg1 RVSF))) [ ignore $itl ] ] ] ] [ if (checkrange $_arg1 0 1) [ - loop itl 21 [ + loop itl (+ (highestcn) 1) [ if (isclient $itl) [ if (= (player $itl team) $_arg1) [ ignore $itl ] ] diff --git a/source/src/command.cpp b/source/src/command.cpp index 970b0812..08b3e9b2 100644 --- a/source/src/command.cpp +++ b/source/src/command.cpp @@ -1298,6 +1298,64 @@ void strreplace (const char *source, const char *search, const char *replace) } } +void sortlist(char *list) +{ + static char buf[255]; strcpy(buf, ""); //output + + if (strcmp(list, "") == 0) {result(buf); return;} //no input + + vector elems; + explodelist(list, elems); + elems.sort(stringsort); + + strcpy(buf, elems[0]); + for(int i = 1; i < elems.length(); i++) + { + strcat(buf, " "); + strcat(buf, elems[i]); + } + + result(buf); //result +} + +void swapelements(char *list, char *v) +{ + static char buf[255]; strcpy(buf, ""); //output + + if (strcmp(list, "") == 0) {result(buf); return;} //no input + + vector elems; + explodelist(list, elems); + + vector swap; + explodelist(v, swap); + + if (strcmp(v, "") == 0 || //no input + swap.length()%2 != 0) //incorrect input + {result(buf); return;} + + char tmp[255]; strcpy (tmp, ""); + + for(int i = 0; i < swap.length(); i+=2) + { + if (elems.inrange(atoi(swap[i])) && elems.inrange(atoi(swap[i + 1]))) + { + strcpy(tmp, elems[atoi(swap[i])]); + strcpy(elems[atoi(swap[i])], elems[atoi(swap[i+1])]); + strcpy(elems[atoi(swap[i+1])], tmp); + } + } + + strcpy(buf, elems[0]); + for(int i = 1; i < elems.length(); i++) + { + strcat(buf, " "); + strcat(buf, elems[i]); + } + + result(buf); //result +} + COMMANDN(c, colora, "s"); COMMANDN(loop, loopa, "sis"); COMMAND(looplist, "sss"); @@ -1318,7 +1376,9 @@ COMMAND(addpunct, "si"); COMMANDN(tolower, toLower, "s"); COMMANDN(toupper, toUpper, "s"); COMMAND(testchar, "si"); +COMMAND(sortlist, "c"); COMMAND(strreplace, "sss"); +COMMAND(swapelements, "ss"); void add(int *a, int *b) { intret(*a + *b); } COMMANDN(+, add, "ii"); void mul(int *a, int *b) { intret(*a * *b); } COMMANDN(*, mul, "ii");