BlackBeltPanda

Math

May 28th, 2014
699
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.40 KB | None | 0 0
  1. #Square root, nth root, arc sin, arc tan, and arc cos functions courtesy of "bi0qaw" (http://dev.bukkit.org/profiles/bi0qaw/)
  2. #Rotation function courtesy of "Cool3303" (http://dev.bukkit.org/profiles/Cool3303/)
  3. #These commands should be able to approximate the functions of the number argument passed to them to an accuracy of about {@accuracy}
  4. #Remember to change your "number accuracy:" in your Skript config file to {@accuracy} for best results.
  5.  
  6. Options:
  7. accuracy: 10 #How accurate should our numbers be? 10 is accurate to 7-10 decimal places usually
  8. permission: "math.calc" #Permission node required to execute the math commands
  9. message: "true" #Whether or not to message the results to the player executing the command
  10. e: 2.7182818284
  11. pi: 3.14159265358979323846
  12.  
  13. #Calculate the square root of a number by exponentiating by 0.5
  14. Command /sqrt <number>:
  15. Permission: {@permission}
  16. Trigger:
  17. Set {_x} to number-argument
  18. If {_x} is smaller than 0:
  19. If {@message} is "true":
  20. Send "You cannot square root a negative number!"
  21. Stop
  22. Set {_x} to {_x}^0.5
  23. Set {sqrt.value} to {_x}
  24. If {@message} is "true":
  25. Send "%{sqrt.value.%player%}%" to player
  26.  
  27. #Calculate the nth-root of a number by exponentiating by 1/n
  28. Command /rt <integer> <number>:
  29. Permission: {@permission}
  30. Usage: /rt <root-number> <number>
  31. Trigger:
  32. Set {_x} to number-argument-2
  33. Set {_n} to integer-argument-1
  34. If {_x} is smaller than 0:
  35. If {@message} is "true":
  36. Send "You cannot root a negative number!"
  37. Stop
  38. Set {_x} to {_x}^(1/{_n})
  39. Set {rt.value} to {_x}
  40. If {@message} is "true":
  41. Send "%{rt.value.%player%}%" to player
  42.  
  43. #Calculate the factorial of a number
  44. Command /fact <number>:
  45. Permission: {@permission}
  46. Trigger:
  47. Set {_x} to number-argument
  48. Set {_i} to {_x} - 1
  49. Loop {_i} times:
  50. Set {_x} to {_x} * {_i}
  51. Subtract 1 from {_i}
  52. Set {fact.value} to {_x}
  53. If {@message} is "true":
  54. Send "%{fact.value.%player%}%" to player
  55.  
  56. #Calculate the sine of a degree by converting it to radians and looping through a Taylor Series formula
  57. Command /sin <number>:
  58. Permission: {@permission}
  59. Trigger:
  60. Set {_x} to (number-argument / 180) * {@pi}
  61. Set {_s} to {_x}
  62. Loop {@accuracy} times:
  63. Set {_n} to loop-number * 2 + 1
  64. Execute console command "/fact %{_n}%"
  65. Set {_f} to {fact.value}
  66. Set {_s} to {_s} + (({_x} ^ {_n}) / {_f}) * (-1 ^ loop-number)
  67. Set {sin.value} to {_s}
  68. If {@message} is "true":
  69. Send "%{sin.value}%" to player
  70.  
  71. #Calculate the cosine of a degree by converting it to radians and looping through a Taylor Series formula
  72. Command /cos <number>:
  73. Permission: {@permission}
  74. Trigger:
  75. Set {_x} to (number-argument / 180) * {@pi}
  76. Set {_c} to 1
  77. Loop {@accuracy} times:
  78. Set {_n} to loop-number * 2
  79. Execute console command "/fact %{_n}%"
  80. Set {_f} to {fact.value}
  81. Set {_c} to {_c} + (({_x} ^ {_n}) / {_f}) * (-1 ^ loop-number)
  82. Set {cos.value} to {_c}
  83. If {@message} is "true":
  84. Send "%{cos.value}%" to player
  85.  
  86. #Calculate the tangent of a degree
  87. Command /tan <number>:
  88. Permission: {@permission}
  89. Trigger:
  90. Execute console command "/sin %number-argument%"
  91. Set {_sin} to {sin.value}
  92. Execute console command "/cos %number-argument%"
  93. Set {_cos} to {cos.value}
  94. Set {_t} to {_sin} / {_cos}
  95. Set {tan.value} to {_t}
  96. If {@message} is "true":
  97. Send "%{tan.value}%" to player
  98.  
  99. #Calculate the arcsine of a sine of a degree
  100. Command /arcsin <number>:
  101. Permission: {@permission}
  102. Usage: /arcsin <sin(degree)>
  103. Trigger:
  104. Set {_x} to number-argument
  105. If {_x} is smaller than -1:
  106. Send "The value has to be bigger/equal to -1" to player
  107. If {_x} is bigger than 1:
  108. Send "The value has to be smaller/equal to 1" to player
  109. Execute console command "/arccos %{_x}%"
  110. Set {_ac} to {arccos.value}
  111. Set {_ac} to {_ac} * 2 * {@pi} / 360
  112. Set {_as} to ({@pi} / 2 - {_ac}) * 360 / (2 * {@pi})
  113. Set {arcsin.value} to {_as}
  114. If {@message} is "true":
  115. Send "%{arcsin.value}%" to player
  116.  
  117. #Calculate the arccosine of a cosine of a degree
  118. Command /arccos <number>:
  119. Permission: {@permission}
  120. Usage: /arccos <cos(degree)>
  121. Trigger:
  122. Set {_x} to number-argument
  123. If {_x} is smaller than -1:
  124. Send "The value has to be bigger/equal to -1" to player
  125. If {_x} is bigger than 1:
  126. Send "The value has to be smaller/equal to 1" to player
  127. Set {_ac} to ((-0.69813170079773212 * {_x} * {_x} - 0.87266462599716477) * {_x} + 1.5707963267948966) * 360 / (2 * {@pi})
  128. Set {arccos.value} to {_ac}
  129. IF {@message} is "true":
  130. Send "%{arccos.value}%" to player
  131.  
  132. #Calculate the arctangent of a tangent of a degree
  133. Command /arctan <number>:
  134. Permission: {@permission}
  135. Usage: /arctan <tan(degree)>
  136. Trigger:
  137. Set {_x} to number-argument
  138. If {_x} is smaller than -1:
  139. Send "The value has to be bigger/equal to -1" to player
  140. stop
  141. If {_x} is bigger than 1:
  142. Send "The value has to be smaller/equal to 1" to player
  143. stop
  144. Set {_absx} to ({_x} ^ 2) ^ 0.5
  145. Set {_at} to ({@pi} / 4 * {_x} - ({_absx} - 1) * (0.2447 + 0.0663 * {_absx})) * 360 / (2 * {@pi})
  146. Set {arctan.value} to {_at}
  147. If {@message} is "true":
  148. Send "%{arctan.value}%" to player
  149.  
  150. #Calculate a rotation
  151. Command /rotate <number> <number>:
  152. Permission: {@permission}
  153. Trigger:
  154. Set {_Radius} to argument 1
  155. Set {_Angle} to argument 2
  156. Set {_Number} to floor( 360 / {_Angle} )
  157. Loop {_Number} times:
  158. If {_Current} is not set:
  159. Set {_Current} to 0
  160. Else:
  161. Add {_Angle} to {_Current}
  162. Set {_x} to ( {_Current} / 180 ) * 3.14159265358979323846
  163. Set {_c} to 1
  164. Loop 10 times:
  165. Set {_n} to loop-number-2 * 2
  166. Set {_f} to {_n}
  167. Set {_i} to {_f} - 1
  168. Loop {_i} times:
  169. Set {_f} to {_f} * {_i}
  170. Subtract 1 from {_i}
  171. Set {_c} to {_c} + (({_x} ^ {_n}) / {_f}) * (-1 ^ loop-number-2)
  172. Set {_c} to ( {_c} * {_Radius})
  173. Set {_s} to {_x}
  174. Loop 10 times:
  175. Set {_n} to loop-number-2 * 2 + 1
  176. Set {_f} to {_n}
  177. Set {_i} to {_f} - 1
  178. Loop {_i} times:
  179. Set {_f} to {_f} * {_i}
  180. Subtract 1 from {_i}
  181. Set {_s} to {_s} + (({_x} ^ {_n}) / {_f}) * (-1 ^ loop-number-2)
  182. Set {_s} to ( {_s} * {_Radius})
  183. Set {_Particlespawn} to location of player
  184. Increase x-coordinate of {_Particlespawn} by {_c}
  185. Increase Z-coordinate of {_Particlespawn} by {_s}
  186. Set {rotate.value} to {_Particlespawn}
  187. If {@message} is "true":
  188. Broadcast "%{_Particlespawn}%"
Advertisement
Add Comment
Please, Sign In to add comment