# Math Formulas

A page dedicated for helping users of Ssomar's plugins to create more complex things that require advanced math formulas

### Player-Direction Offset Formula

X: %math_2*SIN({player_yaw}*-1)*COS({player_pitch}*-1)%
Y: %math_2*SIN({player_pitch}*-1)%
Z: %math_2*COS({player_yaw}*-1)*COS({player_pitch}*-1)%
Requires: - PlaceholderAPI & Math Expansion
Example Usage:
- execute at %player% run particle flame ~ ~1.6 ~ %math_2*SIN({player_yaw}*-1)*COS({player_pitch}*-1)% %math_2*SIN({player_pitch}*-1)% %math_2*COS({player_yaw}*-1)*COS({player_pitch}*-1)% 0.7 0
Command below shoots firework particles like a shotgun (Commands below are in config form)
- 'LOOP START: 20'
- 'RANDON RUN: 1'
- execute at %player% run particle firework ~ ~1.6 ~ %math_2*SIN(({player_yaw}+{rng_-10,10})*-1)*COS(({player_pitch}+{rng_-10,10})*-1)%
%math_2*SIN(({player_pitch}+{rng_-10,10})*-1)% %math_2*COS(({player_yaw}+{rng_-10,10})*-1)*COS(({player_pitch}+{rng_-10,10})*-1)%
0.%rng_5,70% 0
- RANDOM END
- LOOP END
How this works is that, a RNG placeholder was used to add/subtract values from your yaw pitch values in the formula so it would try to "spread" out the particles.
Basically the rng placeholders are there just to "make" you look somewhere since the math formula depends on your yaw pitch values.
The reason why there's a *-1 in the formula because when the original formula was used, it made particles move in complete opposite of where you're looking at
You can also use this very same method to perform directional dashes which FRONTDASH is unable to perform
- CUSTOMDASH1 %math_{player_x_long}+(2*SIN({player_yaw}*-1)*COS({player_pitch}*-1))%
%math_{player_y_long}+(2*SIN({player_pitch}*-1))% %math_{player_z_long}+(2*COS({player_yaw}*-1)*COS({player_pitch}*-1))%
You could use (%x%) instead of {player_x_long] but I'll explain the more detailed stuff.
The formula above ONLY gets the displacement between 2 points but CUSTOMDASH1 requires the xyz location because it doesn't have your xyz location as a reference so you have to add your xyz values to the equation to properly launch yourself towards your direction. To increase the speed of the launch, increase the distance value which is the "2" value that you can see in the math formula.
As to why you have to use the xyz placeholder that gives decimal values instead of non-decimal values, it is to make sure you're landing at the correct location or else you would be flying off somewhere.

### Distance from XYZ

Requires: - PlaceholderAPI - Math Expansion - Player Expansion
Example Usage: You want to get the distance between you and a specific XYZ location which is x:30, y:60, z:-120
%math_0_(ABS({player_x}-(30))+ABS({player_y}-(60))+ABS({player_z}-(-120)))%
How this works is that it computes the difference between your x coordinates and the mentioned x coordinates then sets the difference into absolute value so it would always be a positive number no matter what. Same goes for computing the difference of y and z coordinates.
After getting the absolute values of the difference of the x y z values, it adds it up and you get the sum of the distance between your location and the said location.

## Using offsets to distance target from location

X: %math_(<x>)+(((<x>)-({player_x}))*-(<multiplier>))%
Y: %math_(<y>)+(((<y>)-({player_y}))*-(<multiplier>))%
Z: %math_(<z>)+(((<z>)-({player_z}))*-(<multiplier>))%
How this works is first, you get the displacement of 2 points.
The formula above for example, would use the target block's xyz and the player's xyz values to get the displacement between the 2 points then add it along with the target block's xyz coordinates so you would be able to either pull yourself more towards the location or away from the location.
The formula currently has `*-(<multiplier>)` at where it is at. The higher the number in `<multiplier>`, the greater the displacement value. If you want to distance the user away from that point, use the negative symbol. Otherwise, remove the negative symbol to further pull the player towards the location
Example Usage:
commands:
- CUSTOMDASH1 %math_(%block_x%)+(((%block_x%)-({player_x}))*-2)% %math_(%block_y%)+(((%block_y%)-({player_y}))*-2)%
%math_(%block_z%)+(((%block_z%)-({player_z}))*-2)%

## Threshold Value Math Formula

%math_{player_health}-IF({player_health}>500, {player_health}-500, 0)%
This is an example of a math formula where it deals with the player health placeholder. But if the player health value surpasses the value of 500, it will stop there.
The detailed explanation goes like this. in the IF() formula, it first checks if the placeholder would return a number greater than 500.
• If the placeholder's value is greater than 500, it would get the difference between the placeholder's value and 500 and use that value to subtract from the placeholder's value to prevent it from going above 500.
• If the placeholder's value is less than 500, nothing happens