Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //---FUNCTIONS---\\//---FUNCTIONS---\\//---FUNCTIONS---\\//---FUNCTIONS---\\//---FUNCTIONS---\\
- //Function to invert and alias integer values, usage: /!!i <value>
- "!!i" = [$arg1 = (? (< $$arg1 0) (abs $$arg1) (* -1 $arg1))]
- //Function to invert and alias real values, usage: /!!f <value>
- "!!f" = [$arg1 = (? (<f $$arg1 0) (absf $$arg1) (*f -1 $arg1))]
- // Function to compare given value against a given min & max limit and result boolean, usage: (>< <value> <min> <max>)
- "><" = [&& (>= $arg1 $arg2) (<= $arg1 $arg3)]
- // Function to invert and alias boolean values, usage: /!! var
- "!!" = [$arg1 = (! (getalias $arg1))]
- // Function to add 1 to given value and alias it back, usage: /++ var
- "++" = [$arg1 = (+ (getalias $arg1) 1)]
- // Function to subtract 1 from given value and alias it back, usage: /-- var
- "--" = [$arg1 = (- (getalias $arg1) 1)]
- // Function similar to the common + that allows you to add more than 2 values at once
- "+++" = [
- local tmp
- loop i $numargs [
- tmp = (+ $tmp $[arg@(+ $i 1)])
- ]
- result $tmp
- ]
- // Function similar to the common + that allows you to subtract more than 2 values at once
- "---" = [
- local tmp
- loop i $numargs [
- tmp = (- $tmp $[arg@(+ $i 1)])
- ]
- result $tmp
- ]
- // Function to clamp real numbers to a specific amount of digits, usage: (procf <real> <len>)
- procf = [substr $arg1 0 (+ (strstr $arg1 .) (+ $arg2 1))]
- // Function to append item to list, usage: /append <list> <item>
- append = [$arg1 = (concat (getalias $arg1) $arg2)]
- // Function to append item to list without a space inbetween, usage: /appendword <list> <name>
- appendword = [$arg1 = (concatword (getalias $arg1) $arg2)]
- // Function that clamps the value of given variable to given min/max value and aliases it, usage: /clamp <variable> <min> <max>)
- clamp = [$arg1 = (max $arg2 (min $arg3 (getalias $arg1)))]
- // Function that does the same as clamp, except it works for real numbers, usage: /clampf <variable> <min> <max>)
- clampf = [$arg1 = (maxf $arg2 (minf $arg3 (getalias $arg1)))]
- // Function that returns given value clamped to given min/max value, usage: (clampval <value> <min> <max>)
- clampval = [max $arg2 (min $arg3 $arg1)]
- // Function that does the same as clampval, except it works for real numbers, usage: (clampvalf <value> <min> <max>)
- clampvalf = [maxf $arg2 (minf $arg3 $arg1)]
- // Function to execute all configs found in given path, usage: /execdir <path/is/placed/here>
- execdir = [loopfiles f $arg1 cfg [exec (format "%1/%2.cfg" $arg1 $f)]]
- // Function that formats given value in seconds to MM:SS, usage: (timeleft <value>)
- timeleft = [concatword (div $arg1 60) ":" (mod $arg1 60)]
- // Function that formats given command for display purposes, usage: /quote <command>
- quote = [if $numargs [say [@arg1 = [@@[@arg1]]]]]
- // Self referencing quine, usage: /quine
- quine = [echo quine = [[@@quine]]]
- // Function that checks whether string contains given substring
- // and returns boolean value, usage: (strfind <string> <substring>)
- strfind = [> (strstr $arg1 $arg2) -1]
- // Function that returns random item from given list, usage: (rndo $list)
- rndo = [at $arg1 (rnd (listlen $arg1))]
- // Function that generates random real value for given min/max real numbers, usage: (rndf <max> <min>)
- rndf = [divf (rnd (*f $arg1 1000) (*f $arg2 1000)) 1000]
- // Function that returns the length of given path, usage: (pathlen <path/is/placed/here>)
- pathlen = [listlen (strreplace $arg1 "/" " ")]
- // Function that returns a specific folder out of given path, usage: (getfolder <path/is/placed/here> <index>)
- getfolder = [at (strreplace $arg1 "/" " ") $arg2]
- // Function that returns a part of given path, starting from given folder
- // index for given amount, usage: (getpath <path/is/placed/here> <index> <amount>)
- getpath = [strreplace (sublist (strreplace $arg1 "/" " ") $arg2 $arg3) " " "/"]
- // Function that returns the total amount of clients, usage is the same as (listclients)
- numclients = [listlen (listclients $arg1)]
- // Function that returns the CN of any client possensing master/admin, -1 otherwise, usage: (getmaster)
- getmaster = [at [-1 @(listclients 1)] (listfind i [-1 @(listclients 1)] [ismaster $i])]
- //---COMMANDS---\\//---COMMANDS---\\//---COMMANDS---\\//---COMMANDS---\\//---COMMANDS---\\//---COMMANDS---\\
- // Exchange the content of two variables, usage: /swapval VAR1 VAR2
- swapval = [
- $arg1 = (^ $$arg1 $$arg2)
- $arg2 = (^ $$arg1 $$arg2)
- $arg1 = (^ $$arg1 $$arg2)
- ]
- // Check for file availability in given path and return boolean, usage: (chkfile <path/is/placed/here> <filename.extension>)
- chkfile = [
- local tmp l
- tmp = 0
- l = (strlen $arg2)
- loopfiles f $arg1 (substr $arg2 (- $l 3)) [
- tmp = (=s (substr $arg2 0 (- $l 4)) $f)
- ]
- result $tmp
- ]
- // Practically the same as the previous chkfile, except it accepts an extension as
- // the third argument, usage (chkfile <path/is/placed/here> <filename> <extension>)
- chkfile = [
- local tmp
- tmp = 0
- loopfiles f $arg1 $arg3 [tmp = (=s $arg2 $f)]
- result $tmp
- ]
- // Format given string into either lowercase or
- // uppercase, usage: (charcase "string" <lower(0)/upper(1)>
- charcase = [
- local tmp char
- tmp = $arg1
- char = [? $arg1 $char_upper $char_lower]
- loopchar c $arg1 [
- if (strfind @(char (! $arg2)) $c) [
- tmp = (strreplace $tmp $c (
- substr @@(char $arg2) (strstr @@(char (! $arg2)) $c) 1
- ))
- ]
- ]
- result $tmp
- ]
- // Break given list into a specific amount of parts and quote them
- // then return the new list, usage: (breaklist $list <part amount>)
- breaklist = [
- local tmp l
- l = (listlen $arg1)
- loop i (+ (div $l $arg2) (> (mod $l $arg2) 0)) [
- append tmp [[@@(sublist $arg1 (* $i $arg2) $arg2))]]
- ]
- result $tmp
- ]
- // Return the string with the lowest order in ASCII from given list, usage: (mins $list)
- mins = [
- local tmp
- tmp = (at $arg1 0)
- looplist i $arg1 [if (<s $i $tmp) [tmp = $i]]
- result $tmp
- ]
- // Return the string with the highest order in ASCII from given list, usage: (maxs $list)
- maxs = [
- local tmp
- tmp = (at $arg1 0)
- looplist i $arg1 [if (>s $i $tmp) [tmp = $i]]
- result $tmp
- ]
- // Return given list with its strings sorted on a descending/ascenting
- // order (second argument 0/1) based on the ASCII order, usage: (sortlistdes $list)
- sortlist = [
- local tmp
- loop p (listlen $arg1) [
- append tmp ((? $arg2 maxs mins) (listdel $arg1 $tmp))
- ]
- result $tmp
- ]
- // Function that resets given value if it goes off given min/max range, usage: /clampreset <var <min> <max>
- clampreset = [
- createine $arg1 $arg2
- cond (< $$arg1 $arg2) [$arg1 = $arg3] (> $$arg1 $arg3) [$arg1 = $arg2]
- ]
- // Function that returns the next item in a list, usage: /nextitem $list
- nextitem = [
- ++ _val ; clampreset _val 0 (listlen $arg1)
- result (at $arg1 (mod $_val (listlen $arg1)))
- ]
- // Function that returns the previous item in a list, usage: /previtem $list
- previtem = [
- -- _val ; clampreset _val -1 (- (listlen $arg1) 1)
- result (at $arg1 (mod $_val (listlen $arg1)))
- ]
- // Command similar to 'while' only it first runs the command set given before checking
- // the given case and looping again, usage: /until [action] [case]
- until = [
- arg1
- while [! (arg2)] arg1
- ]
- // Function to bind given key to given variable so that it may toggle its value, usage: /bindvar <key> <variable>
- bindvar = [bind $arg1 [@arg2 (! $@arg2) ; echo "^f7#" @arg2 (? $@arg2 "^f0ON" "^f3OFF")]]
- editbindvar = [editbind $arg1 [@arg2 (! $@arg2) ; echo "^f7#" @arg2 (? $@arg2 "^f0ON" "^f3OFF")]]
- specbindvar = [specbind $arg1 [@arg2 (! $@arg2) ; echo "^f7#" @arg2 (? $@arg2 "^f0ON" "^f3OFF")]]
- // Functions for alternative chat function, commandbuf error backtrace annoying. Bind them to a key.
- sayworld = [inputcommand "" [say $commandbuf] "^f2[world]^f7" s]
- sayally = [inputcommand "" [sayteam $commandbuf] "^f1[team]^f7" s]
- sayexec = [inputcommand "" commandbuf "^f5[exec]^f7" s]
- // Loops through a given string's characters
- // usage: /loopchar VAR "string" [action]
- loopchar = [
- loop $arg1 (strlen $arg2) [
- $arg1 = (substr $arg2 $$arg1 1)
- arg3
- ]
- ]
- // Loops normally, except it can skip execution based on a step value, and may also start from any
- // given index, usage: /steploop VAR <amount> <skip N each time> <start index> [action]
- steploop = [
- loop $arg1 $arg2 [
- if (! (mod $$arg1 $arg3)) [
- $arg1 = (+ $$arg1 $arg4)
- arg5
- ]
- ]
- ]
- // Loops normally, except a sleep value may be specified
- // usage: /zloop VAR <amount> <sleep (ms)> [action]
- zloop = [
- loop $arg1 $arg2 [
- sleep (* $$arg1 $arg3) [
- @@arg1 = @[@arg1]
- @@arg4
- ]
- ]
- ]
- //zloop i 4 200 [echo $i]
- // Scrambles the contents of given list
- // usage: /scramblelist <list>
- scramblelist = [
- local tmp
- loop i (listlen $arg1) [
- append tmp (rndo (listdel $arg1 $tmp))
- ]
- result $tmp
- ]
- // Function which results a new string from given list for each millis
- // step given, usage: (strswap 250 [string string string ..])
- strswap = [at $arg2 (mod (div (getmillis) $arg1) (listlen $arg2))]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement