Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // tools.cfg -- A collection of useful CubeScript tools by V-Man -- version 1.1.0.8, 2/16/2011
- // *************************************************************************************************************
- // check2add -- a sane way to generically standardize check-based alias and keybind addition
- alias addcheck [if (strstr (getalias $arg1) $arg2) [] [add2alias $arg1 $arg2]]
- alias add2bind [if (strstr (keybind $arg1) $arg2) [] [bind $arg1 (concat (keybind $arg1) ";" $arg2)]]
- alias add2list [if (strcmp "" (getalias $arg1)) [$arg1 = $arg2] [$arg1 = (concat (getalias $arg1) $arg2)]]]
- // Some commonly-used native aliases that do not get emptied:
- alias addcheck_msa [addcheck mapstartalways $arg1]
- alias addcheck_si [addcheck start_intermission $arg1]
- alias addcheck_onquit [addcheck onQuit $arg1]
- alias addcheck_sb [addcheck sbconnect $arg1]
- // A way to add aliases to be cleared OnQuit:
- alias addlistonquit [alias_list = $arg1; loop i (+ (listlen $alias_list ) 1) [addOnQuit (concat "delalias" (at $alias_list $i))]]
- // example: addlistonquit [newalias newalias1 newalias2 newalias3 newalias4 newalias5]
- // They will be cleared on quitting the game, if users prefer to keep saved.cfg clear.
- // *************************************************************************************************************
- // findbind -- A method of back-searching for key commands, phrases, or aliases in keybinds
- alias bindcheck [if (strstr (keybind $arg1) $arg2) [result 1] [result 0]]
- alias findbind [
- alias bindloopresult []
- alias fblc 0
- alias itemtofind $arg1
- findbind_loop
- result $bindloopresult]
- alias findbind_loop [
- loop i 144 [if (bindcheck (at $keylist $i) $itemtofind) [alias bindloopresult (concat $bindloopresult (at $keylist $i))] []]]
- 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
- // Method for dealing with multiple results in findbind:
- alias numbinds [listlen (findbind $arg1)] // number of keys having the designated term in their binds
- // add2bind every key that has the designated term:
- alias add2eachbind [
- alias addition $arg2
- if (findbind $arg1) [
- loop i (numbinds $itemtofind) [add2bind (at (findbind $itemtofind) $i) $addition]]]
- // Example:
- // add2eachbind reload [echo "reloading..."]
- // *************************************************************************************************************
- // wstr -- finds a given string among muddled messes of CubeScript punctuation.
- // Parentheses were not possible. :(
- // This is a very laborious, resource-intensive process. AssaultCube will hang for a moment each time this is used.
- alias wprefixes (concat "[" "[[" "[[[" "[[[[")
- alias wsuffixes (concat "]" "]]" "]]]" "]]]]" ";")
- alias wordcheckloop [loop w (listlen $searchlist) [loop p 4 [loop s 5 [
- if (strcmp $itemtofind (at $searchlist $w)) [alias wmatch 1] [
- if (strcmp (concatword (at $wprefixes $p) $itemtofind (at $wsuffixes $s)) (at $searchlist $w)) [alias wmatch 1] [
- if (strcmp (concatword (at $wprefixes $p) $itemtofind) (at $searchlist $w)) [alias wmatch 1] [
- if (strcmp (concatword $itemtofind (at $wsuffixes $s)) (at $searchlist $w)) [alias wmatch 1] []]]]]]]]
- // A Beast of a string-comparison tool
- alias wstr [
- alias itemtofind $arg2
- alias searchlist $arg1
- alias wmatch 0
- wordcheckloop
- result $wmatch]
- // 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.
- // *************************************************************************************************************
- // wfindbind -- A more accurate method of back-searching for key commands, phrases, or aliases in keybinds
- alias wbindcheck [if (wstr (keybind $arg1) $arg2) [result 1] [result 0]]
- alias wfindbind [
- alias bindloopresult []
- alias fblc 0
- alias itemtofind $arg1
- wfindbind_loop
- result $bindloopresult]
- alias wfindbind_loop [
- loop i 144 [if (wbindcheck (at $keylist $i) $itemtofind) [alias bindloopresult (concat $bindloopresult (at $keylist $i))] []]]
- // Method for dealing with multiple results in wfindbind:
- alias wnumbinds [listlen (wfindbind $arg1)] // number of keys having the designated term in their binds
- // add2bind every key that has the designated term:
- alias wadd2eachbind [
- alias addition $arg2
- if (wfindbind $arg1) [
- loop i (wnumbinds $itemtofind) [add2bind (at (wfindbind $itemtofind) $i) $addition]]]
- // Example:
- // wadd2eachbind reload [echo "reloading..."]
- // *************************************************************************************************************
- // initialize -- for the introduction of large lists of new aliases
- alias initialize [loop i (listlen $arg1) [checkinit (at $arg1 $i) $arg2]]
- alias checkinit [if (checkalias $arg1) [] [alias $arg1 $arg2]] // Defines an alias if the alias does not exist yet
- // initialize [qwer wert erty rtyu tyui yuio uiop asdf sdfg dfgh fghj ghjk hjlk zxcv xcvb cvbn vbnm] 0
- // All 17 aliases are defined as 0 if they (each) do not already exist
- // *************************************************************************************************************
- // integer, float, and number checks by Kirin.
- alias isfloat [if (strcmp (+f $arg1 0) $arg1) [result 1] [result 0]]
- alias isint [if (strcmp (+ $arg1 0) $arg1) [result 1] [result 0]]
- alias isnumber [if (|| (isfloat $arg1) (isint $arg1)) [result 1] [result 0]]
- // *************************************************************************************************************
- // serial and nestalias -- quickly create a nested alias or a series of multiple, numbered aliases (and delete them)
- alias serial [
- tmp_command = $arg3
- serialnum = 0
- loop sa $arg2 [
- if (checkalias (concatword $arg1 $sa)) [] [alias (concatword $arg1 $sa) (tmp_command)]
- += serialnum 1]] // serial (base name) (number to make) [meta-command]
- // Uses $serialnum as its counting variable
- // Will not make the alias if the alias already exists
- alias nestalias [
- tmp_name = $arg1
- tmp_layers = $arg2
- tmp_command = $arg3
- nestnum = 0
- tmp_alias = (alias $tmp_name [])
- loop nn $tmp_layers [
- tmp_alias = (concat "alias" $tmp_name "[" $tmp_alias "]" ";" (tmp_command))
- += nestnum 1]
- alias $tmp_name $tmp_alias] // nestalias (alias name) (number of layers) [side meta-command]
- // Uses $nestnum as its counting variable
- alias delserial [
- loop ds $arg2 [
- delalias (concatword $arg1 $ds)]] // delserial (base name) (number to delete up to)
- // *************************************************************************************************************
- // storeargs -- conveniently store arguments into tmp aliases -- by V-Man
- alias storeargs [
- loop st $numargs [
- alias (concatword "tmp" (+ $st 1)) (getalias (concatword "arg" (+ $st 1)))]
- ] // storeargs $arg1 $arg2 $arg3 $arg4 $arg5
- // stores arguments in tmp1, tmp2, tmp3, tmp4, tmp5 for future use
- addcheck_onquit [delserial tmp 9]
- // *************************************************************************************************************
- // self-recursive alias maker -- creates an alias which calls itself -- by V-Man
- alias recursive [
- storeargs $arg1 $arg2 $arg3
- if (isnumber $tmp1) [
- echo You must use a string for the alias!] [
- if (isint $tmp2) [
- alias (getalias tmp1) (concat (getalias tmp3) ";" "sleep" (getalias tmp2) (getalias tmp1))
- ] [echo You must use an integer for the sleep!]]
- delserial tmp 4]
- // recursive (name of alias) (sleep time) (command)
- // recursive rave 500 [scalelights 99 1337]
- // "rave" can then be added into mapstartalways using addcheck_msa
- // *************************************************************************************************************
- // conloop -- A generic looping conline checker.
- checkinit if_conline_list []
- alias if_conline_has [
- check_for = $arg1
- if (|| (|| (strcmp $arg2 "but_not") (strcmp $arg2 "and_also")) (strcmp $arg2 "or_else")) [
- tmp_other = $arg3
- action_if_yes = $arg4
- action_if_no = $arg5
- if (strcmp $arg2 "but_not") [
- if (&& (strstr $conline $check_for) (! (strstr $conline $tmp_other))) [action_if_yes] [action_if_no]] []
- if (strcmp $arg2 "and_also") [
- if (&& (strstr $conline $check_for) (strstr $conline $tmp_other)) [action_if_yes] [action_if_no]] []
- if (strcmp $arg2 "or_else") [
- if (|| (strstr $conline $check_for) (strstr $conline $tmp_other)) [action_if_yes] [action_if_no]] []
- ] [
- action_if_yes = $arg2
- action_if_no = $arg3
- if (strstr $conline $check_for) [action_if_yes] [action_if_no]]]
- alias add2conloop [ addcheck if_conline_list $arg1 ]
- recursive conloop 0 [if_conline_list; conline [ ]]
- addcheck_msa conloop
- // Example:
- // add2conloop [if_conline_has "connected: " [whois (findcn (at $conline 1))] []]
- // *************************************************************************************************************
- // Exponent script made by Kirin (iterative pow algorithm, exponents are forced into integers)
- alias pow [
- alias pow_exp $arg2
- alias pow_base $arg1
- if (= $pow_exp 0) [result 1] [
- if (< $pow_exp 0) [*= pow_exp -1] []
- -= pow_exp 1
- loop i $pow_exp [*=f pow_base $arg1]
- if (> $arg2 0) [result $pow_base] [result (divf 1 $pow_base)]]]
- // *************************************************************************************************************
- // roundf by Gibstick -- returns the nearest integer
- roundf = [
- if (>= (+f ($arg1) 0.5) (+ ($arg1) 1.0)) [
- (+ ($arg1) 1)] [
- (+ ($arg1) 0)]]
- // *************************************************************************************************************
- // average by V-Man -- input the list of numbers to be rounded as a single argument in brackets
- alias average [
- alias avsum 0
- loop i (listlen $arg1) [+= avsum (at $arg1 $i)]
- divf $avsum (listlen $arg1)]
- // Example:
- // average [1 3 3 7]
- // returns 3.5
- // *************************************************************************************************************
- // add2menu -- Quickly append to any already-defined menu without having to open its cfg file for editing
- alias add2menu [
- newmenu $arg1
- arg2]
- alias add2mainmenu [
- add2menu main $arg1]
- // *************************************************************************************************************
- // curplayers -- Returns the number of players in the server or bot game -- by DES|Bukz.
- // Modified by Wifey and V-Man.
- alias curplayers [
- players = 0
- if $connected [
- loop x 21 [if (= (at (pstat_score $x) 4) -1) [] [+= players 1]]
- result $players
- ] [
- loop x 41 [if (strcmp (findpn $x) "") [] [+= players 1]]
- result $players
- ]]
- // *************************************************************************************************************
- // delfromlist -- A set of tools to modify lists
- alias delfromlistend [
- delalias tmp_list1
- loop de (- (listlen $arg1) $arg2) [
- add2list tmp_list1 (at $arg1 $de)]
- result (getalias tmp_list1) ] // echo (delfromlistend $testlist 3)
- alias delfromliststart [
- delalias tmp_list2
- loop ds (- (listlen $arg1) $arg2) [
- add2list tmp_list2 (at $arg1 (+ $ds $arg2))]
- result (getalias tmp_list2) ] // echo (delfromliststart $testlist 3)
- alias delfromlist [
- delalias tmp_list3
- loop dl (listlen $arg1) [
- if (strcmp (at $arg1 $dl) $arg2) [] [
- add2list tmp_list3 (at $arg1 $dl)]]
- result (getalias tmp_list3) ] // echo (delfromlist $testlist k)
- alias delfromlist_mult [
- alias tmp_list4 $arg1
- loop mu (listlen $arg2) [alias tmp_list4 (delfromlist $tmp_list4 (at $arg2 $mu))]
- result (getalias tmp_list4) ] // echo (delfromlist_mult $testlist [a c e g i k])
- alias replacestr [
- delalias tmp_list5
- loop rs (listlen $arg1) [
- if (strcmp (at $arg1 $rs) $arg2) [add2list tmp_list5 $arg3] [add2list tmp_list5 (at $arg1 $rs)]
- ]
- result $tmp_list5 ] // replacestr [I do not like CubeScript] "not" "really"
- alias swapstrpos [
- delalias tmp_list6
- alias strpos1 (findlist $arg1 $arg2)
- alias strpos2 (findlist $arg1 $arg3)
- loop sw (listlen $arg1) [
- if (= $sw $strpos1) [add2list tmp_list6 $arg3] [
- if (= $sw $strpos2) [add2list tmp_list6 $arg2] [
- add2list tmp_list6 (at $arg1 $sw)]]]
- result $tmp_list6 ] // swapstrpos [I do really like CubeScript] "do" "really"
- // *************************************************************************************************************
- // validcnumlist by V-Man: counts the number of (non-duplicated) client numbers
- alias validcnumlist [
- validcnums = []
- if $connected [
- loop n 21 [if (= (at (pstat_score $n) 4) -1) [] [add2list validcnums $n]]
- result $validcnums
- ] [
- loop n 41 [if (strcmp (findpn $n) "") [] [add2list validcnums $n]]
- result $validcnums ]]
- // kickbots: kickbots 1 3 5 7 9 kicks multiple bots
- alias kickbots [
- loop o $numargs [
- kickbot (findpn (getalias (concatword "arg" (+ $o 1)))) ]]
- // whoisall: WHOIS check on every client in the server
- alias whoisall [loop w 21 [whois $w]]
- // teamcount: echo (teamcount 1) returns the count for players in RVSF
- alias teamcount [
- tmp_count = 0
- loop p (curplayers) [
- if (= (at (pstat_score (at (validcnumlist) $p)) 4) $arg1) [+= tmp_count 1] []
- ] result $tmp_count ]
- // *************************************************************************************************************
- // Bukz' "cur" scripts -- calculates the highest client number, number of enemies, and individual pstat scores
- // curhighestcn - Returns the highest client number in the current game. - by DES|Bukz
- alias curhighestcn [
- hcn = 0
- if $connected [
- loop q 21 [if (strcmp (findpn $q) "") [] [hcn = $q]]
- ] [
- loop q 41 [if (strcmp (findpn $q) "") [] [hcn = $q]]
- ] result $hcn ]
- // curenemies - Returns the current number of enemies the user may have ATM. - by DES|Bukz
- // Requires tools.cfg & the "curhighestcn" script.
- alias curenemies [
- tmpenemies = 0
- if (|| $connected (curmodeattr bot)) [
- if (curmodeattr team) [
- if (curteam) [
- loop b (+ (curhighestcn) 1) [
- if (= (at (pstat_score $b) 4) 0) [+= tmpenemies 1] []
- ] result $tmpenemies
- ] [
- loop b (+ (curhighestcn) 1) [
- if (= (at (pstat_score $a) 4) 1) [+= tmpenemies 1] []
- ] result $tmpenemies]] [
- tmpenemies = (- (curplayers) 1)
- result $tmpenemies]] [result -1]]
- // curdeaths - Returns the number of deaths a client has in the current game. - by DES|Bukz
- // Returns -1 if an invalid client number was given.
- alias curdeaths [
- tmpdeaths = 0
- if (strcmp (findpn $arg1) "") [result -1] [
- tmpdeaths = (at (pstat_score $arg1) 2)
- result $tmpdeaths ]]
- // curfrags - Returns the number of frags a client has in the current game. - by DES|Bukz
- // Returns -1 if an invalid client number was given.
- alias curfrags [
- tmpfrags = 0
- if (strcmp (findpn $arg1) "") [result -1] [
- tmpfrags = (at (pstat_score $arg1) 1)
- result $tmpfrags ]]
- // curratio - Returns the given clients ratio in a floating point decimal by DES|Bukz
- // Returns -1 if an invalid client number was given.
- alias curratio [
- if (strcmp (findpn $arg1) "") [result -1] [
- alias tmpfrags (at (pstat_score $arg1) 1)
- alias tmpdeaths (at (pstat_score $arg1) 2)
- if (< $tmpdeaths 2) [
- alias tmpratio (concatword $tmpfrags .0)
- ] [alias tmpratio (divf $tmpfrags $tmpdeaths)]
- result $tmpratio ]]
- // curscore - Returns the current score (in points) that a given client has ATM by DES|Bukz
- alias curscore [
- if (strcmp (findpn $arg1) "") [result -1] [
- tmpscore = (at (pstat_score $arg1) 3)
- result $tmpscore ]]
- // *************************************************************************************************************
- // sloop -- add sleep to a loop -- idea by macm, abused by V-Man
- alias sloop [
- storeargs $arg1 $arg2 $arg3 $arg4
- if (isnumber $tmp1) [
- echo You must use a string for the alias!] [
- (getalias tmp1) = 0
- if (isint $tmp3) [
- alias sloopme [
- if (< (getalias (getalias tmp1)) $tmp2) [
- tmp4
- += (getalias tmp1) 1
- sleep $tmp3 [sloopme]
- ] [delalias sloopme; delalias (getalias tmp1); delserial tmp 5]]
- sloopme] [echo You must use an integer for the sleep!]]]
- // sloop (alias to use as counter) (number of loops) (sleep time) (command)
- // sloop temp 5 500 [echo Number (concatword (getalias temp) !)]
- // *************************************************************************************************************
- // Clearing the tools on quit
- 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