{{tag>proxy part}} {{htmlmetatags>metatag-keywords=(pac3, wiki, part, proxy, expression) metatag-description=(Alters a value based on a mathematical expression.) metatag-og:title=(Proxy | Part) metatag-og:description=(Alters a value based on a mathematical expression.) }} ====== Proxy ====== Alters a value based on a mathematical expression. {{fa>info?color=#3bb0ff&fw&lg}} Easy setup is useless, learn expressions. ===== Location ===== This part can be found under: * :poseparameter: **Modifier** > [[:part:proxy]] {{page>:includes#location}} ===== Usage & Examples ===== ==== Basic proxy ==== * Add a [[:part:proxy]] part to an existing part * Enter the name of the value with you want changed into [[#variable name]] or click the (...) button to browse available part parameters * Enter a value or mathematical expression into [[#expression]] (such as 2+2 or sin(time())) {{fa>download?color=#7ab353&fw&lg}} **Download:** {{:part:proxy:proxy_basic.txt}} ==== Proxy targets ==== Proxies can affect parts that are not directly connected to them. Enter the name of the part into [[#target-part]] or select it with the (...) button. {{fa>download?color=#7ab353&fw&lg}} **Download:** {{:part:proxy:proxy_target.txt}} ==== Button Controlled Proxy - Simple Switch ==== Simple proxy switch. Press R and T to change size. {{fa>download?color=#7ab353&fw&lg}} **Download:** {{:part:proxy:proxy_button.txt}} ==== Button Controlled Proxy - Feedback + Command ==== The command() proxy can be changed at any time by using console commands, it can be used together with feedback() to affect the previous proxy value. Below you'll find a simple example that lets you change the scale of a model using buttons (Hold F to scale up and R to scale down.) {{fa>download?color=#7ab353&fw&lg}} **Download:** {{:part:proxy:proxy_button_feedback.txt}} ==== Affect children ==== [[#Affect children]] sets the proxy to affect all of its children instead of the parent. This also disables the [[#target part]] field. ==== Multiple axes ==== Each proxy can use up to 3 [[#expression|expressions]], one for each axis (**X**, **Y**, **Z**). These expressions need to be separated with a comma , Setting a value as nil or null will ignore the given axis. Expression set to time(), null, 2+2 will set the **X** axis to **time()**, ignore the **Y** axis and set the **Z** axis to **4**. {{fa>download?color=#7ab353&fw&lg}} **Download:** {{:part:proxy:proxy_axis.txt}} {{fa>fas fa-exclamation-circle?color=#ff9900&fw&lg}} This method conflicts with the [[#axis]] field, if you wanna use it make sure that the [[#axis]] field is empty. ===== Functions and Operations ===== The following is a list of operations/functions available to use in the [[#expression]] ^**//Operation//** ^ **//Operator//** ^ **//Example//** ^ |Multiplication | * | time()*2 | |Division | / | time()/2 | |Addition | + | time()+2 | |Subtraction | - | time()-2 | |Parentheses | () | 3*(time()+2) | |Exponent | ^ | time()^2 | |[[https://en.wikipedia.org/wiki/Modular_arithmetic|Modulus]] | % | time()%2 | \\ //To use, enter an input value or expression between the parenthesis. Remember to respect the number of arguments in the function, since not all functions have one argument. clamp(x, %%min%%, %%max%%) for example has three arguments.// ^**//Function//** ^ **//Explanation//** ^ |**abs(x)**| Returns the [[https://en.wikipedia.org/wiki/Absolute_value|absolute value]] of a given number. \\ **x** --- a number| |**sgn(**x**)**| Returns the sign of the given number (-1 for values below 0, 0 for 0 and 1 for values above 0). \\ **x** --- a number| ^ ^^ |**ceil(**x**)**| Rounds a number up. \\ **x** --- a number| |**floor(**x**)**| Rounds a number down. \\ x --- a number| ^ ^^ |**min(**numbers**)**| Returns the smallest value of all arguments. \\ **numbers** --- numbers to get the smallest from, separated with a comma (**,**) | |**max(**numbers**)**| Returns the largest value of all arguments. \\ **numbers** - numbers to get the largest from, separated with a comma (**,**) | |**clamp(**x**, **%%min%%**, **%%max%%**)**| Clamps a number between a minimum and maximum value. \\ **x** - the input value/function \\ **%%min%%** - the minimum value that the function can return \\ **%%max%%** - the maximum value that the function can return | ^ ^^ |**PI**| This is **NOT** a function, it's a variable containing the mathematical constant pi: 3.1416...| |**log(x, base)**| With one argument, returns the natural logarithm of **x** (to base e). With two arguments, returns the logarithm of **x** to the given **base**. \\ **x** - a number\\ **base** - the logarithmic base, optional| |**log10(x)**| Returns the base-10 logarithm of **x**. This is usually more accurate than **log(**x**, 10)**. \\ **x** --- a number| |**sqrt(**x**)**| Returns the square root of the number. \\ **x** - a number| |**rand(**m**, **n**)**| When called without arguments returns a random float between 0 and 1. When called with one argument (**m**) returns an integer between 1 and **m**. When called with both arguments (**m** and **n**) returns an integer between **m** and **n**.\\ **m** - lower limit (two arguments) or upper limit (one argument) \\ **n** - upper limit| |**randx(**min**, **max**)**| Returns a random float between min and max. \\ **min** - the minimum value \\ **max** - the maximum value| ^ ^^ |**rad(x)**| Returns the value converted to radians. \\ **x** - the angle measured in degrees | |**deg(x)**| Returns the value converted to degrees. \\ **x** - the angle measured in radians | ^ ^^ |**sin(x)**| Returns the [[http://en.wikipedia.org/wiki/sine|sine]] of a given angle. \\ **x** - angle in radians| |**asin(sin)**| Returns the [[http://en.wikipedia.org/wiki/arc_sine|arc sine]] (an angle in radians, between -PI/2 and PI/2, which has the given sine value). NaN if the argument is out of range. \\ **sin** - sine value in range of -1 to 1| |**sinh(x)**| Returns the [[http://en.wikipedia.org/wiki/hyperbolic_sine|hyperbolic sine]] of the given angle. \\ **x** - angle in radians| ^ ^^ |**cos(x)**| Returns the [[http://en.wikipedia.org/wiki/cosine|cosine]] of a given angle. \\ **x** - angle in radians| |**acos(cos)**| Returns the [[http://en.wikipedia.org/wiki/arc_cosine|arc cosine]] (an angle in radians, between 0 and PI, which has the given cosine value). NaN if the argument is out of range. \\ **cos** - cosine value in range of -1 to 1| |**cosh(x)**| Returns the [[http://en.wikipedia.org/wiki/hyperbolic_cosine|hyperbolic cosine]] of the given angle. \\ **x** - angle in radians| ^ ^^ |**tan(x)**| Returns the [[http://en.wikipedia.org/wiki/tangent_(trigonometry)|tangent]] of a given angle. \\ **x** - angle in radians| |**atan(tan)**| Returns the [[http://en.wikipedia.org/wiki/arc_tangent|arc tangent]] (an angle in radians, between -pi/2 and pi/2, which has the given tangent value). \\ **tan** - a tangent value| |**atan2(y, x)**| Returns the [[https://en.wikipedia.org/wiki/Atan2|2-argument arc tangent]] (the angle of the line from (0, 0) to (x, y) in radians, between -PI and PI). \\ **y** - Y coordinate \\ **x** - X coordinate| |**tanh(x)**| Returns the [[http://en.wikipedia.org/wiki/hyperbolic_tangents|hyperbolic tangent]] of the given angle. \\ **x** - angle in radians| \\ ===== Miscellaneous Functions ===== //Remember to include the parentheses for each function even if there is nothing between them. Most of these are nullary functions (without arguments) but they are nevertheless Lua functions that need to be written with proper syntax to be interpreted as such.// {{fa>info?color=#3bb0ff&fw&lg}} For the full list, you may consult the code here in case we missed some or add more in the future: https://github.com/CapsAdmin/pac3/blob/develop/lua/pac3/core/client/parts/proxy.lua ^**//Function//** ^ **//Explanation//** ^ |**aim_length()**| Returns the distance between a model and the point it is aiming at (aim direction is defined by the red arrow). Maximum distance is 16000.| |**aim_length_fraction()**| Same as above but outputs a fraction calculated from distance/16000.| |**part_distance(uid1, uid2)** | Measures the distance between two base_movable parts (models, bones, sprites, etc). You can find out a part's Unique ID by selecting the part and going to tools - "copy global id". \\ **uid1** - the first Unique ID to search for a part. \\ **uid2** - the second Unique ID to search for a part.| |**event_alternative(**event_uid**, **a**, **b**)** | A simple if/else statement. Searches a part's UID and tries to get its state if it's an event. If the event is showing, returns **a**, otherwise returns **b**.| |**number_operator_alternative(**number1**, **operator**, **number2**, **a**, **b**)** | A simple if/else statement. Computes a number comparison based on **number1**, **operator** and **number2**. If it's true, returns **a**, otherwise returns **b**. \\ For example: number_operator_alternative(1,">",0,2,3) means if 1 is above 0 (which it is), returns 2, otherwise returns 3. Different choices for the operator: \\ equal: "=", "==", "equal" \\ above: ">", "above", "greater", "greater than" \\ equal or above: ">=", "above or equal", "greater or equal", "greater than or equal" \\ below: "<", "below", "less", "less than" \\ equal or below: "<=", "below or equal", "less or equal", "less than or equal" \\ not equal: "~=", "not equal"| |**ambient_light_r()**| Returns the RED color value of the ambient color of the map.| |**ambient_light_g()**| Returns the GREEN color value of the ambient color of the map.| |**ambient_light_b()**| Returns the BLUE color value of the ambient color of the map.| |**command()** | Can be controlled by the pac_proxy console command.\\ is name of the proxy part you want to affect\\ is the value you want to set it to.| |**command(**name**)** | The same as command(), controlled by the same pac_proxy console command, but with this extra string argument, the function will search for the registered value by **name** directly instead of requiring the proxy part to be named.| |**eye_angle_distance()** | Returns the normalized distance between the object and the view angle. Looking directly at the object equals 0.5, looking away from the object lowers the value. There is no negative values so an object that is directly behind your view angle also equals 0.5. | |**eye_position_distance()** | Returns the distance between the object and the view position. | |**feedback()** | Returns the proxy's previous value. | |**feedback_x()** or **feedback_y()** or **feedback_z()** | Returns the proxy's previous value on a given axis. | |**framenumber()** or **fnumber()** | Returns the number of frames rendered since the game was launched. | |**frametime()** or **ftime()** | Returns the time in seconds it took to render the last frame. Equal to [[https://wiki.garrysmod.com/page/Global/FrameTime|FrameTime]] | |**hsv_to_color(h, s, v)** | Converts {{ :asset:hsv.png?linkonly|HSV}} formatted color into RGB formatted color. Returns red, green, blue. \\ **h** - color hue, from 0 to 360 \\ **s** - color saturation, optional, from 0 to 1, default is 1 \\ **v** - color value, optional, from 0 to 1, default is 1 | |**lerp(f, start, end)** | Linear interpolation from one value to another. \\ **f** - the fraction for finding the result \\ **start** - the starting number, the result will be equal to this when **f** is 0 \\ **end** - the ending number, the result will be equal to this when **f** is 1| |The Ease Library. \\ **Ease(f, start, end)** | Similar to lerp but more special. Interpolates from one value to another with more choices of curves that lead to more dynamic movement. https://wiki.facepunch.com/gmod/math.ease \\ **f** - the fraction for finding the result \\ **start** - the starting number, the result will be equal to this when **f** is 0 \\ **end** - the ending number, the result will be equal to this when **f** is 1 \\ For every type of interpolation (InSine, InOutSine, OutSine, InElastic, ...), there are different ways to access it for convenience: easeX, ease_X, X. \\ For instance, InSine, easeInSine and ease_InSine are all aliases that lead to the same function. | |**light_amount_r()**| Returns the RED color value of the light amount at the current position of the object.| |**light_amount_g()**| Returns the GREEN color value of the light amount at the current position of the object.| |**light_amount_b()**| Returns the BLUE color value of the light amount at the current position of the object.| |**light_value()**| Returns the light value in 0 to 1 range.| |**owner_armor()**| Returns the amount of player's armor.| |**owner_eye_angle_pitch()**| Returns the pitch value of the owner's eye angle in the -0.0056179768 (looking down) to 1.0056179768 (looking up) range. This is limited to 0-1 (89°) for players.| |**owner_eye_angle_yaw()**| Returns the yaw value of the owner's eye angle in the -2 to 2 range. Multiply by 90 to match object's yaw to owner's yaw.| |**owner_eye_angle_roll()**| Returns the roll value of the owner's eye angle in the -2 to 2 range. Multiply by 90 to match object's roll to owner's roll.| |**owner_fov()**| Returns the owner's field of view value.| |**owner_health()**| Returns the owner's health value.| |**owner_max_health()**| Returns the owner's maximum health value.| |**owner_position()**| Returns the owner's X,Y,Z position.| |**owner_position_x()**| Returns the owner's X position.| |**owner_position_y()**| Returns the owner's Y position.| |**owner_position_z()**| Returns the owner's Z position.| |**owner_scale_x()** or **owner_scale_y()** or **owner_scale_z()**| Returns the owner's scale on a given axis. | |**visible()**| Outputs whether the part is visible within a radius. Morphs between 0 and 1. | radius | x | |**time()** | Outputs a time value that is not synced/affected by the game ( equal to [[https://wiki.garrysmod.com/page/Global/RealTime|RealTime]] ) | | x | |**synced_time()** | Outputs a time value that is synced to the game ( equal to [[https://wiki.garrysmod.com/page/Global/CurTime|CurTime]] ) | | x | |**systime()** or **stime()** | Returns a highly accurate time in seconds since the start up | |**frametime()** or **ftime()** | Returns the [[https://wiki.garrysmod.com/page/Global/CurTime|CurTime]]-based time in seconds it took to render the last frame. Equal to [[https://wiki.garrysmod.com/page/Global/FrameTime|FrameTime]] | |**framenumber()** or **fnumber()**| Returns the number of frames rendered since the game was launched. | |**random()** | Quickly outputs random numbers between 0 and 1 | | x | |**random(**min**, **max**)** | The same as random(), but with additional optional arguments, similar to rand(m,n) \\ **min** - minimum value, if specified. otherwise 0 \\ **max** - maximum value, if specified. otherwise 1| | x | |**random_once(**id**, **min**, **max**)** | generates a random value only once, and the part can reuse this value many times as long as it's identified with a "seed" (although it's not technically a seed for predictable number generation, it's just an unique identifier we have to use in case we want more separate random values) \\ For example, we might have 50*random_once(),50*random_once(),50*random_once() but it would output the same values e.g. 35.6123,35.6123,35.6123 because of the limitations of the part and the code. 50*random_once(1),50*random_once(2),50*random_once(3) would yield separate generations e.g. 35.6123,83.41263,15.2142 \\ **min** - minimum value, if specified. otherwise 0 \\ **max** - maximum value, if specified. otherwise 1 | | x | |**timeex()** | Outputs a time value that begins to count the seconds when the proxy is shown | | x | |**eye_position_distance()** | Outputs the distance between the part and eye position | | x | |**eye_angle_distance()** | Outputs the distance between the part and eye angle | | x | |**owner_velocity_length()** | Outputs the velocity of the owner, in any direction | | x | |**owner_velocity_forward()** | Outputs the velocity of the owner, either forwards or backwards | | x | |**owner_velocity_right()** | Outputs the velocity of the owner, either right or left | | x | |**owner_velocity_up()** | Outputs the velocity of the owner, either up or down | | x | |**owner_velocity_length_increase()** | Outputs the velocity of the owner, in any direction ( additive ) | | x | |**owner_velocity_forward_increase()** | Outputs the velocity of the owner, either forwards or backwards ( additive )| | x | |**owner_velocity_right_increase()** | Outputs the velocity of the owner, either right or left ( additive ) | | x | |**owner_velocity_up_increase()** | Outputs the velocity of the owner, either up or down ( additive )| | x | |**parent_velocity_length()** | Outputs the velocity of the parent part, in any direction | | x | |**parent_velocity_forward()** | Outputs the velocity of the parent part, either forwards or backwards | | x | |**parent_velocity_right()** | Outputs the velocity of the parent part, either right or left | | x | |**parent_velocity_up()** | Outputs the velocity of the parent part, either up or down | | x | |**voice_volume()** | Outputs a number between 0 and 1 based on the owner's voice chat microphone input | | x | |**pose_parameter(**name**)** | Returns the value of the owner's pose parameter **name**, but normalized between 0 and 1 \\ For example you need a (-1+2*pose_parameter("head_yaw")) unit to make a symmetrical value range based on your head's yaw. | | x | |**pose_parameter_true(**name**)** | Returns the value of the owner's pose parameter **name**, but unnormalized to its actual value. | | x | |**owner_health()** | Outputs how much health the owner has | | x | |**owner_armor()** | Outputs how much armor the owner has | | x | |**owner_max_armor()** | Outputs the maximum armor of the owner | | x | |**owner_max_health()** | Outputs the maximum health of the owner | | x | |**owner_health_fraction()** | Outputs the health of the owner as a fraction (0 to 1) | | x | |**owner_armor_fraction()** | Outputs the armor of the owner as a fraction (0 to 1) | | x | |**player_color_r()** | Outputs the red value of the owner's player color ( between 0 and 1 ) | | x | |**player_color_g()** | Outputs the green value of the owner's player color ( between 0 and 1 ) | | y | |**player_color_b()** | Outputs the blue value of the owner's player color ( between 0 and 1 ) | | z | |**weapon_color_r()** | Outputs the red value of the owner's weapon color ( between 0 and 1 ) | | x | |**weapon_color_g()** | Outputs the green value of the owner's weapon color ( between 0 and 1 ) | | y | |**weapon_color_b()** | Outputs the blue value of the owner's weapon color ( between 0 and 1 ) | | z | Remember that all of the functions above can be mixed together, you can use one function as input for another, add functions together, etc. ===== Expression Examples ===== ==== Clamp (Min/Max Value) ==== Example: clamp(5 + timeex(), 5, 10) When shown, the proxy starts at 5 and moves up over time thanks to timeex(), clamp(input, min, max) is used to limit the output so the value never goes above 10. ==== Rainbow Color ==== Example: hsv_to_color(timeex() * 50) Here timeex() is used as the (h)ue input for hsv_to_color(h, s, v) which changes the color over time. Multiplying the timeex() by 50 speeds up the color transition. {{fa>download?color=#7ab353&fw&lg}} **Download:** {{:part:proxy:hsv.txt}} \\ ===== Properties ===== ^//**easy setup**// ^^ |input | //Select a miscellaneous function// | |function | //Select a math function to act on the miscellaneous function ( none = use misc. function directly )// | |axis | //(??)// FIXME | |min | //Sets the minimum value that the function may be ( if a sine or cosine )// | |max | //Sets the maximum value that the function may be ( if a sine or cosine )// | |offset | //Sets the horizontal offset ( adding/removing the input before applying the function, ie. sin(time()-2) )// | |input multiplier | //Multiplies the input before applying the function, ie. sin(time()*2))// | |input divider | //Divides the input before applying the function, ie. sin(time()/2))// | |pow | //Raises the entire expression up by an exponential power, ie. sin(time())^2// | ^//**behavior**//^^ |additive | //Determines whether to output normally ( disabled ) or add each output to the previous output ( enabled )// | |player angles | //(??)// FIXME | |zero eye pitch | //(??)// FIXME | |reset velocities on hide | //Determines whether to treat velocity functions normally ( disabled ) or set them to 0 upon hiding/unhiding ( enabled )// | |velocity roughness | //Sets how quickly velocity functions change their value// | ^//**generic**// ^^ |variable name | //The name of the value you'd like the proxy to alter// | |root owner | //(??)// FIXME | |target part name | //Name of a part to be affected by the proxy ( leave empty to affect the parent or child of the proxy )// | |affect children | //Determines whether to affect a target part or parent ( disabled ) or affect all of the proxy's children ( enabled )// | |expression | //A mathematical expression to alter the value ( overrides ''easy setup'' )// | |name | //The name of the proxy ( not altering this will allow the proxy to display its output )// | |hide | //Determines whether to render the proxy or ignore/hide it// | |is disturbing | //Determines whether to hide the proxy for players who have pac_hide_disturbing set to 1// | ^//**orientation**// ^^ |parent name | //The name of the proxy's parent part ( the proxy will move under said part if you decide to change this )// | ---- ~~AUTHORS~~