Advertisement
Guest User

autoMowing.cs

a guest
Feb 3rd, 2015
546
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.26 KB | None | 0 0
  1. {$CLEO}
  2. 0000: NOP
  3. 0B34: samp register_client_command "mow" to_label @activate
  4. //30@ = entrance switcher
  5.  
  6. :First
  7. wait 0
  8.  
  9. if 31@ == 1
  10. then
  11. if 00DF: actor $PLAYER_ACTOR driving
  12. then
  13. if 0AB1: @is_cp_active 0
  14. then
  15. 0811: 0@ = actor $PLAYER_ACTOR used_car
  16. 0AB1: call_scm_func @set_max_speed 2 car 0@ speedValue 10.0
  17. 0AB1: @get_cp_pos 0 1@ 2@ 3@
  18. 00A0: store_actor $PLAYER_ACTOR position_to 4@ 5@ 6@
  19. 0AB1: call_scm_func @turning_mechanism 4 XY 1@ 2@ XY 4@ 5@ _returnedAngle 7@
  20. 0AB1: call_scm_func @check_for_block 3 car 0@ angle 7@ blocks 29@ _returned blocks 29@
  21.  
  22.  
  23. //check for things infront of me
  24. // 4@ 5@ 6@ = my position
  25. 9@ = 1.0
  26. 02E3: 8@ = car 0@ speed
  27. 006B: 9@ *= 8@ // distance depending on the speed
  28.  
  29. 0174: 15@ = car 0@ Z_angle
  30. 077D: 8@ = car 0@ x_angle
  31. 0AB1: call_scm_func @z_angles 1 angle 15@ _returnedAngles 14@ 16@ //14@ 15@ 16@ are the angles to detect any obstacles
  32. 0AB1: call_scm_func @x_angle_correction 1 angle 8@ _returnedAngle 8@ //to avoid false obstacles (detecting ground as obstacle) due to bumpy surface
  33. 0AB1: call_scm_func @obstacle_line 6 XYZ 4@ 5@ 6@ Z_Angle 14@ Y_Angle 8@ Distance 9@ _returnedStatus 10@ //draws line and checks for obstacles, 10@ == 1 indicates obstacle, 10@ == 0 indicates free space
  34. 0AB1: call_scm_func @obstacle_line 6 XYZ 4@ 5@ 6@ Z_Angle 15@ Y_Angle 8@ Distance 9@ _returnedStatus 11@
  35. 0AB1: call_scm_func @obstacle_line 6 XYZ 4@ 5@ 6@ Z_Angle 16@ Y_Angle 8@ Distance 9@ _returnedStatus 12@
  36. if or
  37. 10@ == 1
  38. 11@ == 1
  39. 12@ == 1
  40. then
  41. 33@ = 0
  42. repeat
  43. wait 0
  44. if 0033: 180.0 >= 7@
  45. then
  46. 0B56: set_game_key 0 state 255 //press right
  47. else
  48. 0B56: set_game_key 0 state -255 //press left
  49. end
  50. 0B56: set_game_key 16 state 255 //accelerate
  51. until 33@ > 800
  52. 0B56: set_game_key 0 state 0
  53. 33@ = 0
  54. repeat
  55. wait 0
  56. 0B56: set_game_key 16 state 255
  57. until 33@ > 600
  58. end
  59. //end of check
  60.  
  61. //check for other side (to avoid water)
  62. //my position x=4@ y=5@
  63. //marker mosition x=1@ y=2@
  64. if and
  65. 0023: 1966.0 > 4@ //if I'm on the left side
  66. 0021: 1@ > 1966.0 //if the marker is on the right side
  67. then
  68. if 0023: -1197.0 > 5@ //if i'm at the bottom
  69. then
  70. 1@ = 1936.0 //to 1990.0
  71. 2@ = -1239.0 //to -1232.0
  72. 30@ = 1
  73. else
  74. 1@ = 1937.0 //to 1992.0
  75. 2@ = -1157.0 //to -1157.0
  76. 30@ = 2
  77. end
  78. jump @Change_Side
  79. end
  80.  
  81. if and
  82. 0023: 1966.0 > 1@ //if the marker is on the left side
  83. 0021: 4@ > 1966.0 //if I'm on the right side
  84. then
  85. if 0023: -1197.0 > 5@ //if i'm at the bottom
  86. then
  87. 1@ = 1997.0 // 1943.0
  88. 2@ = -1232.0 // -1239.0
  89. 30@ = 4
  90. else
  91. 1@ = 1999.0 // 1944.0
  92. 2@ = -1157.0 // -1157.0
  93. 30@ = 5
  94. end
  95. jump @Change_Side
  96. end
  97. //end of check
  98. end
  99. end
  100. end
  101.  
  102. if key_down 48
  103. then
  104. 31@ = 0
  105. end
  106. jump @First
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114. :Change_Side
  115. wait 0
  116. if 31@ == 1
  117. then
  118. if 00DF: actor $PLAYER_ACTOR driving
  119. then
  120. if 0AB1: @is_cp_active 0
  121. then
  122. 0811: 0@ = actor $PLAYER_ACTOR used_car
  123. 0AB1: call_scm_func @set_max_speed 2 car 0@ speedValue 10.0
  124. 00A0: store_actor $PLAYER_ACTOR position_to 4@ 5@ 6@
  125. 0509: 3@ = distance_between_XY 1@ 2@ and_XY 4@ 5@
  126.  
  127. if 0023: 2.0 > 3@ //if i'm at the entrance
  128. then
  129. if 30@ == 1
  130. then
  131. 1@ = 1990.0
  132. 2@ = -1233.5
  133. 30@ = 3 //switcher indicate that I arrived to the first point of entrance and now I'm going to the other side
  134. else
  135. if 30@ == 2
  136. then
  137. 1@ = 1992.0
  138. 2@ = -1159.5
  139. 30@ = 3
  140. else
  141. if 30@ == 4
  142. then
  143. 1@ = 1943.0
  144. 2@ = -1241.5
  145. 30@ = 6
  146. else
  147. if 30@ == 5
  148. then
  149. 1@ = 1944.0
  150. 2@ = -1158.5
  151. 30@ = 6
  152. else
  153. if 30@ == 6 //if I arrived succesfully (going to the left)
  154. then
  155. jump @First
  156. else
  157. if 30@ == 3 //if I arrived succesfully (going to the right)
  158. then
  159. jump @First
  160. end
  161. end
  162. end
  163. end
  164. end
  165. end
  166. end
  167.  
  168. 0AB1: call_scm_func @turning_mechanism 4 XY 1@ 2@ XY 4@ 5@ _returnedAngle 7@
  169.  
  170. if or
  171. 30@ == 1
  172. 30@ == 2
  173. 30@ == 4
  174. 30@ == 5
  175. then
  176. //check for block
  177. 0AB1: call_scm_func @check_for_block 3 car 0@ angle 7@ blocks 29@ _returned blocks 29@
  178.  
  179. //end of the block
  180.  
  181. //check for things infront of me
  182. // 4@ 5@ 6@ = my position
  183. 9@ = 1.0
  184. 02E3: 8@ = car 0@ speed
  185. 006B: 9@ *= 8@ // distance depending on the speed
  186.  
  187. 0174: 15@ = car 0@ Z_angle
  188. 077D: 8@ = car 0@ x_angle
  189. 0AB1: call_scm_func @z_angles 1 angle 15@ _returnedAngles 14@ 16@ //14@ 15@ 16@ are the angles to detect any obstacles
  190. 0AB1: call_scm_func @x_angle_correction 1 angle 8@ _returnedAngle 8@
  191. 0AB1: call_scm_func @obstacle_line 6 XYZ 4@ 5@ 6@ Z_Angle 14@ Y_Angle 8@ Distance 9@ _returnedStatus 10@
  192. 0AB1: call_scm_func @obstacle_line 6 XYZ 4@ 5@ 6@ Z_Angle 15@ Y_Angle 8@ Distance 9@ _returnedStatus 11@
  193. 0AB1: call_scm_func @obstacle_line 6 XYZ 4@ 5@ 6@ Z_Angle 16@ Y_Angle 8@ Distance 9@ _returnedStatus 12@
  194. if or
  195. 10@ == 1
  196. 11@ == 1
  197. 12@ == 1
  198. then
  199. 33@ = 0
  200. repeat
  201. wait 0
  202. if 0033: 180.0 >= 7@
  203. then
  204. 0B56: set_game_key 0 state 255 //press right
  205. else
  206. 0B56: set_game_key 0 state -255 //press left
  207. end
  208. 0B56: set_game_key 16 state 255
  209. until 33@ > 800
  210. 0B56: set_game_key 0 state 0
  211. 33@ = 0
  212. repeat
  213. wait 0
  214. 0B56: set_game_key 16 state 255
  215. until 33@ > 600
  216. end
  217.  
  218. //end of check
  219. end
  220. end
  221. end
  222. end
  223.  
  224. if key_down 48
  225. then
  226. 31@ = 0
  227. end
  228. jump @Change_Side
  229.  
  230.  
  231. :activate
  232. 0B12: 31@ = 31@ XOR 1
  233. samp.CmdRet
  234.  
  235.  
  236. //0AB1: call_scm_func @set_max_speed 2 car 0@ speedValue 10.0
  237. :set_max_speed
  238. 02E3: 31@ = car 0@ speed
  239. if 0025: 31@ > 1@ // (float)
  240. then
  241. 04BA: set_car 0@ speed_to 1@
  242. end
  243. 0AB2: ret 0
  244.  
  245. //0AB1: call_scm_func @obstacle_line 6 XYZ 4@ 5@ 6@ Z_Angle 14@ Y_Angle 8@ Distance 9@ _returnedStatus @
  246. :obstacle_line
  247. 03F0: enable_text_draw 1
  248. 0AB1: call_scm_func @get3DXYZInFrontOf 6 XYZ 0@ 1@ 2@ Z_Angle 3@ Y_Angle 4@ Distance 5@ Return_XYZ_To 3@ 4@ 5@
  249. 0AB1: call_scm_func @getScreenXYFrom3DCoords 3 3D_coords_X 3@ 4@ 5@ store_screen_X_to 20@ Y_to 21@
  250. 0AB1: call_scm_func @getScreenXYFrom3DCoords 3 3D_coords_X 0@ 1@ 2@ store_screen_X_to 22@ Y_to 23@
  251. if 06BD: no_obstacles_between 3@ 4@ 5@ and 0@ 1@ 2@ solid 1 car 0 actor 1 object 1 particle 0
  252. then
  253. 0AB1: call_scm_func @drawLine 9 x1y1 20@ 21@ x2y2 22@ 23@ thickness 1.0 R 255 G 255 B 255 A 255 //no obstacle /white line
  254. 31@ = 0
  255. else
  256. 0AB1: call_scm_func @drawLine 9 x1y1 20@ 21@ x2y2 22@ 23@ thickness 1.0 R 255 G 0 B 0 A 255 //no obstacle /red line
  257. 31@ = 1
  258. end
  259. 0AB2: ret 1 31@
  260.  
  261. //0AB1: call_scm_func @check_for_block 3 car 0@ angle 7@ blocks 29@ _returned blocks 29@
  262. :check_for_block
  263. 02E3: 31@ = car 0@ speed
  264. if 0033: 0.4 >= 31@
  265. then
  266. 2@ += 1
  267. if 2@ > 7
  268. then
  269. 2@ = 0
  270. 0AB1: call @keyPress 2 key 83 time 1500 //s
  271. 33@ = 0
  272. wait 1500
  273. repeat
  274. wait 0
  275. if 0033: 180.0 >= 1@
  276. then
  277. 0B56: set_game_key 0 state 255 //press right
  278. else
  279. 0B56: set_game_key 0 state -255 //press left
  280. end
  281. 0B56: set_game_key 16 state 255
  282. until 33@ > 900
  283. 0B56: set_game_key 0 state 0
  284. 33@ = 0
  285. repeat
  286. wait 0
  287. 0B56: set_game_key 16 state 255
  288. until 33@ > 900
  289. end
  290. end
  291. 0AB2: ret 1 2@
  292.  
  293. //0AB1: call_scm_func @turning_mechanism 4 XY XY _returnedAngle 1@
  294. :turning_mechanism
  295. 0AB1: @getZAngleBetweenPoints 4 from_XY 0@ 1@ and_XY 2@ 3@ store_to 31@
  296. 0172: 30@ = actor $PLAYER_ACTOR Z_angle
  297. 30@ -= 360.0
  298. 0097: make 30@ absolute_float
  299. 005B: 31@ += 30@
  300. 02F6: 30@ = sine 31@
  301. 02F7: 31@ = cosine 31@
  302. 0604: get_Z_angle_for_point 30@ 31@ store_to 31@
  303. if and
  304. 0021: 31@ > 180.0
  305. 0023: 355.0 > 31@
  306. then //press left
  307. 0B56: set_game_key 0 state -255
  308. 0B56: set_game_key 16 state 255
  309. if
  310. 0023: 200.0 > 31@
  311. then
  312. 0B56: set_game_key 6 state 255
  313. else
  314. 0B56: set_game_key 6 state 0
  315. end
  316. else
  317. if and
  318. 0021: 31@ > 5.0
  319. 0033: 180.0 >= 31@ //lower or equal
  320. then //press right
  321. 0B56: set_game_key 0 state 255
  322. 0B56: set_game_key 16 state 255
  323. if
  324. 0021: 31@ > 160.0
  325. then
  326. 0B56: set_game_key 6 state 255
  327. else
  328. 0B56: set_game_key 6 state 0
  329. end
  330. else
  331. 0B56: set_game_key 0 state 0
  332. 0B56: set_game_key 6 state 0
  333. 0B56: set_game_key 16 state 255
  334. end
  335. end
  336. 0AB2: ret 1 31@
  337.  
  338. //0AB1: call_scm_func @z_angles 1 angle 0@ _returnedAngles 1@ 2@
  339. :z_angles
  340. 0087: 1@ = 0@ // (float)
  341. 0@ -= 5.0
  342. 1@ += 5.0
  343. if 0021: 1@ > 360.0
  344. then
  345. 1@ -= 360.0
  346. end
  347. if 0023: 0.0 > 0@
  348. then
  349. 0@ += 360.0
  350. end
  351. 0AB2: ret 2 0@ 1@
  352.  
  353. //0AB1: call_scm_func @x_angle_correction 1 angle 0@ _returnedAngle 1@
  354. :x_angle_correction
  355. if and
  356. 0021: 0@ > 0.0
  357. 0023: 90.0 > 0@
  358. then
  359. 0@ += 15.0
  360. else
  361. if
  362. 0021: 0@ > 270.0
  363. then
  364. 0@ += 15.0
  365. if
  366. 0021: 0@ > 360.0
  367. then
  368. 0@ -= 360.0
  369. end
  370. end
  371. end
  372. 0AB2: ret 1 0@
  373.  
  374.  
  375.  
  376.  
  377.  
  378. :keyPress
  379. // 0@ - key, 1@ - time
  380. // Example: 0AB1: call @keyPress 2 key 0@ time 1@
  381.  
  382. if 0AA2: 2@ = load_library "User32.dll"
  383. then
  384. if 0AA4: 2@ = get_proc_address "keybd_event" library 2@
  385. then
  386. 0AA5: call 2@ num_params 4 pop 0 0 0 0 0@
  387. wait 1@
  388. 0AA5: call 2@ num_params 4 pop 0 0 0x02 0 0@
  389. end
  390. end
  391. 0AB2: ret 0
  392. {
  393. 0 left/right ~k~~VEHICLE_STEERLEFT~/ ~k~~VEHICLE_STEERRIGHT~
  394. 1 steer back/up ~k~~VEHICLE_STEERUP~/ ~k~~VEHICLE_STEERDOWN~
  395. 2 special ctrl left/right ~k~~VEHICLE_TURRETLEFT~/ ~k~~VEHICLE_TURRETRIGHT~ (NUM6)
  396. 3 special control up/down ~k~~VEHICLE_TURRETUP~/ ~k~~VEHICLE_TURRETDOWN~
  397. 4 secondary fire ~k~~VEHICLE_FIREWEAPON_ALT~
  398. 5 look left ~k~~VEHICLE_LOOKLEFT~
  399. 6 hand brake ~k~~VEHICLE_HANDBRAKE~
  400. 7 look right ~k~~VEHICLE_LOOKRIGHT~
  401. 8 next radio station ~k~~VEHICLE_RADIO_STATION_UP~
  402. 9 previous radio station ~k~~VEHICLE_RADIO_STATION_DOWN~
  403. 10 no ~k~~CONVERSATION_NO~
  404. 11 yes / trip skip ~k~~CONVERSATION_YES~
  405. 12 (does not exist) -- -- --
  406. 13 camera ~k~~CAMERA_CHANGE_VIEW_ALL_SITUATIONS~
  407. 14 brake/reserve ~k~~VEHICLE_BRAKE~
  408. 15 enter/exit ~k~~VEHICLE_ENTER_EXIT~
  409. 16 accelerate ~k~~VEHICLE_ACCELERATE~
  410. 17 fire ~k~~VEHICLE_FIREWEAPON~
  411. 18 horn ~k~~VEHICLE_HORN~
  412. 19 submission ~k~~TOGGLE_SUBMISSIONS~
  413. }
  414. :is_cp_active
  415. IF 0AA2: 0@ = loadlib "samp.dll"
  416. THEN 0A8E: 1@ = 0@ + 0x212A94
  417. 0A8D: 1@ = readMem 1@ sz 4 vp 0
  418. 1@ += 0x24
  419. 0A8D: 1@ = readMem 1@ sz 4 vp 0
  420. IF 1@ == TRUE
  421. THEN 0485: return_true
  422. ELSE 059A: return_false
  423. END
  424. 0AA3: freelib 0@
  425. END
  426. 0AB2: ret 0
  427.  
  428. :get_cp_pos
  429. IF 0AA2: 0@ = loadlib "samp.dll"
  430. THEN 0A8E: 1@ = 0@ + 0x212A94
  431. 0A8D: 1@ = readMem 1@ sz 4 vp 0
  432. 1@ += 0xC
  433. 0A8D: 2@ = readMem 1@ sz 4 vp 0
  434. 1@ += 0x4
  435. 0A8D: 3@ = readMem 1@ sz 4 vp 0
  436. 1@ += 0x4
  437. 0A8D: 4@ = readMem 1@ sz 4 vp 0
  438. 0AA3: freelib 0@
  439. END
  440. 0AB2: ret 3 2@ 3@ 4@
  441.  
  442. :getZAngleBetweenPoints
  443. 0063: 0@ -= 2@
  444. 0063: 1@ -= 3@
  445. 0604: get_Z_angle_for_point 0@ 1@ store_to 4@
  446. 0AB2: 1 4@
  447.  
  448. :get3DXYZInFrontOf{X,Y,Z,ZA,YA,Distance}
  449. {
  450. Return:
  451. PosX-InFrontOf
  452. PosY-InFrontOf
  453. PosZ-InFrontOf
  454.  
  455. Example: 0AB1: call_scm_func @get3DXYZInFrontOf 6 XYZ 1@ 2@ 3@ Z_Angle 4@ Y_Angle 5@ Distance 7.0 Return_XYZ_To 6@ 7@ 8@
  456.  
  457. }
  458. 3@ *= -1.0
  459. 02F6: 6@ = sine 3@
  460. 006B: 6@ *= 5@
  461. 005B: 0@ += 6@
  462. 02F7: 6@ = cosine 3@
  463. 006B: 6@ *= 5@
  464. 005B: 1@ += 6@
  465. 02F7: 6@ = cosine 4@
  466. 0073: 5@ /= 6@
  467. 02F6: 6@ = sine 4@
  468. 006B: 5@ *= 6@
  469. 005B: 2@ += 5@
  470. 0AB2: ret 3 0@ 1@ 2@
  471.  
  472. //0AB1: call_scm_func @getScreenXYFrom3DCoords 3 3D_coords_X 0@ Y 1@ Z 2@ store_screen_X_to 3@ Y_to 4@
  473. :getScreenXYFrom3DCoords
  474. 0AA7: call_function 0x70CE30 num_params 6 pop 6 clipNear 1 clipFar 1 yMult 7@s xMult 6@s outVector 2@s inVector 0@s result 29@
  475. 0073: 2@ /= 6@
  476. 0073: 2@ /= 4@
  477. 0073: 3@ /= 7@
  478. 0073: 3@ /= 4@
  479. 2@ *= 640.0
  480. 3@ *= 448.0
  481. 0AB2: ret 2 2@ 3@
  482.  
  483. :drawLine
  484. //0AB1: call_scm_func drawLine 9 x1y1 0@ 1@ x2y2 2@ 3@ thickness 1.0 R 255 G 255 B 255 A 255
  485. 0390: load_txd_dictionary 'LD_DUAL'
  486. 038F: load_texture "white" as 300
  487. 0509: 9@ = distance_between_XY 0@ 1@ and_XY 2@ 3@
  488. 0063: 2@ -= 0@
  489. 0063: 3@ -= 1@
  490. 0604: get_Z_angle_for_point 2@ 3@ store_to 10@
  491. 10@ += 90.0
  492. 0017: 2@ /= 2.0
  493. 0017: 3@ /= 2.0
  494. 005B: 0@ += 2@
  495. 005B: 1@ += 3@
  496. 074B: draw_texture 300 position 0@ 1@ scale 9@ 4@ angle 10@ color_RGBA 5@ 6@ 7@ 8@
  497. 0391: release_textures
  498. 0AB2: ret 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement