Advertisement
Guest User

Bukz

a guest
Feb 26th, 2011
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 17.82 KB | None | 0 0
  1. // tools.cfg -- A collection of useful CubeScript tools by V-Man -- version 1.1.0.8, 2/16/2011
  2. // *************************************************************************************************************
  3. // check2add -- a sane way to generically standardize check-based alias and keybind addition
  4. alias addcheck [if (strstr (getalias $arg1) $arg2) [] [add2alias $arg1 $arg2]]
  5. alias add2bind [if (strstr (keybind $arg1) $arg2) [] [bind $arg1 (concat (keybind $arg1) ";" $arg2)]]
  6. alias add2list [if (strcmp "" (getalias $arg1)) [$arg1 = $arg2] [$arg1 = (concat (getalias $arg1) $arg2)]]]
  7. // Some commonly-used native aliases that do not get emptied:
  8. alias addcheck_msa [addcheck mapstartalways $arg1]
  9. alias addcheck_si [addcheck start_intermission $arg1]
  10. alias addcheck_onquit [addcheck onQuit $arg1]
  11. alias addcheck_sb [addcheck sbconnect $arg1]
  12. // A way to add aliases to be cleared OnQuit:
  13. alias addlistonquit [alias_list = $arg1; loop i (+ (listlen $alias_list ) 1) [addOnQuit (concat "delalias" (at $alias_list $i))]]
  14. // example: addlistonquit [newalias newalias1 newalias2 newalias3 newalias4 newalias5]
  15. // They will be cleared on quitting the game, if users prefer to keep saved.cfg clear.
  16. // *************************************************************************************************************
  17. // findbind -- A method of back-searching for key commands, phrases, or aliases in keybinds
  18. alias bindcheck [if (strstr (keybind $arg1) $arg2) [result 1] [result 0]]
  19.  
  20. alias findbind [
  21. alias bindloopresult []
  22. alias fblc 0
  23. alias itemtofind $arg1
  24. findbind_loop
  25. result $bindloopresult]
  26.  
  27. alias findbind_loop [
  28. loop i 144 [if (bindcheck (at $keylist $i) $itemtofind) [alias bindloopresult (concat $bindloopresult (at $keylist $i))] []]]
  29.  
  30. alias keylist [ MOUSE1 MOUSE2 MOUSE3 MOUSE4 MOUSE5 MOUSE6 MOUSE7 MOUSE8 BACKSPACE TAB CLEAR RETURN PAUSE ESCAPE SPACE EXCLAIM QUOTEDBL HASH DOLLAR AMPERSAND QUOTE LEFTPAREN RIGHTPAREN ASTERISK PLUS COMMA MINUS PERIOD SLASH 0 1 2 3 4 5 6 7 8 9 COLON SEMICOLON LESS EQUALS GREATER QUESTION AT LEFTBRACKET BACKSLASH RIGHTBRACKET CARET UNDERSCORE BACKQUOTE A B C D E F G H I J K L M N O P Q R S T U V W X Y Z DELETE KP0 KP1 KP2 KP3 KP4 KP5 KP6 KP7 KP8 KP9 KP_PERIOD KP_DIVIDE KP_MULTIPLY KP_MINUS KP_PLUS KP_ENTER KP_EQUALS UP DOWN RIGHT LEFT INSERT HOME END PAGEUP PAGEDOWN F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 F13 F14 F15 NUMLOCK CAPSLOCK SCROLLOCK RSHIFT LSHIFT RCTRL LCTRL RALT LALT RMETA LMETA LSUPER RSUPER MODE COMPOSE HELP PRINT SYSREQ BREAK MENU SZ UE OE AE ] // listlen = 144
  31. // Method for dealing with multiple results in findbind:
  32. alias numbinds [listlen (findbind $arg1)] // number of keys having the designated term in their binds
  33. // add2bind every key that has the designated term:
  34. alias add2eachbind [
  35. alias addition $arg2
  36. if (findbind $arg1) [
  37. loop i (numbinds $itemtofind) [add2bind (at (findbind $itemtofind) $i) $addition]]]
  38. // Example:
  39. // add2eachbind reload [echo "reloading..."]
  40. // *************************************************************************************************************
  41. // wstr -- finds a given string among muddled messes of CubeScript punctuation.
  42. // Parentheses were not possible. :(
  43. // This is a very laborious, resource-intensive process. AssaultCube will hang for a moment each time this is used.
  44. alias wprefixes (concat "[" "[[" "[[[" "[[[[")
  45. alias wsuffixes (concat "]" "]]" "]]]" "]]]]" ";")
  46.  
  47. alias wordcheckloop [loop w (listlen $searchlist) [loop p 4 [loop s 5 [
  48. if (strcmp $itemtofind (at $searchlist $w)) [alias wmatch 1] [
  49.  if (strcmp (concatword (at $wprefixes $p) $itemtofind (at $wsuffixes $s)) (at $searchlist $w)) [alias wmatch 1] [
  50.   if (strcmp (concatword (at $wprefixes $p) $itemtofind) (at $searchlist $w)) [alias wmatch 1] [
  51.    if (strcmp (concatword $itemtofind (at $wsuffixes $s)) (at $searchlist $w)) [alias wmatch 1] []]]]]]]]
  52. // A Beast of a string-comparison tool
  53. alias wstr [
  54.  alias itemtofind $arg2
  55.  alias searchlist $arg1
  56.  alias wmatch 0
  57.  wordcheckloop
  58.  result $wmatch]
  59. // Finds exact word matches, even if it is touching brackets or a semicolon. This will not show as a match words that are made of your search term. For example, (wstr saycommand say) will return 0, but (wstr [if $connected [echo not connected] [sleep 2000 [say HEY GUYS]]] say) will return 1.
  60. // *************************************************************************************************************
  61. // wfindbind -- A more accurate method of back-searching for key commands, phrases, or aliases in keybinds
  62. alias wbindcheck [if (wstr (keybind $arg1) $arg2) [result 1] [result 0]]
  63.  
  64. alias wfindbind [
  65. alias bindloopresult []
  66. alias fblc 0
  67. alias itemtofind $arg1
  68. wfindbind_loop
  69. result $bindloopresult]
  70.  
  71. alias wfindbind_loop [
  72. loop i 144 [if (wbindcheck (at $keylist $i) $itemtofind) [alias bindloopresult (concat $bindloopresult (at $keylist $i))] []]]
  73. // Method for dealing with multiple results in wfindbind:
  74. alias wnumbinds [listlen (wfindbind $arg1)] // number of keys having the designated term in their binds
  75. // add2bind every key that has the designated term:
  76. alias wadd2eachbind [
  77. alias addition $arg2
  78. if (wfindbind $arg1) [
  79. loop i (wnumbinds $itemtofind) [add2bind (at (wfindbind $itemtofind) $i) $addition]]]
  80. // Example:
  81. // wadd2eachbind reload [echo "reloading..."]
  82. // *************************************************************************************************************
  83. // initialize -- for the introduction of large lists of new aliases
  84. alias initialize [loop i (listlen $arg1) [checkinit (at $arg1 $i) $arg2]]
  85. alias checkinit [if (checkalias $arg1) [] [alias $arg1 $arg2]] // Defines an alias if the alias does not exist yet
  86. // initialize [qwer wert erty rtyu tyui yuio uiop asdf sdfg dfgh fghj ghjk hjlk zxcv xcvb cvbn vbnm] 0
  87. // All 17 aliases are defined as 0 if they (each) do not already exist
  88. // *************************************************************************************************************
  89. // integer, float, and number checks by Kirin.
  90. alias isfloat [if (strcmp (+f $arg1 0) $arg1) [result 1] [result 0]]
  91. alias isint [if (strcmp (+ $arg1 0) $arg1) [result 1] [result 0]]
  92. alias isnumber [if (|| (isfloat $arg1) (isint $arg1)) [result 1] [result 0]]
  93. // *************************************************************************************************************
  94. // serial and nestalias -- quickly create a nested alias or a series of multiple, numbered aliases (and delete them)
  95. alias serial [
  96. tmp_command = $arg3
  97. serialnum = 0
  98. loop sa $arg2 [
  99. if (checkalias (concatword $arg1 $sa)) [] [alias (concatword $arg1 $sa) (tmp_command)]
  100. += serialnum 1]] // serial (base name) (number to make) [meta-command]
  101. // Uses $serialnum as its counting variable
  102. // Will not make the alias if the alias already exists
  103.  
  104. alias nestalias [
  105. tmp_name = $arg1
  106. tmp_layers = $arg2
  107. tmp_command = $arg3
  108. nestnum = 0
  109. tmp_alias = (alias $tmp_name [])
  110. loop nn $tmp_layers [
  111.  tmp_alias = (concat "alias" $tmp_name "[" $tmp_alias "]" ";" (tmp_command))
  112.  += nestnum 1]
  113. alias $tmp_name $tmp_alias] // nestalias (alias name) (number of layers) [side meta-command]
  114. // Uses $nestnum as its counting variable
  115.  
  116. alias delserial [
  117. loop ds $arg2 [
  118.  delalias (concatword $arg1 $ds)]] // delserial (base name) (number to delete up to)
  119. // *************************************************************************************************************
  120. // storeargs -- conveniently store arguments into tmp aliases -- by V-Man
  121. alias storeargs [
  122. loop st $numargs [
  123.  alias (concatword "tmp" (+ $st 1)) (getalias (concatword "arg" (+ $st 1)))]
  124. ] // storeargs $arg1 $arg2 $arg3 $arg4 $arg5
  125. // stores arguments in tmp1, tmp2, tmp3, tmp4, tmp5 for future use
  126. addcheck_onquit [delserial tmp 9]
  127. // *************************************************************************************************************
  128. // self-recursive alias maker -- creates an alias which calls itself -- by V-Man
  129. alias recursive [
  130. storeargs $arg1 $arg2 $arg3
  131. if (isnumber $tmp1) [
  132.  echo You must use a string for the alias!] [
  133.  if (isint $tmp2) [
  134.   alias (getalias tmp1) (concat (getalias tmp3) ";" "sleep" (getalias tmp2) (getalias tmp1))
  135.   ] [echo You must use an integer for the sleep!]]
  136. delserial tmp 4]
  137. // recursive (name of alias) (sleep time) (command)
  138. // recursive rave 500 [scalelights 99 1337]
  139. // "rave" can then be added into mapstartalways using addcheck_msa
  140. // *************************************************************************************************************
  141. // conloop -- A generic looping conline checker.
  142. checkinit if_conline_list []
  143.  
  144. alias if_conline_has [
  145. check_for = $arg1
  146. if (|| (|| (strcmp $arg2 "but_not") (strcmp $arg2 "and_also")) (strcmp $arg2 "or_else")) [
  147.  tmp_other = $arg3
  148.  action_if_yes = $arg4
  149.  action_if_no = $arg5
  150.  if (strcmp $arg2 "but_not") [
  151.   if (&& (strstr $conline $check_for) (! (strstr $conline $tmp_other))) [action_if_yes] [action_if_no]] []
  152.  if (strcmp $arg2 "and_also") [
  153.   if (&& (strstr $conline $check_for) (strstr $conline $tmp_other)) [action_if_yes] [action_if_no]] []
  154.  if (strcmp $arg2 "or_else") [
  155.   if (|| (strstr $conline $check_for) (strstr $conline $tmp_other)) [action_if_yes] [action_if_no]] []
  156.  ] [
  157.  action_if_yes = $arg2
  158.  action_if_no = $arg3
  159.  if (strstr $conline $check_for) [action_if_yes] [action_if_no]]]
  160.  
  161. alias add2conloop [ addcheck if_conline_list $arg1 ]
  162.  
  163. recursive conloop 0 [if_conline_list; conline [ ]]
  164.  
  165. addcheck_msa conloop
  166. // Example:
  167. // add2conloop [if_conline_has "connected: " [whois (findcn (at $conline 1))] []]
  168. // *************************************************************************************************************
  169. // Exponent script made by Kirin (iterative pow algorithm, exponents are forced into integers)
  170. alias pow [
  171. alias pow_exp $arg2
  172. alias pow_base $arg1
  173. if (= $pow_exp 0) [result 1] [
  174. if (< $pow_exp 0) [*= pow_exp -1] []
  175. -= pow_exp 1
  176. loop i $pow_exp [*=f pow_base $arg1]
  177. if (> $arg2 0) [result $pow_base] [result (divf 1 $pow_base)]]]
  178. // *************************************************************************************************************
  179. // roundf by Gibstick -- returns the nearest integer
  180. roundf = [
  181. if (>= (+f ($arg1) 0.5) (+ ($arg1) 1.0)) [
  182. (+ ($arg1) 1)] [
  183. (+ ($arg1) 0)]]
  184. // *************************************************************************************************************
  185. // average by V-Man -- input the list of numbers to be rounded as a single argument in brackets
  186. alias average [
  187. alias avsum 0
  188. loop i (listlen $arg1) [+= avsum (at $arg1 $i)]
  189. divf $avsum (listlen $arg1)]
  190. // Example:
  191. // average [1 3 3 7]
  192. // returns 3.5
  193. // *************************************************************************************************************
  194. // add2menu -- Quickly append to any already-defined menu without having to open its cfg file for editing
  195. alias add2menu [
  196. newmenu $arg1
  197. arg2]
  198. alias add2mainmenu [
  199. add2menu main $arg1]
  200. // *************************************************************************************************************
  201. // curplayers -- Returns the number of players in the server or bot game -- by DES|Bukz.
  202. // Modified by Wifey and V-Man.
  203. alias curplayers [
  204.  players = 0
  205.  if $connected [
  206.   loop x 21 [if (= (at (pstat_score $x) 4) -1) [] [+= players 1]]
  207.   result $players
  208.  ] [
  209.   loop x 41 [if (strcmp (findpn $x) "") [] [+= players 1]]
  210.   result $players
  211. ]]
  212. // *************************************************************************************************************
  213. // delfromlist -- A set of tools to modify lists
  214. alias delfromlistend [
  215. delalias tmp_list1
  216. loop de (- (listlen $arg1) $arg2) [
  217.  add2list tmp_list1 (at $arg1 $de)]
  218. result (getalias tmp_list1) ] // echo (delfromlistend $testlist 3)
  219.  
  220. alias delfromliststart [
  221. delalias tmp_list2
  222. loop ds (- (listlen $arg1) $arg2) [
  223.  add2list tmp_list2 (at $arg1 (+ $ds $arg2))]
  224. result (getalias tmp_list2) ] // echo (delfromliststart $testlist 3)
  225.  
  226. alias delfromlist [
  227. delalias tmp_list3
  228. loop dl (listlen $arg1) [
  229.  if (strcmp (at $arg1 $dl) $arg2) [] [
  230.   add2list tmp_list3 (at $arg1 $dl)]]
  231. result (getalias tmp_list3) ] // echo (delfromlist $testlist k)
  232.  
  233. alias delfromlist_mult [
  234. alias tmp_list4 $arg1
  235. loop mu (listlen $arg2) [alias tmp_list4 (delfromlist $tmp_list4 (at $arg2 $mu))]
  236. result (getalias tmp_list4) ] // echo (delfromlist_mult $testlist [a c e g i k])
  237.  
  238. alias replacestr [
  239. delalias tmp_list5
  240. loop rs (listlen $arg1) [
  241.  if (strcmp (at $arg1 $rs) $arg2) [add2list tmp_list5 $arg3] [add2list tmp_list5 (at $arg1 $rs)]
  242.  ]
  243. result $tmp_list5 ] // replacestr [I do not like CubeScript] "not" "really"
  244.  
  245. alias swapstrpos [
  246. delalias tmp_list6
  247. alias strpos1 (findlist $arg1 $arg2)
  248. alias strpos2 (findlist $arg1 $arg3)
  249. loop sw (listlen $arg1) [
  250.  if (= $sw $strpos1) [add2list tmp_list6 $arg3] [
  251.   if (= $sw $strpos2) [add2list tmp_list6 $arg2] [
  252.    add2list tmp_list6 (at $arg1 $sw)]]]
  253. result $tmp_list6 ] // swapstrpos [I do really like CubeScript] "do" "really"
  254. // *************************************************************************************************************
  255. // validcnumlist by V-Man: counts the number of (non-duplicated) client numbers
  256. alias validcnumlist [
  257. validcnums = []
  258.  if $connected [
  259.   loop n 21 [if (= (at (pstat_score $n) 4) -1) [] [add2list validcnums $n]]
  260.   result $validcnums
  261.  ] [
  262.   loop n 41 [if (strcmp (findpn $n) "") [] [add2list validcnums $n]]
  263.   result $validcnums ]]
  264. // kickbots: kickbots 1 3 5 7 9 kicks multiple bots
  265. alias kickbots [
  266.  loop o $numargs [
  267.   kickbot (findpn (getalias (concatword "arg" (+ $o 1)))) ]]
  268. // whoisall: WHOIS check on every client in the server
  269. alias whoisall [loop w 21 [whois $w]]
  270. // teamcount: echo (teamcount 1) returns the count for players in RVSF
  271. alias teamcount [
  272. tmp_count = 0
  273. loop p (curplayers) [
  274.  if (= (at (pstat_score (at (validcnumlist) $p)) 4) $arg1) [+= tmp_count 1] []
  275. ] result $tmp_count ]
  276. // *************************************************************************************************************
  277. // Bukz' "cur" scripts -- calculates the highest client number, number of enemies, and individual pstat scores
  278. // curhighestcn - Returns the highest client number in the current game. - by DES|Bukz
  279. alias curhighestcn [
  280.  hcn = 0
  281.  if $connected [
  282.   loop q 21 [if (strcmp (findpn $q) "") [] [hcn = $q]]
  283.   ] [
  284.   loop q 41 [if (strcmp (findpn $q) "") [] [hcn = $q]]
  285.   ] result $hcn ]
  286. // curenemies - Returns the current number of enemies the user may have ATM. - by DES|Bukz
  287. // Requires tools.cfg & the "curhighestcn" script.
  288. alias curenemies [
  289.  tmpenemies = 0
  290.  if (|| $connected (curmodeattr bot)) [
  291.   if (curmodeattr team) [
  292.    if (curteam) [
  293.     loop b (+ (curhighestcn) 1) [
  294.      if (= (at (pstat_score $b) 4) 0) [+= tmpenemies 1] []
  295.      ] result $tmpenemies
  296.      ] [
  297.      loop b (+ (curhighestcn) 1) [
  298.       if (= (at (pstat_score $a) 4) 1) [+= tmpenemies 1] []
  299.       ] result $tmpenemies]] [
  300.   tmpenemies = (- (curplayers) 1)
  301.   result $tmpenemies]] [result -1]]
  302. // curdeaths - Returns the number of deaths a client has in the current game. - by DES|Bukz
  303. // Returns -1 if an invalid client number was given.
  304. alias curdeaths [
  305.  tmpdeaths = 0
  306.   if (strcmp (findpn $arg1) "") [result -1] [
  307.    tmpdeaths = (at (pstat_score $arg1) 2)
  308.    result $tmpdeaths ]]
  309. // curfrags - Returns the number of frags a client has in the current game. - by DES|Bukz
  310. // Returns -1 if an invalid client number was given.
  311. alias curfrags [
  312.  tmpfrags = 0
  313.  if (strcmp (findpn $arg1) "") [result -1] [
  314.   tmpfrags = (at (pstat_score $arg1) 1)
  315.   result $tmpfrags ]]
  316. // curratio - Returns the given clients ratio in a floating point decimal by DES|Bukz
  317. // Returns -1 if an invalid client number was given.
  318. alias curratio [
  319.  if (strcmp (findpn $arg1) "") [result -1] [
  320.   alias tmpfrags (at (pstat_score $arg1) 1)
  321.   alias tmpdeaths (at (pstat_score $arg1) 2)
  322.   if (< $tmpdeaths 2) [
  323.    alias tmpratio (concatword $tmpfrags .0)
  324.    ] [alias tmpratio (divf $tmpfrags $tmpdeaths)]
  325.   result $tmpratio ]]
  326.   // curscore - Returns the current score (in points) that a given client has ATM by DES|Bukz
  327. alias curscore [
  328.  if (strcmp (findpn $arg1) "") [result -1] [
  329.   tmpscore = (at (pstat_score $arg1) 3)
  330.    result $tmpscore ]]
  331. // *************************************************************************************************************
  332. // sloop -- add sleep to a loop -- idea by macm, abused by V-Man
  333. alias sloop [
  334. storeargs $arg1 $arg2 $arg3 $arg4
  335. if (isnumber $tmp1) [
  336.  echo You must use a string for the alias!] [
  337.  (getalias tmp1) = 0
  338.  if (isint $tmp3) [
  339.  alias sloopme [
  340.   if (< (getalias (getalias tmp1)) $tmp2) [
  341.    tmp4
  342.    += (getalias tmp1) 1
  343.    sleep $tmp3 [sloopme]
  344.    ] [delalias sloopme; delalias (getalias tmp1); delserial tmp 5]]
  345.  sloopme] [echo You must use an integer for the sleep!]]]
  346. // sloop (alias to use as counter) (number of loops) (sleep time) (command)
  347. // sloop temp 5 500 [echo Number (concatword (getalias temp) !)]
  348. // *************************************************************************************************************
  349. // Clearing the tools on quit
  350. addlistonquit [addcheck add2bind add2list addcheck_msa addcheck_si addcheck_onquit addcheck_sb addlistonquit findbind bindcheck bindloopresult fblc itemtofind findbind_loop keylist numbinds add2eachbind addition wprefixes wsuffixes wordcheckloop wmatch wstr wbindcheck wfindbind wfindbind_loop wnumbinds wadd2eachbind searchlist initialize checkinit if_conline_has check_for has_not action_if_yes action_if_no add2conloop conloop if_conline_list pow pow_exp pow_base roundf average avsum add2menu add2mainmenu players curplayers serial tmp_command serialnum nestalias tmp_name tmp_command tmp_layers nestnum tmp_alias delfromlistend delfromliststart delfromlist delfromlist_mult replacestr swapstrpos tmp_list tmp_list1 tmp_list2 tmp_list3 tmp_list4 tmp_list5 tmp_list6 strpos1 strpos2 validcnumlist validcnums kickbots teamcount tmp_count curhighestcn hcn curenemies tmpenemies curdeaths tmpdeaths curfrags tmpfrags curratio tmpratio storeargs sloop sloopme recursive isfloat isint isnumber alias_list onQuit]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement