Advertisement
RaZgRiZ

Functions Library - 27/09/2012

Oct 16th, 2011
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.93 KB | None | 0 0
  1. //---FUNCTIONS---\\//---FUNCTIONS---\\//---FUNCTIONS---\\//---FUNCTIONS---\\//---FUNCTIONS---\\
  2.  
  3. //Function to invert and alias integer values, usage: /!!i <value>
  4. "!!i" = [$arg1 = (? (< $$arg1 0) (abs $$arg1) (* -1 $arg1))]
  5.  
  6. //Function to invert and alias real values, usage: /!!f <value>
  7. "!!f" = [$arg1 = (? (<f $$arg1 0) (absf $$arg1) (*f -1 $arg1))]
  8.  
  9. // Function to compare given value against a given min & max limit and result boolean, usage: (>< <value> <min> <max>)
  10. "><" = [&& (>= $arg1 $arg2) (<= $arg1 $arg3)]
  11.  
  12. // Function to invert and alias boolean values, usage: /!! var
  13. "!!" = [$arg1 = (! (getalias $arg1))]
  14.  
  15. // Function to add 1 to given value and alias it back, usage: /++ var
  16. "++" = [$arg1 = (+ (getalias $arg1) 1)]
  17.  
  18. // Function to subtract 1 from given value and alias it back, usage: /-- var
  19. "--" = [$arg1 = (- (getalias $arg1) 1)]
  20.  
  21. // Function similar to the common + that allows you to add more than 2 values at once
  22. "+++" = [
  23.     local tmp
  24.     loop i $numargs [
  25.         tmp = (+ $tmp $[arg@(+ $i 1)])
  26.     ]
  27.     result $tmp
  28. ]
  29.  
  30. // Function similar to the common + that allows you to subtract more than 2 values at once
  31. "---" = [
  32.     local tmp
  33.     loop i $numargs [
  34.         tmp = (- $tmp $[arg@(+ $i 1)])
  35.     ]
  36.     result $tmp
  37. ]
  38.  
  39. // Function to clamp real numbers to a specific amount of digits, usage: (procf <real> <len>)
  40. procf = [substr $arg1 0 (+ (strstr $arg1 .) (+ $arg2 1))]
  41.  
  42. // Function to append item to list, usage: /append <list> <item>
  43. append = [$arg1 = (concat (getalias $arg1) $arg2)]
  44.  
  45. // Function to append item to list without a space inbetween, usage: /appendword <list> <name>
  46. appendword = [$arg1 = (concatword (getalias $arg1) $arg2)]
  47.  
  48. // Function that clamps the value of given variable to given min/max value and aliases it, usage: /clamp <variable> <min> <max>)
  49. clamp = [$arg1 = (max $arg2 (min $arg3 (getalias $arg1)))]
  50.  
  51. // Function that does the same as clamp, except it works for real numbers, usage: /clampf <variable> <min> <max>)
  52. clampf = [$arg1 = (maxf $arg2 (minf $arg3 (getalias $arg1)))]
  53.  
  54. // Function that returns given value clamped to given min/max value, usage: (clampval <value> <min> <max>)
  55. clampval = [max $arg2 (min $arg3 $arg1)]
  56.  
  57. // Function that does the same as clampval, except it works for real numbers, usage: (clampvalf <value> <min> <max>)
  58. clampvalf = [maxf $arg2 (minf $arg3 $arg1)]
  59.  
  60. // Function to execute all configs found in given path, usage: /execdir <path/is/placed/here>
  61. execdir = [loopfiles f $arg1 cfg [exec (format "%1/%2.cfg" $arg1 $f)]]
  62.  
  63. // Function that formats given value in seconds to MM:SS, usage: (timeleft <value>)
  64. timeleft = [concatword (div $arg1 60) ":" (mod $arg1 60)]
  65.  
  66. // Function that formats given command for display purposes, usage: /quote <command>
  67. quote = [if $numargs [say [@arg1 = [@@[@arg1]]]]]
  68.  
  69. // Self referencing quine, usage: /quine
  70. quine = [echo quine = [[@@quine]]]
  71.  
  72. // Function that checks whether string contains given substring
  73. // and returns boolean value, usage: (strfind <string> <substring>)
  74. strfind = [> (strstr $arg1 $arg2) -1]
  75.  
  76. // Function that returns random item from given list, usage: (rndo $list)
  77. rndo = [at $arg1 (rnd (listlen $arg1))]
  78.  
  79. // Function that generates random real value for given min/max real numbers, usage: (rndf <max> <min>)
  80. rndf = [divf (rnd (*f $arg1 1000) (*f $arg2 1000)) 1000]
  81.  
  82. // Function that returns the length of given path, usage: (pathlen <path/is/placed/here>)
  83. pathlen = [listlen (strreplace $arg1 "/" " ")]
  84.  
  85. // Function that returns a specific folder out of given path, usage: (getfolder <path/is/placed/here> <index>)
  86. getfolder = [at (strreplace $arg1 "/" " ") $arg2]
  87.  
  88. // Function that returns a part of given path, starting from given folder
  89. // index for given amount, usage: (getpath <path/is/placed/here> <index> <amount>)
  90. getpath = [strreplace (sublist (strreplace $arg1 "/" " ") $arg2 $arg3) " " "/"]
  91.  
  92. // Function that returns the total amount of clients, usage is the same as (listclients)
  93. numclients = [listlen (listclients $arg1)]
  94.  
  95. // Function that returns the CN of any client possensing master/admin, -1 otherwise, usage: (getmaster)
  96. getmaster = [at [-1 @(listclients 1)] (listfind i [-1 @(listclients 1)] [ismaster $i])]
  97.  
  98. //---COMMANDS---\\//---COMMANDS---\\//---COMMANDS---\\//---COMMANDS---\\//---COMMANDS---\\//---COMMANDS---\\
  99.  
  100. // Exchange the content of two variables, usage: /swapval VAR1 VAR2
  101. swapval = [
  102.     $arg1 = (^ $$arg1 $$arg2)
  103.     $arg2 = (^ $$arg1 $$arg2)
  104.     $arg1 = (^ $$arg1 $$arg2)
  105. ]
  106.  
  107. // Check for file availability in given path and return boolean, usage: (chkfile <path/is/placed/here> <filename.extension>)
  108. chkfile = [
  109.     local tmp l
  110.     tmp = 0
  111.     l = (strlen $arg2)
  112.     loopfiles f $arg1 (substr $arg2 (- $l 3)) [
  113.         tmp = (=s (substr $arg2 0 (- $l 4)) $f)
  114.     ]
  115.     result $tmp
  116. ]
  117.  
  118. // Practically the same as the previous chkfile, except it accepts an extension as
  119. // the third argument, usage (chkfile <path/is/placed/here> <filename> <extension>)
  120. chkfile = [
  121.     local tmp
  122.     tmp = 0
  123.     loopfiles f $arg1 $arg3 [tmp = (=s $arg2 $f)]
  124.     result $tmp
  125. ]
  126.  
  127. // Format given string into either lowercase or
  128. // uppercase, usage: (charcase "string" <lower(0)/upper(1)>
  129. charcase = [
  130.     local tmp char
  131.     tmp = $arg1
  132.     char = [? $arg1 $char_upper $char_lower]
  133.     loopchar c $arg1 [
  134.         if (strfind @(char (! $arg2)) $c) [
  135.             tmp = (strreplace $tmp $c (
  136.                 substr @@(char $arg2) (strstr @@(char (! $arg2)) $c) 1
  137.             ))
  138.         ]
  139.     ]
  140.     result $tmp
  141. ]
  142.  
  143.  
  144. // Break given list into a specific amount of parts and quote them
  145. // then return the new list, usage: (breaklist $list <part amount>)
  146. breaklist = [
  147.     local tmp l
  148.     l = (listlen $arg1)
  149.     loop i (+ (div $l $arg2) (> (mod $l $arg2) 0)) [
  150.         append tmp [[@@(sublist $arg1 (* $i $arg2) $arg2))]]
  151.     ]
  152.     result $tmp
  153. ]
  154.  
  155. // Return the string with the lowest order in ASCII from given list, usage: (mins $list)
  156. mins = [
  157.     local tmp
  158.     tmp = (at $arg1 0)
  159.     looplist i $arg1 [if (<s $i $tmp) [tmp = $i]]
  160.     result $tmp
  161. ]
  162.  
  163. // Return the string with the highest order in ASCII from given list, usage: (maxs $list)
  164. maxs = [
  165.     local tmp
  166.     tmp = (at $arg1 0)
  167.     looplist i $arg1 [if (>s $i $tmp) [tmp = $i]]
  168.     result $tmp
  169. ]
  170.  
  171. // Return given list with its strings sorted on a descending/ascenting
  172. // order (second argument 0/1) based on the ASCII order, usage: (sortlistdes $list)
  173. sortlist = [
  174.     local tmp
  175.     loop p (listlen $arg1) [
  176.         append tmp ((? $arg2 maxs mins) (listdel $arg1 $tmp))
  177.     ]
  178.     result $tmp
  179. ]
  180.  
  181. // Function that resets given value if it goes off given min/max range, usage: /clampreset <var <min> <max>
  182. clampreset = [
  183.     createine $arg1 $arg2
  184.     cond (< $$arg1 $arg2) [$arg1 = $arg3] (> $$arg1 $arg3) [$arg1 = $arg2]
  185. ]
  186.  
  187. // Function that returns the next item in a list, usage: /nextitem $list
  188. nextitem = [
  189.     ++ _val ; clampreset _val 0 (listlen $arg1)
  190.     result (at $arg1 (mod $_val (listlen $arg1)))
  191. ]
  192.  
  193. // Function that returns the previous item in a list, usage: /previtem $list
  194. previtem = [
  195.     -- _val ; clampreset _val -1 (- (listlen $arg1) 1)
  196.     result (at $arg1 (mod $_val (listlen $arg1)))
  197. ]
  198.  
  199. // Command similar to 'while' only it first runs the command set given before checking
  200. // the given case and looping again, usage: /until [action] [case]
  201. until = [
  202.     arg1
  203.     while [! (arg2)] arg1
  204. ]
  205.  
  206. // Function to bind given key to given variable so that it may toggle its value, usage: /bindvar <key> <variable>
  207. bindvar = [bind $arg1 [@arg2 (! $@arg2) ; echo "^f7#" @arg2 (? $@arg2 "^f0ON" "^f3OFF")]]
  208. editbindvar = [editbind $arg1 [@arg2 (! $@arg2) ; echo "^f7#" @arg2 (? $@arg2 "^f0ON" "^f3OFF")]]
  209. specbindvar = [specbind $arg1 [@arg2 (! $@arg2) ; echo "^f7#" @arg2 (? $@arg2 "^f0ON" "^f3OFF")]]
  210.  
  211. // Functions for alternative chat function, commandbuf error backtrace annoying. Bind them to a key.
  212. sayworld = [inputcommand "" [say $commandbuf] "^f2[world]^f7" s]
  213. sayally = [inputcommand "" [sayteam $commandbuf] "^f1[team]^f7" s]
  214. sayexec = [inputcommand "" commandbuf "^f5[exec]^f7" s]
  215.  
  216. // Loops through a given string's characters
  217. // usage: /loopchar VAR "string" [action]
  218. loopchar = [
  219.     loop $arg1 (strlen $arg2) [
  220.         $arg1 = (substr $arg2 $$arg1 1)
  221.         arg3
  222.     ]
  223. ]
  224.  
  225. // Loops normally, except it can skip execution based on a step value, and may also start from any
  226. // given index, usage: /steploop VAR <amount> <skip N each time> <start index> [action]
  227. steploop = [
  228.     loop $arg1 $arg2 [
  229.         if (! (mod $$arg1 $arg3)) [
  230.             $arg1 = (+ $$arg1 $arg4)
  231.             arg5
  232.         ]
  233.     ]
  234. ]
  235.  
  236. // Loops normally, except a sleep value may be specified
  237. // usage: /zloop VAR <amount> <sleep (ms)> [action]
  238. zloop = [
  239.     loop $arg1 $arg2 [
  240.         sleep (* $$arg1 $arg3) [
  241.             @@arg1 = @[@arg1]
  242.             @@arg4
  243.         ]
  244.     ]
  245. ]
  246. //zloop i 4 200 [echo $i]
  247.  
  248. // Scrambles the contents of given list
  249. // usage: /scramblelist <list>
  250. scramblelist = [
  251.     local tmp
  252.     loop i (listlen $arg1) [
  253.         append tmp (rndo (listdel $arg1 $tmp))
  254.     ]
  255.     result $tmp
  256. ]
  257.  
  258. // Function which results a new string from given list for each millis
  259. // step given, usage: (strswap 250 [string string string ..])
  260. strswap = [at $arg2 (mod (div (getmillis) $arg1) (listlen $arg2))]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement