Here are some examples:
if $x eq "agressor" then agressor_setup else normal_setup
if_num $x ge 5 then echo "it's over 5" else do_nothing
for_num i from 10 to 110 by 10 do set_zoom
math circ eq $diameter mul 3.14
What's new in this version:
- input_number allows your alias to get a number that the player types
input_digit allows your alias to get a signle digit that the player types
aot_userbind stores your aliases in the user bind menu so the user can change the binds to his/her own preference without having to edit the config files
Download the file below and place it in your Nexuiz/data directory.
http://t2net.com/nexuiz/configplus_1_0.pk3
Then add this line to autoexec.cfg:
exec "configplus.cfg"
Note: In the original post I named the files config_logic, but since it goes beyond just logic statements now to various utilities, I renamed them configplus. If you've downloaded config_logic.pk3, delete it and replace with configplus for additional and improved functions.
Below is the documentation on the commands. Note that these are just the comments from the config file, not the actual commands. If you want to see the aliases for the commands, unzip the pk3.
- Code: Select all
// -------------------------------------------------------------------------------------
// Config Plus v 1.0 -------------------------------------------------------------------
// -------------------------------------------------------------------------------------
// If you have ideas or comments on Config Plus, please post them at alientrap.org/forum
// -------------------------------------------------------------------------------------
//
// Note that in the comments below two dollar signs are used instead of one dollar sign.
// This is because Nexuiz will try to replace a single dollar sign with a variable value
// even if the line is a comment. So anywhere you see $$ in a comment, it should really
// be a single dollar sign.
//
// -------------------------------------------------------------------------------------
//
// do_nothing does nothing which is handy in scripting sometimes
// if command --------------------------------------------------------------------------
// syntax: if value1 eq value2 then alias1 else alias2
// or: if value1 ne value2 then alias1 else alias2
// value1 and value 2 can be numbers or single-word strings
// alias1 and alias2 can be commands or aliases and can
// include parameters if quoted (see example)
//
// description: Works like a regular if command, but only allows tests for equal (eq)
// or not equal (ne)
//
// example: alias my_true_alias "echo true"
// alias my_false_alias "echo false"
// set x 5
// set y 7
// set s "apple"
// set s2 "spaced text"
// if $x eq 5 then my_true_alias else my_false_alias
// -> true
// if $x ne 5 then my_true_alias else my_false_alias
// -> false
// if $x ne $y then my_true_alias else my_false_alias
// -> true
// if $s eq apple then "echo it is an apple" else my_false_alias
// -> it is an apple
// if "$s" eq "" then my_true_alias else my_false_alias
// -> false
// if "$s2" eq "spaced text" then my_true_alias else my_false_alias
// -> true
//
// The last 3 examples above use quotes since strings with spaces
// and empty strings are used. Also use quotes around variables if they
// might contain spaces or might be empty.
// When you use if in an alias, you would need to use \" as in:
// alias my_example "if $x eq 5 then \"echo x is 5\" else \"echo not 5\""
//
// if_num command --------------------------------------------------------------------------
// syntax: if_num value1 operator1 value2 then alias1 else alias2
// value1 and value 2 must be numbers
// operator1 is one of the following:
// eq (equal)
// ne (not equal)
// gt (greater than)
// lt (less than)
// ge (greater than or equal to)
// le (less than or equal to)
// alias1 and alias2 can be commands or aliases and can
// include parameters if quoted (see example)
//
// description: Works like the regular if command, but only with numbers and has more operators
//
// example: alias my_true_alias "echo true"
// alias my_false_alias "echo false"
// set x 5
// set y 7
// if_num $x lt 5 then my_true_alias else my_false_alias
// -> true
// if_num $x ge 5 then my_true_alias else my_false_alias
// -> false
// if_num $x ne $y then my_true_alias else my_false_alias
// -> true
//
// warning: 1. If value1 or value2 are strings they will be treated as 0.
// 2. Must be used after Nexuiz loads. Use regular if during startup.
// That is, using if_num in an alias or bind is fine if it runs
// after Nexuiz loads, but it can't be used directly in autoexec.cfg
// since the rpn calculator isn't loaded yet.
//
// for_pre command -------------------------------------------------------------------------
// syntax: for cvar1 to value1 do alias1
// cvar1 is a variable name that is used for a loop counter
// value1 can be a number from 2 to 20
// alias1 can be a command or an alias and can
// include parameters if quoted
// for_pre_exit can be executed to leave the loop early
// description: Executes an alias up to 20 times, incrementing the
// value of the loop variable each time it runs.
// for_pre works when Nexuiz first loads.
// The regular for only works after a game starts.
// example: alias my_count_alias "echo loop $i"
// for_pre i upto 5 do my_count_alias
// -> loop 1
// -> loop 2
// -> loop 3
// -> loop 4
// -> loop 5
// warning: The maximum number of loops is 20. Any other value is treated as a 1
// If you need more, you would have to edit the for_pre code.
//
// for command -------------------------------------------------------------------------
// syntax: for cvar1 from value1 to value2 by value3 do alias1
// cvar1 is a variable name that is used for a loop counter
// value1, value2 and value3 are numbers
// alias1 can be a command or an alias and can
// include parameters if quoted
// for_exit can be executed to leave the loop early
// description: Executes an alias in a loop, incrementing the
// value of the loop variable each time it runs.
// example: alias my_count_alias "echo loop $i"
// for i from 2 to 10 by 2 do my_count_alias
// -> loop 2
// -> loop 4
// -> loop 6
// -> loop 8
// -> loop 10
// warning: 1. If value1, value2 or value3 are strings they will be treated as 0.
// 2. Must be used after Nexuiz loads. Use for_pre during startup.
// That is, using if_num in an alias or bind is fine if it runs
// after Nexuiz loads, but it can't be used directly in autoexec.cfg
// since the rpn calculator isn't loaded yet.
//
// math command -------------------------------------------------------------------------
// syntax: math cvar1 eq value1 operator1 value2
// cvar1 is the name of the variable that gets the result
// operator1 is one of the following:
// add, sub (subtract)
// mul (multiply), div (divide)
// mod (modulus), max (maximum), min (minimum)
// The operators below return a 1 for true and a 0 for false:
// eq (equal)
// ne (not equal)
// gt (greater than)
// lt (less than)
// ge (greater than or equal to)
// le (less than or equal to)
// value1 and value2 are numbers
// description: does a math or comparison calculation and stores the
// result in the specified variable.
// example: set x 10
// math x eq $x add 5
// echo $x
// -> 15
// math x eq 100 div 3.5
// echo $x
// -> 28.571428
// math x eq 5 gt 3.5
// echo $x
// -> 1
// warning: 1. If value1or value2 are strings they will be treated as 0.
// 2. Must be used after Nexuiz loads. Use for_pre during startup.
// That is, using if_num in an alias or bind is fine if it runs
// after Nexuiz loads, but it can't be used directly in autoexec.cfg
// since the rpn calculator isn't loaded yet.
//
// input_number command -----------------------------------------------------------------
// syntax: input_number alias1
// alias1 is the alias that is called, passing the number pressed as $1
// description: gets numbers pressed by player until enter is pressed
// and stores the result in the specified variable.
// example: alias aot_inputfov "set fov $1"
// bind b "input_number aot_inputfov"
// [player types b then 130 then ENTER]
// -> [fov is set to 130]
// warning: This only works in a game, since typing in the console just types.
//
// input_digit command ------------------------------------------------------------------
// syntax: input_digit alias1
// alias1 is the alias that is called, passing the digit pressed as $1
// description: gets a single numeric digit pressed by player
// and passes the result to the specified alias or command.
// example: alias tell_hi "tell #${1} hi"
// bind b "input_digit tell_hi"
// [player presses b then 3]
// AceOfThumbs tells player #3 -> hi
// warning: This only works in a game, since typing in the console just types.
//
// aot_userbind command -----------------------------------------------------------------
// syntax: aot_userbind
// description: Searches userbinds for a specified bind name.
// If found, it does nothing.
// If not found, it searches for first empty slot and stores the bind.
// If there are no empty lots, it does a normal bind
// example: set aot_userbind_key "MOUSE4"
// set aot_userbind_name "quick_zoom - hold for 2x zoom"
// set aot_userbind_alias "+aot_zoom_temp"
// set aot_userbind_alias_release "-aot_zoom_temp"
// aot_userbind
// -> quick_zoom - hold for 2x zoom is in userbind 3