priMELval

calc 1.2 macro

Feb 1st, 2017
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. $${
  2. // Calc v 1.2
  3. STRIP(&chat,%CHAT%)
  4. IFMATCHES(%&chat%,"^(/?)/calc")
  5. FILTER
  6. MATCH(%&chat%,"calc (.*)$",{&calc})
  7. REPLACE(&calc," ")
  8. IFMATCHES(%&calc%,"^(-?[0-9]+[*/+-]-?[0-9]+([*/+-]-?[0-9]+)*)$")
  9.  
  10.  
  11. DO(100)
  12.  
  13. IFMATCHES(%&calc%,"(-?[0-9]+)([*/])(-?[0-9]+)")
  14. MATCH(%&calc%,"(-?[0-9]+)([*/])(-?[0-9]+)",{#num1,&operator,#num2})
  15. ELSE
  16. IFMATCHES(%&calc%,"(-?[0-9]+)([+-])(-?[0-9]+)")
  17. MATCH(%&calc%,"(-?[0-9]+)([+-])(-?[0-9]+)",{#num1,&operator,#num2})
  18. ENDIF
  19. ENDIF
  20.  
  21.  
  22. //Division
  23. IF(%&operator%=="/")
  24. SET(&calc,"&4please god no division")
  25. BREAK
  26.  
  27. //Multiplication
  28. ELSEIF(%&operator%=="*")
  29. #answer = #num1 * #num2
  30. SET(&answer,%#answer%)
  31.  
  32. //Addition
  33. ELSEIF(%&operator%=="+")
  34. #answer = #num1 + #num2
  35. SET(&answer,%#answer%)
  36.  
  37. //Subtraction
  38. ELSEIF(%&operator%=="-")
  39. #answer = #num1 - #num2
  40. SET(&answer,%#answer%)
  41.  
  42. ENDIF
  43.  
  44.  
  45. REGEXREPLACE(&calc,"((-?[0-9]+)\%&operator%(-?[0-9]+))","%#answer%")
  46.  
  47. IFMATCHES(%&calc%,"([*/+-])")
  48. SET(loop)
  49. ELSE
  50. UNSET(loop)
  51. ENDIF
  52. WHILE(%loop%)
  53.  
  54. LOG("&6[&4CALC&6]&a %&calc%")
  55. ELSE
  56. LOG("&6[&4CALC&6] &aBasic Calculator that doesn't work well")
  57. LOG("&6[&4CALC&6] &aPlease do not use decimals because &athe calculator is dumb")
  58. LOG("&6[&4CALC&6] &av 1.2")
  59. ENDIF
  60. ENDIF
  61. }$$
Advertisement
Add Comment
Please, Sign In to add comment