MrGarretto

Impossible Getaway Code

Jun 28th, 2017
1,021
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 59.18 KB | None | 0 0
  1. # objective horseRide = stat.horseOneCm
  2. # objective driveTime = how long the car has been in motion
  3. # objective idleTime = how long the car has been idling
  4. # objective uniCount = universal counter for using /execute to check amount of certain entities
  5. # objective checkObCount = amount of times the checkingObstacles loop has run
  6. # objective obs_valid_loc = 1 if check_obs armorstand is in an intersection, otherwise 0
  7. # objective car_damage = car damage
  8. # objective points = Player's score in the game
  9. # objective powerup = Time until powerup runs out (0 if player doesn't have powerup)
  10. # objective eventTimer = Does a random event every 400 ticks
  11. # objective money_bags = how many money bags the player has picked up
  12.  
  13. function reset() {
  14.  
  15. removeOld()
  16.  
  17. scoreboard players tag @a remove alreadyBegun
  18. scoreboard players tag @a remove game_over
  19. scoreboard players tag @a remove isLoading
  20. scoreboard players tag @a remove isPlaying
  21. scoreboard players tag @a remove failed_objective
  22. scoreboard players tag @a remove winner
  23. scoreboard players set @a policeNum -1
  24. scoreboard players set @a car_damage 0
  25. scoreboard players set @a eventTimer -1
  26. scoreboard players set @a points 0
  27. scoreboard players set @e[tag=car] powerup 0
  28. scoreboard players tag @e[tag=toll_3] remove toll_1
  29. scoreboard players tag @e[tag=toll_3] remove toll_2
  30. scoreboard players set @a money_bags 0
  31. scoreboard players tag @a remove unlockedTolls
  32. scoreboard players tag @a remove criticalmessage
  33.  
  34. tp @e[tag=car_model] @e[tag=car]
  35.  
  36. stopAllEvents()
  37.  
  38. stop forceCar
  39. stop driveCar
  40. stop checkForStart
  41. stop carSelect
  42. stop openGarageDoor
  43. stop generateObstacles
  44. stop checkingObstacles
  45. stop gameplay
  46.  
  47. setup()
  48.  
  49. }
  50.  
  51. # In case these somehow get destroyed
  52. # summon armor_stand ~ ~ ~ {Tags:["car_model"],NoGravity:1,ArmorItems:[{},{},{},{id:diamond_hoe,Count:1,Damage:1}],Invisible:1}
  53. # summon horse ~ ~ ~ {Tags:["car"],Attributes:[{Name:"generic.movementSpeed",Base:0.1f},{Name:"horse.jumpStrength",Base:0f}],Tame:1,SaddleItem:{id:saddle,Count:1},Silent:1,Invisible:1}
  54.  
  55. function removeOld() {
  56.  
  57. # Remove old entities
  58. # Don't leave behind extra barriers
  59. execute @e[tag=NPCCar] ~ ~ ~ fill ~-1 ~ ~-1 ~1 ~1 ~1 air 0 replace barrier
  60. kill @e[tag=NPCCar]
  61. kill @e[tag=police_car_part]
  62. kill @e[tag=tank_part]
  63. tp @e[tag=target_sheep] ~ ~-1000 ~
  64. kill @e[type=item]
  65. kill @e[tag=powerup_part]
  66. kill @e[tag=meteor]
  67.  
  68. }
  69.  
  70. function criticalDamageMessage() {
  71.  
  72. scoreboard players tag @a add criticalmessage
  73. execute @a ~ ~ ~ playsound critical_damage neutral @a ~ ~ ~ 10
  74. start criticalDamageMessageRepeat
  75. delay 100 {
  76. stop criticalDamageMessageRepeat
  77. }
  78.  
  79. }
  80.  
  81. repeat criticalDamageMessageRepeat:off {
  82.  
  83. title @a actionbar ["",{"text":"!","bold":true,"color":"gold"},{"text":"!","bold":true,"color":"black"},{"text":"!","bold":true,"color":"gold"},{"text":"!","bold":true,"color":"black"},{"text":" ","bold":true},{"text":"Car Damage Critical","bold":true,"color":"dark_red"},{"text":" ","bold":true},{"text":"!","bold":true,"color":"gold"},{"text":"!","bold":true,"color":"black"},{"text":"!","bold":true,"color":"gold"},{"text":"!","bold":true,"color":"black"}]
  84.  
  85. }
  86.  
  87. function helpScreen() {
  88.  
  89. tp @a 1034 9 974.35 180 90
  90.  
  91. start helpScreenTp
  92.  
  93. title @a actionbar {"text":""}
  94.  
  95. execute @a ~ ~ ~ playsound help neutral @a ~ ~ ~ 10
  96.  
  97. effect @a invisibility 100000 1 true
  98.  
  99. delay 1 {
  100. entitydata @e[tag=help_screen] {ArmorItems:[{},{},{},{id:golden_hoe,Count:1,Damage:11,tag:{Unbreakable:1}}]}
  101. delay 140
  102. {
  103. entitydata @e[tag=help_screen] {ArmorItems:[{},{},{},{id:golden_hoe,Count:1,Damage:12,tag:{Unbreakable:1}}]}
  104. delay 120
  105. {
  106. entitydata @e[tag=help_screen] {ArmorItems:[{},{},{},{id:golden_hoe,Count:1,Damage:13,tag:{Unbreakable:1}}]}
  107. delay 120
  108. {
  109. entitydata @e[tag=help_screen] {ArmorItems:[{},{},{},{id:golden_hoe,Count:1,Damage:14,tag:{Unbreakable:1}}]}
  110. delay 120
  111. {
  112. entitydata @e[tag=help_screen] {ArmorItems:[{},{},{},{id:golden_hoe,Count:1,Damage:15,tag:{Unbreakable:1}}]}
  113. delay 120
  114. {
  115. entitydata @e[tag=help_screen] {ArmorItems:[{},{},{},{id:golden_hoe,Count:1,Damage:16,tag:{Unbreakable:1}}]}
  116. delay 120
  117. {
  118. stop helpScreenTp
  119. stopsound @a
  120. execute @a ~ ~ ~ playsound whoosh neutral @a ~ ~ ~ 10
  121. reset()
  122. }
  123. }
  124. }
  125. }
  126. }
  127. }
  128.  
  129. }
  130.  
  131. }
  132.  
  133. repeat helpScreenTp:off {
  134.  
  135. tp @a 1034 9 974.35 180 90
  136.  
  137. }
  138.  
  139. repeat forceCar:off {
  140.  
  141. # If player gets out of car
  142. execute @a[x=1011,y=7,z=995,dx=200,dy=10,dz=200,tag=!game_over] ~ ~ ~ execute @s[tag=!driving] ~ ~ ~ gameOver()
  143. execute @a[tag=!driving] ~ ~ ~ scoreboard players tag @s[x=1011,y=7,z=995,dx=200,dy=10,dz=200,tag=!game_over] add game_over
  144.  
  145. }
  146.  
  147. repeat main {
  148.  
  149. title @a[x=1000,y=6,z=999,dx=2,dy=2,dz=2] actionbar ["",{"text":"Set your render distance to 12,","bold":true,"color":"yellow"},{"text":" then press SPACE!","bold":true}]
  150. execute @a ~ ~ ~ detect ~ ~-1 ~ concrete_powder 15 helpScreen()
  151.  
  152. execute @a ~ ~ ~ detect ~ ~-1 ~ jukebox -1 reset()
  153.  
  154. # Aesthetic
  155. particle droplet 1017 11 1020 0.3 0 0.3 1 10
  156.  
  157. tp @a[x=1000,y=7,z=991,dx=2,dy=3,dz=2] ~ ~ ~ 0 0
  158.  
  159. # weather clear 10000
  160.  
  161. scoreboard players tag @a remove driving
  162. scoreboard players tag @a add driving {RootVehicle:{Entity:{id:"minecraft:horse"}}}
  163.  
  164. effect @e[tag=car] minecraft:invisibility 5 1 true
  165. effect @a[tag=driving] minecraft:invisibility 5 1 true
  166.  
  167. execute @a[tag=alreadyBegun] ~ ~ ~ teleport @e[tag=target_sheep] ~ ~3 ~
  168. effect @e[type=sheep] invisibility 10 1 true
  169. effect @e[type=sheep] resistance 10 5 true
  170.  
  171. if (@a[tag=driving]) {
  172. # Player is driving the car
  173.  
  174. start driveCar
  175.  
  176. } else {
  177. # The car is inactive
  178.  
  179. stop driveCar
  180. entitydata @e[tag=car] {Attributes:[{Name:"generic.movementSpeed",Base:0.0f},{Name:"horse.jumpStrength",Base:0f}],NoAI:1}
  181. scoreboard players set @e[tag=car] driveTime 0
  182. scoreboard players set @a idleTime 0
  183.  
  184. }
  185.  
  186. # Loading screen
  187. execute @a[tag=!isSelectingCar] ~ ~ ~ execute @a[tag=isLoading] ~ ~ ~ tp @e[tag=loading_spinner] ~ ~ ~ ~4 ~
  188. execute @a[tag=!isSelectingCar] ~ ~ ~ tp @a[tag=isLoading] 1013 9 974 180 90
  189. execute @a[tag=!isSelectingCar] ~ ~ ~ title @a[tag=isLoading] actionbar [""]
  190.  
  191. execute @e[tag=tank_top] ~ ~ ~ teleport @e[tag=tank_bottom,c=1] ~ ~ ~
  192. execute @e[tag=tank_wolf] ~ ~ ~ tp @e[tag=tank_top,c=1] @e[tag=tank_wolf,c=1]
  193. # Multi-purpose dummy objective used to make tank rotations look cooler
  194. scoreboard players add @e[tag=tank_wolf] MP 1
  195. execute @e[tag=tank_wolf,score_MP_min=40] ~ ~ ~ tp @e[tag=tank_bottom,c=1] @e[tag=tank_top,c=1]
  196. scoreboard players reset @e[tag=tank_wolf,score_MP_min=40] MP
  197. # Tanks only move once player is within 32 blocks
  198. execute @a ~ ~ ~ effect @e[tag=tank_wolf,rm=32] minecraft:slowness 4 100 true
  199. execute @a ~ ~ ~ execute @e[tag=tank_wolf,r=32] ~ ~ ~ tankControl()
  200.  
  201. # Check if the player's car has taken too much damage
  202. execute @a[tag=!winner] ~ ~ ~ execute @a[score_car_damage_min=80,tag=!game_over] ~ ~ ~ gameOver()
  203. scoreboard players set @a[score_car_damage_min=80] car_damage 0
  204.  
  205. if ("clear @a redstone_torch 0 1") {
  206. reset()
  207. }
  208.  
  209. if ("clear @a baked_potato 0 1") {
  210. # Player picked up a powerup
  211.  
  212. activatePowerup()
  213.  
  214. }
  215.  
  216. scoreboard players remove @e[tag=car,score_powerup_min=1] powerup 1
  217.  
  218. # Cartoon outlines
  219. #scoreboard teams join cartoonOutline @e[tag=cartoon_outline]
  220. #effect @e[tag=cartoon_outline] glowing 10
  221.  
  222. # During the Game OVER screen
  223. execute @e[tag=car] ~ ~ ~ teleport @a[tag=game_over] ~ ~5 ~ ~1 90
  224. scoreboard players set @a[tag=game_over] car_damage -999
  225. effect @a[tag=game_over] invisibility 1 1 true
  226. execute @a[tag=game_over] ~ ~ ~ execute @e[tag=car] ~ ~ ~ particle smoke ~ ~ ~ 0.5 0.5 0.5 0.001 5
  227.  
  228. # Make horse (car) invincible
  229. effect @e[tag=car] minecraft:resistance 30 5 true
  230.  
  231. # Winning
  232. execute @a[tag=!winner] ~ ~ ~ execute @e[tag=car] ~ ~ ~ detect ~ ~-2 ~ sponge -1 wonGame()
  233. execute @a[tag=!winner] ~ ~ ~ execute @e[tag=car] ~ ~ ~ detect ~ ~-2 ~ sponge -1 scoreboard players tag @a add winner
  234.  
  235. # Critical damage
  236. execute @a[tag=!criticalmessage,score_car_damage_min=40] ~ ~ ~ criticalDamageMessage()
  237. execute @a[score_car_damage_min=40] ~ ~ ~ execute @e[tag=car] ~ ~ ~ particle smoke ~ ~ ~ 0 0 0 0.2 2
  238.  
  239. }
  240.  
  241. repeat driveCar:off {
  242.  
  243. # keep the car_model at the horse entity at all times while driving
  244. tp @e[tag=car_model] @e[tag=car]
  245.  
  246. # driveTime tracking
  247. scoreboard players set @e[score_horseRide_min=1] idleTime 0
  248. scoreboard players add @e[score_horseRide=0] idleTime 1
  249. execute @a[score_horseRide=0,score_idleTime_min=5] ~ ~ ~ scoreboard players set @e[tag=car] driveTime 1
  250. execute @a[score_horseRide_min=1] ~ ~ ~ scoreboard players add @e[tag=car] driveTime 1
  251. scoreboard players set @a[tag=driving] horseRide 0
  252.  
  253. # Ignition sound
  254. execute @a[score_idleTime_min=1,score_idleTime=1,tag=CarNotStarted] ~ ~ ~ playsound ignition neutral @a ~ ~ ~ 0.3
  255. execute @a[score_idleTime_min=1,score_idleTime=1,tag=CarNotStarted] ~ ~ ~ start forceCar
  256. scoreboard players tag @a[score_idleTime_min=1,score_idleTime=1,tag=CarNotStarted] remove CarNotStarted
  257.  
  258. # acceleration
  259. entitydata @e[tag=car,score_driveTime_min=1] {Attributes:[{Name:"generic.movementSpeed",Base:0.1f},{Name:"horse.jumpStrength",Base:0f}],NoAI:0}
  260. entitydata @e[tag=car,score_driveTime_min=4] {Attributes:[{Name:"generic.movementSpeed",Base:0.15f},{Name:"horse.jumpStrength",Base:0f}]}
  261. entitydata @e[tag=car,score_driveTime_min=8] {Attributes:[{Name:"generic.movementSpeed",Base:0.2f},{Name:"horse.jumpStrength",Base:0f}]}
  262. entitydata @e[tag=car,score_driveTime_min=15] {Attributes:[{Name:"generic.movementSpeed",Base:0.25f},{Name:"horse.jumpStrength",Base:0f}]}
  263. entitydata @e[tag=car,score_driveTime_min=30] {Attributes:[{Name:"generic.movementSpeed",Base:0.3f},{Name:"horse.jumpStrength",Base:0f}]}
  264. entitydata @e[tag=car,score_driveTime_min=65] {Attributes:[{Name:"generic.movementSpeed",Base:0.32f},{Name:"horse.jumpStrength",Base:0f}]}
  265. execute @e[tag=car,score_driveTime_min=40] ~ ~ ~ execute @e[tag=car_model] ~ ~ ~ particle smoke ~ ~-0.5 ~ 0 0 0 0.1 10
  266. execute @e[tag=car,score_driveTime=5] ~ ~ ~ stopsound @a neutral engine_accelerate
  267. execute @e[tag=car,score_driveTime_min=5,score_driveTime=5] ~ ~ ~ playsound engine_accelerate neutral @a ~ ~ ~ 10
  268.  
  269. # Car bounce (suspension) - very minor and not noticable unless you specifically look for it
  270. #entitydata @e[tag=car_model,c=1] {Pose:{Head:[0f,0f,0f]}}
  271. #execute @e[tag=car,score_driveTime_min=2,score_driveTime=4] ~ ~ ~ entitydata @e[tag=car_model,c=1] {Pose:{Head:[-1f,0f,0f]}}
  272. #execute @e[tag=car,score_driveTime_min=5,score_driveTime=8] ~ ~ ~ entitydata @e[tag=car_model,c=1] {Pose:{Head:[-2f,0f,0f]}}
  273. #execute @e[tag=car,score_driveTime_min=9,score_driveTime=15] ~ ~ ~ entitydata @e[tag=car_model,c=1] {Pose:{Head:[-3f,0f,0f]}}
  274. #execute @e[tag=car,score_driveTime_min=16,score_driveTime=19] ~ ~ ~ entitydata @e[tag=car_model,c=1] {Pose:{Head:[-2f,0f,0f]}}
  275. #execute @e[tag=car,score_driveTime_min=20,score_driveTime=22] ~ ~ ~ entitydata @e[tag=car_model,c=1] {Pose:{Head:[-1f,0f,0f]}}
  276.  
  277. # Puddles
  278. execute @e[tag=car,score_driveTime_min=5] ~ ~ ~ detect ~ ~ ~ carpet 11 scoreboard players set @e[tag=car,c=1,r=1] driveTime 6
  279. execute @e[tag=car,score_driveTime_min=5] ~ ~ ~ detect ~ ~ ~ carpet 11 particle splash ~ ~ ~ 0.8 0.8 0.8 1 20
  280. }
  281.  
  282. // Coordinates of spawn box
  283. $spawnCapsule = "1001 7.6 992";
  284.  
  285. # Changed to a trigger (stepping on a jukebox)
  286. #delay 10 {
  287. # reset()
  288. # delay 5 {
  289. # setup()
  290. # }
  291. #}
  292.  
  293. function setup() {
  294.  
  295. // Runs to setup the game and put the player into the menu screen
  296.  
  297. tp @a $spawnCapsule
  298. replaceitem entity @a slot.armor.head air
  299. replaceitem entity @a slot.armor.head pumpkin
  300. effect @a minecraft:invisibility 10000 1 true
  301. stopsound @a
  302.  
  303. delay 20 {
  304.  
  305. // Delay so that the sound plays in the new location after the /tp
  306. execute @a ~ ~ ~ playsound menu neutral @a ~ ~ ~ 10
  307.  
  308. }
  309.  
  310. start checkForStart
  311.  
  312. }
  313.  
  314. function activatePowerup() {
  315. # Player has picked up a powerup
  316.  
  317. stopsound @a
  318. execute @a ~ ~ ~ playsound powerup neutral @a ~ ~ ~ 10
  319.  
  320. title @a times 10 20 10
  321. title @a subtitle {"text":"Demolish other cars","italic":true,"color":"dark_purple"}
  322. title @a title {"text":"Powerup!","bold":true,"color":"dark_red"}
  323.  
  324. delay 45 {
  325.  
  326. execute @e[tag=car] ~ ~ ~ particle dragonbreath ~ ~ ~ 0 0 0 0.3 100
  327. scoreboard players set @e[tag=car] powerup 240
  328. effect @e[tag=car_model] glowing 13
  329.  
  330. }
  331.  
  332. }
  333.  
  334. repeat checkForStart:off {
  335.  
  336. // If there is an emerald block under the player, then they
  337. // have pressed space meaning they are ready to start the game
  338. # say checking for emerald block
  339.  
  340. # Just for testing purposes to exit the menu easier
  341. replaceitem entity @a[x=1000,y=7,z=991,dx=2,dy=3,dz=2,score_sneak_min=3] slot.armor.head air
  342. stopsound @a[x=1000,y=7,z=991,dx=2,dy=3,dz=2,score_sneak_min=3]
  343. tp @a[x=1000,y=7,z=991,dx=2,dy=3,dz=2,score_sneak_min=3] ~-6 ~ ~
  344. scoreboard players set @a[score_sneak_min=3] sneak 0
  345.  
  346. execute @a ~ ~ ~ detect ~ ~-1 ~ emerald_block -1 gotoCarSelect()
  347.  
  348. }
  349.  
  350. function gotoCarSelect() {
  351.  
  352. # Go to car select screen
  353.  
  354. stopsound @a
  355. stop checkForStart
  356.  
  357. replaceitem entity @a slot.armor.head air
  358.  
  359. instant obstacleSetup()
  360.  
  361. delay 10 {
  362.  
  363. tp @a @e[tag=CarSelect,name=CarSelect]
  364. scoreboard players tag @e[tag=CarSelect] remove CarSelectMove
  365. scoreboard players tag @a add isSelectingCar
  366.  
  367. delay 2 {
  368. execute @a ~ ~ ~ playsound apocal master @a ~ ~ ~ 0.45
  369. }
  370.  
  371. start carSelect
  372. title @a actionbar ["",{"text":"Use","color":"gray"},{"text":" A "},{"text":"and D to switch / / ","color":"gray"},{"text":"SPACE "},{"text":"to select","color":"gray"}]
  373.  
  374. }
  375.  
  376. }
  377.  
  378. $_selectedCar = 1
  379. $_selectedCarCD = 0
  380.  
  381. $_unlockedCars = 1
  382. $_checkUnlocked = 0
  383.  
  384. repeat carSelect:off {
  385.  
  386. // Scrolling left and right through the cars
  387. scoreboard players tag @e[tag=CarSelect] remove CarSelectMove
  388. execute @a ~ ~ ~ detect ~ ~ ~1 pumpkin -1 scoreboard players tag @e[tag=CarSelect,c=1] add CarSelectMove
  389.  
  390.  
  391. // Scroll left
  392. if (@e[type=armor_stand,name=CarSelectLeft,tag=CarSelectMove] and $_selectedCarCD==0) {
  393.  
  394. $_selectedCar--
  395. $_selectedCarCD = 5
  396. execute @a ~ ~ ~ playsound click neutral @a
  397.  
  398. }
  399.  
  400. // Scroll right
  401. if (@e[type=armor_stand,name=CarSelectRight,tag=CarSelectMove] and $_selectedCarCD==0) {
  402.  
  403. $_selectedCar++
  404. $_selectedCarCD = 5
  405. execute @a ~ ~ ~ playsound click neutral @a
  406.  
  407. }
  408.  
  409. if (@e[type=armor_stand,name=CarSelectRight,tag=CarSelectMove] and $_unlockedCars==1) {
  410.  
  411. title @a actionbar ["",{"text":"You haven't unlocked any more cars yet! ","bold":true,"italic":true,"color":"dark_red"},{"text":"Press SPACE to play","color":"yellow"}]
  412. execute @a ~ ~ ~ playsound error neutral @a
  413.  
  414. }
  415.  
  416. if ($_selectedCarCD > 0) {
  417. $_selectedCarCD--
  418. }
  419.  
  420. if ($_selectedCar<1) {
  421. $_selectedCar = $_unlockedCars
  422. }
  423.  
  424. # Si no lo tiene
  425. $_checkUnlocked = $_selectedCar
  426. $_checkUnlocked -= $_unlockedCars
  427. if ($_checkUnlocked>0) {
  428. # say set to 1
  429. $_selectedCar = 1
  430. }
  431.  
  432. if ($_selectedCar==1) {
  433. entitydata @e[tag=CarDisplay] {ArmorItems:[{},{},{},{id:"diamond_hoe",Count:1,Damage:1}]}
  434. }
  435. if ($_selectedCar==2) {
  436. entitydata @e[tag=CarDisplay] {ArmorItems:[{},{},{},{id:"diamond_hoe",Count:1,Damage:2}]}
  437. }
  438. if ($_selectedCar==3) {
  439. entitydata @e[tag=CarDisplay] {ArmorItems:[{},{},{},{id:"diamond_hoe",Count:1,Damage:3}]}
  440. }
  441. if ($_selectedCar==4) {
  442. entitydata @e[tag=CarDisplay] {ArmorItems:[{},{},{},{id:"diamond_hoe",Count:1,Damage:4}]}
  443. }
  444. if ($_selectedCar==5) {
  445. entitydata @e[tag=CarDisplay] {ArmorItems:[{},{},{},{id:"diamond_hoe",Count:1,Damage:7}]}
  446. }
  447. if ($_selectedCar==6) {
  448. entitydata @e[tag=CarDisplay] {ArmorItems:[{},{},{},{id:"diamond_hoe",Count:1,Damage:6}]}
  449. }
  450. if ($_selectedCar==7) {
  451. entitydata @e[tag=CarDisplay] {ArmorItems:[{},{},{},{id:"diamond_hoe",Count:1,Damage:5}]}
  452. }
  453.  
  454. # tellraw @a [{"text":"selected: "},$_selectedCar]
  455. # tellraw @a [{"text":"cd: "},$_selectedCarCD]
  456.  
  457. execute @e[tag=CarSelectMove,name=!CarSelect] ~ ~ ~ tp @a @e[tag=CarSelect,name=CarSelect]
  458. tp @e[tag=CarDisplay] 992 7 977 ~2 ~
  459.  
  460. tp @a ~ ~ ~ 180 30
  461.  
  462. execute @a ~ ~ ~ detect ~ ~ ~1 emerald_block -1 stop carSelect
  463. execute @a ~ ~ ~ detect ~ ~ ~1 emerald_block -1 scoreboard players tag @a remove isSelectingCar
  464. execute @a ~ ~ ~ detect ~ ~ ~1 emerald_block -1 stopsound @a
  465. execute @a ~ ~ ~ detect ~ ~ ~1 emerald_block -1 playsound menu neutral @a ~ ~ ~ 10
  466. execute @a ~ ~ ~ detect ~ ~ ~1 emerald_block -1 tp @a 978 7 994
  467.  
  468. }
  469.  
  470.  
  471. $carSpawnLoc = "1020 7 1014.0"
  472.  
  473. function begin() {
  474.  
  475. tp @e[tag=car] ~ ~-1000 ~
  476.  
  477. stopsound @a
  478.  
  479. effect @a clear
  480. effect @a blindness 4 4 true
  481. tp @a 1017 8 1021 -80 15
  482. execute @a ~ ~ ~ playsound alarm neutral @a
  483.  
  484. # the first one doesn't have the money_bag tag so that it can't disappear over time
  485. summon item 1023 9 1020 {Item:{id:cooked_rabbit,Count:1,Age:-32768}}
  486. # the rest are spawned in the spawnCoins() function below
  487.  
  488. tp @e[tag=garage_door] ~ 8.0 ~
  489.  
  490. execute @a ~ ~30 ~ summon sheep ~ ~ ~ {Tags:["target_sheep"],Silent:1,NoGravity:1}
  491.  
  492. # Also spawns powerups
  493. spawnCoins()
  494. start spawnMoneyBags
  495.  
  496. musicLoop()
  497.  
  498. tp @e[tag=car_model] $carSpawnLoc -90 0
  499. summon horse $carSpawnLoc {Tags:["car","carPart"],Attributes:[{Name:"generic.movementSpeed",Base:0.1f},{Name:"horse.jumpStrength",Base:0f}],Rotation:[-90f,0f],Tame:1,SaddleItem:{id:saddle,Count:1},Silent:1,Invisible:1}
  500.  
  501. scoreboard players set @e[tag=car] powerup 0
  502. scoreboard players set @a car_damage 0
  503.  
  504. spawnPedestrian()
  505.  
  506. spawnNPCCars()
  507. # This ~might~ does not work
  508. # stop spawnPolice
  509.  
  510. delay 130 {
  511.  
  512. scoreboard players set @a policeNum 0
  513.  
  514. spawnPolice()
  515.  
  516. start openGarageDoor
  517.  
  518. scoreboard players set @a eventTimer 0
  519.  
  520. }
  521.  
  522. execute @e[tag=toll_1] ~ ~ ~ clone 965 7 1015 971 12 1021 ~-3 ~ ~-3
  523. execute @e[tag=toll_2] ~ ~ ~ clone 965 7 1023 971 12 1029 ~-3 ~ ~-3
  524. execute @e[tag=toll_3] ~ ~ ~ clone 973 7 1015 979 12 1021 ~-3 ~ ~-3
  525.  
  526. scoreboard players tag @e[tag=toll_3] add toll_1
  527. scoreboard players tag @e[tag=toll_3] add toll_2
  528.  
  529. start gameplay
  530. scoreboard players tag @a add isPlaying
  531. scoreboard players tag @a add CarNotStarted
  532.  
  533. }
  534.  
  535. repeat openGarageDoor:off {
  536.  
  537. # Garage door
  538. tp @e[tag=garage_door,x=1017,y=7,z=1004,dx=2,dy=3,dz=3] ~ ~0.03 ~
  539.  
  540. }
  541.  
  542. function musicLoop() {
  543.  
  544. execute @a[tag=isPlaying] ~ ~ ~ playsound shopping neutral @a ~ ~ ~ 1000
  545.  
  546. delay 3055 {
  547.  
  548. execute @a[tag=isPlaying] ~ ~ ~ playsound mangowalk neutral @a ~ ~ ~ 1000
  549.  
  550. delay 4015 {
  551.  
  552. musicLoop()
  553.  
  554. }
  555.  
  556. }
  557.  
  558. }
  559.  
  560. function obstacleSetup() {
  561.  
  562. kill @e[tag=check_obs]
  563. scoreboard players tag @e[tag=intersection] add unused
  564. execute @e[tag=intersection] ~ ~ ~ fill ~-3 ~ ~-3 ~3 ~10 ~3 air
  565. start generateObstacles
  566.  
  567. }
  568.  
  569. $tempObstacleCoords = 982 7 1015
  570. $tempObstacleCoords2 = 988 16 1021
  571.  
  572. repeat generateObstacles:off {
  573.  
  574. # 7x7 Obstacle squares = squareobstacle
  575. # Centers of intersections = intersection
  576. # Starting corner = start_corner
  577. # 2 armorstands at the final corner = obs_fin
  578.  
  579. # Temporary obstacle holding coordinates = 982 7 1015 or $tempObstacleCoords
  580. # Other corner of temp. obstacle coordinates = 988 16 1021 or $tempObstacleCoords2
  581.  
  582. //say generateObstacles is running
  583.  
  584. scoreboard players tag @r[type=armor_stand,tag=unused] add cur_loc
  585. execute @r[type=armor_stand,tag=squareobstacle] ~ ~ ~ clone ~ ~ ~ ~6 ~10 ~6 $tempObstacleCoords
  586. execute @e[tag=cur_loc] ~ ~ ~ execute @e[tag=!obs_fin,c=1,r=1] ~ ~ ~ clone $tempObstacleCoords $tempObstacleCoords2 ~-3 ~ ~-3
  587.  
  588. scoreboard players tag @e[tag=cur_loc] remove unused
  589. scoreboard players tag @e[tag=cur_loc] remove cur_loc
  590.  
  591. #say Placed obstacle.
  592.  
  593. scoreboard players set @a uniCount 0
  594. execute @e[tag=unused] ~ ~ ~ scoreboard players add @a uniCount 1
  595.  
  596. //execute @a[score_uniCount=0] ~ ~ ~ say Obstacle generation complete.
  597. execute @a[score_uniCount=0] ~ ~ ~ stop generateObstacles
  598. execute @a[score_uniCount=0] ~ ~ ~ checkObstacles()
  599.  
  600. }
  601.  
  602. function checkObstacles() {
  603.  
  604. kill @e[tag=check_obs]
  605. execute @e[tag=start_corner] ~ ~ ~ summon armor_stand ~ ~ ~ {NoGravity:1,Marker:1,Invisible:1,Tags:["check_obs"]}
  606. scoreboard players set @a checkObCount 0
  607. #execute @e[tag=intersection] ~ ~ ~ setblock ~ ~11 ~ air
  608. scoreboard players tag @a add isLoading
  609. start checkingObstacles
  610.  
  611. }
  612.  
  613. repeat checkingObstacles:off {
  614.  
  615. # Makes sure that the obstacle placement doesn't make it impossible to reach the end
  616. # If it is impossible, obstacleSetup() should be called again to redo the obstacles
  617. # If it is possible, there should be a check_obs armorstand at one of the armorstands near the final corner
  618.  
  619. //say checking obstacles
  620.  
  621. scoreboard players tag @e[tag=check_obs] add check_obs_old
  622. execute @e[tag=check_obs_old] ~ ~ ~ summon armor_stand ~24 ~ ~ {NoGravity:1,Marker:1,Invisible:1,Tags:["check_obs"]}
  623. execute @e[tag=check_obs_old] ~ ~ ~ summon armor_stand ~ ~ ~24 {NoGravity:1,Marker:1,Invisible:1,Tags:["check_obs"]}
  624. execute @e[tag=check_obs_old] ~ ~ ~ summon armor_stand ~-24 ~ ~ {NoGravity:1,Marker:1,Invisible:1,Tags:["check_obs"]}
  625. execute @e[tag=check_obs_old] ~ ~ ~ summon armor_stand ~ ~ ~-24 {NoGravity:1,Marker:1,Invisible:1,Tags:["check_obs"]}
  626. scoreboard players set @e[tag=check_obs] obs_valid_loc 0
  627. execute @e[tag=is_valid_loc] ~ ~ ~ scoreboard players set @e[tag=check_obs,r=2,c=1] obs_valid_loc 1
  628. execute @e[tag=check_obs] ~ ~ ~ detect ~ ~ ~ wool 15 scoreboard players set @e[tag=check_obs,r=1] obs_valid_loc 0
  629. kill @e[tag=check_obs,score_obs_valid_loc=0]
  630. kill @e[tag=check_obs_old]
  631.  
  632. #execute @e[tag=check_obs] ~ ~ ~ setblock ~ ~11 ~ gold_block
  633.  
  634. #scoreboard players set @a uniCount 0
  635. #execute @e[tag=check_obs] ~ ~ ~ scoreboard players add @a uniCount 1
  636.  
  637. # If this is successful, then the current obstacles are possible
  638. //execute @e[tag=obs_fin] ~ ~ ~ execute @e[tag=check_obs,r=2] ~ ~ ~ say POSSIBLE
  639. execute @e[tag=obs_fin] ~ ~ ~ execute @e[tag=check_obs,r=2] ~ ~ ~ scoreboard players tag @a remove isLoading
  640. execute @e[tag=obs_fin] ~ ~ ~ execute @e[tag=check_obs,r=2] ~ ~ ~ start tryBegin
  641. execute @e[tag=obs_fin] ~ ~ ~ execute @e[tag=check_obs,r=2] ~ ~ ~ stop checkingObstacles
  642.  
  643. # Once it reaches this point and it is still going, it is for sure impossible, so it will start over
  644. execute @a[score_checkObCount_min=16] ~ ~ ~ obstacleSetup()
  645. execute @a[score_checkObCount_min=16] ~ ~ ~ stop checkingObstacles
  646.  
  647. scoreboard players add @a checkObCount 1
  648.  
  649. }
  650.  
  651. repeat tryBegin:off {
  652.  
  653. execute @a[tag=!isSelectingCar] ~ ~ ~ execute @a[tag=!alreadyBegun] ~ ~ ~ begin()
  654. scoreboard players tag @a[tag=!isSelectingCar] add alreadyBegun
  655. execute @a[tag=!isSelectingCar] ~ ~ ~ stop tryBegin
  656.  
  657. }
  658.  
  659. repeat gameplay:off {
  660.  
  661. # Runs while the game is playing
  662.  
  663. # Pedestrians
  664. if (@a[tag=!game_over]) {
  665. tp @e[type=villager,name=pedestrian,tag=ped_south] ~ ~ ~.3
  666. tp @e[type=villager,name=pedestrian,tag=ped_north] ~ ~ ~-.3
  667. tp @e[type=villager,name=pedestrian,tag=ped_east] ~.3 ~ ~
  668. tp @e[type=villager,name=pedestrian,tag=ped_west] ~-.3 ~ ~
  669. }
  670. execute @e[type=villager,name=pedestrian] ~ ~ ~ detect ~ ~ ~ stone_slab -1 tp @e[type=villager,name=pedestrian,c=1,r=1] ~ 7.5 ~
  671. execute @e[type=villager,name=pedestrian] ~ ~ ~ detect ~ ~-1 ~ coal_block -1 tp @e[type=villager,name=pedestrian,c=1,r=1] ~ 7.0 ~
  672. scoreboard players add @e[type=villager,name=pedestrian] ped_walk 1
  673. tp @e[type=villager,score_ped_walk_min=45] ~ ~-100 ~
  674.  
  675. execute @e[type=villager,name=pedestrian] ~ ~ ~ execute @e[tag=car,r=3] ~ ~ ~ pedestrianCollision()
  676.  
  677. scoreboard players add @e[type=villager,name=hit_pedestrian] MP 1
  678. tp @e[type=villager,name=hit_pedestrian,score_MP_min=50] ~ ~-0.2 ~
  679.  
  680. # Near misses
  681. execute @e[tag=NPCCar] ~ ~ ~ scoreboard players tag @e[tag=car,rm=2,r=3] add tryNearMiss
  682. execute @e[tag=tryNearMiss] ~ ~ ~ tryNearMiss()
  683.  
  684. # Collecting coins
  685. if ("clear @a pumpkin_pie 0 1")
  686. {
  687. execute @a ~ ~ ~ playsound entity.experience_orb.pickup neutral @a ~ ~ ~ 1 2
  688. scoreboard players add @a points 2
  689. }
  690.  
  691. # Collecting money bags
  692. if ("clear @a cooked_rabbit 0 1")
  693. {
  694. execute @a ~ ~ ~ playsound cinematic neutral @a ~ ~ ~ 10
  695. execute @e[tag=car] ~ ~ ~ particle fireworksSpark ~ ~ ~ 0 0 0 0.4 50
  696. scoreboard players add @a money_bags 1
  697. title @a actionbar ["",{"text":"=== ","bold":true,"color":"dark_red"},{"text":"Collected money bag ","bold":true,"color":"yellow"},{"score":{"name":"@a","objective":"money_bags"},"color":"gold"},{"text":" / 5","color":"gold"},{"text":" ===","bold":true,"color":"dark_red"}]
  698. scoreboard players add @a points 50
  699.  
  700. }
  701.  
  702. # Random events such as meteor showers
  703. scoreboard players add @a[score_eventTimer_min=0] eventTimer 1
  704. execute @a[score_eventTimer_min=700] ~ ~ ~ doRandomEvent()
  705. scoreboard players set @a[score_eventTimer_min=700] eventTimer 0
  706.  
  707. # Barrier particles at toll booths
  708. execute @a[score_money_bags=4] ~ ~ ~ execute @e[tag=toll_1] ~ ~ ~ particle barrier ~ ~3 ~-4 0 0 0 1
  709. execute @a[score_money_bags=4] ~ ~ ~ execute @e[tag=toll_2] ~ ~ ~ particle barrier ~-4 ~3 ~ 0 0 0 1
  710.  
  711. execute @a[score_money_bags_min=5,tag=!unlockedTolls] ~ ~ ~ openTollBooths()
  712.  
  713. # Remove glow when powerup runs out
  714. execute @e[tag=car,score_powerup=0] ~ ~ ~ effect @e[tag=car_model] clear
  715. }
  716.  
  717. function tryNearMiss() {
  718.  
  719. scoreboard players tag @e[tag=hitNPCCar] remove tryNearMiss
  720. execute @e[tag=NPCCar] ~ ~ ~ scoreboard players tag @e[tag=hitNPCCar,rm=5,r=6] remove hitNPCCar
  721. execute @e[tag=NPCCar] ~ ~ ~ execute @e[tag=car,r=2] ~ ~ ~ scoreboard players tag @e[tag=car] add hitNPCCar
  722. execute @e[tag=NPCCar] ~ ~ ~ execute @e[tag=tryNearMiss,rm=4,r=5] ~ ~ ~ didTrick("Near Miss!", 5)
  723. execute @e[tag=NPCCar] ~ ~ ~ scoreboard players tag @e[tag=tryNearMiss,rm=4,r=5] remove tryNearMiss
  724.  
  725. }
  726.  
  727. function pedestrianCollision() {
  728.  
  729. execute @e[type=villager,name=pedestrian] ~ ~ ~ execute @e[tag=car,r=4] ~ ~ ~ playsound minecraft:entity.villager.hurt neutral @a
  730. execute @e[tag=car,score_powerup=0] ~ ~ ~ execute @e[type=villager,name=pedestrian,r=4] ~ ~ ~ scoreboard players set @e[tag=car] driveTime 1
  731. execute @e[tag=car] ~ ~ ~ execute @e[type=villager,name=pedestrian,r=4] ~ ~ ~ particle crit ~ ~ ~ 0 0 0 1 50
  732. execute @e[tag=car,score_powerup=0] ~ ~ ~ execute @e[type=villager,name=pedestrian,r=4] ~ ~ ~ scoreboard players add @a car_damage 15
  733. execute @e[tag=car,score_powerup=0] ~ ~ ~ entitydata @e[type=villager,name=pedestrian,r=4] {NoAI:0,NoGravity:0,Motion:[0.0d,2.0d,0.0d],CustomName:hit_pedestrian}
  734. execute @e[tag=car,score_powerup_min=1] ~ ~ ~ execute @e[type=villager,name=pedestrian,r=4] ~ ~ ~ particle endRod ~ ~ ~ 0 0 0 0.1 100
  735. execute @e[tag=car,score_powerup_min=1] ~ ~ ~ execute @e[type=villager,name=pedestrian,r=4] ~ ~ ~ title @a actionbar ["",{"text":"Kapow! ","bold":true,"color":"dark_purple"},{"text":"(+20 points)","italic":true,"color":"gold"}]
  736. execute @e[tag=car,score_powerup_min=1] ~ ~ ~ execute @e[type=villager,name=pedestrian,r=4] ~ ~ ~ summon item ~ ~ ~ {Item:{id:pumpkin_pie,Count:20},Age:-32768,Tags:["coin"],PickupDelay:1}
  737. execute @e[tag=car,score_powerup_min=1] ~ ~ ~ tp @e[type=villager,name=pedestrian,r=4] ~ ~-1000 ~
  738.  
  739. }
  740.  
  741. function displayMessage($messageText)
  742. {
  743.  
  744. title @a actionbar ["",{"text":"=== ","bold":true,"color":"dark_red"},{"text":"$messageText","bold":true,"color":"yellow"},{"text":" ===","bold":true,"color":"dark_red"}]
  745.  
  746. }
  747.  
  748. function didTrick($trickText, $trickPoints)
  749. {
  750.  
  751. title @a actionbar ["",{"text":"$trickText ","bold":true,"color":"dark_purple"},{"text":"(+$trickPoints points)","italic":true,"color":"gold"}]
  752.  
  753. execute @a ~ ~ ~ summon item ~ ~ ~ {Item:{id:pumpkin_pie,Count:$trickPoints},Age:-32768,Tags:["coin"],PickupDelay:1}
  754. #scoreboard players add @a points $trickPoints
  755.  
  756. }
  757.  
  758. function spawnPedestrian() {
  759.  
  760. if (@a[tag=isPlaying]) {
  761. execute @r[type=armor_stand,name=intersection,x=1042,y=5,z=1023,dx=140,dy=10,dz=140] ~ ~ ~ summon villager ~-7 ~0.5 ~-6 {CustomName:pedestrian,Tags:["pedestrian","ped_south","cartoon_outline"],Rotation:[0f],Invulnerable:1,NoGravity:1,NoAI:1}
  762. execute @r[type=armor_stand,name=intersection,x=1042,y=5,z=1023,dx=140,dy=10,dz=140] ~ ~ ~ summon villager ~-7 ~0.5 ~6 {CustomName:pedestrian,Tags:["pedestrian","ped_north","cartoon_outline"],Rotation:[180f],Invulnerable:1,NoGravity:1,NoAI:1}
  763. execute @r[type=armor_stand,name=intersection,x=1042,y=5,z=1023,dx=140,dy=10,dz=140] ~ ~ ~ summon villager ~-6 ~0.5 ~-7 {CustomName:pedestrian,Tags:["pedestrian","ped_east","cartoon_outline"],Rotation:[-90f],Invulnerable:1,NoGravity:1,NoAI:1}
  764. execute @r[type=armor_stand,name=intersection,x=1042,y=5,z=1023,dx=140,dy=10,dz=140] ~ ~ ~ summon villager ~6 ~0.5 ~-7 {CustomName:pedestrian,Tags:["pedestrian","ped_west","cartoon_outline"],Rotation:[90f],Invulnerable:1,NoGravity:1,NoAI:1}
  765. }
  766.  
  767. delay 30 {
  768. spawnPedestrian()
  769. }
  770.  
  771. }
  772.  
  773. function spawnPolice() {
  774.  
  775. scoreboard players add @a[score_policeNum_min=0] policeNum 1
  776.  
  777. delay 240 {
  778.  
  779. execute @p[tag=isPlaying,score_policeNum_min=0,score_policeNum=6] ~ ~ ~ execute @e[tag=police_spawner] ~ ~ ~ summon minecraft:wolf ~ ~2 ~ {Angry:1,CustomName:police_car,CustomNameVisible:1,Attributes:[{Name:"generic.followRange",Base:500},{Name:"generic.movementSpeed",Base:0.4f},{Name:"generic.attackDamage",Base:0}],Silent:1,Invulnerable:1,ActiveEffects:[{Id:14,Amplifier:0,Duration:2147483647,ShowParticles:0b}],Tags:["police_car","police_car_part"],Passengers:[{id:armor_stand,Tags:["police_car_part","cartoon_outline"],Invisible:1,Marker:1,ArmorItems:[{},{},{},{id:iron_hoe,Count:1}]}]}
  780.  
  781. # Limit to 6 police
  782. execute @p[tag=isPlaying,score_policeNum_min=0,score_policeNum=6] ~ ~ ~ spawnPolice()
  783.  
  784. execute @e[tag=police_car] ~ ~ ~ playsound siren neutral @a[r=25] ~ ~ ~ 3 1
  785.  
  786. }
  787.  
  788. }
  789.  
  790.  
  791. # NPC Cars Traffic control
  792.  
  793. # npcCarCD = Cooldown for rotation changes on NPC cars
  794. # npcCarRot = Rotation of NPC car (1 = X+, 2 = Z+, 3 = X-, 4 = Z-)
  795.  
  796.  
  797. function spawnNPCCars() {
  798.  
  799. execute @e[tag=spawnNPCCar] ~ ~ ~ summon armor_stand ~ ~ ~ {Tags:["NPCCar","cartoon_outline"],NoGravity:1,ArmorItems:[{},{},{},{id:golden_hoe,Damage:1,tag:{Unbreakable:1},Count:1}],Invisible:1,Marker:1}
  800.  
  801. entitydata @r[type=armor_stand,tag=NPCCar,c=10] {ArmorItems:[{},{},{},{id:golden_hoe,Damage:2,tag:{Unbreakable:1},Count:1}]}
  802. entitydata @r[type=armor_stand,tag=NPCCar,c=9] {ArmorItems:[{},{},{},{id:golden_hoe,Damage:3,tag:{Unbreakable:1},Count:1}]}
  803. entitydata @r[type=armor_stand,tag=NPCCar,c=8] {ArmorItems:[{},{},{},{id:golden_hoe,Damage:4,tag:{Unbreakable:1},Count:1}]}
  804. entitydata @r[type=armor_stand,tag=NPCCar,c=7] {ArmorItems:[{},{},{},{id:golden_hoe,Damage:5,tag:{Unbreakable:1},Count:1}]}
  805.  
  806.  
  807. # Set initial directions
  808. execute @e[tag=NPCCar] ~ ~ ~ detect ~ ~-2 ~-2 gold_block 0 scoreboard players set @s npcCarRot 1
  809. execute @e[tag=NPCCar] ~ ~ ~ detect ~2 ~-2 ~ gold_block 0 scoreboard players set @s npcCarRot 2
  810. execute @e[tag=NPCCar] ~ ~ ~ detect ~ ~-2 ~2 gold_block 0 scoreboard players set @s npcCarRot 3
  811. execute @e[tag=NPCCar] ~ ~ ~ detect ~-2 ~-2 ~ gold_block 0 scoreboard players set @s npcCarRot 4
  812.  
  813. #delay 10 {
  814.  
  815. # For cases where 2 cars spawned in the same spot
  816. #execute @e[tag=NPCCar] ~ ~ ~ detect ~ ~-2 ~-2 gold_block 0 scoreboard players set @e[tag=NPCCar,c=1,r=1] npcCarRot 1
  817. #execute @e[tag=NPCCar] ~ ~ ~ detect ~2 ~-2 ~ gold_block 0 scoreboard players set @e[tag=NPCCar,c=1,r=1] npcCarRot 2
  818. #execute @e[tag=NPCCar] ~ ~ ~ detect ~ ~-2 ~2 gold_block 0 scoreboard players set @e[tag=NPCCar,c=1,r=1] npcCarRot 3
  819. #execute @e[tag=NPCCar] ~ ~ ~ detect ~-2 ~-2 ~ gold_block 0 scoreboard players set @e[tag=NPCCar,c=1,r=1] npcCarRot 4
  820.  
  821. #}
  822.  
  823. # Also spawns the tanks
  824. execute @e[tag=tank_spawner] ~ ~ ~ summon wolf ~ ~ ~ {Angry:1,Attributes:[{Name:"generic.followRange",Base:500},{Name:"generic.movementSpeed",Base:0.22f},{Name:"generic.attackDamage",Base:0}],Silent:1,Invulnerable:1,ActiveEffects:[{Id:14,Amplifier:0,Duration:2147483647,ShowParticles:0b}],Tags:["tank_part","tank_wolf"]}
  825. execute @e[tag=tank_spawner] ~ ~ ~ summon armor_stand ~ ~ ~ {Tags:["tank_part","tank_bottom","cartoon_outline"],Invisible:1,Marker:1,NoGravity:1,ArmorItems:[{},{},{},{id:golden_hoe,Damage:6,Count:1,tag:{Unbreakable:1}}]}
  826. execute @e[tag=tank_spawner] ~ ~ ~ summon armor_stand ~ ~ ~ {Tags:["tank_part","tank_top","cartoon_outline"],Invisible:1,Marker:1,NoGravity:1,ArmorItems:[{},{},{},{id:golden_hoe,Damage:7,Count:1,tag:{Unbreakable:1}}]}
  827. }
  828.  
  829. repeat traffic {
  830.  
  831. # Player collisions with NPC cars
  832. execute @e[tag=NPCCar] ~ ~ ~ fill ~-1 ~ ~-1 ~1 ~1 ~1 air 0 replace barrier
  833. execute @e[tag=NPCCar] ~ ~ ~ fill ~ ~ ~ ~ ~1 ~ barrier 0 replace air
  834.  
  835. # This starts running at r=3 so that it has a head start to catch it on time in the function call (1 tick later)
  836. execute @e[tag=NPCCar] ~ ~ ~ execute @e[tag=car,r=3] ~ ~ ~ npcCollision()
  837.  
  838. # If a pedestrian is near an NPC car, the car will stop moving until the pedestrian crosses the road
  839. scoreboard players tag @e[tag=NPCCar] remove near_pedestrian
  840. execute @e[tag=pedestrian] ~ ~ ~ scoreboard players tag @e[tag=NPCCar,r=5] add near_pedestrian
  841.  
  842. if (@a[tag=!game_over]) {
  843. execute @a ~ ~ ~ tp @e[tag=!near_pedestrian,score_npcCarRot_min=1,score_npcCarRot=1,r=50] ~0.3 ~ ~ 90 0
  844. execute @a ~ ~ ~ tp @e[tag=!near_pedestrian,score_npcCarRot_min=2,score_npcCarRot=2,r=50] ~ ~ ~0.3 180 0
  845. execute @a ~ ~ ~ tp @e[tag=!near_pedestrian,score_npcCarRot_min=3,score_npcCarRot=3,r=50] ~-0.3 ~ ~ -90 0
  846. execute @a ~ ~ ~ tp @e[tag=!near_pedestrian,score_npcCarRot_min=4,score_npcCarRot=4,r=50] ~ ~ ~-0.3 0 0
  847. }
  848.  
  849. scoreboard players add @e[tag=NPCCar] npcCarCD 0
  850.  
  851. # Deciding whether to continue or turn
  852. execute @e[tag=!atDeadEnd,score_npcCarCD=0] ~ ~ ~ detect ~ ~-2 ~ diamond_block 0 npcControl()
  853.  
  854. scoreboard players remove @e[tag=NPCCar,score_npcCarCD_min=1] npcCarCD 1
  855.  
  856. # Turning around at dead ends
  857. scoreboard players tag @e[tag=NPCCar] remove atDeadEnd
  858. execute @a ~ ~ ~ execute @e[tag=NPCCar,score_npcCarRot_min=1,score_npcCarRot=1,r=50] ~ ~ ~ detect ~3 ~ ~ wool 15 scoreboard players tag @e[tag=NPCCar,c=1,r=1] add atDeadEnd
  859. execute @a ~ ~ ~ execute @e[tag=NPCCar,score_npcCarRot_min=2,score_npcCarRot=2,r=50] ~ ~ ~ detect ~ ~ ~3 wool 15 scoreboard players tag @e[tag=NPCCar,c=1,r=1] add atDeadEnd
  860. execute @a ~ ~ ~ execute @e[tag=NPCCar,score_npcCarRot_min=3,score_npcCarRot=3,r=50] ~ ~ ~ detect ~-3 ~ ~ wool 15 scoreboard players tag @e[tag=NPCCar,c=1,r=1] add atDeadEnd
  861. execute @a ~ ~ ~ execute @e[tag=NPCCar,score_npcCarRot_min=4,score_npcCarRot=4,r=50] ~ ~ ~ detect ~ ~ ~-3 wool 15 scoreboard players tag @e[tag=NPCCar,c=1,r=1] add atDeadEnd
  862.  
  863. execute @e[tag=atDeadEnd] ~ ~ ~ npcUTurns()
  864.  
  865. # In case any car somehow gets off track
  866. execute @e[tag=NPCCarRand] ~ ~ ~ detect ~ ~-1 ~ stained_hardened_clay 3 tp @e[tag=NPCCarRand,c=1,r=1] 1100 7 1081
  867.  
  868. # Police cars catching the player
  869. execute @e[tag=police_car] ~ ~ ~ execute @e[tag=car,r=9] ~ ~ ~ execute @a[score_car_damage=999,tag=!game_over] ~ ~ ~ playsound siren neutral @a ~ ~ ~ 10
  870. execute @e[tag=police_car] ~ ~ ~ execute @e[tag=car,r=3] ~ ~ ~ execute @a[score_car_damage=999,tag=!game_over] ~ ~ ~ playsound impact.random neutral @a ~ ~ ~ 10
  871. execute @e[tag=police_car] ~ ~ ~ execute @e[tag=car,r=3] ~ ~ ~ scoreboard players set @a[score_car_damage=999] car_damage 1000
  872.  
  873. # Hitting meteors
  874. execute @e[tag=car] ~ ~ ~ execute @e[tag=meteor,r=2] ~ ~ ~ hitMeteor()
  875.  
  876. }
  877.  
  878. function hitMeteor() {
  879.  
  880. execute @e[tag=car] ~ ~ ~ execute @e[tag=meteor,r=3] ~ ~ ~ scoreboard players add @a car_damage 25
  881. execute @e[tag=car] ~ ~ ~ execute @e[tag=meteor,r=3] ~ ~ ~ particle crit ~ ~ ~ 0 0 0 1 100
  882. execute @e[tag=car] ~ ~ ~ execute @e[tag=meteor,r=3] ~ ~ ~ playsound impact.random neutral @a ~ ~ ~ 10
  883. execute @e[tag=car] ~ ~ ~ kill @e[tag=meteor,r=3]
  884.  
  885. }
  886.  
  887. function npcCollision() {
  888.  
  889. execute @e[tag=NPCCar] ~ ~ ~ execute @e[tag=car,r=2,score_powerup=0] ~ ~ ~ scoreboard players add @a car_damage 3
  890. execute @e[tag=NPCCar] ~ ~ ~ execute @e[tag=car,r=2] ~ ~ ~ execute particle explode ~ ~ ~ 0 0 0 0.3 20
  891. execute @e[tag=NPCCar] ~ ~ ~ execute @e[tag=car,r=2] ~ ~ ~ playsound impact.random neutral @a[tag=!game_over]
  892. execute @e[tag=car,score_powerup_min=1] ~ ~ ~ execute @e[tag=NPCCar,r=2] ~ ~ ~ particle endRod ~ ~ ~ 0 0 0 0.1 100
  893. execute @e[tag=car,score_powerup_min=1] ~ ~ ~ execute @e[tag=NPCCar,r=2] ~ ~ ~ title @a actionbar ["",{"text":"Demolished a car! ","bold":true,"color":"dark_purple"},{"text":"(+15 points)","italic":true,"color":"gold"}]
  894. execute @e[tag=car,score_powerup_min=1] ~ ~ ~ execute @e[tag=NPCCar,r=2] ~ ~ ~ summon item ~ ~ ~ {Item:{id:pumpkin_pie,Count:15},Age:-32768,Tags:["coin"],PickupDelay:1}
  895. # Spawn new NPC car somewhere, to make up for loss
  896. execute @e[tag=car,score_powerup_min=1] ~ ~ ~ execute @e[tag=NPCCar,r=2] ~ ~ ~ execute @r[type=armor_stand,tag=spawnNPCCar,rm=20] ~ ~ ~ summon armor_stand ~ ~ ~ {Tags:["NPCCar","cartoon_outline"],NoGravity:1,ArmorItems:[{},{},{},{id:golden_hoe,Damage:1,tag:{Unbreakable:1},Count:1}],Invisible:1,Marker:1}
  897. execute @e[tag=NPCCar] ~ ~ ~ detect ~ ~-2 ~-2 gold_block 0 scoreboard players set @s npcCarRot 1
  898. execute @e[tag=NPCCar] ~ ~ ~ detect ~2 ~-2 ~ gold_block 0 scoreboard players set @s npcCarRot 2
  899. execute @e[tag=NPCCar] ~ ~ ~ detect ~ ~-2 ~2 gold_block 0 scoreboard players set @s npcCarRot 3
  900. execute @e[tag=NPCCar] ~ ~ ~ detect ~-2 ~-2 ~ gold_block 0 scoreboard players set @s npcCarRot 4
  901.  
  902. execute @e[tag=car,score_powerup_min=1] ~ ~ ~ execute @e[tag=NPCCar,r=2] ~ ~ ~ fill ~-1 ~ ~-1 ~1 ~1 ~1 air 0 replace barrier
  903. execute @e[tag=car,score_powerup_min=1] ~ ~ ~ kill @e[tag=NPCCar,r=2]
  904.  
  905. }
  906.  
  907. function npcControl() {
  908.  
  909. execute @e[tag=NPCCar,score_npcCarCD=0] ~ ~ ~ detect ~ ~-2 ~ diamond_block 0 execute @e[tag=NPCCar,score_npcCarCD=0,c=1] ~ ~ ~ detect ~1 ~-2 ~ bedrock 0 summon armor_stand ~ ~ ~ {CustomName:"NPCCarRand1",Tags:["NPCCarRand"],Invisible:1,Marker:1,NoGravity:1}
  910. execute @e[tag=NPCCar,score_npcCarCD=0] ~ ~ ~ detect ~ ~-2 ~ diamond_block 0 execute @e[tag=NPCCar,score_npcCarCD=0,c=1] ~ ~ ~ detect ~ ~-2 ~1 bedrock 0 summon armor_stand ~ ~ ~ {CustomName:"NPCCarRand2",Tags:["NPCCarRand"],Invisible:1,Marker:1,NoGravity:1}
  911. execute @e[tag=NPCCar,score_npcCarCD=0] ~ ~ ~ detect ~ ~-2 ~ diamond_block 0 execute @e[tag=NPCCar,score_npcCarCD=0,c=1] ~ ~ ~ detect ~-1 ~-2 ~ bedrock 0 summon armor_stand ~ ~ ~ {CustomName:"NPCCarRand3",Tags:["NPCCarRand"],Invisible:1,Marker:1,NoGravity:1}
  912. execute @e[tag=NPCCar,score_npcCarCD=0] ~ ~ ~ detect ~ ~-2 ~ diamond_block 0 execute @e[tag=NPCCar,score_npcCarCD=0,c=1] ~ ~ ~ detect ~ ~-2 ~-1 bedrock 0 summon armor_stand ~ ~ ~ {CustomName:"NPCCarRand4",Tags:["NPCCarRand"],Invisible:1,Marker:1,NoGravity:1}
  913. execute @e[tag=NPCCar,score_npcCarCD=0] ~ ~ ~ detect ~ ~-2 ~ diamond_block 0 scoreboard players tag @r[type=armor_stand,tag=NPCCarRand,r=1] add NPCCarRandSelect
  914. execute @e[tag=NPCCarRandSelect,name=NPCCarRand1] ~ ~ ~ scoreboard players set @e[tag=NPCCar,score_npcCarCD=0,c=1,r=1] npcCarRot 1
  915. execute @e[tag=NPCCarRandSelect,name=NPCCarRand2] ~ ~ ~ scoreboard players set @e[tag=NPCCar,score_npcCarCD=0,c=1,r=1] npcCarRot 2
  916. execute @e[tag=NPCCarRandSelect,name=NPCCarRand3] ~ ~ ~ scoreboard players set @e[tag=NPCCar,score_npcCarCD=0,c=1,r=1] npcCarRot 3
  917. execute @e[tag=NPCCarRandSelect,name=NPCCarRand4] ~ ~ ~ scoreboard players set @e[tag=NPCCar,score_npcCarCD=0,c=1,r=1] npcCarRot 4
  918. execute @e[tag=NPCCar,score_npcCarCD=0] ~ ~ ~ detect ~ ~-2 ~ diamond_block 0 scoreboard players set @e[tag=NPCCar,score_npcCarCD=0,c=1,r=0] npcCarCD 50
  919.  
  920. kill @e[tag=NPCCarRand]
  921.  
  922. }
  923.  
  924. function npcUTurns() {
  925.  
  926. # Turn left (start of U-turn)
  927. scoreboard players remove @e[tag=atDeadEnd] npcCarRot 1
  928. # Rotation boundaries
  929. scoreboard players set @e[tag=atDeadEnd,score_npcCarRot=0] npcCarRot 4
  930. scoreboard players set @e[tag=atDeadEnd,score_npcCarRot_min=5] npcCarRot 1
  931.  
  932. # Move to other side of road
  933. execute @e[tag=atDeadEnd] ~ ~ ~ fill ~-1 ~ ~-1 ~1 ~1 ~1 air 0 replace barrier
  934. tp @e[tag=atDeadEnd,score_npcCarRot_min=1,score_npcCarRot=1] ~4 ~ ~ 90 0
  935. tp @e[tag=atDeadEnd,score_npcCarRot_min=2,score_npcCarRot=2] ~ ~ ~4 180 0
  936. tp @e[tag=atDeadEnd,score_npcCarRot_min=3,score_npcCarRot=3] ~-4 ~ ~ -90 0
  937. tp @e[tag=atDeadEnd,score_npcCarRot_min=4,score_npcCarRot=4] ~ ~ ~-4 0 0
  938.  
  939. # Turn left again then the U-turn is done
  940. scoreboard players remove @e[tag=atDeadEnd] npcCarRot 1
  941. # Rotation boundaries
  942. scoreboard players set @e[tag=atDeadEnd,score_npcCarRot=0] npcCarRot 4
  943. scoreboard players set @e[tag=atDeadEnd,score_npcCarRot_min=5] npcCarRot 1
  944.  
  945. }
  946.  
  947. $tankShotCD = 30
  948.  
  949. function tankControl() {
  950. # This function runs every tick when a players is within 32 blocks of a tank
  951.  
  952. # MP on tag=tank_top is used to count the time until the tank should shoot
  953. execute @a[tag=!game_over] ~ ~ ~ scoreboard players add @e[tag=tank_top,r=32] MP 1
  954.  
  955. # Facing Motion generator http://i.imgur.com/15Qfr9o.png
  956. execute @e[tag=tank_top,score_MP_min=$tankShotCD,rym=-180,ry=-158] ~ ~ ~ summon armor_stand ~ ~1 ~ {Tags:["tank_bullet"],Invisible:1,Marker:1,ArmorItems:[{},{},{},{id:spider_eye,Count:1}],Motion:[0.45855d,0.4d,-2.25383d]}
  957. execute @e[tag=tank_top,score_MP_min=$tankShotCD,rym=-157,ry=-135] ~ ~ ~ summon armor_stand ~ ~1 ~ {Tags:["tank_bullet"],Invisible:1,Marker:1,ArmorItems:[{},{},{},{id:spider_eye,Count:1}],Motion:[1.30273d,0.4d,-1.89549d]}
  958. execute @e[tag=tank_top,score_MP_min=$tankShotCD,rym=-134,ry=-112] ~ ~ ~ summon armor_stand ~ ~1 ~ {Tags:["tank_bullet"],Invisible:1,Marker:1,ArmorItems:[{},{},{},{id:spider_eye,Count:1}],Motion:[1.93980d,0.4d,-1.23579d]}
  959. execute @e[tag=tank_top,score_MP_min=$tankShotCD,rym=-111,ry=-89] ~ ~ ~ summon armor_stand ~ ~1 ~ {Tags:["tank_bullet"],Invisible:1,Marker:1,ArmorItems:[{},{},{},{id:spider_eye,Count:1}],Motion:[2.26846d,0.4d,-0.37961d]}
  960. execute @e[tag=tank_top,score_MP_min=$tankShotCD,rym=-88,ry=-66] ~ ~ ~ summon armor_stand ~ ~1 ~ {Tags:["tank_bullet"],Invisible:1,Marker:1,ArmorItems:[{},{},{},{id:spider_eye,Count:1}],Motion:[2.23645d,0.4d,0.53692d]}
  961. execute @e[tag=tank_top,score_MP_min=$tankShotCD,rym=-65,ry=-43] ~ ~ ~ summon armor_stand ~ ~1 ~ {Tags:["tank_bullet"],Invisible:1,Marker:1,ArmorItems:[{},{},{},{id:spider_eye,Count:1}],Motion:[1.84887d,0.4d,1.36809d]}
  962. execute @e[tag=tank_top,score_MP_min=$tankShotCD,rym=-42,ry=-20] ~ ~ ~ summon armor_stand ~ ~1 ~ {Tags:["tank_bullet"],Invisible:1,Marker:1,ArmorItems:[{},{},{},{id:spider_eye,Count:1}],Motion:[1.16734d,0.4d,1.98175d]}
  963. execute @e[tag=tank_top,score_MP_min=$tankShotCD,rym=-19,ry=3] ~ ~ ~ summon armor_stand ~ ~1 ~ {Tags:["tank_bullet"],Invisible:1,Marker:1,ArmorItems:[{},{},{},{id:spider_eye,Count:1}],Motion:[0.30021d,0.4d,2.28032d]}
  964. execute @e[tag=tank_top,score_MP_min=$tankShotCD,rym=4,ry=26] ~ ~ ~ summon armor_stand ~ ~1 ~ {Tags:["tank_bullet"],Invisible:1,Marker:1,ArmorItems:[{},{},{},{id:spider_eye,Count:1}],Motion:[-0.61465d,0.4d,2.21635d]}
  965. execute @e[tag=tank_top,score_MP_min=$tankShotCD,rym=27,ry=49] ~ ~ ~ summon armor_stand ~ ~1 ~ {Tags:["tank_bullet"],Invisible:1,Marker:1,ArmorItems:[{},{},{},{id:spider_eye,Count:1}],Motion:[-1.43178d,0.4d,1.80000d]}
  966. execute @e[tag=tank_top,score_MP_min=$tankShotCD,rym=50,ry=72] ~ ~ ~ summon armor_stand ~ ~1 ~ {Tags:["tank_bullet"],Invisible:1,Marker:1,ArmorItems:[{},{},{},{id:spider_eye,Count:1}],Motion:[-2.02128d,0.4d,1.09747d]}
  967. execute @e[tag=tank_top,score_MP_min=$tankShotCD,rym=73,ry=95] ~ ~ ~ summon armor_stand ~ ~1 ~ {Tags:["tank_bullet"],Invisible:1,Marker:1,ArmorItems:[{},{},{},{id:spider_eye,Count:1}],Motion:[-2.28941d,0.4d,0.22045d]}
  968. execute @e[tag=tank_top,score_MP_min=$tankShotCD,rym=96,ry=118] ~ ~ ~ summon armor_stand ~ ~1 ~ {Tags:["tank_bullet"],Invisible:1,Marker:1,ArmorItems:[{},{},{},{id:spider_eye,Count:1}],Motion:[-2.19355d,0.4d,-0.69162d]}
  969. execute @e[tag=tank_top,score_MP_min=$tankShotCD,rym=119,ry=141] ~ ~ ~ summon armor_stand ~ ~1 ~ {Tags:["tank_bullet"],Invisible:1,Marker:1,ArmorItems:[{},{},{},{id:spider_eye,Count:1}],Motion:[-1.74893d,0.4d,-1.49373d]}
  970. execute @e[tag=tank_top,score_MP_min=$tankShotCD,rym=142,ry=164] ~ ~ ~ summon armor_stand ~ ~1 ~ {Tags:["tank_bullet"],Invisible:1,Marker:1,ArmorItems:[{},{},{},{id:spider_eye,Count:1}],Motion:[-1.02625d,0.4d,-2.05835d]}
  971. execute @e[tag=tank_top,score_MP_min=$tankShotCD,rym=165,ry=187] ~ ~ ~ summon armor_stand ~ ~1 ~ {Tags:["tank_bullet"],Invisible:1,Marker:1,ArmorItems:[{},{},{},{id:spider_eye,Count:1}],Motion:[-0.14041d,0.4d,-2.29571d]}
  972. execute @e[tag=tank_top,score_MP_min=$tankShotCD] ~ ~ ~ particle smoke ~ ~ ~ 0 0 0 0.3 60
  973. execute @e[tag=tank_top,score_MP_min=$tankShotCD] ~ ~ ~ playsound tank_shot neutral @a ~ ~ ~ 10
  974.  
  975. scoreboard players reset @e[tag=tank_top,score_MP_min=$tankShotCD] MP
  976.  
  977. # Make the bullets sink into the ground and disappear after a bit
  978. scoreboard players add @e[tag=tank_bullet] MP 1
  979. tp @e[tag=tank_bullet,score_MP_min=60] ~ ~-0.03 ~
  980. kill @e[tag=tank_bullet,score_MP_min=120]
  981.  
  982. # Getting hit by tank bullets
  983. execute @e[tag=tank_bullet] ~ ~ ~ execute @e[tag=car,r=3] ~ ~ ~ scoreboard players add @a car_damage 40
  984. execute @e[tag=tank_bullet] ~ ~ ~ execute @e[tag=car,r=3] ~ ~ ~ particle flame ~ ~ ~ 0 0 0 0.2 50
  985. execute @e[tag=car] ~ ~ ~ tp @e[tag=tank_bullet,r=3] ~ ~-1000 ~
  986.  
  987. # If the player runs into the tank or is hit by a bullet
  988. execute @e[tag=tank_wolf] ~ ~ ~ execute @e[tag=car,r=3] ~ ~ ~ scoreboard players add @a car_damage 3
  989. execute @e[tag=tank_wolf] ~ ~ ~ execute @e[tag=car,r=3] ~ ~ ~ execute particle explode ~ ~ ~ 0 0 0 0.3 20
  990. execute @e[tag=tank_wolf] ~ ~ ~ execute @e[tag=car,r=3] ~ ~ ~ playsound impact.random neutral @a[tag=!game_over]
  991.  
  992. }
  993.  
  994. function spawnCoins() {
  995.  
  996. # Spawn coins
  997.  
  998. execute @r[type=armor_stand,tag=intersection,c=10] ~ ~ ~ summon armor_stand ~ ~ ~ {Tags:["spawn_coins"],Invisible:1,Marker:1,NoGravity:1}
  999.  
  1000. execute @e[tag=spawn_coins] ~ ~ ~ detect ~-4 ~-2 ~ gold_block 0 summon armor_stand ~-2 ~ ~ {Tags:["spawn_coins"],Invisible:1,Marker:1,NoGravity:1}
  1001. execute @e[tag=spawn_coins] ~ ~ ~ detect ~ ~-2 ~-4 gold_block 0 summon armor_stand ~ ~ ~-2 {Tags:["spawn_coins"],Invisible:1,Marker:1,NoGravity:1}
  1002.  
  1003. execute @e[tag=spawn_coins] ~ ~ ~ detect ~-2 ~-2 ~ gold_block 0 summon armor_stand ~-4 ~ ~ {Tags:["spawn_coins"],Invisible:1,Marker:1,NoGravity:1}
  1004. execute @e[tag=spawn_coins] ~ ~ ~ detect ~ ~-2 ~-2 gold_block 0 summon armor_stand ~ ~ ~-4 {Tags:["spawn_coins"],Invisible:1,Marker:1,NoGravity:1}
  1005.  
  1006. execute @e[tag=spawn_coins] ~ ~ ~ detect ~-4 ~-2 ~ gold_block 0 summon armor_stand ~-8 ~ ~ {Tags:["spawn_coins"],Invisible:1,Marker:1,NoGravity:1}
  1007. execute @e[tag=spawn_coins] ~ ~ ~ detect ~ ~-2 ~-4 gold_block 0 summon armor_stand ~ ~ ~-8 {Tags:["spawn_coins"],Invisible:1,Marker:1,NoGravity:1}
  1008.  
  1009. execute @e[tag=spawn_coins] ~ ~ ~ detect ~-8 ~-2 ~ gold_block 0 summon armor_stand ~-16 ~ ~ {Tags:["spawn_coins"],Invisible:1,Marker:1,NoGravity:1}
  1010. execute @e[tag=spawn_coins] ~ ~ ~ detect ~ ~-2 ~-8 gold_block 0 summon armor_stand ~ ~ ~-16 {Tags:["spawn_coins"],Invisible:1,Marker:1,NoGravity:1}
  1011.  
  1012. execute @e[tag=spawn_coins] ~ ~ ~ summon item ~ ~ ~ {Item:{id:pumpkin_pie,Count:1},Age:-32768,Tags:["coin"]}
  1013.  
  1014. kill @e[tag=spawn_coins]
  1015.  
  1016. delay 50 {
  1017.  
  1018. scoreboard players tag @e[tag=coin] add bad_coin
  1019. execute @e[tag=coin] ~ ~ ~ detect ~ ~-2 ~ gold_block 0 scoreboard players tag @e[tag=coin,c=1,r=1] remove bad_coin
  1020. kill @e[tag=bad_coin]
  1021.  
  1022. }
  1023.  
  1024. # Spawn powerups
  1025. execute @r[type=armor_stand,tag=intersection,c=3] ~ ~ ~ summon armor_stand ~ ~ ~ {Tags:["powerup_part","powerup_base"],Invisible:1,Marker:1,NoGravity:1,ArmorItems:[{},{},{},{id:potato,Count:1}]}
  1026. execute @e[tag=powerup_base] ~ ~ ~ detect ~ ~ ~ wool 15 tp @e[tag=powerup_base,c=1,r=1] ~ ~ ~-8
  1027. execute @e[tag=powerup_base] ~ ~ ~ summon item ~ ~ ~ {Item:{id:baked_potato,Count:1},Age:-32768,Tags:["powerup_part","powerup"]}
  1028.  
  1029. # Spawn money bags
  1030. execute @r[type=armor_stand,tag=spawn_money_bag,c=5] ~ ~ ~ summon item ~ ~ ~ {Tags:["money_bag"],Item:{id:cooked_rabbit,Count:1,Age:-32768}}
  1031. execute @e[tag=money_bag] ~ ~ ~ detect ~ ~ ~ wool -1 tp @s ~ ~ ~-15
  1032. execute @e[tag=powerup_base] ~ ~ ~ tp @e[tag=money_bag,r=2] ~ ~ ~8
  1033.  
  1034.  
  1035. }
  1036.  
  1037. $_spawn_moneyBag = 0
  1038. repeat spawnMoneyBags:off {
  1039.  
  1040. execute @e[tag=money_bag] ~ ~ ~ kill @e[tag=coin,r=2]
  1041.  
  1042. if ("execute @a ~ ~ ~ testfor @e[tag=money_bag,r=10]")
  1043. {
  1044. $_spawn_moneyBag = 0
  1045. }
  1046.  
  1047. $_spawn_moneyBag++
  1048.  
  1049. if ($_spawn_moneyBag > 300)
  1050. {
  1051.  
  1052. # execute @a ~ ~ ~ kill @e[tag=money_bag,c=-1]
  1053. execute @e[tag=car] ~ ~ ~ execute @r[type=armor_stand,tag=spawn_money_bag,rm=15] ~ ~ ~ summon item ~ ~ ~ {Tags:["money_bag"],Item:{id:cooked_rabbit,Count:1,Age:-32768}}
  1054. $_spawn_moneyBag = 0
  1055.  
  1056.  
  1057. }
  1058.  
  1059. }
  1060.  
  1061. function gameOver() {
  1062.  
  1063. # Used to prevent cars from moving and pedestrians from walking
  1064. scoreboard players tag @a add game_over
  1065.  
  1066. execute @a ~ ~ ~ playsound gameover neutral @a ~ ~ ~ 10
  1067.  
  1068. # Makes the police and tanks stop moving
  1069. entitydata @e[type=wolf] {NoAI:1,Attributes:[{Name:"generic.movementSpeed",Base:0.0f}]}
  1070.  
  1071. delay 40 {
  1072.  
  1073. title @a times 20 100 20
  1074. title @a subtitle {"score":{"name":"@a","objective":"points"},"color":"yellow","bold":true}
  1075. title @a title {"text":"Game OVER","color":"dark_purple","bold":true}
  1076.  
  1077. delay 170 {
  1078. # Done showing Game OVER and the player's score
  1079.  
  1080. tp @e[tag=car] 967 6 995
  1081.  
  1082. reset()
  1083.  
  1084. }
  1085.  
  1086. }
  1087.  
  1088. }
  1089.  
  1090. function failedObjective($reason) {
  1091.  
  1092. # Used to prevent cars from moving and pedestrians from walking
  1093. scoreboard players tag @a add game_over
  1094. scoreboard players tag @a add failed_objective
  1095.  
  1096. execute @a ~ ~ ~ playsound gameover neutral @a ~ ~ ~ 10
  1097.  
  1098. # Makes the police and tanks stop moving
  1099. entitydata @e[type=wolf] {NoAI:1,Attributes:[{Name:"generic.movementSpeed",Base:0.0f}]}
  1100.  
  1101. delay 40 {
  1102.  
  1103. title @a times 20 100 20
  1104. title @a subtitle {"text":"$reason","color":"dark_red","bold":true}
  1105. title @a title {"text":"You Failed!","color":"dark_purple","bold":true}
  1106.  
  1107. delay 170 {
  1108. # Done showing Game OVER and the player's score
  1109.  
  1110. tp @e[tag=car] 967 6 995
  1111.  
  1112. reset()
  1113.  
  1114. }
  1115.  
  1116. }
  1117.  
  1118. }
  1119.  
  1120. function displayTitle($message) {
  1121.  
  1122. title @a times 10 60 10
  1123. title @a subtitle {"text":"$message","color":"dark_purple","bold":true}
  1124. title @a title {"text":"","color":"dark_purple"}
  1125.  
  1126. }
  1127.  
  1128. function wonGame() {
  1129. # The player won the game (reached the desert area)
  1130. # This function will run once
  1131.  
  1132. stopAllEvents()
  1133.  
  1134. title @a times 20 100 20
  1135. title @a subtitle {"text":"Congrats!"}
  1136. title @a title {"text":"You WON!","bold":true,"color":"gold"}
  1137.  
  1138. tp @e[tag=car] 991 7 1095
  1139. tp @e[tag=car_model] 991 7 1095
  1140.  
  1141. execute @e[tag=car_model] ~ ~ ~ teleport @a ~-2 ~1 ~2.5 -140 45
  1142. stopsound @a
  1143. execute @a ~ ~ ~ playsound win neutral @a ~ ~ ~ 10
  1144.  
  1145. start winnerScreen
  1146.  
  1147. delay 180 {
  1148. # Title and subtitle are done being shown
  1149.  
  1150. title @a times 20 100 20
  1151. title @a subtitle {"text":"Your Score","bold":true,"color":"dark_red"}
  1152. title @a title {"score":{"name":"@a","objective":"points"},"bold":true,"color":"dark_purple"}
  1153.  
  1154. delay 180 {
  1155. # Second title and subtitle are done being shown
  1156.  
  1157. title @a times 20 60 20
  1158. title @a subtitle {"text":"New car unlocked!","bold":true,"color":"dark_purple"}
  1159. title @a title {"text":""}
  1160.  
  1161. delay 100 {
  1162. # All titles done
  1163.  
  1164. # Player unlocks the next car
  1165. stop winnerScreen
  1166.  
  1167. delay 3 {
  1168. $_unlockedCars++
  1169. reset()
  1170. }
  1171.  
  1172. }
  1173.  
  1174. }
  1175.  
  1176. }
  1177.  
  1178. }
  1179.  
  1180. repeat winnerScreen:off {
  1181.  
  1182. tp @e[tag=car_model] ~ ~ ~0.2 0 0
  1183. execute @e[tag=car_model] ~ ~ ~ teleport @a ~-2 ~1 ~2.5 -140 45
  1184. effect @a invisibility 2 1 true
  1185. execute @e[tag=car_model] ~ ~ ~ teleport @e[tag=NPCVan] ~-2.5 ~ ~-6
  1186.  
  1187. }
  1188.  
  1189. function openTollBooths() {
  1190.  
  1191. scoreboard players tag @a add unlockedTolls
  1192.  
  1193. execute @e[tag=toll_booth] ~ ~ ~ fill ~-3 ~ ~-3 ~3 ~10 ~3 concrete 5 replace concrete 14
  1194. execute @e[tag=toll_booth] ~ ~ ~ fill ~-3 ~ ~-3 ~3 ~10 ~3 air 0 replace end_rod
  1195.  
  1196. execute @a ~ ~ ~ playsound entity.player.levelup neutral @a
  1197.  
  1198. #displayMessage("You now have enough money to pass through toll booths!")
  1199. displayTitle("Toll booths have opened!")
  1200.  
  1201. }
  1202.  
  1203. #$_ring1 = -1
  1204. #repeat tollBoothOpen:off {
  1205. # Makes cars able to pass through to
  1206. #$_ring1 += 8
  1207. #execute @e[tag=car] ~ ~ ~ particle happyVillager ~$sin($_ring1) ~ ~$cos($_ring1) 0 0 0 1 1
  1208. #if ($_ring1>360) {
  1209. # $_ring1=-1
  1210. #}
  1211. #}
  1212.  
  1213. $_randEvent = -1
  1214.  
  1215. function doRandomEvent() {
  1216.  
  1217. #say DO RANDOM EVENT
  1218.  
  1219. $_randEvent = $random(1, 3)
  1220. # tellraw @a $_randEvent
  1221.  
  1222. if ($_randEvent==1) {
  1223.  
  1224. instant displayMessage("Meteor Shower!")
  1225.  
  1226. start eventMeteors
  1227.  
  1228. eventEndTimer()
  1229.  
  1230. }
  1231.  
  1232. if ($_randEvent==2) {
  1233.  
  1234. instant displayMessage("Dust Storm!")
  1235.  
  1236. start eventDustStorm
  1237.  
  1238. execute @a[tag=!game_over] ~ ~ ~ playsound wind neutral @a ~ ~ ~ 10
  1239.  
  1240. eventEndTimerShort()
  1241.  
  1242. }
  1243.  
  1244. if ($_randEvent==3) {
  1245.  
  1246. # Earthquake (message is shown through the dropMoneyBag function below)
  1247.  
  1248. start eventEarthquake
  1249.  
  1250. eventEndTimer()
  1251.  
  1252. execute @a[score_money_bags_min=1] ~ ~ ~ dropMoneyBag()
  1253.  
  1254. }
  1255.  
  1256. }
  1257.  
  1258.  
  1259. $_meteorTimer = 0
  1260. $_meteorRand = 0
  1261.  
  1262. repeat eventMeteors:off {
  1263.  
  1264. $_meteorTimer++
  1265.  
  1266. if ($_meteorTimer > 2) {
  1267.  
  1268. execute @e[tag=car] ~ ~ ~ summon armor_stand ~ ~ ~ {Tags:["spawn_meteor"],Invisible:1,Marker:1,NoGravity:1}
  1269. execute @e[tag=car] ~ ~ ~ spreadplayers ~ ~ 15 16 false @e[tag=spawn_meteor]
  1270.  
  1271. $_meteorRand = $random(0, 2)
  1272.  
  1273. if ($_meteorRand == 0) {
  1274. execute @e[tag=spawn_meteor] ~ ~ ~ summon armor_stand ~ ~20 ~ {Tags:["meteor"],Invisible:1,Marker:1,ArmorItems:[{},{},{},{id:golden_hoe,Damage:8,Count:1,tag:{Unbreakable:1}}]}
  1275. }
  1276. if ($_meteorRand == 1) {
  1277. execute @e[tag=spawn_meteor] ~ ~ ~ summon armor_stand ~ ~20 ~ {Tags:["meteor"],Invisible:1,Marker:1,ArmorItems:[{},{},{},{id:golden_hoe,Damage:9,Count:1,tag:{Unbreakable:1}}]}
  1278. }
  1279. if ($_meteorRand == 2) {
  1280. execute @e[tag=spawn_meteor] ~ ~ ~ summon armor_stand ~ ~20 ~ {Tags:["meteor"],Invisible:1,Marker:1,ArmorItems:[{},{},{},{id:golden_hoe,Damage:10,Count:1,tag:{Unbreakable:1}}]}
  1281. }
  1282.  
  1283. kill @e[tag=spawn_meteor]
  1284. execute @a[tag=!game_over] ~ ~ ~ playsound meteor neutral @a ~ ~ ~ 0.6
  1285.  
  1286. $_meteorTimer = 0
  1287.  
  1288. }
  1289.  
  1290. scoreboard players add @e[tag=meteor] MP 1
  1291. # say meteor loop
  1292. tp @e[tag=meteor,score_MP_min=50] ~ ~-0.1 ~
  1293. kill @e[tag=meteor,score_MP_min=100]
  1294.  
  1295. }
  1296.  
  1297. repeat eventDustStorm:off {
  1298.  
  1299. execute @a ~ ~ ~ particle blockcrack ~ ~ ~ 3 2 3 0.1 150 force @a 12
  1300. execute @a ~ ~ ~ particle blockcrack ~ ~ ~ 3 2 3 0.1 150 force @a 13
  1301.  
  1302. scoreboard players set @e[tag=car,score_driveTime_min=30] driveTime 15
  1303.  
  1304. }
  1305.  
  1306. repeat eventEarthquake:off {
  1307.  
  1308. #scoreboard players add @e[tag=car] onGround 0
  1309. #scoreboard players remove @e[tag=car,score_onGround_min=1] onGround 1
  1310. #scoreboard players set @e[tag=car] onGround 6 {OnGround:1b}
  1311.  
  1312. execute @e[tag=car,score_onGround_min=1] ~ ~ ~ particle blockcrack ~ 7.0 ~ 8 0 8 1 100 force @a 173
  1313. #tp @e[tag=car,score_onGround_min=1] ~ ~0.3 ~
  1314.  
  1315. }
  1316.  
  1317. function dropMoneyBag() {
  1318.  
  1319. instant displayMessage("Earthquake!")
  1320.  
  1321. delay 50 {
  1322.  
  1323. execute @a ~ ~ ~ summon armor_stand ~ ~ ~ {Tags:["drop_money"],Invisible:1,Marker:1,NoGravity:1}
  1324.  
  1325. delay 10 {
  1326.  
  1327. execute @e[tag=drop_money] ~ ~ ~ summon item ~ ~ ~ {Tags:["money_bag"],Item:{id:cooked_rabbit,Count:1,Age:-32768}}
  1328. kill @e[tag=drop_money]
  1329. scoreboard players remove @a money_bags 1
  1330. title @a actionbar ["",{"text":"=== ","bold":true,"color":"dark_red"},{"text":"The earthquake made you drop a money bag! ","bold":true,"color":"yellow"},{"score":{"name":"@a","objective":"money_bags"},"color":"gold"},{"text":" / 5","color":"gold"},{"text":" ===","bold":true,"color":"dark_red"}]
  1331.  
  1332. }
  1333.  
  1334. }
  1335.  
  1336. }
  1337.  
  1338. function eventEndTimer() {
  1339.  
  1340. # regular end timer
  1341. delay 150 {
  1342. stopAllEvents()
  1343. }
  1344.  
  1345. }
  1346.  
  1347. function eventEndTimerShort() {
  1348.  
  1349. # shortened end timer
  1350. delay 100 {
  1351. stopAllEvents()
  1352. }
  1353.  
  1354. }
  1355.  
  1356. function stopAllEvents() {
  1357.  
  1358. stop eventMeteors
  1359. stop eventDustStorm
  1360. stop eventEarthquake
  1361.  
  1362. }
Advertisement
Add Comment
Please, Sign In to add comment