home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2003 June / macformat-130.iso / mac / Reviewed⁄Demos / Spearhead Demo / demota / pak1.pk3 / global / barrel.scr < prev    next >
Encoding:
Text File  |  2002-10-21  |  17.3 KB  |  602 lines

  1. ////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  MoH: Allied Assault Script File  
  4. //  Global function: Exploding and launching barrels
  5. //  Script Written By: Benson 'elmagoo' Russell
  6. //
  7. ////////////////////////////////////////////////////////////////////////////////////////
  8.  
  9. //**************************************************************************
  10. //*** will setup all specified barrels in the editor for explosive barrels
  11. //*** syntax --------------------------------
  12. //*** explosive_barrel
  13. //**************************************************************************
  14. explosive_barrel:
  15.  
  16. level.damage_delay = .3
  17.  
  18. //*** setup normal explosive barrels
  19. if ($explosive_barrel == NULL)
  20. {
  21.     println "^~^~^ No explosive barrels in the level!!"
  22.     goto explosive_barrel_launch_setup
  23. }
  24.  
  25. for (local.i = 1; local.i <= $explosive_barrel.size ; local.i ++)
  26. {
  27.            $explosive_barrel[local.i] thread explosive_barrel_spawn local.i
  28. }
  29.  
  30. explosive_barrel_launch_setup:
  31. //*** setup explosive launching barrels
  32. if ($explosive_barrel_launch == NULL)
  33. {
  34.     println "^~^~^ No explosive launch barrels in the level!!"
  35.     goto explosive_barrel_end
  36. }
  37.  
  38. for (local.i = 1; local.i <= $explosive_barrel_launch_dummy.size; local.i ++)
  39. {
  40.     local.lookup[$explosive_barrel_launch_dummy[local.i].set] = local.i
  41. }
  42.  
  43. for (local.i = 1; local.i <= $explosive_barrel_launch.size ; local.i ++)
  44. {
  45.     $explosive_barrel_launch[local.i].dummy_index = local.lookup[$explosive_barrel_launch[local.i].set]
  46.     $explosive_barrel_launch[local.i] thread explosive_barrel_launch_spawn local.i
  47. }
  48.  
  49. local.lookup = NIL
  50.  
  51. explosive_barrel_end:
  52. end
  53.  
  54.  
  55. //**************************************************************************
  56. //*** thread for the explosive barrel
  57. //*** syntax --------------------------------
  58. //*** <crate> explosive_barrel_spawn <array index>
  59. //**************************************************************************
  60. explosive_barrel_spawn local.index:
  61.  
  62. //*** set temp variables
  63. local.spawn_origin = local.self.origin
  64. local.spawn_origin[2] += 32
  65. local.spawn_targetname = (local.self.targetname + "_explosive_" + local.index)
  66.  
  67. if (local.self.dmg != NIL)
  68. {
  69.     local.dmg = local.self.dmg
  70. }
  71. else
  72. {
  73.     local.dmg = 250
  74. }
  75.  
  76. if (local.self.radius != NIL)
  77. {
  78.     local.radius = local.self.radius
  79. }
  80. else
  81. {
  82.     local.radius = 256
  83. }
  84.  
  85. if (self.script_health != NIL)
  86. {
  87.     self.health = self.script_health
  88. }
  89. else
  90. {
  91.     self.health = 1
  92.     //println "z:       barrel: " self " health: " self.health
  93. }
  94.  
  95. //*** wait till the barrel is destroyed
  96. local.self waittill death
  97.  
  98.  
  99.     //*** if a thread is set, run it and wait for it's completion
  100.     if (self.run_thread != NIL)
  101.         {
  102.             self thread level.script::self.run_thread
  103.         }
  104.  
  105. //*** spawn the explosion
  106. spawn "models/fx/barrel_gas_destroyed" targetname local.spawn_targetname angle "-1"
  107. local.spawn_targetname = $(local.self.targetname + "_explosive_" + local.index)
  108.  
  109. //*** reset the explosions origin
  110. local.spawn_targetname.origin = local.spawn_origin
  111.  
  112. local.spawn_targetname anim idle
  113.  
  114. //*** get the distance to the player
  115. local.distance = vector_length (local.self.origin - $player.origin)
  116. local.check_distance = (local.radius * 1.5)
  117. local.outter_distance = (local.radius * 2.5)
  118.  
  119. //*** shake his view
  120. if (local.distance <= local.check_distance)  //*** inner distance check
  121. {
  122.     if (local.dmg <= 150)
  123.         {
  124.             thread jitter_small
  125.         }
  126.     else
  127.     {
  128.         thread jitter_normal
  129.     }
  130. }
  131. else if (local.distance <= local.outter_distance)  //*** outter distance check
  132. {
  133.     if (local.dmg <= 150)
  134.         {
  135.             thread jitter_tiny
  136.         }
  137.     else
  138.     {
  139.         thread jitter_small
  140.     }
  141. }
  142.  
  143. wait level.damage_delay // wait a bit so barrels stagger
  144.  
  145. //*** damage the player  <origin> <damage> <radius> [consitent]
  146. radiusdamage local.spawn_targetname.origin local.dmg local.radius
  147.  
  148. wait (randomint 3 + 4)
  149.  
  150. //*** delete the effect out of the world now that it's done
  151. local.spawn_targetname remove
  152.  
  153. end
  154.  
  155.  
  156. //**************************************************************************
  157. //*** thread for the explosive launching barrels
  158. //*** syntax --------------------------------
  159. //*** <crate> explosive_barrel_launch_spawn <array index>
  160. //**************************************************************************
  161. explosive_barrel_launch_spawn local.index:
  162.  
  163. //*** get the dummy targetname
  164. //println "EXPLOSIVE LAUNCH: current barrel: " local.index
  165. //println "EXPLOSIVE LAUNCH: current barrel dummy index: " local.self.dummy_index
  166. local.dummy = $explosive_barrel_launch_dummy[local.self.dummy_index]
  167.  
  168. //*** check to see if a dummy barrel exists for this launcher, if not, turn it into a normal exploder
  169. if (local.dummy == NULL)
  170. {
  171.     println "^~^~^ No dummy barrel for launcher barrel with set number: "  local.self.set "  - converting to normal exploder!!"
  172.     local.self thread explosive_barrel_spawn local.i
  173.     goto explosive_barrel_launch_spawn_end
  174. }
  175.  
  176. //*** make the dummy invisible and not solid and place it
  177. local.dummy notsolid
  178. local.dummy hide
  179. local.dummy.origin = local.self.origin
  180.  
  181. //*** set temp variables
  182. local.spawn_origin = local.self.origin
  183. local.spawn_origin[2] += 32
  184. local.spawn_targetname = (local.self.targetname + "_explosive_" + local.index)
  185. local.spawn_smoke_targetname = (local.self.targetname + "_smoke_" + local.index)
  186.  
  187. if (local.self.dmg != NIL)
  188. {
  189.     local.dmg = local.self.dmg
  190. }
  191. else
  192. {
  193.     local.dmg = 250
  194. }
  195.  
  196. if (local.self.radius != NIL)
  197. {
  198.     local.radius = local.self.radius
  199. }
  200. else
  201. {
  202.     local.radius = 256
  203. }
  204.  
  205. if (self.script_health != NIL)
  206. {
  207.     self.health = self.script_health
  208. }
  209. else
  210. {
  211.     self.health = 1
  212. }
  213.  
  214. //*** wait till the barrel is destroyed
  215. local.self waittill death
  216.  
  217.     //*** if a thread is set, run it and wait for it's completion
  218.     if (self.run_thread != NIL)
  219.         {
  220.             self thread level.script::self.run_thread
  221.         }
  222.  
  223. //*** spawn the explosion and smoke for the dummy
  224. spawn "models/fx/barrel_gas_destroyed" targetname local.spawn_targetname
  225. local.spawn_targetname = $(local.self.targetname + "_explosive_" + local.index)
  226.  
  227. spawn "models/emitters/firesmoke" targetname local.spawn_smoke_targetname angle "-2"
  228. local.spawn_smoke_targetname = $(local.self.targetname + "_smoke_" + local.index)
  229.  
  230. //println "BARREL LAUNCH: targetname: " local.spawn_smoke_targetname
  231.  
  232. //*** reset the explosions origin
  233. local.spawn_targetname.origin = local.spawn_origin
  234. local.spawn_smoke_targetname.origin = local.dummy.origin
  235.  
  236. //println "BARREL LAUNCH: dummy smoke origin: " local.spawn_smoke_targetname.origin
  237. //println "BARREL LAUNCH: dummy origin: " local.dummy.origin
  238. //println "BARREL LAUNCH: barrel origin[2] +32: " local.spawn_origin
  239.  
  240. //*** bind the dummy smoke to the dummy
  241. local.spawn_smoke_targetname bind local.dummy
  242.  
  243. //*** show the dummy and execute the thread to launch it into the air
  244. local.dummy show
  245. local.dummy thread explosive_barrel_launch_dummy_fly
  246.  
  247. local.spawn_targetname anim idle
  248.  
  249.  
  250. //*** get the distance to the player
  251. local.distance = vector_length (local.self.origin - $player.origin)
  252. local.check_distance = (local.radius * 1.5)
  253. local.outter_distance = (local.radius * 2.5)
  254.  
  255. //*** shake his view
  256. if (local.distance <= local.check_distance)  //*** inner distance check
  257. {
  258.     if (local.dmg <= 150)
  259.         {
  260.             thread jitter_small
  261.         }
  262.     else
  263.     {
  264.         thread jitter_normal
  265.     }
  266. }
  267. else if (local.distance <= local.outter_distance)  //*** outter distance check
  268. {
  269.     if (local.dmg <= 150)
  270.         {
  271.             thread jitter_tiny
  272.         }
  273.     else
  274.     {
  275.         thread jitter_small
  276.     }
  277. }
  278.  
  279.  
  280. wait level.damage_delay  // wait a bit so barrels stagger
  281.  
  282. //*** damage the player  <origin> <damage> <radius> [consitent]
  283. radiusdamage local.spawn_targetname.origin local.dmg local.radius
  284.  
  285. wait (randomint 3 + 4)
  286.  
  287. //*** delete the effect out of the world now that it's done
  288. local.spawn_targetname remove
  289.  
  290. //added by Z. dont emit smoke forever
  291. wait 10
  292. local.spawn_smoke_targetname remove
  293.  
  294. explosive_barrel_launch_spawn_end:
  295. end
  296.  
  297.  
  298. //**************************************************************************
  299. //*** thread for making the exploding luncher dummy barrels fly fly fly.....
  300. //*** syntax --------------------------------
  301. //*** <dummy barrel> explosive_barrel_launch_dummy_fly
  302. //**************************************************************************
  303. explosive_barrel_launch_dummy_fly:
  304.  
  305. //*** grab it's starting position
  306. local.start = local.self.origin
  307.  
  308. //*** see if the scripter wants a different min height than default
  309. if (local.self.min_height != NIL)
  310. {
  311.     local.fly_min_height = local.self.min_height
  312. }
  313. else
  314. {
  315.     local.fly_min_height = 500
  316.  
  317. //println "BARREL LAUNCH FLY: fly min height: " local.fly_min_height
  318.  
  319. //*** see if the scripter wants a different max height than default
  320. if (local.self.max_height != NIL)
  321. {
  322.     local.fly_max_height = local.self.max_height - local.fly_min_height
  323.     local.fly_max_height ++
  324.     if (local.fly_max_height < 0)
  325.         {
  326.             println "^~^~^ Maximum desired height is lower than minimum desired height!!!  Setting to 0"
  327.         local.fly_max_height = 1
  328.         }
  329. }
  330. else
  331. {
  332.     local.fly_max_height = 151
  333. }
  334.  
  335. //println "BARREL LAUNCH FLY: fly max height: " local.fly_max_height
  336.  
  337. //*** calculate the target vector for it to fly on
  338. local.fly_vector = (0 0 0)
  339. local.fly_vector[0] = ((randomint 96) - 48)
  340. local.fly_vector[1] = ((randomint 96) - 48)
  341. local.fly_vector[2] = (randomint local.fly_max_height + local.fly_min_height)
  342.  
  343. //println "BARREL LAUNCH FLY: dummy fly vector heigth: " local.fly_vector[2]
  344.  
  345. //*** rotate barrel to orient to the fly vector
  346. //println "BARREL LAUNCH FLY: dummy start angles: " local.self.angles
  347.  
  348. local.start_angles = vector_toangles local.fly_vector
  349. local.self.angles = (0 local.start_angles[1] 0)
  350.  
  351. //println "BARREL LAUNCH FLY: dummy adjusted angles: " local.self.angles
  352. //println "BARREL LAUNCH FLY: dummy origin: " local.self.origin
  353.  
  354. //*** launch the barrel
  355. local.self physics_velocity (local.fly_vector)
  356. wait .2
  357. local.self physics_on 1
  358. local.self physics_velocity (local.fly_vector)
  359.  
  360. //*** make it solid and set the motion flag for rotation
  361. local.self solid
  362. local.inmotion = 1
  363.  
  364. //*** calculate the initial spin by first getting the top down distance moved from it's start point
  365. local.check_start = (local.start[0] local.start[1] 0)
  366. //println "BARREL LAUNCH FLY: check starting position, reset Z: " local.check_start
  367. local.check_end = ((local.start[0] + local.fly_vector[0]) (local.start[1] + local.fly_vector[1]) 0)
  368. //println "BARREL LAUNCH FLY: check fly position, reset Z: " local.check_end
  369.  
  370. local.spin_length = vector_length(local.check_start - local.check_end)
  371. //println "BARREL LAUNCH FLY: initial spin length calculation: " local.spin_length
  372.  
  373. //*** scale the spin value up to a noticable value
  374. local.spin_length = local.spin_length * 1.5
  375.  
  376. //*** start spinning the barrel
  377. local.self rotatex local.spin_length
  378.  
  379. //*** check for major direction changes to adjust rotation accordingly
  380. local.pos_prev = local.self.origin
  381.  
  382. waitframe
  383.  
  384. //*** loop to check for sharp changes in direction
  385. while (local.inmotion == 1)
  386. {
  387.     //println "BARREL CHECK: pos_prev: " local.pos_prev
  388.     //println "BARREL CHECK: pos_current: " local.self.origin 
  389.     local.vel = local.self.origin - local.pos_prev
  390.     //println "BARREL CHECK: velocity from past to current: " local.vel
  391.     //println "BARREL CHECK: current angles facing: " local.self.angles
  392.     //*** old value local.pos_next = local.self.origin + local.vel + (0 0 -1.28)
  393.     local.pos_next = local.self.origin + local.vel + (0 0 -2)
  394.     //println "BARREL CHECK: pos_next: " local.pos_next
  395.     local.pos_prev = local.self.origin
  396.  
  397.     waitframe
  398.     local.pos_diff = vector_length (local.self.origin - local.pos_next)
  399.     //println "BARREL CHECK: pos_current after predition: " local.self.origin
  400.     //println "BARREL CHECK: difference in prediction and actual: " local.pos_diff
  401.     //println "BARREL CHECK: local.self.velocity: " local.self.velocity
  402.     if (local.pos_diff > 0 && local.self.velocity != (0 0 0))
  403.         {
  404.             //println "BARREL COLLISION DETECTED"
  405.         local.vel_new = local.self.origin - local.pos_prev
  406.         //println "BARREL COLLISION: original vel: " local.vel
  407.         //println "BARREL COLLISION: new vel: " local.vel_new
  408.         local.vel_diff_x = local.vel_new[0] - local.vel[0]
  409.         //println "BARREL COLLISION: x difference: " local.vel_diff_x  
  410.         local.vel_diff_y = local.vel_new[1] - local.vel[1]
  411.         //println "BARREL COLLISION: y difference: " local.vel_diff_y
  412.         local.vel_diff_z = local.vel_new[2] - local.vel[2]
  413.         //println "BARREL COLLISION: z difference: " local.vel_diff_z
  414.         
  415.         //*** check for a difference on the horizontal plane
  416.         if ((local.vel_diff_x + local.vel_diff_y) > local.vel_diff_z)
  417.                 {
  418.                     //println "BARREL COLLISION CHECK: horizontal change detected"
  419.                 }
  420.         
  421.         //*** check for a difference on the vertical plane
  422.         if (local.vel_diff_z != 0)
  423.                 {
  424.                     //println "BARREL COLLISION CHECK: vertical change detected"
  425.             local.spin_z = local.vel_diff_z * 5
  426.             //*** check which direction to spin
  427.             if ((local.self.angles[0] >= 0 && local.self.angles[0] <= 90) || (local.self.angles[0] >= 180 && local.self.angles[0] <= 270))
  428.                         {
  429.                             local.self rotatex local.spin_z
  430.                         }
  431.             else
  432.             {
  433.                 local.spin_z = local.spin_z * -1
  434.                 local.self rotatex local.spin_z
  435.             }
  436.                 }
  437.         }
  438.     else if (local.self.velocity == (0 0 0))
  439.     {
  440.         //println "BARREL CHECK: the barrel has stopped moving, exiting"
  441.         local.inmotion = 0
  442.     }
  443. }
  444.  
  445. //*** align the barrel with the ground
  446. if (local.self.angles[0] >= 0 && local.self.angles[0] <= 10)
  447. {
  448.     local.self time .75
  449.     local.self rotatexdownto 0
  450.     local.self move
  451. }
  452. else if (local.self.angles[0] >= 350 && local.self.angles[0] < 0)
  453. {
  454.     local.self time .75
  455.     local.self rotatexupto 0
  456.     local.self move
  457. }
  458. else if (local.self.angles[0] >= 170 && local.self.angles[0] <= 180)
  459. {
  460.     local.self time .75
  461.     local.self rotatexupto 180
  462.     local.self move
  463. }
  464. else if (local.self.angles[0] >= 181 && local.self.angles[0] <= 190)
  465. {
  466.     local.self time .75
  467.     local.self rotatexdownto 180
  468.     local.self move
  469. }
  470. else if (local.self.angles[0] >= 11 && local.self.angles[0] <= 90)
  471. {
  472.     //println "BARREL ALIGN: quadrant 1 move"
  473.     local.self physics_off
  474.     
  475.     //println "BARREL ALIGN: start accel"
  476.     local.distance = 90 - local.self.angles[0]
  477.     local.distance = local.distance / 4
  478.     //*** accelerate the final movement
  479.     for (local.accel = .25 ; local.accel >= .1 ; local.accel = local.accel - .05)
  480.     {
  481.         //println "BARREL ALIGN: rotating, local.accel: " local.accel
  482.         local.self time local.accel
  483.         local.self rotatexup local.distance
  484.         local.self movedown 3
  485.         local.self waitmove
  486.     }
  487. }
  488. else if (local.self.angles[0] >= 91 && local.self.angles[0] <= 169)
  489. {
  490.     //println "BARREL ALIGN: quadrant 2 move"
  491.     local.self physics_off
  492.         
  493.     //println "BARREL ALIGN: start accel"
  494.     local.distance = local.self.angles[0] - 90
  495.     local.distance = local.distance / 4
  496.     //*** accelerate the final movement
  497.     for (local.accel = .25 ; local.accel >= .1 ; local.accel = local.accel - .05)
  498.     {
  499.         //println "BARREL ALIGN: rotating, local.accel: " local.accel
  500.         local.self time local.accel
  501.         local.self rotatexdown local.distance
  502.         local.self movedown 3
  503.         local.self waitmove
  504.     }
  505. else if (local.self.angles[0] >= 191 && local.self.angles[0] <= 269)
  506. {
  507.     //println "BARREL ALIGN: quadrant 3 move"
  508.     local.self physics_off
  509.     
  510.     //println "BARREL ALIGN: start accel"
  511.     local.distance = 270 - local.self.angles[0]
  512.     local.distance = local.distance / 4
  513.     //*** accelerate the final movement
  514.     for (local.accel = .25 ; local.accel >= .1 ; local.accel = local.accel - .05)
  515.     {
  516.         //println "BARREL ALIGN: rotating, local.accel: " local.accel
  517.         local.self time local.accel
  518.         local.self rotatexup local.distance
  519.         local.self movedown 3
  520.         local.self waitmove
  521.     }
  522. else if (local.self.angles[0] >= 270 && local.self.angles[0] <= 349)
  523. {
  524.     //println "BARREL ALIGN: quadrant 4 move"
  525.     local.self physics_off
  526.         
  527.     //println "BARREL ALIGN: start accel"
  528.     local.distance = local.self.angles[0] - 270
  529.     local.distance = local.distance / 4
  530.     //*** accelerate the final movement
  531.     for (local.accel = .25 ; local.accel >= .1 ; local.accel = local.accel - .05)
  532.     {
  533.         //println "BARREL ALIGN: rotating, local.accel: " local.accel
  534.         local.self time local.accel
  535.         local.self rotatexdown local.distance
  536.         local.self movedown 3
  537.         local.self waitmove
  538.     }
  539.  
  540. end
  541.  
  542.  
  543. //*******************************
  544. // random positive / negative choice
  545. //*******************************
  546. random_sign:
  547.  
  548. local.choice = (randomint 3 - 1)
  549.  
  550. if (local.choice == 0)
  551. {
  552.     goto random_sign
  553. }
  554.  
  555. end local.choice
  556.  
  557.  
  558. //******************************
  559. // jitter effect
  560. // jitter_normal
  561. //******************************
  562. jitter_normal:
  563.  
  564. waitexec global/earthquake.scr .4 3 0 0
  565.  
  566. waitexec global/earthquake.scr .5 1 0 0
  567.  
  568. //waitexec global/earthquake.scr .5 1 0 0
  569.  
  570. end
  571.  
  572.  
  573. //*********************************
  574. // jitter effect
  575. // jitter_small
  576. //*********************************
  577. jitter_small:
  578.  
  579. waitexec global/earthquake.scr .3 1.5 0 0
  580.  
  581. waitexec global/earthquake.scr .35 .75 0 0
  582.  
  583. //waitexec global/earthquake.scr .5 1 0 0
  584.  
  585. end
  586.  
  587.  
  588. //*********************************
  589. // jitter effect
  590. // jitter_tiny
  591. //*********************************
  592. jitter_tiny:
  593.  
  594. waitexec global/earthquake.scr 1 .3 0 0
  595.  
  596. //waitexec global/earthquake.scr .5 1 0 0
  597.  
  598. end