Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. $${
  2. // Calc v 1.3
  3. // Bind to onSendChatMessage
  4. // Made by Mel
  5.  
  6. //lol idk what my code does
  7. //comments look pretty
  8. STRIP(&chat,%CHAT%)
  9. IFMATCHES(%&chat%,"^(/?)/calc")
  10. IFMATCHES(%&chat%,"^(/?)/calc$")
  11. SET(&calc,"help")
  12. ELSE
  13. MATCH(%&chat%,"calc (.*)$",{&calc})
  14. REPLACE(&calc," ")
  15. ENDIF
  16.  
  17. IFMATCHES(%&calc%,"^-?[0-9]+(\.[0-9]+)*([*/+-]-?[0-9]+(\.[0-9]+)*)*$")
  18.  
  19. //infinite loops are bad
  20. DO(100)
  21.  
  22. //Order of Operations
  23. IFMATCHES(%&calc%,"(-?[0-9]+(?:\.[0-9]+)*)([*/])(-?[0-9]+(?:\.[0-9]+)*)")
  24. MATCH(%&calc%,"(-?[0-9]+(?:\.[0-9]+)*)([*/])(-?[0-9]+(?:\.[0-9]+)*)",{&num1,&operator,&num2})
  25. ELSE
  26. IFMATCHES(%&calc%,"(-?[0-9]+(?:\.[0-9]+)*)([+-])(-?[0-9]+(?:\.[0-9]+)*)")
  27. MATCH(%&calc%,"(-?[0-9]+(?:\.[0-9]+)*)([+-])(-?[0-9]+(?:\.[0-9]+)*)",{&num1,&operator,&num2})
  28. ENDIF
  29. ENDIF
  30.  
  31.  
  32. IFMATCHES(%&operator%,"\*|/)
  33.  
  34. //Are there decimals?
  35. IFCONTAINS(%&num1%,".")
  36. SET(#num1hasdec,1)
  37. MATCH(%&num1%00,"(-?[0-9]+)\.?([0-9]{2})",{#num1whole,&num1dec})
  38. SET(#num1,%#num1whole%%&num1dec%)
  39. ELSE
  40. SET(#num1hasdec,0)
  41. SET(#num1,%&num1%)
  42. ENDIF
  43. IFCONTAINS(%&num2%,".")
  44. SET(#num2hasdec,1)
  45. MATCH(%&num2%00,"(-?[0-9]+)\.?([0-9]{2})",{#num2whole,&num2dec})
  46. SET(#num2,%#num2whole%%&num2dec%)
  47. ELSE
  48. SET(#num2hasdec,0)
  49. SET(#num2,%&num2%)
  50. ENDIF
  51. #decimals = #num1hasdec + #num2hasdec
  52.  
  53. //Division
  54. //rip me
  55. IF(%&operator%=="/")
  56. #num1a = #num1 * 1000
  57. #answer = #num1a / #num2
  58. SET(&answerwhole,%#answer%)
  59.  
  60.  
  61. IF(%#decimals%==1)
  62. IF(%#num1hasdec%==1)
  63. MATCH(0000%#answer%,(-?[0-9]+)([0-9]{2})(.{3})$,{#answerwhole,&answerdec})
  64. ELSE
  65. MATCH(0000%#answer%,(-?[0-9]+)([0-9])$,{#answerwhole,&answerdec})
  66. ENDIF
  67. ELSE
  68. MATCH(0000%#answer%,(-?[0-9]+)([0-9]{2})(.)$,{#answerwhole,&answerdec})
  69. ENDIF
  70.  
  71. //Multiplication
  72. ELSEIF(%&operator%=="*")
  73. #answer = #num1 * #num2
  74.  
  75. IF(%#decimals%==2)
  76. MATCH(%#answer%,(-?[0-9]+)([0-9]{2})(.{2})$,{#answerwhole,&answerdec})
  77. ELSEIF(%#decimals%==1)
  78. MATCH(%#answer%,(-?[0-9]+)([0-9]{2})$,{#answerwhole,&answerdec})
  79. ELSE
  80. MATCH(%#answer%00,(-?[0-9]+)([0-9]{2})$,{#answerwhole,&answerdec})
  81. ENDIF
  82.  
  83. ENDIF
  84.  
  85. ELSE
  86. //deal with potential decimals
  87. MATCH(%&num1%00,"(-?[0-9]+)\.?([0-9]{2})",{#num1whole,&num1dec})
  88. MATCH(%&num2%00,"(-?[0-9]+)\.?([0-9]{2})",{#num2whole,&num2dec})
  89. SET(#num1,%#num1whole%%&num1dec%)
  90. SET(#num2,%#num2whole%%&num2dec%)
  91.  
  92. //Addition
  93. IF(%&operator%=="+")
  94. #answer = #num1 + #num2
  95.  
  96. //Subtraction
  97. ELSEIF(%&operator%=="-")
  98. #answer = #num1 - #num2
  99.  
  100. ENDIF
  101.  
  102. MATCH(%#answer%,(-?[0-9]+)([0-9]{2})$,{#answerwhole,&answerdec})
  103. ENDIF
  104.  
  105. SET(#answerdec,%&answerdec%)
  106.  
  107. IF(%#answerdec%>0)
  108. SET(&answer,"%#answerwhole%.%&answerdec%")
  109. ELSE
  110. SET(&answer,"%#answerwhole%)
  111. ENDIF
  112.  
  113. //Sub the answer back in
  114. REPLACE(&calc,"%&num1%%&operator%%&num2%","%&answer%")
  115.  
  116. //Repeat if needed
  117. IFMATCHES(%&calc%,"([*/+-])")
  118. SET(loop)
  119. ELSE
  120. UNSET(loop)
  121. ENDIF
  122. WHILE(%loop%)
  123.  
  124. //teh answer
  125. LOG("&6[&4CALC&6]&a %&calc%")
  126. ELSE
  127. LOG("&6[&4CALC&6] &aBasic Calculator that doesn't work well")
  128. LOG("&6[&4CALC&6] &aThe decimals probably aren't that accurate because the calculator is dumb")
  129. LOG("&6[&4CALC&6] &aRounding is for nubs")
  130. LOG("&6[&4CALC&6] &av 1.3")
  131. ENDIF
  132.  
  133. FILTER
  134. ENDIF
  135. }$$