Advertisement
Guest User

calculator

a guest
Apr 3rd, 2015
825
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.65 KB | None | 0 0
  1. {$CLEO}
  2. {$INCLUDE SF}
  3. 0000: NOP
  4. repeat
  5. wait 50
  6. until 0AFA: is_samp_available
  7.  
  8. 0B34: samp register_client_command "cc" to_label @calculate
  9. 0AC8: 31@ = allocate_memory_size 64
  10. 0AC8: 30@ = allocate_memory_size 64
  11. 0AC8: 29@ = allocate_memory_size 64
  12. 0AC8: 28@ = allocate_memory_size 64
  13. 0AC8: 25@ = allocate_memory_size 124 //formula
  14. 0AC8: 26@ = allocate_memory_size 64 //result
  15. 27@ = 0 //27@ = switcher
  16.  
  17. 0B5A: get_screen_resolution 22@ 23@
  18. 22@ /= 10
  19. 22@ *= 4
  20. 23@ /= 10
  21. 23@ *= 1
  22.  
  23. 0B80: dialog 24@ = create "Calculator"
  24. 0B84: dialog 24@ set_pos_XY 22@ 23@ size 300 120
  25. 0B91: dialog 24@ add_static id 1 text "Formula" pos_XY 25 20 size 300 20
  26. 0B91: dialog 24@ add_static id 2 text "=" pos_XY 105 40 size 300 20
  27. 0B91: dialog 24@ add_static id 3 text "Result" pos_XY 25 60 size 300 20
  28. 0B86: dialog 24@ set_visible false
  29.  
  30.  
  31. while true
  32. wait 0
  33. if 27@ == 1
  34. then
  35. 27@ = 0
  36. 33@ = 0
  37. 0B94: dialog 24@ set_control 1 text 25@
  38. 0B94: dialog 24@ set_control 3 text 26@
  39. 0B86: dialog 24@ set_visible true
  40. end
  41.  
  42. if 33@ > 15000
  43. then
  44. 0B86: dialog 24@ set_visible false
  45. end
  46. end
  47.  
  48. :calculate
  49. SAMP.IsCommandTyped(0@)
  50. //
  51. //4 numbers
  52. //
  53. if
  54. 0AD4: $nefolosit = 0@ format "%d%c%d%c%d%c%d" 1@ 31@ 2@ 30@ 3@ 29@ 4@
  55. then
  56. 0AD3: 31@ = format "%c" 31@
  57. 0AD3: 30@ = format "%c" 30@
  58. 0AD3: 29@ = format "%c" 29@
  59.  
  60. 0085: 5@ = 1@ // result
  61. 0085: 6@ = 2@ // num2
  62. 0085: 7@ = 3@ // num3
  63. 0093: 1@ = integer 1@ to_float
  64. 0093: 2@ = integer 2@ to_float
  65. 0093: 3@ = integer 3@ to_float
  66. 0093: 4@ = integer 4@ to_float
  67. 0093: 5@ = integer 5@ to_float
  68. 0093: 6@ = integer 6@ to_float
  69. 0093: 7@ = integer 7@ to_float
  70. if 0AB1: @p_3 3 31@ 30@ 29@
  71. then
  72. 0AB1: @do_maths 3 num 5@ num2 2@ operator 31@ _returnedNum 5@
  73. 0AB1: @do_maths 3 num 5@ num2 3@ operator 30@ _returnedNum 5@
  74. 0AB1: @do_maths 3 num 5@ num2 4@ operator 29@ _returnedNum 5@
  75. else
  76. if 0AB1: @n_2 2 30@ 29@
  77. then
  78. 0AB1: @do_maths 3 num 5@ num2 2@ operator 31@ _returnedNum 5@
  79. 0AB1: @do_maths 3 num 5@ num2 3@ operator 30@ _returnedNum 5@
  80. 0AB1: @do_maths 3 num 5@ num2 4@ operator 29@ _returnedNum 5@
  81. else
  82. if 0AB1: @p_n 2 30@ 29@
  83. then
  84. 0AB1: @do_maths 3 num 2@ num2 3@ operator 30@ _returnedNum 2@
  85. 0AB1: @do_maths 3 num 5@ num2 2@ operator 31@ _returnedNum 5@
  86. 0AB1: @do_maths 3 num 5@ num2 4@ operator 29@ _returnedNum 5@
  87. else
  88. if 0AB1: @p_n 2 29@ 30@
  89. then
  90. 0AB1: @do_maths 3 num 3@ num2 4@ operator 29@ _returnedNum 3@
  91. 0AB1: @do_maths 3 num 5@ num2 2@ operator 31@ _returnedNum 5@
  92. 0AB1: @do_maths 3 num 5@ num2 3@ operator 30@ _returnedNum 5@
  93. else
  94. if 0AB1: @p_2 2 30@ 29@
  95. then
  96. 0AB1: @do_maths 3 num 2@ num2 3@ operator 30@ _returnedNum 2@
  97. 0AB1: @do_maths 3 num 2@ num2 4@ operator 29@ _returnedNum 2@
  98. 0AB1: @do_maths 3 num 5@ num2 2@ operator 31@ _returnedNum 5@
  99. else
  100. 0AF8: samp add_message_to_chat "Error: Unknown order of operations (the script is incorrect)" color -1
  101. end
  102. end
  103. end
  104. end
  105. end
  106.  
  107. 0AD3: 25@ = format "%.0f %s %.0f %s %.0f %s %.0f" 1@ 31@ 6@ 30@ 7@ 29@ 4@
  108. if 0AB1: @decimal_check_result 1 5@
  109. then
  110. 0AD3: 26@ = format "%0.4f" 5@
  111. else
  112. 0AD3: 26@ = format "%.0f" 5@
  113. end
  114. 27@ = 1
  115. else
  116. //
  117. //3 numbers
  118. //
  119. if
  120. 0AD4: $nefolosit = 0@ format "%d%c%d%c%d" 1@ 31@ 2@ 30@ 3@
  121. then
  122. 0AD3: 31@ = format "%c" 31@
  123. 0AD3: 30@ = format "%c" 30@
  124. 0085: 4@ = 1@ // result
  125. 0085: 5@ = 2@ // num2
  126. 0093: 1@ = integer 1@ to_float
  127. 0093: 2@ = integer 2@ to_float
  128. 0093: 3@ = integer 3@ to_float
  129. 0093: 4@ = integer 4@ to_float
  130. 0093: 5@ = integer 5@ to_float
  131.  
  132. if 0AB1: @p_2 2 31@ 30@
  133. then
  134. 0AB1: @do_maths 3 num 4@ num2 2@ operator 31@ _returnedNum 4@
  135. 0AB1: @do_maths 3 num 4@ num2 3@ operator 30@ _returnedNum 4@
  136. else
  137. if
  138. 0AB1: @no_priority 1 30@ //no
  139. then
  140. 0AB1: @do_maths 3 num 4@ num2 2@ operator 31@ _returnedNum 4@
  141. 0AB1: @do_maths 3 num 4@ num2 3@ operator 30@ _returnedNum 4@
  142. else
  143. 0AB1: @do_maths 3 num 2@ num2 3@ operator 30@ _returnedNum 2@
  144. 0AB1: @do_maths 3 num 4@ num2 2@ operator 31@ _returnedNum 4@
  145. end
  146. end
  147.  
  148. 0AD3: 25@ = format "%.0f %s %.0f %s %.0f" 1@ 31@ 5@ 30@ 3@
  149. if 0AB1: @decimal_check_result 1 4@
  150. then
  151. 0AD3: 26@ = format "%0.4f" 4@
  152. else
  153. 0AD3: 26@ = format "%.0f" 4@
  154. end
  155. 27@ = 1
  156. else
  157. //
  158. //2 numbers
  159. //
  160. if
  161. 0AD4: $nefolosit = 0@ format "%d%c%d" 1@ 31@ 2@
  162. then
  163. 0AD3: 31@ = format "%c" 31@
  164. 0085: 4@ = 1@ // result
  165. 0093: 1@ = integer 1@ to_float
  166. 0093: 2@ = integer 2@ to_float
  167. 0093: 4@ = integer 4@ to_float
  168. 0AB1: @do_maths 3 num 4@ num2 2@ operator 31@ _returnedNum 4@
  169.  
  170. 0AD3: 25@ = format "%.0f %s %.0f" 1@ 31@ 2@
  171. if 0AB1: @decimal_check_result 1 4@
  172. then
  173. 0AD3: 26@ = format "%0.4f" 4@
  174. else
  175. 0AD3: 26@ = format "%.0f" 4@
  176. end
  177. 27@ = 1
  178. else
  179. printf "Usage: /cc 2+2+2+2 [ + - / x * ]" 5000
  180. end
  181. end
  182. end
  183. SAMP.CmdRet
  184.  
  185. //0AB1: @do_maths 3 num num2 operator _returnedNum
  186. :do_maths
  187. if 0C14: strcmp string1 2@ string2 "+"
  188. then
  189. 005B: 0@ += 1@ // (float)
  190. else
  191. if 0C14: strcmp string1 2@ string2 "-"
  192. then
  193. 0063: 0@ -= 1@ // (float)
  194. else
  195. if or
  196. 0C14: strcmp string1 2@ string2 "x"
  197. 0C14: strcmp string1 2@ string2 "*"
  198. then
  199. 006B: 0@ *= 1@ // (float)
  200. else
  201. if 0C14: strcmp string1 2@ string2 "/"
  202. then
  203. 0073: 0@ /= 1@ // (float)
  204. end
  205. end
  206. end
  207. end
  208. 0AB2: ret 1 0@
  209.  
  210. //if 0AB1: @ 1
  211. :p_3
  212. 31@ = 0
  213. if or
  214. 0C14: strcmp string1 0@ string2 "x"
  215. 0C14: strcmp string1 0@ string2 "*"
  216. 0C14: strcmp string1 0@ string2 "/"
  217. then
  218. 31@++
  219. end
  220.  
  221. if or
  222. 0C14: strcmp string1 1@ string2 "x"
  223. 0C14: strcmp string1 1@ string2 "*"
  224. 0C14: strcmp string1 1@ string2 "/"
  225. then
  226. 31@++
  227. end
  228.  
  229. if or
  230. 0C14: strcmp string1 2@ string2 "x"
  231. 0C14: strcmp string1 2@ string2 "*"
  232. 0C14: strcmp string1 2@ string2 "/"
  233. then
  234. 31@++
  235. end
  236.  
  237. if 31@ == 3
  238. then
  239. 0485: return_true
  240. else
  241. 059A: return_false
  242. end
  243. 0AB2: ret 0
  244.  
  245. :p_2
  246. 31@ = 0
  247. if or
  248. 0C14: strcmp string1 0@ string2 "x"
  249. 0C14: strcmp string1 0@ string2 "*"
  250. 0C14: strcmp string1 0@ string2 "/"
  251. then
  252. 31@++
  253. end
  254.  
  255. if or
  256. 0C14: strcmp string1 1@ string2 "x"
  257. 0C14: strcmp string1 1@ string2 "*"
  258. 0C14: strcmp string1 1@ string2 "/"
  259. then
  260. 31@++
  261. end
  262.  
  263. if 31@ == 2
  264. then
  265. 0485: return_true
  266. else
  267. 059A: return_false
  268. end
  269. 0AB2: ret 0
  270.  
  271.  
  272. :n_2
  273. 31@ = 0
  274. if or
  275. 0C14: strcmp string1 0@ string2 "x"
  276. 0C14: strcmp string1 0@ string2 "*"
  277. 0C14: strcmp string1 0@ string2 "/"
  278. then
  279. 31@++
  280. end
  281.  
  282. if or
  283. 0C14: strcmp string1 1@ string2 "x"
  284. 0C14: strcmp string1 1@ string2 "*"
  285. 0C14: strcmp string1 1@ string2 "/"
  286. then
  287. 31@++
  288. end
  289.  
  290. if 31@ > 0
  291. then
  292. 059A: return_false
  293. else
  294. 0485: return_true
  295. end
  296. 0AB2: ret 0
  297.  
  298.  
  299. :p_n
  300. 31@ = 0
  301. if or
  302. 0C14: strcmp string1 0@ string2 "x"
  303. 0C14: strcmp string1 0@ string2 "*"
  304. 0C14: strcmp string1 0@ string2 "/"
  305. then
  306. 31@++
  307. end
  308.  
  309. if or
  310. 0C14: strcmp string1 1@ string2 "x"
  311. 0C14: strcmp string1 1@ string2 "*"
  312. 0C14: strcmp string1 1@ string2 "/"
  313. then
  314. wait 0
  315. else
  316. 31@++
  317. end
  318.  
  319. if 31@ == 2
  320. then
  321. 0485: return_true
  322. else
  323. 059A: return_false
  324. end
  325. 0AB2: ret 0
  326.  
  327.  
  328. //if 0AB1: @is_priority 1
  329. :priority
  330. if or
  331. 0C14: strcmp string1 0@ string2 "x"
  332. 0C14: strcmp string1 0@ string2 "*"
  333. 0C14: strcmp string1 0@ string2 "/"
  334. then
  335. 0485: return_true
  336. else
  337. 059A: return_false
  338. end
  339. 0AB2: ret 0
  340.  
  341. //if 0AB1: @not_priority 1
  342. :no_priority
  343. if or
  344. 0C14: strcmp string1 0@ string2 "x"
  345. 0C14: strcmp string1 0@ string2 "*"
  346. 0C14: strcmp string1 0@ string2 "/"
  347. then
  348. 059A: return_false
  349. else
  350. 0485: return_true
  351. end
  352. 0AB2: ret 0
  353.  
  354. //if 0AB1: @decimal_check_result 1
  355. :decimal_check_result
  356. 0092: 1@ = float 0@ to_integer
  357. 0093: 1@ = integer 1@ to_float
  358. if or
  359. 0025: 1@ > 0@ // (float)
  360. 0025: 0@ > 1@ // (float)
  361. then
  362. 0485: return_true
  363. else
  364. 059A: return_false
  365. end
  366. 0AB2: ret 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement