./m12.lua

  1. --[[ 
  2. 	m12.lua 
  3. 	SR3 Mission Script 
  4. 	DATE: 07-02-2010 
  5. 	AUTHOR:	Craig Williams 
  6. ]]-- 
  7.  
  8. -- Debug flags -- 
  9.  
  10. -- Tweakable Parameters -- 
  11. 	M12_WEAPON_UNEQUIP_TIME				= 10000 -- Time in miliseconds that the player has to unequip their weapon 
  12. 	M12_DISTANCE_TO_JOSH_FOR_ZSCENE	= 14.0  -- How close you can get to Josh before the ZScene starts 
  13. 	M12_MIN_SPAWN_DIST					= 21.0  -- Minimum distance a player must be from a spawn point, in order for that spawn point to be used. 
  14. 	M12_DELAY_AFTER_GRAB_JOSH_ZSCENE	= 2.0 
  15. 	M12_ELEVATOR_OPEN_PROXIMITY			= 6.0 
  16. 	M12_GARAGE_MIN_NOTORIETY			= 4 
  17. 	M12_GARAGE_MAX_NOTORIETY			= 5 
  18. 	M12_NO_COPS_TIME                    = 120.0 -- Time that no cops spawn ambiently and police notoriety is capped at zero. 
  19. 	M12_ESCAPE_VEHICLE                  = "Script_Vehicle 004" 
  20. 	M12_TEMP_PISTOL_NAME                = "Pistol-Gang" 
  21.  
  22. -- Characters -- 
  23. 	NPC_SUKO = "npc_suko_start" -- Part of group "homies_start_group" 
  24. 	NPC_JOSH = "npc_josh"       -- Part of group "josh_group" 
  25.  
  26. -- Groups -- 
  27. 	-- List of all the groups in the mission 
  28. 	M12_groups = { 
  29. 		vehicle_start   = {name = "vehicle_start_group"}, 
  30. 		homies          = {name = "homies_start_group"}, 
  31. 		josh            = {name = "josh_group", char = "npc_josh" }, 
  32. 		workers_lobby   = { 
  33. 			name = "workers_lobby_group", 
  34. 			members = { 	"worker_lobby_001", 	"worker_lobby_002", 	"worker_lobby_003", 	"worker_lobby_004", 
  35. 								"worker_lobby_005", 	"worker_lobby_006" } , 
  36. 			second_floor_receptionist = "worker_lobby_006", 
  37. 		}, 
  38. 		workers_cubical = {name = "workers_cubical_group"}, 
  39. 		workers_studio  = { 
  40. 			name = "workers_studio_group", 
  41. 			members = { "worker_studio_001", "worker_studio_002", "worker_studio_003", "worker_studio_004", 
  42. 							"worker_studio_005", "worker_studio_006", "worker_studio_007" }, 
  43. 		}, 
  44. 		stag_lobby      = { 
  45. 			name = "stag_lobby_group", 
  46. 			members = { "stag_lobby_001", "stag_lobby_002", "stag_lobby_003", "stag_lobby_004", "stag_lobby_005", "stag_lobby_006", "stag_lobby_007",} 
  47. 		}, 
  48. 		stag_cubical    = {name = "stag_cubical_group"}, 
  49. 		stag_studio     = { 
  50. 			name = "stag_studio_group", 
  51. 			members = { "stag_studio_001", "stag_studio_002", "stag_studio_003", "stag_studio_004", "stag_studio_005" } 
  52. 		}, 
  53. 		lobby_escape    = {name = "lobby_escape_group"}, 
  54. 		garage_cars     = { 
  55. 			name = "temp_car_group", 
  56. 			vehicles = {"Script_Vehicle 003", "Script_Vehicle 004", "Script_Vehicle 005", "Script_Vehicle 006",  
  57. 						"Script_Vehicle 008", "Script_Vehicle 009", }, 
  58. 		}, 
  59. 		stag_window_rush = { 
  60. 			name = "stag_window_rush_group", 
  61. 			chars = { 
  62. 				{name = "stag_window_rush_01", nav = "nav_win_rush 01", behavior = "advance"}, 
  63. 				--{name = "stag_window_rush_02", nav = "nav_win_rush 02", behavior = "advance"}, 
  64. 			}, 
  65. 			triggers = {"trigger_window_rush"}, 
  66. 		}, 
  67. 		stag_studio_rush_01 = { 
  68. 			name = "stag_studio_rush_group 001", 
  69. 			chars = { 
  70. 				{ name = "stag_studio_rush_01 001", nav = "nav_studio_rush_01 001", behavior = "advance" }, 
  71. 				{ name = "stag_studio_rush_01 002", nav = "nav_studio_rush_01 002", behavior = "advance" }, 
  72. 			}, 
  73. 			triggers = { "trigger_stag_studio_rush 001" }, 
  74. 		}, 
  75. 		stag_studio_rush_02 = { 
  76. 			name = "stag_studio_rush_group 002", 
  77. 			chars = { 
  78. 				{ name = "stag_studio_rush_02 001", nav = "nav_studio_rush_02 001", behavior = "take_cover" }, 
  79. 				{ name = "stag_studio_rush_02 002", nav = "nav_studio_rush_02 002", behavior = "take_cover" }, 
  80. 				{ name = "stag_studio_rush_02 003", nav = "nav_studio_rush_02 003", behavior = "take_cover" }, 
  81. 			}, 
  82. 			triggers = { "trigger_stag_studio_rush 002" }, 
  83. 		}, 
  84. 		stag_outside_garage = { 
  85. 			name = "stag_outside_garage_group", 
  86. 			vehicle_paths = { 
  87. 				{ 
  88. 					vehicle	= "vehicle_outside_garage <001>", 
  89. 					members	= {"stag_outside_garage <001>",}, 
  90. 					path		= "outside_garage_path <001>", 
  91. 					thread	= 	INVALID_THREAD_HANDLE, 
  92. 				}, 
  93. 				{ 
  94. 					vehicle	= "vehicle_outside_garage <002>", 
  95. 					members	= {"stag_outside_garage <002>",}, 
  96. 					path		= "outside_garage_path <002>", 
  97. 					thread	= 	INVALID_THREAD_HANDLE, 
  98. 				}, 
  99. 			}, 
  100. 		}, 
  101. 		stag_chasers_001 = { 
  102. 			name = "stag_chase_group 001", 
  103. 			vehicles = { 
  104. 				{ 
  105. 					vehicle	= "vehicle_chaser 001", 
  106. 					driver	= "stag_chaser_driver 001", 
  107. 					gunner	= "stag_chaser_gunner 001", 
  108. 				}, 
  109. 				{ 
  110. 					vehicle	= "vehicle_chaser 002", 
  111. 					driver	= "stag_chaser_driver 002", 
  112. 					gunner	= "stag_chaser_gunner 002", 
  113. 				}, 
  114. 			}, 
  115. 		}, 
  116. 		stag_chasers_002 = { 
  117. 			name = "stag_chase_group 002", 
  118. 			vehicles = { 
  119. 				{ 
  120. 					vehicle	= "vehicle_chaser 003", 
  121. 					driver	= "stag_chaser_driver 003", 
  122. 					gunner	= "stag_chaser_gunner 003", 
  123. 				}, 
  124. 				{ 
  125. 					vehicle	= "vehicle_chaser 004", 
  126. 					driver	= "stag_chaser_driver 004", 
  127. 					gunner	= "stag_chaser_gunner 004", 
  128. 				}, 
  129. 			}, 
  130. 		}, 
  131. 		fleeing_peds_001 = { 
  132. 			name = "fleeing_ped_group 001", 
  133. 			members = {"fleeing_ped <001>", "fleeing_ped <002>",}, 
  134. 			navs = {"nav_ped_flee <001>", "nav_ped_flee <002>",}, 
  135. 		}, 
  136. 	} 
  137. 	 
  138. 	-- list of spawn groups and their associated spawn regions. 
  139. 	-- See m12_setup_spawn_group() 
  140. 	M12_spawn_groups = { 
  141. 		cubical_wave_1 = { 
  142. 			regions = {"cubical_region 002"}, 
  143. 			groups  = {"stag_spawn_group 004"}, 
  144. 		}, 
  145. 		 
  146. 		cubical_wave_2 = { 
  147. 			regions = {"cubical_region 001", "cubical_region 002"}, 
  148. 			groups  = {"stag_spawn_group 005"}, 
  149. 		}, 
  150. 		 
  151. 		lobby_escape = { 
  152. 			regions = {"lobby_region 001", "lobby_region 002"}, 
  153. 			groups  = {"lobby_spawn_group 001", "lobby_spawn_group 002"}, 
  154. 		} 
  155. 	} 
  156. 	 
  157. 	-- Map between group members and the nav to call ai_do_scripted_move() on. 
  158. 	-- This should be used with m12_move_members() 
  159. 	M12_scripted_move = { 
  160. 		stag_cubical = { 
  161. 			members = {	"stag_cubical_001",	"stag_cubical_002",	"stag_cubical_003",	"stag_cubical_004",  
  162. 							"stag_cubical_005", 	"stag_cubical_006", 	"stag_cubical_007",     "stag_cubical_008"	}, 
  163. 			navs    = {	"cubical_nav 001",  	"cubical_nav 002",  	"cubical_nav 003",  	"cubical_nav 004", 
  164. 							"cubical_nav 005", 	"cubical_nav 006", 	"cubical_nav 007",  "cubical_nav 008"		} 
  165. 		} 
  166. 	} 
  167. 	 
  168. -- Navpoints -- 
  169. 	 
  170. 	M12_nav = { 
  171. 		player_car_start = { 
  172. 			"player_car_start_local", "player_car_start_remote", 
  173. 		}, 
  174. 		 
  175. 		lobby_desk = "nav_lobby_desk_ped", 
  176. 	 
  177. 		-- List of nav points for Josh to flee to if he escapes 
  178. 		josh_flee_to = { 
  179. 			"nav_josh_flee_to 001", "nav_josh_flee_to 002", "nav_josh_flee_to 003", "nav_josh_flee_to 004", "nav_josh_flee_to 005", 
  180. 			"nav_josh_flee_to 006", "nav_josh_flee_to 007", "nav_josh_flee_to 008", "nav_josh_flee_to 009", 
  181. 		}, 
  182. 		 
  183. 		-- Lists of nav points to teleport the player and Josh to if Josh is dropped while over the player's shoulder. 
  184. 		josh_dropped = { 
  185. 			floor_3 = { 
  186. 				"nav_josh_dropped_3f_1", "nav_josh_dropped_3f_2", "nav_josh_dropped_3f_3", 
  187. 			}, 
  188. 			floor_2 = { 
  189. 				"nav_josh_dropped_2f_1", "nav_josh_dropped_2f_2", 
  190. 			}, 
  191. 			lobby = { 
  192. 				"nav_josh_dropped_1f_1", "nav_josh_dropped_1f_2", "nav_josh_dropped_1f_3", "nav_josh_dropped_1f_4",  
  193. 				"nav_josh_dropped_1f_5", "nav_josh_dropped_1f_6", "nav_josh_dropped_1f_7", "nav_josh_dropped_1f_8",  
  194. 			}, 
  195. 			garage = { 
  196. 				"nav_josh_dropped_garage",  
  197. 			}, 
  198. 		}, 
  199.  
  200. 		-- Location to teleport the player to after a mission completion/failure 
  201. 		saints_hq_local  = "nav_saints_hq_local", 
  202. 		saints_hq_remote = "nav_saints_hq_remote", 
  203.  
  204. 		-- Mission objective nav points 
  205. 		pr_center_enterance = "nav_pr_center_entrance", 
  206. 		elevator_to_studio  = "nav_elevator_to_studio", 
  207. 		stairs_to_cubical   = "nav_stairs_to_cubical",  -- On the studio level 
  208. 		stairs_to_studio    = "nav_stairs_to_studio",   -- On the cubical level 
  209. 		elevator_to_lobby   = "nav_elevator_to_lobby", 
  210. 		elevator_to_garage  = "nav_elevator_to_garage", 
  211. 		saints_hq_enterance = "nav_saints_hq_enterance", 
  212. 		load_josh           = "nav_load_josh", 
  213. 		 
  214. 		-- Ambient life nav points 
  215. 		stag_pace	= { "nav_stag_pace_001", "nav_stag_pace_002", "nav_stag_pace_003" }, 
  216. 	} 
  217. 	 
  218. -- Teleportation Navpoints -- 
  219. 	-- Teleportation Navpoint tables. The following tables map to 
  220. 	--   [1] - Local Player 
  221. 	--   [2] - Remote Player (if M12_in_coop) 
  222. 	--   [3] - Suko 
  223. 	--   [4] - Josh 
  224. 	-- See the helper function m12_teleport_team_to() 
  225. 	M12_teleport = { 
  226. 		start				= {"nav_start_local",				"nav_start_remote",				"nav_start_suko",				"nav_studio_josh"}, 
  227. 		lobby				= {"nav_lobby_local",				"nav_lobby_remote",				"nav_lobby_suko",				"nav_studio_josh"}, 
  228. 		studio			= {"nav_studio_local",				"nav_studio_remote",				"nav_studio_suko",			"nav_studio_josh"}, 
  229. 		have_josh		= {"nav_have_josh_local",			"nav_have_josh_remote",			"nav_have_josh_suko",		"nav_have_josh_josh"}, 
  230. 		cubical			= {"nav_cubical_local",				"nav_cubical_remote",			"nav_cubical_suko",			"nav_cubical_josh"}, 
  231. 		lobby_elevator	= {"nav_lobby_elevator_local",	"nav_lobby_elevator_remote",	"nav_lobby_elevator_suko",	"nav_lobby_elevator_josh"}, 
  232. 		nav_garage		= {"nav_garage_local",				"nav_garage_remote",				"nav_garage_suko",			"nav_garage_josh"}, 
  233. 		garage_outside	= {"nav_garage_outside_local",	"nav_garage_outside_remote",	"nav_garage_outside_suko",	"nav_garage_outside_josh"}, 
  234. 	} 
  235. 	 
  236. -- Triggers -- 
  237. 	M12_trigger = { 
  238. 		pr_center_front			= "trigger_pr_center_front", 
  239. 		pr_center_enterance		= "trigger_pr_center_enterance", 
  240. 		reception					= "trigger_reception", 
  241. 		door_to_josh				= "trigger_door_to_josh", 
  242. 		-- elev_conv_01				= "trigger_elev_conv 01", 
  243. 		elev_conv_02				= "trigger_elev_conv 02", 
  244. 		studio_01					= "trigger_studio 001", 
  245. 		studio_02					= "trigger_studio 002", 
  246. 		studio_03					= "trigger_studio 003", 
  247. 		studio_door_to_stairs 	= "trigger_studio_door_to_stairs", 
  248. 		stairs_marker				= "trigger_stairs_marker", 
  249. 		cubicle_01					= "trigger_cubicle 001", 
  250. 		start_spawning				= "trigger_start_spawning", 
  251. 		lobby_spawn					= "trigger_lobby_spawn", 
  252. 		garage_door					= "trigger_garage_door", 
  253. 		saints_hq					= "trigger_saints_hq", 
  254. 		saints_hq_freeze			= "trigger_saints_hq_freeze", 
  255. 		lobby_middle				= "trigger_lobby_middle", 
  256. 		lobby_floor					= "trigger_lobby_floor", 
  257. 		lobby_top					= "trigger_lobby_top", 
  258. 		lobby_enter_1				= "trigger_lobby_enter 001", 
  259. 		lobby_enter_2				= "trigger_lobby_enter 002", 
  260. 		lobby_exit					= "trigger_lobby_exit 001", 
  261. 		stag_outside_garage		= "trigger_stag_outside_garage", 
  262. 		chasers_1					= "trigger_start_chasers 001", 
  263. 		chasers_2					= "trigger_start_chasers 002", 
  264. 		fleeing_peds_1				= "trigger_fleeing_peds 001", 
  265. 		load_josh               = "trigger_load_josh", 
  266. 		block_traffic				= "tgr_block_traffic 001", 
  267. 	} 
  268. 	 
  269. -- Elevator Door Movers -- 
  270. 	M12_elevator = { 
  271. 		lobby_lower = { 
  272. 			left	= {name = "door_lobby_lower_left", trigger = "trigger_lobby_lower_left", add_marker = false,}, 
  273. 			right	= {name = "door_lobby_lower_right", trigger = "trigger_lobby_lower_right", add_marker = true,}, 
  274. 		}, 
  275. 		 
  276. 		lobby_upper = { 
  277. 			left	= {name = "door_lobby_upper_left", trigger = "trigger_lobby_upper_left", add_marker = true,}, 
  278. 			right	= {name = "door_lobby_upper_right", trigger = "trigger_lobby_upper_right", add_marker = false,}, 
  279. 		}, 
  280. 		 
  281. 		cubical = { 
  282. 			left	= {name = "door_cubical_left", trigger = "trigger_cubical_left", add_marker = true,}, 
  283. 			--right	= {name = "door_cubical_right", trigger = "trigger_cubical_right", add_marker = false,}, 
  284. 		}, 
  285. 		 
  286. 		studio = { 
  287. 			left	= {name = "door_studio_left", trigger = "trigger_studio_left", add_marker = false,}, 
  288. 		}, 
  289. 	} 
  290. 	 
  291. 	M12_front_doors = { 
  292. 		"lobby_front_door 001", "lobby_front_door 003", 
  293. 	} 
  294. 	 
  295. -- Trigger Flags -- 
  296. 	M12_in_coop					= false 
  297. 	M12_weapon_equipped		= false 
  298. 	 
  299. 	-- m12_goto_a_trigger() flags 
  300. 	M12_trigger_reached		= false 
  301. 	 
  302. 	M12_fleeing_peds_triggered = false 
  303. 	 
  304. 	-- m12_goto_a_elevator() flags 
  305. 	M12_player_in_elevator	= false	-- Local or remote player is in a elevator 
  306. 	M12_local_in_elevator	= false 
  307. 	M12_remote_in_elevator	= false 
  308. 	M12_josh_in_elevator		= false 
  309.  
  310. -- Text -- 
  311. 	M12_OBJ_UNEQUIP_YOUR_WEAPON      = {name = "m12_obj_unequip_your_weapon",		icon = OI_ASSET_USE,} 
  312. 	M12_OBJ_GO_TO_THE_PR_CENTER      = {name = "m12_obj_go_to_the_pr_center",		icon = OI_ASSET_LOCATION,} 
  313. 	M12_OBJ_ENTER_THE_PR_CENTER      = {name = "m12_obj_enter_the_pr_center",		icon = OI_ASSET_LOCATION,} 
  314. 	M12_OBJ_ENTER_THE_ELEVATOR       = {name = "m12_obj_enter_the_elevator",		icon = OI_ASSET_LOCATION,} 
  315. 	M12_OBJ_GO_TO_RECEPTION				= {name = "m12_obj_go_to_reception_desk",		icon = OI_ASSET_LOCATION,} 
  316. 	M12_OBJ_FIND_JOSH_BIRK           = {name = "m12_obj_find_josh_birk",				icon = OI_ASSET_LOCATION,} 
  317. 	M12_OBJ_GRAB_JOSH_BIRK           = {name = "m12_obj_grab_josh_birk",				icon = OI_ASSET_USE,} 
  318. 	M12_OBJ_ESCAPE_THE_STAG_BUILDING = {name = "m12_obj_escape_the_stag_building",icon = OI_ASSET_LOCATION,} 
  319. 	M12_OBJ_GET_TO_THE_ELEVATORS     = {name = "m12_obj_get_to_the_elevators",		icon = OI_ASSET_LOCATION,} 
  320. 	M12_OBJ_GET_TO_THE_GARAGE        = {name = "m12_obj_get_to_the_garage",			icon = OI_ASSET_LOCATION,} 
  321. 	M12_OBJ_STEAL_A_VEHICLE          = {name = "m12_obj_steal_a_vehicle",			icon = OI_ASSET_USE,} 
  322. 	M12_OBJ_PICKUP_JOSH_BIRK         = {name = "m12_pickup_josh_birk",				icon = OI_ASSET_USE,} 
  323. 	M12_OBJ_ESCAPE_TO_THE_SAINTS_HQ  = {name = "m12_obj_escape_to_the_saints_hq",	icon = OI_ASSET_LOCATION,} 
  324.  
  325. 	M12_FAILURE_SUKO_DIED            = "m12_failure_suko_died" 
  326. 	M12_FAILURE_JOSH_DIED            = "m12_failure_josh_died" 
  327. 	M12_FAILURE_COVER_BLOWN          = "m12_failure_cover_blown" 
  328. 	M12_FAILURE_JOSH_ABANDONED			= "m12_failure_josh_abandoned" 
  329. 	M12_FAILURE_SUKO_ABANDONED			= "m12_failure_suko_abandoned" 
  330. 	 
  331. -- Threads -- 
  332. 	M12_thread = { 
  333. 		no_cops         = INVALID_THREAD_HANDLE, 
  334. 		unequip_weapon	= INVALID_THREAD_HANDLE, 
  335. 		hs_check			= INVALID_THREAD_HANDLE, 
  336. 		pickup_josh		= INVALID_THREAD_HANDLE, 
  337. 		josh_shield_check = INVALID_THREAD_HANDLE, 
  338. 		stop_player_car = INVALID_THREAD_HANDLE, 
  339. 		play_line       = INVALID_THREAD_HANDLE, 
  340. 	} 
  341.  
  342. -- Checkpoints -- 
  343. 	M12_CHECKPOINT_START             = MISSION_START_CHECKPOINT			-- defined in ug_lib.lua 
  344. 	M12_CHECKPOINT_GRAB_JOSH         = "m12_checkpoint_grab_josh" 
  345. 	M12_CHECKPOINT_CUBICAL_BATTLE    = "m12_checkpoint_cubical_battle" 
  346. 	M12_CHECKPOINT_ESCAPE            = "m12_checkpoint_escape" 
  347. 	 
  348. -- Cutscenes -- 
  349. 	CUTSCENE_MISSION_INTRO = "12_In" 
  350. 	CUTSCENE_GRAB_JOSH     = "12_z01" 
  351. 	CUTSCENE_MISSION_OUTRO = "12_Out" 
  352. 	 
  353. -- Music 
  354. 	M12_music = { 
  355. 		josh_grabbed = "M12_music_escape_PR_center", 
  356. 		josh_loaded_into_car = "M12_music_escape_PR_center_end", 
  357. 		garage_exited = "M12_music_drive_to_Saints_HQ", 
  358. 		arrived_at_saints_hq = "M12_music_drive_to_Saints_HQ_end", 
  359. 		restart_drive_to_hq = "M12_music_Saints_HQ_Checkpoint", 
  360. 		restart_pr_center = "M12_music_escape_PR_Checkpoint", 
  361. 		stop = "M12_music_STOP", 
  362. 	} 
  363.  
  364. -- Personas -- 
  365. 	M12_personas = { 
  366. 		{ name = "Suko", 				handle = INVALID_PERSONA_HANDLE }, 
  367. 		{ name = "Interrogation", 	handle = INVALID_PERSONA_HANDLE }, 
  368. 		{ name = "Josh", 				handle = INVALID_PERSONA_HANDLE }, 
  369. 	} 
  370. 	 
  371. 	M12_persona_line = { 
  372. 		hide_guns = 		{ name = "M12_Hide_Guns", 					character = LOCAL_PLAYER, 			play_2d = false 	}, 
  373. 		up_on_floor_7 = 	{ name = "M12_Elevator", 					character = "worker_lobby_006", 	play_2d = false 	}, 
  374. 		thats_him = 		{ name = "M12_Found_Josh", 				character = "Suko", 					play_2d = true 	}, 
  375. 		secure_building =   { name = "M12_Secure_Building",             character = "",                     play_2d = false     }, 
  376. 		stunned_01 = 		{ name = "M12_Josh_Stunned_01", 			character = NPC_JOSH, 				play_2d = false 	}, 
  377. 		stunned_02 = 		{ name = "M12_Josh_Stunned_02", 			character = NPC_JOSH, 				play_2d = false 	}, 
  378. 		stunned_03 = 		{ name = "M12_Josh_Stunned_03", 			character = NPC_JOSH, 				play_2d = false 	}, 
  379. 		stunned_04 = 		{ name = "M12_Josh_Stunned_04", 			character = NPC_JOSH, 				play_2d = false 	}, 
  380. 		stunned_05 = 		{ name = "M12_Josh_Stunned_05", 			character = NPC_JOSH, 				play_2d = false 	}, 
  381. 		stunned_06 = 		{ name = "M12_Josh_Stunned_06", 			character = NPC_JOSH, 				play_2d = false 	}, 
  382. 		stunned_07 = 		{ name = "M12_Josh_Stunned_07",			character = NPC_JOSH, 				play_2d = false 	}, 
  383. 		stunned_08 = 		{ name = "M12_Josh_Stunned_08", 			character = NPC_JOSH, 				play_2d = false 	}, 
  384. 		stunned_09 = 		{ name = "M12_Josh_Stunned_09", 			character = NPC_JOSH, 				play_2d = false 	}, 
  385. 		stunned_10 = 		{ name = "M12_Josh_Stunned_10", 			character = NPC_JOSH, 				play_2d = false 	}, 
  386. 		ele_to_lobby = 	{ name = "M12_See_Elevator_To_Lobby",	character = LOCAL_PLAYER, 			play_2d = false 	}, 
  387. 		ele_to_garage = 	{ name = "M12_See_Elevator_To_Garage",	character = "Suko", 					play_2d = true 	}, 
  388. 		get_in = 			{ name = "M12_Get_In_Car",					character = LOCAL_PLAYER, 			play_2d = false 	}, 
  389. 	} 
  390. 	 
  391. -- Conversations -- 
  392. 	-- Table of audio conversations to play. Either a actual audio file can be specifed, or a message can be used in its place. 
  393. 	-- Expected Table Members: 
  394. 	--   name    - Name of the audio file to play 
  395. 	--   delay   - Amount of time (in seconds) to delay after a audio file has played 
  396. 	--   message - Supplementary message to display if no audio file is provided 
  397. 	M12_convo = { 
  398. 		-- Stars along with the mission 
  399. 		to_pr_center = { 
  400. 			files = { 
  401. 				{name = "m12_convo_1", 						delay = 15.0,}, 
  402. 				{name = "m12_begin_drive_to_center", 	delay = 15.0,}, 
  403. 				{name = "m12_drive_to_center", 			delay =  0.0,}, 
  404. 			}, 
  405. 			thread = INVALID_THREAD_HANDLE, 
  406. 		}, 
  407. 	 
  408. 		-- Starts when you enter the PR Center lobby 
  409. 		to_studio = { 
  410. 			files = { 
  411. 				{name = "m12_arrive_at_center", 	delay =  4.0,}, 
  412. 				{name = "m12_convo_3", 				delay =  0.0,}, 
  413. 			}, 
  414. 			thread = INVALID_THREAD_HANDLE, 
  415. 		}, 
  416. 		 
  417. 		-- Starts when Josh is taken hostage, after the Z-Scene 
  418. 		escaping_01 = { 
  419. 			files = { 
  420. 				{name = "m12_convo_5", 						delay = 2.0,}, 
  421. 				{name = M12_persona_line.stunned_01,	delay = 6.0,}, 
  422. 				{name = "m12_office_combat",				delay = 6.0,}, 
  423. 				{name = M12_persona_line.stunned_02,	delay = 15.0,}, 
  424. 				{name = M12_persona_line.stunned_03,	delay = 15.0,}, 
  425. 				{name = M12_persona_line.stunned_04,	delay = 15.0,}, 
  426. 				{name = M12_persona_line.stunned_05,	delay = 15.0,}, 
  427. 			}, 
  428. 			thread = INVALID_THREAD_HANDLE, 
  429. 		}, 
  430. 		 
  431. 		-- Starts when the player enters the cubicle area 
  432. 		escaping_02 = { 
  433. 			files = { 
  434. 				{name = M12_persona_line.stunned_06,	delay = 10.0,}, 
  435. 				{name = M12_persona_line.stunned_07,	delay = 6.0,}, 
  436. 				{name = "m12_lobby_combat", 				delay = 6.0,}, 
  437. 				{name = M12_persona_line.stunned_08,	delay = 12.0,}, 
  438. 				{name = M12_persona_line.stunned_09,	delay = 13.0,}, 
  439. 				{name = M12_persona_line.stunned_10,	delay = 14.0,}, 
  440. 			}, 
  441. 			thread = INVALID_THREAD_HANDLE, 
  442. 		}, 
  443. 		 
  444. 		-- Starts when player tries to take upper elevators after taking Josh 
  445. 		elevator = { 
  446. 			files = { 
  447. 				{name = "m12_elevator_blocked", 	delay = 0.0,}, 
  448. 			}, 
  449. 			thread = INVALID_THREAD_HANDLE, 
  450. 		}, 
  451. 		 
  452. 		-- Starts when the player enters the lobby with Josh. 
  453. 		lobby_escape = { 
  454. 			files = { 
  455. 				{name = "m12_enter_lobby", 				delay = 10.0,}, 
  456. 			}, 
  457. 			thread = INVALID_THREAD_HANDLE, 
  458. 		}, 
  459. 		 
  460. 		-- Played while the player gets into the garage. 
  461. 		flee_to_hq = { 
  462. 			files = { 
  463. 				{name = "M12_Escape_To_HQ",				delay = 0.0,}, 
  464. 			}, 
  465. 			thread = INVALID_THREAD_HANDLE, 
  466. 		}, 
  467. 		 
  468. 		-- Played when the player gets into the car. 
  469. 		flee_to_hq_nightblade = { 
  470. 			files = { 
  471. 				{name = "M12_Escape_To_HQ_Nightblade",	delay = 10.0,}, 
  472. 			}, 
  473. 			thread = INVALID_THREAD_HANDLE, 
  474. 		}, 
  475. 	} 
  476. 	 
  477. 	M12_runtime = { 
  478. 		ambush_groups = { } 
  479. 	} 
  480. 	 
  481. -- Other -- 
  482. 	M12_STAG_NOTORIETY = "police" 
  483.  
  484. -- Variables -- 
  485. 	M12_active_triggers        = {} 
  486. 	M12_current_obj            = "" 
  487. 	M12_secondary_obj          = "" 
  488. 	M12_josh_flee_to_nav	   = false 
  489. 	M12_begin_load_josh        = false 
  490. 	M12_escape_vehicle_entered = false 
  491. 	M12_inv_restricted_for_carrying_josh = false 
  492. 	M12_cur_josh_dropped_nav_list = {} 
  493. 	 
  494. 	M12_active_convo = "" 
  495.  
  496. -- ************************* 
  497. -- 
  498. -- Standard functions 
  499. -- 
  500. -- ************************* 
  501.  
  502. -- This is the primary entry point for the mission, and is responsible for starting up the mission 
  503. -- at the specified checkpoint. 
  504. -- CALLED FROM CODE 
  505. -- 
  506. -- m12_checkpoint:  The checkpoint the mission should begin at 
  507. -- is_restart:      TRUE if the mission is restarting, FALSE otherwise 
  508. -- 
  509. function m12_start(m12_checkpoint, is_restart) 
  510. 	M12_in_coop = coop_is_active() 
  511.  
  512. 	-- Check if this mission starting from the beginning 
  513. 	if (m12_checkpoint == M12_CHECKPOINT_START) then 
  514. 		if (is_restart == false) then 
  515. 			-- First time playing mission 
  516. 			cutscene_play(CUTSCENE_MISSION_INTRO, nil, {M12_teleport.start[1], M12_teleport.start[2]}, false) 
  517. 		end 
  518. 	end 
  519.  
  520. 	-- Handle mission initialization for the current checkpoint 
  521. 	m12_initialize(m12_checkpoint, is_restart) 
  522.  
  523. 	-- Run the mission from the current checkpoint 
  524. 	m12_run(m12_checkpoint) 
  525. end 
  526.  
  527. -- This is the primary function responsible for running the entire mission from start to finish. 
  528. -- 
  529. -- first_checkpoint:	The first checkpoint to begin running the mission at 
  530. -- 
  531. function m12_run(first_checkpoint) 
  532. 	local current_checkpoint = first_checkpoint 
  533. 	 
  534. 	-- Warp to the Saints HQ if the player cancels. 
  535. 	mission_set_cancel_warp_location(M12_nav.saints_hq_local, M12_nav.saints_hq_remote) 
  536. 	 
  537. 	-- Run the mission from the beginning 
  538. 	if current_checkpoint == M12_CHECKPOINT_START then 
  539. 		m12_start_convo_thread(M12_convo.to_pr_center) 
  540. 		m12_goto_a_trigger(M12_trigger.pr_center_front, M12_OBJ_GO_TO_THE_PR_CENTER, true) 
  541.  
  542. 		m12_cleanup_start_world() 
  543. 		 
  544. 		m12_setup_start_lobby() 
  545. 		m12_enter_stealth_section() 
  546. 		m12_dont_allow_weapons() 
  547.  
  548. 		m12_unload_all_convos() 
  549. 		m12_goto_a_trigger(M12_trigger.pr_center_enterance, M12_OBJ_ENTER_THE_PR_CENTER, false) 
  550. 		m12_goto_a_trigger(M12_trigger.reception, M12_OBJ_GO_TO_RECEPTION, false) 
  551. 				 
  552. 		 
  553. 		m12_start_convo_thread(M12_convo.to_studio) 
  554. 		delay(6.0) 
  555. 		ai_do_scripted_move(M12_groups.workers_lobby.second_floor_receptionist, M12_nav.lobby_desk) 
  556. 		-- Additional breadcrumbing. Re-add if people have trouble getting to the upper elevators. 
  557. 		m12_goto_a_trigger(M12_trigger.lobby_middle, M12_OBJ_ENTER_THE_ELEVATOR, false, M12_trigger.lobby_enter_1) 
  558. 		m12_goto_a_trigger(M12_trigger.lobby_top, M12_OBJ_ENTER_THE_ELEVATOR, false, M12_trigger.lobby_enter_2) 
  559. 		-- m12_setup_trigger(M12_trigger.elev_conv_01, "m12_elev_persona_cb", "") 
  560. 		m12_goto_a_elevator(M12_elevator.lobby_upper, M12_OBJ_ENTER_THE_ELEVATOR, false) 
  561. 		--turn_to(M12_groups.workers_lobby.second_floor_receptionist, LOCAL_PLAYER) 
  562.  
  563. 		m12_unload_all_convos() 
  564. 		m12_cleanup_start_lobby() 
  565. 		 
  566. 		m12_teleport_team_to(M12_teleport.studio) 
  567. 		 
  568. 		current_checkpoint = M12_CHECKPOINT_GRAB_JOSH 
  569. 		mission_set_checkpoint(current_checkpoint, true) 
  570. 	end 
  571. 	 
  572. 	if current_checkpoint == M12_CHECKPOINT_GRAB_JOSH then 
  573. 		character_ragdoll_set_last_resort_position(M12_teleport.studio[1]) 
  574. 	 
  575. 		zscene_prep(CUTSCENE_GRAB_JOSH)  
  576. 		m12_setup_grab_josh() 
  577. 		m12_enter_stealth_section() 
  578. 		m12_dont_allow_weapons() 
  579. 		m12_play_persona_line(M12_persona_line.thats_him) 
  580. 		 
  581. 		M12_cur_josh_dropped_nav_list = M12_nav.josh_dropped.floor_3 
  582. 		 
  583. 		m12_goto_a_trigger(M12_trigger.door_to_josh, M12_OBJ_FIND_JOSH_BIRK, false) 
  584. 		m12_set_objective(M12_OBJ_GRAB_JOSH_BIRK) 
  585. 		m12_wait_until_josh_is_in_range() 
  586. 		m12_allow_weapons() -- Re-enable weapons before the cutscene so the player doesn't fail the mission while it is playing 
  587. 		m12_play_z_scene() 
  588. 		m12_teleport_team_to(M12_teleport.have_josh, true, true, true) 
  589. 		door_lock(M12_elevator.studio.left.name, true) 
  590. 		m12_unload_all_convos() 
  591. 		group_create_hidden(M12_groups.stag_window_rush.name) 
  592. 		group_create_hidden(M12_groups.stag_studio_rush_01.name) 
  593. 		group_create_hidden(M12_groups.stag_studio_rush_02.name) 
  594. 		m12_setup_trigger(M12_trigger.elev_conv_02, "m12_start_convo_elevator", "") 
  595. 		m12_setup_trigger(M12_trigger.fleeing_peds_1, "m12_start_fleeing_peds_1", "") 
  596. 		 
  597. 		-- Kick off some music. 
  598. 		m12_post_music_event(M12_music.josh_grabbed) 
  599. 		 
  600. 		--m12_studio_window_rush group. After z-scene these guys rush past the window in front of the player 
  601. 		group_show(M12_groups.stag_window_rush.name) 
  602. 		m12_helper_setup_ambush_group(M12_groups.stag_window_rush) 
  603. 	 
  604. 		 
  605. 		-- Allow the patroling guys to enter combat now. 
  606. 		npc_combat_enable(M12_groups.stag_studio.members[1], true) 
  607. 		npc_combat_enable(M12_groups.stag_studio.members[4], true) 
  608. 		--Too many enemies are drawing the player the wrong way 
  609. 		object_destroy(M12_groups.stag_studio.members[2]) 
  610. 		object_destroy(M12_groups.stag_studio.members[3]) 
  611. 	 
  612. 		 
  613. 		-- Give the player a brief amount of time to adjust to the new situation before we 
  614. 		-- let the STAG attack. 
  615. 		-- delay(M12_DELAY_AFTER_GRAB_JOSH_ZSCENE) 
  616. 		 
  617. 		-- Tell the NPCs to attack the player(s) 
  618. 		for key, npc in pairs(M12_groups.stag_studio.members) do 
  619. 			set_attack_enemies_flag(npc, true) 
  620. 		end 
  621. 		 
  622. 		for i, npc in pairs(M12_groups.workers_studio.members) do 
  623. 			flee(npc, LOCAL_PLAYER) 
  624. 		end 
  625. 		 
  626. 		m12_exit_stealth_section() 
  627.  
  628. 		m12_start_convo_thread(M12_convo.escaping_01) 
  629. 		m12_goto_a_trigger(M12_trigger.studio_01, M12_OBJ_ESCAPE_THE_STAG_BUILDING, false) 
  630. 		group_show(M12_groups.stag_studio_rush_01.name) 
  631. 		m12_helper_setup_ambush_group(M12_groups.stag_studio_rush_01)		 
  632. 		m12_goto_a_trigger(M12_trigger.studio_02, M12_OBJ_ESCAPE_THE_STAG_BUILDING, false) 
  633. 		group_show(M12_groups.stag_studio_rush_02.name) 
  634. 		m12_helper_setup_ambush_group(M12_groups.stag_studio_rush_02) 
  635. 		M12_thread.play_line = thread_new("m12_find_nearest_guy_and_play_line", M12_groups.stag_studio_rush_02, M12_persona_line.secure_building, 15.0, 1.25) 
  636. 		m12_goto_a_trigger(M12_trigger.studio_03, M12_OBJ_ESCAPE_THE_STAG_BUILDING, false) 
  637. 		m12_goto_a_trigger(M12_trigger.studio_door_to_stairs, M12_OBJ_ESCAPE_THE_STAG_BUILDING, false, M12_trigger.stairs_marker) 
  638.  
  639. 		-- Don't clean up the convos since they can continue into the cubical scene 
  640. 		m12_cleanup_grab_josh() 
  641. 		 
  642. 		current_checkpoint = M12_CHECKPOINT_CUBICAL_BATTLE 
  643. 		mission_set_checkpoint(current_checkpoint, true) 
  644. 	end 
  645. 	 
  646. 	if current_checkpoint == M12_CHECKPOINT_CUBICAL_BATTLE then 
  647. 		character_ragdoll_set_last_resort_position(M12_teleport.cubical[1]) 
  648. 		 
  649. 		M12_cur_josh_dropped_nav_list = M12_nav.josh_dropped.floor_2 
  650. 		m12_setup_cubical_battle() 
  651. 		m12_start_convo_thread(M12_convo.escaping_02) 
  652. 		m12_goto_a_trigger(M12_trigger.cubicle_01, M12_OBJ_ESCAPE_THE_STAG_BUILDING, false) 
  653. 		m12_goto_a_elevator(M12_elevator.cubical, M12_OBJ_ENTER_THE_ELEVATOR, true) 
  654. 		m12_cleanup_cubical_battle() 
  655.  
  656. 		-- Set the next set of recovery navs before teleporting in case something happens. 
  657. 		M12_cur_josh_dropped_nav_list = M12_nav.josh_dropped.lobby 
  658. 		 
  659. 		m12_teleport_team_to(M12_teleport.lobby_elevator, true, true, true) 
  660.  
  661. 		current_checkpoint = M12_CHECKPOINT_ESCAPE 
  662. 		mission_set_checkpoint(current_checkpoint, true) 
  663. 	end 
  664.  
  665. 	if current_checkpoint == M12_CHECKPOINT_ESCAPE then 
  666. 		character_ragdoll_set_last_resort_position(M12_teleport.lobby_elevator[1]) 
  667. 		 
  668. 		M12_cur_josh_dropped_nav_list = M12_nav.josh_dropped.lobby 
  669. 		M12_josh_flee_to_nav = false 
  670. 		m12_setup_escape_lobby() 
  671. 		m12_goto_a_trigger(M12_trigger.lobby_middle, M12_OBJ_ESCAPE_THE_STAG_BUILDING, false, M12_trigger.lobby_exit) 
  672. 		m12_goto_a_elevator(M12_elevator.lobby_lower, M12_OBJ_ENTER_THE_ELEVATOR, true) 
  673. 		m12_cleanup_escape_lobby() 
  674. 		 
  675. 		M12_cur_josh_dropped_nav_list = M12_nav.josh_dropped.garage 
  676. 		 
  677. 		m12_teleport_team_to(M12_teleport.nav_garage, true, true, true) 
  678. 		character_ragdoll_set_last_resort_position(M12_teleport.nav_garage[1]) 
  679. 		m12_load_josh_into_car() 
  680. 		 
  681. 		m12_setup_escape_garage() 
  682.  
  683. 		M12_thread.pickup_josh = thread_new("m12_thread_pickup_josh_marker") 
  684. 		--m12_start_convo_thread(M12_convo.flee_to_hq) 
  685. 		m12_goto_a_trigger(M12_trigger.garage_door, M12_OBJ_ESCAPE_TO_THE_SAINTS_HQ, false) 
  686. 	 
  687. 		-- Stop using the mission specified ragdoll get up last resort. 
  688. 		character_ragdoll_clear_last_resort_position() 
  689. 		 
  690. 		-- Progress the musics. 
  691. 		m12_post_music_event(M12_music.garage_exited) 
  692. 		 
  693. 	 
  694. 		-- Use the innards of m12_goto_a_trigger so we can play the conversation after setting up the waypoint. 
  695. 		--m12_goto_a_trigger(M12_trigger.saints_hq, M12_OBJ_ESCAPE_TO_THE_SAINTS_HQ, true) 
  696. 		m12_goto_a_trigger_setup(M12_trigger.saints_hq, M12_OBJ_ESCAPE_TO_THE_SAINTS_HQ, true, nil) 
  697. 		trigger_enable(M12_trigger.saints_hq_freeze, true) 
  698. 		on_trigger("m12_hq_freeze_cb", M12_trigger.saints_hq_freeze) 
  699. 		 
  700. 		delay(15.0) 
  701. 		m12_start_convo_thread(M12_convo.flee_to_hq_nightblade) 
  702. 		 
  703. 		while not M12_trigger_reached do 
  704. 			thread_yield() 
  705. 		end 
  706. 		 
  707. 		m12_goto_a_trigger_cleanup(M12_trigger.saints_hq, true, nil)		 
  708. 		 
  709. 		-- Progress the musics. 
  710. 		m12_post_music_event(M12_music.arrived_at_saints_hq) 
  711. 		 
  712. 		m12_cleanup_escape_garage() 
  713. 		 
  714. 		-- M12_thread.stop_player_car = thread_new("m12_stop_player_car_thread") 
  715. 	end 
  716.  
  717. 	mission_end_success("m12", CUTSCENE_MISSION_OUTRO, {M12_nav.saints_hq_local, M12_nav.saints_hq_remote}) 
  718. end 
  719.  
  720. -- This is the primary function responsible for cleaning up the entire mission 
  721. -- CALLED FROM CODE (+++MUST RETURN IMMEDIATLY+++) 
  722. -- 
  723. function m12_cleanup() 
  724. 	--[[ INSERT ANY MISSION SPECIFIC CLEAN-UP ]]-- 
  725. 	 
  726. 	-- The mission may have failed due to a remote player disconnecting. Double check to see if they are connected. 
  727. 	if M12_in_coop then 
  728. 		M12_in_coop = coop_is_active() 
  729. 	end 
  730.  
  731. 	m12_clear_seconodary_objective() 
  732. 	m12_clear_objective() 
  733. 	 
  734. 	spawn_region_min_spawn_dist_reset() 
  735. 	 
  736. 	m12_exit_stealth_section() 
  737. 	m12_allow_weapons() 
  738.  
  739. 	m12_unload_all_threads() 
  740. 	m12_unload_personas() 
  741. 	m12_cleanup_all_spawn_groups() 
  742. 	 
  743. 	-- Cleanup all checkpoints 
  744. 	m12_cleanup_start_world() 
  745. 	m12_cleanup_start_lobby() 
  746. 	m12_cleanup_grab_josh() 
  747. 	m12_cleanup_cubical_battle() 
  748. 	m12_cleanup_escape_lobby() 
  749. 	m12_cleanup_escape_garage() 
  750. 	m12_cleanup_load_josh_into_car() 
  751.  
  752. 	m12_cleanup_josh() 
  753. 	m12_cleanup_suko() 
  754. 	 
  755. 	-- Ensure all triggers are disabled 
  756. 	for i, trigger in pairs(M12_trigger) do 
  757. 		m12_cleanup_trigger(M12_trigger) 
  758. 	end 
  759. 	 
  760. 	-- Cleanup any active elevators 
  761. 	for i, elevators in pairs(M12_elevator) do 
  762. 		m12_goto_a_elevator_cleanup(elevators) 
  763. 	end 
  764. 	 
  765. 	if group_is_loaded(M12_groups.garage_cars.name) then 
  766. 		group_destroy(M12_groups.garage_cars.name) 
  767. 	end 
  768.  
  769. 	-- Remove the Player(s) costumes 
  770. 	customization_item_revert() 
  771. 	 
  772. 	-- Reenable party recruiting 
  773. 	party_set_recruitable(true) 
  774. 	 
  775. 	-- Allow ambient cops again. 
  776. 	if M12_thread.no_cops ~= INVALID_THREAD_HANDLE then 
  777. 		thread_kill(M12_thread.no_cops) 
  778. 		M12_thread.no_cops = INVALID_THREAD_HANDLE 
  779. 	end 
  780. 	spawning_allow_cop_ambient_spawns(true) 
  781. 	notoriety_reset("police") 
  782. 	 
  783. 	thread_kill(M12_thread.stop_player_car) 
  784. 	 
  785. 	-- Undo anything we did to set up the player to carry Josh over the shoulder. 
  786. 	m12_cleanup_player_carrying_josh(true) 
  787. 	inv_weapon_disable_all_slots(false, SYNC_LOCAL) 
  788. 	M12_inv_restricted_for_carrying_josh = false 
  789. 	 
  790. 	-- Stop the music. 
  791. 	m12_post_music_event(M12_music.stop) 
  792. 	 
  793. 	-- Stop using the mission specified ragdoll get up last resort. 
  794. 	character_ragdoll_clear_last_resort_position() 
  795. end 
  796.  
  797. -- Called when the mission has ended with success 
  798. -- CALLED FROM CODE (+++MUST RETURN IMMEDIATLY+++) 
  799. -- 
  800. function m12_success() 
  801. 	--[[ INSERT ANY MISSION SPECIFIC SUCCESS STUFF ]]-- 
  802. 	 
  803. end 
  804.  
  805.  
  806. -- ************************* 
  807. -- 
  808. -- Local functions 
  809. -- 
  810. -- ************************* 
  811.  
  812. -- Initialize the mission for the specified checkpoint 
  813. -- 
  814. -- checkpoint:		Checkpoint to initialize the mission to 
  815. -- 
  816. function m12_initialize(checkpoint, is_restart) 
  817. 	-- Make sure the screen is completly faded out 
  818. 	mission_start_fade_out(0.0) 
  819. 	 
  820. 	-- Set the mission author 
  821. 	set_mission_author("Craig Williams") 
  822.  
  823. 	-- Common initialization 
  824. 	m12_initialize_common() 
  825.  
  826. 	-- Checkpoint specific initialization 
  827. 	m12_initialize_checkpoint(checkpoint, is_restart) 
  828. 	 
  829. 	-- Start fading in  
  830. 	mission_start_fade_in() 
  831. end 
  832.  
  833.  
  834. -- *************************************************** 
  835. -- m12_run Helper Functions 
  836. -- *************************************************** 
  837.  
  838. -- Posts a music progression event. 
  839. -- 
  840. function m12_post_music_event(event_name) 
  841. 	audio_object_post_event(event_name, nil, nil, LOCAL_PLAYER) 
  842. end 
  843.  
  844. -- Sets up the player to carry Josh over the shoulder. 
  845. -- Should be called after grabbing Josh. 
  846. -- 
  847. function m12_setup_player_to_carry_josh(start_shield_check_thread) 
  848. 	-- Don't allow the player to ragdoll or flinch, we don't 
  849. 	-- want to break out of the human shield animation. 
  850. 	character_allow_ragdoll(LOCAL_PLAYER, false) 
  851. 	character_prevent_flinching(LOCAL_PLAYER, true) 
  852. 	character_prevent_explosion_fling(LOCAL_PLAYER, true) 
  853. 	character_set_no_explosive_panic(LOCAL_PLAYER, true) 
  854. 	character_set_never_catch_fire(LOCAL_PLAYER, true) 
  855. 	 
  856. 	character_allow_ragdoll(NPC_JOSH, false) 
  857. 	character_prevent_flinching(NPC_JOSH, true) 
  858. 	character_prevent_explosion_fling(NPC_JOSH, true) 
  859. 	character_set_no_explosive_panic(NPC_JOSH, true) 
  860. 	character_set_never_catch_fire(NPC_JOSH, true) 
  861. 	turn_invulnerable(NPC_JOSH) 
  862. 	 
  863. 	-- The OTS animations are only set up for the pistol, smg, and rifle. 
  864. 	if M12_inv_restricted_for_carrying_josh == false then 
  865. 		inv_weapon_disable_all_slots(true, SYNC_LOCAL) 
  866. 		inv_weapon_disable_slot(WEAPON_SLOT_PISTOL, false, SYNC_LOCAL) 
  867. 		inv_weapon_disable_slot(WEAPON_SLOT_SMG, false, SYNC_LOCAL) 
  868. 		inv_weapon_disable_slot(WEAPON_SLOT_RIFLE, false, SYNC_LOCAL) 
  869. 		 
  870. 		-- Equip the pistol for starters. 
  871. 		inv_item_equip_slot("best", LOCAL_PLAYER) 
  872. 		 
  873. 		M12_inv_restricted_for_carrying_josh = true 
  874. 	end 
  875. 	 
  876. 	-- Prevent the player from leaving the human shield by pressing Y. 
  877. 	player_human_shield_lock(LOCAL_PLAYER, true) 
  878. 	 
  879. 	-- Can't throw grenades. 
  880. 	player_grenades_disable() 
  881. 	 
  882. 	-- If at any time Josh becomes un-human shielded, he dies and the mission fails. 
  883. 	if start_shield_check_thread then 
  884. 		M12_thread.josh_shield_check = thread_new("m12_handle_josh_dropped_thread") 
  885. 	end 
  886. end 
  887.  
  888. -- Cleans up settings for carrying Josh over the shoulder. 
  889. -- Should be called before dropping Josh. 
  890. -- 
  891. function m12_cleanup_player_carrying_josh(end_shield_check_thread) 
  892. 	if group_is_loaded(M12_groups.josh) then 
  893. 		ai_clear_scripted_action(NPC_JOSH) 
  894. 		character_allow_ragdoll(NPC_JOSH, true) 
  895. 		character_prevent_flinching(NPC_JOSH, false) 
  896. 		character_prevent_explosion_fling(NPC_JOSH, false) 
  897. 		character_set_no_explosive_panic(NPC_JOSH, false) 
  898. 		character_set_never_catch_fire(NPC_JOSH, false) 
  899. 		turn_vulnerable(NPC_JOSH) 
  900. 	end 
  901. 	player_release_human_shield(LOCAL_PLAYER, true) 
  902. 	 
  903. 	character_allow_ragdoll(LOCAL_PLAYER, true) 
  904. 	character_prevent_flinching(LOCAL_PLAYER, false) 
  905. 	character_prevent_explosion_fling(LOCAL_PLAYER, false) 
  906. 	character_set_no_explosive_panic(LOCAL_PLAYER, false) 
  907. 	character_set_never_catch_fire(LOCAL_PLAYER, false) 
  908. 	 
  909. 	player_human_shield_lock(LOCAL_PLAYER, false) 
  910. 	 
  911. 	player_grenades_enable() 
  912. 	 
  913. 	if end_shield_check_thread then 
  914. 		thread_kill(M12_thread.josh_shield_check) 
  915. 		M12_thread.josh_shield_check = INVALID_THREAD_HANDLE 
  916. 	end 
  917. end 
  918.  
  919. -- Open and unlocks the front doors of the PR Center 
  920. -- 
  921. function m12_open_front_doors() 
  922. 	for key, door in pairs(M12_front_doors) do 
  923. 		door_lock(door, false) 
  924. 		door_open(door) 
  925. 	end 
  926. end 
  927.  
  928. -- Closes and locks the front doors of the PR Center 
  929. -- 
  930. function m12_lock_front_doors() 
  931. 	for key, door in pairs(M12_front_doors) do 
  932. 		door_close(door) 
  933. 		door_lock(door, true) 
  934. 	end 
  935. end 
  936.  
  937. -- Unlocks the front doors of the PR Center 
  938. -- 
  939. function m12_unlock_front_doors() 
  940. 	for key, door in pairs(M12_front_doors) do 
  941. 		door_lock(door, false) 
  942. 	end 
  943. end 
  944.  
  945. -- Waits until a player is in range of Josh 
  946. -- 
  947. function m12_wait_until_josh_is_in_range() 
  948. 	marker_add(NPC_JOSH, MINIMAP_ICON_USE, OI_ASSET_USE, OI_FLAGS_DEFAULT, SYNC_ALL) 
  949. 	 
  950. 	if M12_in_coop then 
  951. 		while get_dist(LOCAL_PLAYER,  NPC_JOSH) > M12_DISTANCE_TO_JOSH_FOR_ZSCENE and 
  952. 				get_dist(REMOTE_PLAYER, NPC_JOSH) > M12_DISTANCE_TO_JOSH_FOR_ZSCENE do 
  953. 			thread_yield() 
  954. 		end 
  955. 	else 
  956. 		while get_dist(LOCAL_PLAYER, NPC_JOSH) > M12_DISTANCE_TO_JOSH_FOR_ZSCENE do 
  957. 			thread_yield() 
  958. 		end 
  959. 	end 
  960.  
  961. 	marker_remove(NPC_JOSH, SYNC_ALL) 
  962. end 
  963. 	 
  964. -- Teleports the team to the specified nav points. This function will also 
  965. -- put Josh into a human shield state if necessary 
  966. -- 
  967. -- nav_table          - Nav points to teleport the group to 
  968. -- tele_josh          - Should Josh be teleported? 
  969. -- josh_over_shoulder - Whether or not Josh should be put over the player's shoulder. 
  970. -- do_fade_out        - Whether or not we should fade out/in 
  971. -- 
  972. function m12_teleport_team_to(nav_table, tele_josh, josh_over_shoulder, do_fade_out) 
  973. 	local ignore_vehicle = true 
  974. 	 
  975. 	if do_fade_out == nil or do_fade_out == true then 
  976. 		if fade_get_percent() == 0.0 then 
  977. 			fade_out(0.5) 
  978. 			fade_out_block() 
  979. 		end 
  980. 	end 
  981. 	 
  982. 	-- Give Josh a reprieve during teleporting; don't kill him while 
  983. 	-- he's not a human shield. 
  984. 	m12_cleanup_player_carrying_josh(true) 
  985. 	 
  986. 	teleport_coop(nav_table[1], nav_table[2], ignore_vehicle) 
  987. 	 
  988. 	-- If anyone is downed, revive them.  Some weird crap happens once in a blue moon 
  989. 	-- if someone is ragdolled while teleporting them between interiors. 
  990. 	if human_is_downed(NPC_SUKO) then 
  991. 		npc_revive(NPC_SUKO) 
  992. 		delay(3.0) 
  993. 	end 
  994. 	 
  995. 	while character_is_ragdolled(NPC_SUKO) do 
  996. 		delay(0.25) 
  997. 	end 
  998. 	 
  999. 	teleport(NPC_SUKO, nav_table[3], true) 
  1000.  
  1001. 	if tele_josh then 
  1002. 		teleport(NPC_JOSH, nav_table[4], ignore_vehicle) 
  1003. 	end 
  1004. 	 
  1005. 	if josh_over_shoulder and m12_who_is_holding_josh() == "" then		 
  1006. 		-- Wait for Josh to be ready if necessary, but only wait so long. 
  1007. 		local delay_handle = thread_new("delay", 5.0) 
  1008. 		while character_is_ready(NPC_JOSH) == false and thread_check_done(delay_handle) == false do 
  1009. 			thread_yield() 
  1010. 		end 
  1011. 		 
  1012. 		player_take_human_shield(LOCAL_PLAYER, NPC_JOSH) 
  1013. 		m12_setup_player_to_carry_josh(true) 
  1014. 	end 
  1015. 	 
  1016. 	if do_fade_out == nil or do_fade_out == true then 
  1017. 		fade_in(0.5) 
  1018. 		fade_in_block() 
  1019. 	end 
  1020. end 
  1021.  
  1022. -- Iterates through a table of npcs and instructs them to move to the specified destination 
  1023. -- 
  1024. -- group - table with the following memebers: 
  1025. --         members	- List of NPCs in the group 
  1026. --         navs		- List of nav points the npcs will move to 
  1027. -- 
  1028. function m12_move_members(group) 
  1029. 	local n = #group.members 
  1030. 	for i = 1, n do 
  1031. 		ai_do_scripted_move(group.members[i], group.navs[i], true, false) 
  1032. 	end 
  1033. end 
  1034.  
  1035. -- Setup a callback to detect notoriety events (mission failure) and setup 
  1036. -- the players party to not be attacked by STAG members. 
  1037. -- 
  1038. function m12_enter_stealth_section() 
  1039. 	-- Register a callback to check to for anything that would blow the players cover 
  1040. 	on_notoriety_event("m12_notoriety_increased", LOCAL_PLAYER) 
  1041. 	-- Prevent the STAG from attacking the player and Suko 
  1042. 	set_player_undercover_team(LOCAL_PLAYER, "STAG") 
  1043. 	set_team(NPC_SUKO, "STAG") 
  1044. 	 
  1045. 	if M12_in_coop then 
  1046. 		on_notoriety_event("m12_notoriety_increased", REMOTE_PLAYER) 
  1047. 		set_player_undercover_team(REMOTE_PLAYER, "STAG") 
  1048. 	end 
  1049.  
  1050. 	npc_combat_enable(NPC_SUKO, false) 
  1051. 	notoriety_set_max(M12_STAG_NOTORIETY, 0) 
  1052. end 
  1053.  
  1054. -- Removes all stealth related callbacks and setting setup by 
  1055. -- m12_enter_stealth_section() 
  1056. -- 
  1057. function m12_exit_stealth_section() 
  1058. 	hud_timer_stop(1) 
  1059. 	hud_timer_hide(1, true) 
  1060. 	on_notoriety_event("", LOCAL_PLAYER) 
  1061. 	set_player_undercover_team(LOCAL_PLAYER, "None") 
  1062. 	 
  1063. 	if M12_in_coop then 
  1064. 		on_notoriety_event("", REMOTE_PLAYER) 
  1065. 		set_player_undercover_team(REMOTE_PLAYER, "None")	 
  1066. 	end 
  1067. 	 
  1068. 	npc_combat_enable(NPC_SUKO, true) 
  1069. 	inv_item_remove_all(NPC_SUKO) 
  1070. 	inv_item_add("Pistol-Gang", 1, NPC_SUKO, true) 
  1071. 	set_team(NPC_SUKO, "Playas") 
  1072. 	 
  1073. 	 
  1074. 	notoriety_set_max(M12_STAG_NOTORIETY, M12_GARAGE_MAX_NOTORIETY) 
  1075. 	notoriety_set(M12_STAG_NOTORIETY, 1) 
  1076. 	notoriety_set_min(M12_STAG_NOTORIETY, 1) 
  1077. 	 
  1078. 	-- Clean up the on_take_damage callbacks that we registered on dudes. 
  1079. 	if group_is_loaded(M12_groups.stag_studio.name) then 
  1080. 		for i, stag in pairs(M12_groups.stag_studio.members) do 
  1081. 			on_take_damage("", stag) 
  1082. 		end 
  1083. 	end 
  1084. end 
  1085.  
  1086. -- Unequips all weapons and then starts to thread to make sure the player(s) 
  1087. -- do not blow their cover by having some guns out in the open for to long. 
  1088. -- 
  1089. function m12_dont_allow_weapons() 
  1090. 	if M12_thread.unequip_weapon == INVALID_THREAD_HANDLE then 
  1091. 		-- Unequip all weapons from each player 
  1092. 		inv_item_remove_all(NPC_SUKO) 
  1093. 		inv_item_equip(nil, LOCAL_PLAYER) 
  1094. 		on_weapon_equip("m12_weapon_was_equipped", LOCAL_PLAYER) 
  1095. 		on_attack_performed("m12_player_fired_weapon", LOCAL_PLAYER) 
  1096. 		 
  1097. 		-- We'll need to unequip the player's weapon again when they exit a vehicle. 
  1098. 		if character_is_in_vehicle(LOCAL_PLAYER) then 
  1099. 			on_vehicle_exit("m12_remove_weapon_on_vehicle_exit", LOCAL_PLAYER) 
  1100. 		end 
  1101. 		 
  1102. 		if M12_in_coop then 
  1103. 			inv_item_equip(nil, REMOTE_PLAYER) 
  1104. 			on_weapon_equip("m12_weapon_was_equipped", REMOTE_PLAYER) 
  1105. 			on_attack_performed("m12_player_fired_weapon", REMOTE_PLAYER) 
  1106. 			 
  1107. 			-- We'll need to unequip the player's weapon again when they exit a vehicle.	 
  1108. 			if character_is_in_vehicle(REMOTE_PLAYER) then 
  1109. 				on_vehicle_exit("m12_remove_weapon_on_vehicle_exit", REMOTE_PLAYER) 
  1110. 			end 
  1111. 		end 
  1112.  
  1113. 		M12_thread.unequip_weapon = thread_new("m12_thread_unequip_your_weapon") 
  1114. 		M12_thread.hs_check = thread_new("m12_thread_human_shield_check") 
  1115. 	end 
  1116. end 
  1117.  
  1118. -- Allows the player(s) to use weapons again 
  1119. -- 
  1120. function m12_allow_weapons() 
  1121. 	if M12_thread.unequip_weapon ~= INVALID_THREAD_HANDLE then 
  1122. 		thread_kill(M12_thread.unequip_weapon) 
  1123. 		thread_kill(M12_thread.hs_check) 
  1124. 		on_weapon_equip("", LOCAL_PLAYER) 
  1125. 		 
  1126. 		--Set player to his best weapon after the cutscene. 
  1127. 		--inv_item_equip_slot( "best", LOCAL_PLAYER ) 
  1128. 		 
  1129. 		on_attack_performed("", LOCAL_PLAYER) 
  1130. 		on_vehicle_exit("", LOCAL_PLAYER) 
  1131. 		if M12_in_coop then 
  1132. 			on_weapon_equip("", REMOTE_PLAYER) 
  1133. 			on_attack_performed("", REMOTE_PLAYER) 
  1134. 			on_vehicle_exit("", REMOTE_PLAYER) 
  1135. 		end 
  1136. 		 
  1137. 		hud_timer_stop(1) 
  1138. 		m12_clear_seconodary_objective() 
  1139. 		M12_thread.unequip_weapon = INVALID_THREAD_HANDLE 
  1140. 		M12_thread.hs_check = INVALID_THREAD_HANDLE 
  1141. 	end 
  1142. end 
  1143.  
  1144. -- Plays the cutscene where Josh is initially taken as a hostage 
  1145. -- 
  1146. function m12_play_z_scene() 
  1147. 	cutscene_play(CUTSCENE_GRAB_JOSH, nil, nil, false) 
  1148. 	 
  1149. 	clear_animation_state(M12_groups.josh.char) 
  1150. 	 
  1151. 	m12_set_objective(M12_OBJ_ESCAPE_THE_STAG_BUILDING) 
  1152. end 
  1153.  
  1154. -- Instructs the player(s) to goto a set of elevators. 
  1155. -- 
  1156. -- elevators 		- Table of elevators with the following members 
  1157. --							name		- Name of the script mover that is linked to a door helper 
  1158. --							trigger	- Name of a trigger inside the elevator. Used to detect entry/exit. 
  1159. -- obj_text			- Objective text to display 
  1160. -- require_josh	- Does josh have to be inside an elevator as well? 
  1161. -- 
  1162. function m12_goto_a_elevator(elevators, obj_text, require_josh) 
  1163. 	m12_goto_a_elevator_setup(elevators, obj_text) 
  1164. 	 
  1165. 	-- If we require Josh to be in the elevator, really we only care if the local player is in there, since 
  1166. 	-- only the local player can carry Josh. 
  1167. 	while not M12_player_in_elevator or (require_josh and not M12_local_in_elevator) do 
  1168. 		m12_elevator_proximity_check(elevators) 
  1169. 		thread_yield() 
  1170. 	end 
  1171. 	 
  1172. 	m12_goto_a_elevator_cleanup(elevators) 
  1173. end 
  1174.  
  1175. -- Initializes all global variables used by m12_goto_a_elevator() and enable all 
  1176. -- elevator triggers to detect human entry/exit 
  1177. -- 
  1178. -- elevator_set	- Table of elevators to enable 
  1179. -- obj_text			- Objective text to display 
  1180. -- 
  1181. function m12_goto_a_elevator_setup(elevator_set, obj_text) 
  1182. 	M12_player_in_elevator	= false 
  1183. 	M12_local_in_elevator	= false 
  1184. 	M12_remote_in_elevator	= false 
  1185. 	M12_josh_in_elevator		= false 
  1186.  
  1187. 	M12_active_triggers = {} 
  1188. 	 
  1189. 	for i, elevator in pairs(elevator_set) do 
  1190. 		if elevator.add_marker then 
  1191. 			local trigger = elevator.trigger 
  1192. 			M12_active_triggers[i] = trigger 
  1193. 			m12_setup_trigger(trigger, "m12_elevator_enter_cback", "m12_elevator_exit_cback") 
  1194. 			 
  1195. 			-- Make sure the door is actually closed 
  1196. 			door_close(elevator.name, false) 
  1197. 		end 
  1198. 	end 
  1199.  
  1200. 	m12_set_objective(obj_text) 
  1201. end 
  1202.  
  1203. -- Disables all elevators setup by m12_goto_a_elevator_setup() 
  1204. -- 
  1205. -- elevator_set - Table of elevators to disable 
  1206. -- 
  1207. function m12_goto_a_elevator_cleanup(elevator_set) 
  1208. 	for i, elevator in pairs(elevator_set) do 
  1209. 		local trigger = elevator.trigger 
  1210. 		m12_cleanup_trigger(trigger) 
  1211. 		 
  1212. 		door_close(elevator.name, false) 
  1213. 	end 
  1214.  
  1215. 	m12_remove_icons_from_active_triggers() 
  1216. 	M12_active_triggers = {} 
  1217. end 
  1218.  
  1219. function m12_add_icons_to_active_triggers()	 
  1220. 	for i, trigger in pairs(M12_active_triggers) do 
  1221. 		marker_add_trigger(trigger, MINIMAP_ICON_LOCATION, INGAME_EFFECT_CHECKPOINT, OI_ASSET_LOCATION, OI_FLAGS_LOCATION, SYNC_ALL) 
  1222. 	end 
  1223. end 
  1224.  
  1225. function m12_remove_icons_from_active_triggers() 
  1226. 	for i, trigger in pairs(M12_active_triggers) do 
  1227. 		marker_remove_trigger(trigger) 
  1228. 	end 
  1229. end 
  1230.  
  1231. -- Checks to see if there is a nearby human. If so, open the elevator, otherwise close it. 
  1232. -- 
  1233. -- elevator_set - List of elevators to check if they need to be opened. 
  1234. -- 
  1235. function m12_elevator_proximity_check(elevator_set) 
  1236. 	for i, elevator in pairs(elevator_set) do 
  1237. 		-- Use the elevator.trigger since they are inside the elevator, rather elevator.name (door helper) which 
  1238. 		-- are next to the elevator on the wall  
  1239. 		local dist_to_npc, npc = get_closest_npc_to_object(elevator.trigger, M12_ELEVATOR_OPEN_PROXIMITY) 
  1240. 		local should_open_npc = false 
  1241. 		local should_open_player = false 
  1242. 		 
  1243. 		if npc ~= "" then 
  1244. 			should_open_npc = true 
  1245.  
  1246. 		else 
  1247. 			-- A script NPC is not in range. Check to see if a player is nearby. 
  1248. 			local dist = get_dist(LOCAL_PLAYER, elevator.trigger) 
  1249. 			if dist < M12_ELEVATOR_OPEN_PROXIMITY then 
  1250. 				should_open_player = true 
  1251. 			end 
  1252. 			 
  1253. 			if M12_in_coop == true then 
  1254. 				dist = get_dist(REMOTE_PLAYER, elevator.trigger) 
  1255. 				if dist < M12_ELEVATOR_OPEN_PROXIMITY then 
  1256. 					should_open_player = true 
  1257. 				end 
  1258. 			end 
  1259.  
  1260. 		end 
  1261. 		 
  1262. 		if should_open_player then 
  1263. 			delay(0.5) 
  1264. 			door_open(elevator.name, false) 
  1265. 		elseif should_open_npc then 
  1266. 			delay(2.0) 
  1267. 			door_open(elevator.name, false) 
  1268. 		else 
  1269. 			door_close(elevator.name, true) 
  1270. 		end 
  1271. 	end 
  1272. end 
  1273.  
  1274.  
  1275. -- General task. Instructs the player to go to the specific trigger. 
  1276. -- 
  1277. -- trigger  - Name of the trigger to activate and go to. 
  1278. -- obj_text - Objective text to display 
  1279. -- gps      - Should a gps waypoint be added? 
  1280. -- marker_trigger - Alternative trigger to add a marker to. If one is not specified, the param trigger will be used instead. 
  1281. -- 
  1282. function m12_goto_a_trigger(trigger, obj_text, gps, marker_trigger) 
  1283. 	if gps == nil then 
  1284. 		gps = false 
  1285. 	end 
  1286. 	 
  1287. 	m12_goto_a_trigger_setup(trigger, obj_text, gps, marker_trigger) 
  1288. 	 
  1289. 	while not M12_trigger_reached do 
  1290. 		thread_yield() 
  1291. 	end 
  1292. 	 
  1293. 	m12_goto_a_trigger_cleanup(trigger, gps, marker_trigger) 
  1294. end 
  1295.  
  1296. -- Set the objective text and sets up the trigger associated with the objective 
  1297. -- 
  1298. -- trigger  - Name of the trigger to activate and go to. 
  1299. -- obj_text - Objective text to display 
  1300. -- gps      - Should a gps waypoint be added? 
  1301. -- marker_trigger - Alternative trigger to add a marker to. If one is not specified, the param trigger will be used instead. 
  1302. -- 
  1303. function m12_goto_a_trigger_setup(trigger, obj_text, gps, marker_trigger) 
  1304. 	-- Teleportation and navagation related functions don't play nice so give pathfinding 
  1305. 	-- and similar a frame to finialize everything. 
  1306. 	thread_yield() 
  1307. 	 
  1308. 	if marker_trigger ~= nil and marker_trigger ~= "" then 
  1309. 		trigger_enable(marker_trigger, true) -- Needs to be enabled for a minimap icon to attach to it. 
  1310. 		M12_active_triggers = {marker_trigger} 
  1311. 	else 
  1312. 		M12_active_triggers = {trigger} 
  1313. 	end 
  1314. 	 
  1315. 	-- Set up the trigger before setting the objective.  The 
  1316. 	-- minimap icon won't appear on a trigger that's disabled. 
  1317. 	m12_setup_trigger(trigger, "m12_trigger_cback", "") 
  1318. 	 
  1319. 	m12_set_objective(obj_text) 
  1320. 	 
  1321. 	if gps then 
  1322. 		waypoint_add(trigger) 
  1323. 	end 
  1324. 	M12_trigger_reached = false 
  1325. end 
  1326.  
  1327. -- Cleans up the trigger and any HUD elements setup by m12_goto_a_trigger_setup() 
  1328. -- 
  1329. -- trigger	- Name of the trigger that was passed to m12_goto_a_trigger_setup() 
  1330. -- gps		- Was a gps route requested? 
  1331. -- 
  1332. function m12_goto_a_trigger_cleanup(trigger, gps, marker_trigger) 
  1333. 	-- Cleanup the task. 
  1334. 	m12_cleanup_trigger(trigger) 
  1335. 	m12_cleanup_trigger(marker_trigger) 
  1336. 	m12_remove_icons_from_active_triggers() 
  1337. 	M12_active_triggers = {} 
  1338. 	 
  1339. 	if gps then 
  1340. 		waypoint_remove() 
  1341. 	end 
  1342. 	 
  1343. 	-- To be on the safe side, give pathfinding a similar a full frame to remove the nav points and such 
  1344. 	thread_yield() 
  1345. end 
  1346.  
  1347. -- Checks to see if a player is holding Josh and sets M12_player_holding_josh to the name of the player holding Josh. 
  1348. -- 
  1349. -- returns: (string) name of the player that is holding Josh, otherwise "" 
  1350. function m12_who_is_holding_josh() 
  1351. 	if character_has_specific_human_shield(LOCAL_PLAYER, NPC_JOSH) then  
  1352. 		return LOCAL_PLAYER 
  1353. 	end 
  1354.  
  1355. 	if M12_in_coop then 
  1356. 		if character_has_specific_human_shield(REMOTE_PLAYER, NPC_JOSH) then 
  1357. 			return REMOTE_PLAYER 
  1358. 		end	 
  1359. 	end 
  1360.  
  1361. 	return "" 
  1362. end 
  1363.  
  1364.  
  1365. -- *************************************************** 
  1366. -- m12_initialize Helper Functions 
  1367. -- *************************************************** 
  1368.  
  1369. -- Handle any common initialization 
  1370. -- 
  1371. function m12_initialize_common() 
  1372. 	--[[ INSERT ANY COMMON INITIALIZATION CODE HERE ]]-- 
  1373.  
  1374. 	spawn_region_min_spawn_dist(M12_MIN_SPAWN_DIST) 
  1375.  
  1376. 	-- Forcefully set the min notoriety to level 0 so restricted zones (includes the PR Center)  
  1377. 	-- will not overwrite the script set levels 
  1378. 	notoriety_set_min(M12_STAG_NOTORIETY, 0) 
  1379. 	notoriety_set_max(M12_STAG_NOTORIETY, M12_GARAGE_MAX_NOTORIETY) 
  1380. 	notoriety_force_no_spawn(M12_STAG_NOTORIETY, true) 
  1381. 	notoriety_force_no_spawn("stag", true) 
  1382. 	 
  1383. 	-- Boot everyone out of the player's party and disable recruiting. 
  1384. 	party_dismiss_all() 
  1385. 	party_set_recruitable(false) 
  1386. 	 
  1387. 	-- Suko should always exists 
  1388. 	m12_setup_suko() 
  1389. 	 
  1390. 	m12_load_personas() 
  1391. 	 
  1392. 	customization_outfit_wear("Cardinal") 
  1393. 	--customization_item_wear("cardinal hat", "cm_hat_cardinal.cmeshx", "Cardinal Hat") 
  1394. 	--customization_item_wear("cardinal glasses", "cm_eye_cardinal.cmeshx", "Cardinal Glasses") 
  1395. 	--customization_item_wear("cm_suit_cardinal", "cm_suit_cardinal.cmeshx", "Cardinal Robe") 
  1396. end 
  1397.  
  1398. -- Checkpoint specific initialization 
  1399. -- 
  1400. -- checkpoint:		The checkpoint to be initialized 
  1401. function m12_initialize_checkpoint(checkpoint, is_restart) 
  1402. 	if checkpoint == M12_CHECKPOINT_START then 
  1403. 		m12_setup_start_world(is_restart) 
  1404. 		 
  1405. 		-- Get the players' vehicles out of the way. 
  1406. 		teleport_player_vehicles(M12_nav.player_car_start[1], M12_nav.player_car_start[2]) 
  1407. 		 
  1408. 	elseif checkpoint == M12_CHECKPOINT_GRAB_JOSH then		 
  1409. 		teleport_coop(M12_teleport.studio[1], M12_teleport.studio[2], true) 
  1410. 		teleport(NPC_SUKO, M12_teleport.studio[3], true) 
  1411. 		 
  1412. 		-- Set a fake team so suko and the player arn't attacked by the STAG or civillians 
  1413. 		m12_enter_stealth_section() 
  1414. 		m12_dont_allow_weapons() 
  1415. 		 
  1416. 	elseif checkpoint == M12_CHECKPOINT_CUBICAL_BATTLE then 
  1417. 		m12_setup_josh() 
  1418. 		M12_cur_josh_dropped_nav_list = M12_nav.josh_dropped.floor_2 
  1419. 		m12_teleport_team_to(M12_teleport.cubical, true, true, false) 
  1420. 		 
  1421. 		-- Kick off some music. 
  1422. 		m12_post_music_event(M12_music.restart_pr_center) 
  1423. 						 
  1424. 	elseif checkpoint == M12_CHECKPOINT_ESCAPE then 
  1425. 		m12_setup_josh() 
  1426. 		M12_cur_josh_dropped_nav_list = M12_nav.josh_dropped.lobby 
  1427. 		m12_teleport_team_to(M12_teleport.lobby_elevator, true, true, false) 
  1428. 		 
  1429. 		-- Kick off some music. 
  1430. 		m12_post_music_event(M12_music.restart_pr_center) 
  1431. 	end 
  1432.  
  1433. 	party_add(NPC_SUKO, LOCAL_PLAYER) 
  1434. end 
  1435.  
  1436. -- Teleports the player(s) to their start location and unequip any weapons since they are 
  1437. -- supposed to sneak into the PR Center 
  1438. -- 
  1439. function m12_setup_start_world(is_restart) 
  1440. 	if is_restart == true then 
  1441. 		teleport_coop(M12_teleport.start[1], M12_teleport.start[2], true) 
  1442. 	end 
  1443. 	 
  1444. 	-- Unequip all weapons from each player 
  1445. 	inv_item_equip(nil, LOCAL_PLAYER) 
  1446. 	inv_item_equip(nil, NPC_SUKO) 
  1447. 	 
  1448. 	if M12_in_coop then 
  1449. 		inv_item_equip(nil, REMOTE_PLAYER) 
  1450. 	end 
  1451. 	 
  1452. 	group_create(M12_groups.vehicle_start.name, true) 
  1453. 	 
  1454. 	tutorial_start("mis_undercover", 0, true, false) --SP 7/12: Added tutorial, feel free to move it if it's in a bad place 
  1455.  
  1456.  
  1457. 	-- Disable cop spawns and prevent the player from getting police notoriety. 
  1458. 	-- This prevents an annoying mission fail when you get to the PR center and 
  1459. 	-- have the guards attack you. 
  1460. 	spawning_allow_cop_ambient_spawns(false) 
  1461. 	notoriety_set_max("police", 0) 
  1462. 	 
  1463. 	-- Start a timer to reset police spawning.  We don't want the player to exploit 
  1464. 	-- the fact that there are no cops for too long. 
  1465. 	M12_thread.no_cops = thread_new("m23_reset_cop_spawning_thread") 
  1466. end 
  1467.  
  1468. function m12_cleanup_start_world() 
  1469. 	-- Don't cleanup the start vehicle until we get into the studio level, since the player 
  1470. 	-- will be able to see it from the lobby 
  1471. end 
  1472.  
  1473. -- This thread waits for a while then resets police notoriety and allows ambient cop spawning again. 
  1474. function m23_reset_cop_spawning_thread() 
  1475. 	-- Wait a bit. 
  1476. 	delay(M12_NO_COPS_TIME) 
  1477.  
  1478. 	-- Allow ambient cops again. 
  1479. 	spawning_allow_cop_ambient_spawns(true) 
  1480. 	notoriety_reset("police") 
  1481. 	M12_thread.no_cops = INVALID_THREAD_HANDLE 
  1482. end 
  1483.  
  1484.  
  1485. -- Spawns the lobby guard and tell the ambient NPCs to wander around 
  1486. -- 
  1487. function m12_setup_start_lobby() 
  1488. 	group_create(M12_groups.stag_lobby.name, true) 
  1489. 	--ai_do_scripted_move(M12_groups.stag_lobby.members[5], M12_nav.stag_pace[1], false, false) 
  1490. 	group_create(M12_groups.workers_lobby.name, true) 
  1491. 	 
  1492. 	for k, v in pairs (M12_groups.workers_lobby.members) do 
  1493. 	 
  1494. 		wander_start(M12_groups.workers_lobby.members[k]) 
  1495. 		--wander_stop(M12_groups.workers_lobby.second_floor_receptionist) 
  1496. 	end 
  1497. 	 
  1498. 	for i, stag in pairs(M12_groups.stag_lobby.members) do 
  1499. 		on_take_damage("m12_npc_damaged_fail", stag) 
  1500. 	end 
  1501. 	 
  1502. 	m12_play_persona_line(M12_persona_line.hide_guns) 
  1503. end 
  1504.  
  1505. function m12_cleanup_start_lobby() 
  1506. 	-- Setup in m12_setup_start_world(). Cleanuped up here since the player can still see 
  1507. 	-- the vehicle from the lobby. 
  1508. 	 
  1509. 	if group_is_loaded(M12_groups.stag_lobby.name) then 
  1510. 		for i, stag in pairs(M12_groups.stag_lobby.members) do 
  1511. 			on_take_damage("", stag) 
  1512. 		end 
  1513. 	end 
  1514. 	 
  1515. 	if group_is_loaded(M12_groups.vehicle_start.name) then 
  1516. 		group_destroy(M12_groups.vehicle_start.name) 
  1517. 	end 
  1518.  
  1519. 	if group_is_loaded(M12_groups.stag_lobby.name) then 
  1520. 		group_destroy(M12_groups.stag_lobby.name) 
  1521. 	end 
  1522. 	 
  1523. 	if group_is_loaded(M12_groups.workers_lobby.name) then 
  1524. 		group_destroy(M12_groups.workers_lobby.name) 
  1525. 	end 
  1526. end 
  1527.  
  1528. -- Move the player(s) to their proper location, spawn Josh, spawn a few ambient NPCs, and 
  1529. -- setup the intial STAG guard 
  1530. -- 
  1531. function m12_setup_grab_josh() 
  1532. 	group_create(M12_groups.stag_studio.name, true) 
  1533. 	ai_do_scripted_move(M12_groups.stag_studio.members[1], M12_nav.stag_pace[2], false, false) 
  1534. 	ai_do_scripted_move(M12_groups.stag_studio.members[4], M12_nav.stag_pace[3], false, false) 
  1535. 	 
  1536. 	-- Prevent the pacing guys from going all combat-ready hunkery. 
  1537. 	npc_combat_enable(M12_groups.stag_studio.members[1], false) 
  1538. 	npc_combat_enable(M12_groups.stag_studio.members[4], false) 
  1539. 	 
  1540. 	group_create(M12_groups.workers_studio.name, true) 
  1541. 	group_create(M12_groups.workers_cubical.name, true) 
  1542. 	 
  1543. 	m12_setup_josh() 
  1544. 	thread_yield() 
  1545. 	set_animation_state(M12_groups.josh.char, "Josh Warmup") 
  1546. 	 
  1547. 	for i, stag in pairs(M12_groups.stag_studio.members) do 
  1548. 		on_take_damage("m12_npc_damaged_fail", stag) 
  1549. 	end 
  1550. end 
  1551.  
  1552. function m12_cleanup_grab_josh() 
  1553. 	-- Clean up the groups in m12_cleanup_cubical_battle() since the player can 
  1554. 	-- travel between the cubical and studio without any transition 
  1555. 	 
  1556. 	thread_kill(M12_thread.play_line) 
  1557. 	M12_thread.play_line = INVALID_THREAD_HANDLE 
  1558. end 
  1559.  
  1560.  
  1561. -- Spawn the statically placed STAG, and setup some continuious spawn groups to keep 
  1562. -- some pressure on the plyaer. 
  1563. -- 
  1564. function m12_setup_cubical_battle() 
  1565. 	group_create(M12_groups.stag_cubical.name, true) 
  1566. 	-- Have the stag members appear like they just arrived, and move them to their intial positions 
  1567. 	m12_move_members(M12_scripted_move.stag_cubical) 
  1568. 	ai_do_scripted_take_cover(M12_scripted_move.stag_cubical.members[1]) 
  1569. 	 
  1570. 	-- m12_setup_spawn_group(M12_spawn_groups.cubical_wave_1, 15.0, false) 
  1571. 	m12_setup_trigger(M12_trigger.start_spawning, "m12_start_spawning", "") 
  1572. end 
  1573.  
  1574. function m12_cleanup_cubical_battle() 
  1575. 	-- Groups from m12_setup_grab_josh(). Clean these up here since the player can go between the 
  1576. 	-- cubical and studio without transition. 
  1577. 	if group_is_loaded(M12_groups.stag_studio.name) then 
  1578. 		group_destroy(M12_groups.stag_studio.name) 
  1579. 	end 
  1580.  
  1581. 	if group_is_loaded(M12_groups.workers_studio.name) then 
  1582. 		group_destroy(M12_groups.workers_studio.name) 
  1583. 	end 
  1584.  
  1585. 	if group_is_loaded(M12_groups.workers_cubical.name) then 
  1586. 		group_destroy(M12_groups.workers_cubical.name) 
  1587. 	end 
  1588.  
  1589. 	-- Groups from m12_setup_cubical_battle() 
  1590. 	if group_is_loaded(M12_groups.stag_cubical.name) then 
  1591. 		group_destroy(M12_groups.stag_cubical.name) 
  1592. 	end 
  1593. 	 
  1594. 	m12_helper_cleanup_ambush_group(M12_groups.stag_window_rush) 
  1595. 	release_to_world(M12_groups.stag_window_rush.name) 
  1596.  
  1597. 	m12_helper_cleanup_ambush_group(M12_groups.stag_studio_rush_01) 
  1598. 	release_to_world(M12_groups.stag_studio_rush_01.name) 
  1599. 	m12_helper_cleanup_ambush_group(M12_groups.stag_studio_rush_02) 
  1600. 	release_to_world(M12_groups.stag_studio_rush_02.name) 
  1601.  
  1602. 	if group_is_loaded(M12_groups.fleeing_peds_001.name) then 
  1603. 		group_destroy(M12_groups.fleeing_peds_001.name) 
  1604. 	end 
  1605.  
  1606. 	m12_cleanup_all_spawn_groups() 
  1607. 	m12_cleanup_trigger(M12_trigger.start_spawning) 
  1608. 	m12_cleanup_trigger(M12_trigger.elev_conv_02) 
  1609. 	m12_cleanup_trigger(M12_trigger.studio_rush) 
  1610. 	m12_cleanup_trigger(M12_trigger.fleeing_peds_1) 
  1611. end 
  1612.  
  1613.  
  1614. -- Spawns the baracade blocking the enterance and setup all the attacking STAG in the 
  1615. -- lobby area. 
  1616. -- 
  1617. function m12_setup_escape_lobby() 
  1618. 	group_create(M12_groups.lobby_escape.name, true) 
  1619. 	group_create(M12_groups.garage_cars.name, true) 
  1620. 	 
  1621. 	traffic_disable_lanes(M12_trigger.block_traffic, true) 
  1622. 	 
  1623. 	m12_lock_front_doors() 
  1624. 	 
  1625. 	m12_setup_trigger(M12_trigger.lobby_spawn, "m12_lobby_spawn_cb", "") 
  1626. 	 
  1627. 	m12_start_convo_thread(M12_convo.lobby_escape) 
  1628. 		 
  1629. 	-- Stop spawning action nodes while in the lobby.  This prevents a flood of STAG. 
  1630. 	action_nodes_enable(false) 
  1631. end 
  1632.  
  1633. function m12_cleanup_escape_lobby() 
  1634. 	if group_is_loaded(M12_groups.lobby_escape.name) then 
  1635. 		group_destroy(M12_groups.lobby_escape.name) 
  1636. 	end 
  1637. 	 
  1638. 	m12_unlock_front_doors() 
  1639.  
  1640. 	m12_cleanup_all_spawn_groups() 
  1641. 		 
  1642. 	-- Re-enable action nodes. 
  1643. 	action_nodes_enable(true) 
  1644. end 
  1645.  
  1646. -- Objective to load josh into the car. 
  1647. -- 
  1648. function m12_load_josh_into_car() 
  1649. 	-- Lock all the cars in the garage 
  1650. 	for i, car in pairs(M12_groups.garage_cars.vehicles) do 
  1651. 		set_unjackable_flag(car, true) 
  1652. 	end 
  1653. 	 
  1654. 	m12_play_persona_line(M12_persona_line.get_in) 
  1655.  
  1656. 	-- Add the objective to load Josh into the car 
  1657. 	m12_set_objective(M12_OBJ_STEAL_A_VEHICLE) 
  1658. 	marker_add_trigger(M12_trigger.load_josh, MINIMAP_ICON_USE, INGAME_EFFECT_LOCATION, OI_ASSET_USE, OI_FLAGS_FULL, SYNC_LOCAL) 
  1659. 	m12_setup_trigger(M12_trigger.load_josh, "m12_on_load_josh", "", SYNC_LOCAL) 
  1660. 	 
  1661. 	-- Wait for the player to use the trigger 
  1662. 	while M12_begin_load_josh == false do 
  1663. 		thread_yield() 
  1664. 	end 
  1665. 	 
  1666. 	-- Progress the musics. 
  1667. 	m12_post_music_event(M12_music.josh_loaded_into_car) 
  1668.  
  1669. 	-- Prevent Josh from exiting the vehicle until the player gets in. 
  1670. 	vehicle_suppress_npc_exit(M12_ESCAPE_VEHICLE, true) 
  1671. 	 
  1672. 	-- Unlock the escape vehicle. 
  1673. 	set_unjackable_flag(M12_ESCAPE_VEHICLE, false) 
  1674. 	 
  1675. 	on_vehicle_enter("m12_escape_vehicle_entered", M12_ESCAPE_VEHICLE) 
  1676. 	 
  1677. 	player_controls_disable(LOCAL_PLAYER) 
  1678. 		 
  1679. 	--  Set the animation state to keep the transition between actions smooth. 
  1680. 	set_animation_state(LOCAL_PLAYER, "m12_plym_overshoulder_exittocar_C") 
  1681. 	set_animation_state(NPC_JOSH, "m12_josh_overshoulder_exittocar_C") 
  1682. 	 
  1683. 	-- Make sure the player has a pistol for this animation. 
  1684. 	local pistol_name = inv_item_in_slot(LOCAL_PLAYER, "pistol") 
  1685. 	if pistol_name == "none" or pistol_name == nil then 
  1686. 		-- Give them a temporary pistol. 
  1687. 		inv_weapon_add_temporary(LOCAL_PLAYER, M12_TEMP_PISTOL_NAME) 
  1688. 	end 
  1689. 	 
  1690. 	-- Make weapon slot match the animation. 
  1691. 	inv_item_equip_slot("pistol", LOCAL_PLAYER) 
  1692. 	 
  1693. 	-- Play the animation to drop Josh off the player's shoulder. 
  1694. 	m12_cleanup_player_carrying_josh(true) 
  1695. 	action_play_synced(LOCAL_PLAYER, NPC_JOSH, "OS_Exit_To_Car", M12_nav.load_josh) 
  1696. 	 
  1697. 	-- Have Josh enter the car and play the action for the player threatening him. 
  1698. 	vehicle_suppress_npc_exit(M12_ESCAPE_VEHICLE, true) 
  1699. 	vehicle_enter(NPC_JOSH, M12_ESCAPE_VEHICLE, 2, false, false, false, "m12_josh_overshoulder_exittocar_b") 
  1700. 	action_play(LOCAL_PLAYER, "m12_plym_overshoulder_exittocar_b") 
  1701. 	 
  1702. 	-- Clear the animation states 
  1703. 	clear_animation_state(LOCAL_PLAYER) 
  1704. 	clear_animation_state(NPC_JOSH) 
  1705. 	 
  1706. 	player_controls_enable(LOCAL_PLAYER) 
  1707. 	 
  1708. 	-- Let the player use all their weapons now that they no longer have Josh. 
  1709. 	inv_weapon_disable_all_slots(false, SYNC_LOCAL) 
  1710. 	M12_inv_restricted_for_carrying_josh = false 
  1711. 	 
  1712. 	-- Add Josh to the player's party at this point to prevent Viola from pulling 
  1713. 	-- him out of the car when the player enters. 
  1714. 	party_add(NPC_JOSH, LOCAL_PLAYER) 
  1715. 	 
  1716. 	-- Wait for the player to get into the car. 
  1717. 	marker_add(M12_ESCAPE_VEHICLE, MINIMAP_ICON_USE, OI_ASSET_USE, OI_FLAGS_FULL) 
  1718. 	while M12_escape_vehicle_entered == false do 
  1719. 		thread_yield() 
  1720. 	end 
  1721. 	marker_remove(M12_ESCAPE_VEHICLE) 
  1722. 	vehicle_suppress_npc_exit(M12_ESCAPE_VEHICLE, false) 
  1723. 	 
  1724. 	-- Remove the temporary pistol if we gave one to the player. 
  1725. 	inv_weapon_remove_temporary(LOCAL_PLAYER, M12_TEMP_PISTOL_NAME) 
  1726. 	 
  1727. 	-- Unlock the rest of the cars in the garage. 
  1728. 	for i, car in pairs(M12_groups.garage_cars.vehicles) do 
  1729. 		set_unjackable_flag(car, false) 
  1730. 	end 
  1731. 	 
  1732. 	m12_start_convo_thread(M12_convo.flee_to_hq) 
  1733. 	 
  1734. 	m12_cleanup_load_josh_into_car() 
  1735. end 
  1736.  
  1737. -- Cleans up the objective to load josh into the car. 
  1738. -- 
  1739. function m12_cleanup_load_josh_into_car() 
  1740. 	player_controls_enable(LOCAL_PLAYER) 
  1741. 	marker_remove_trigger(M12_trigger.load_josh) 
  1742. 	m12_cleanup_trigger(M12_trigger.load_josh) 
  1743. 	on_vehicle_enter("", M12_ESCAPE_VEHICLE) 
  1744. 	clear_animation_state(LOCAL_PLAYER) 
  1745. 	 
  1746. 	if group_is_loaded(M12_groups.josh) then 
  1747. 		clear_animation_state(NPC_JOSH) 
  1748. 	end 
  1749. 	 
  1750. 	M12_begin_load_josh = false 
  1751. 	M12_escape_vehicle_entered = false 
  1752. end 
  1753.  
  1754. -- Callback for when the player uses the trigger to load Josh into the car. 
  1755. -- 
  1756. function m12_on_load_josh(character, trigger) 
  1757. 	-- Only the local player can do this. 
  1758. 	if character ~= LOCAL_PLAYER then 
  1759. 		return 
  1760. 	end 
  1761.  
  1762. 	marker_remove_trigger(M12_trigger.load_josh) 
  1763. 	m12_cleanup_trigger(M12_trigger.load_josh) 
  1764. 	M12_begin_load_josh = true 
  1765. end 
  1766.  
  1767. -- Callback for the player entering the escape vehicle. 
  1768. -- 
  1769. function m12_escape_vehicle_entered(character, vehicle, seat_idx) 
  1770. 	if character ~= LOCAL_PLAYER then 
  1771. 		return 
  1772. 	end 
  1773. 	 
  1774. 	-- Let Josh get out if the player does. 
  1775. 	vehicle_suppress_npc_exit(M12_ESCAPE_VEHICLE, false) 
  1776. 	 
  1777. 	on_vehicle_enter("", vehicle) 
  1778. 	 
  1779. 	M12_escape_vehicle_entered = true 
  1780. end 
  1781.  
  1782. -- Spawn some cars for the player to escape in 
  1783. -- 
  1784. function m12_setup_escape_garage() 
  1785. 	notoriety_set_min(M12_STAG_NOTORIETY, M12_GARAGE_MIN_NOTORIETY) 
  1786. 	set_ped_density(1.0) 
  1787. 	set_traffic_density(1.0) 
  1788. 	 
  1789. 	npc_combat_enable(NPC_JOSH, false) 
  1790. 	 
  1791. 	follower_set_can_abandon(NPC_JOSH, true) 
  1792. 	on_dismiss("m12_party_member_dismissed", NPC_JOSH) 
  1793. 	 
  1794. 	group_create(M12_groups.stag_outside_garage.name, true) 
  1795. 	m12_setup_trigger(M12_trigger.stag_outside_garage, "m12_block_garage_ramp_cb", "") 
  1796. 	 
  1797. 	m12_setup_chaser_group(M12_groups.stag_chasers_001) 
  1798. 	m12_setup_trigger(M12_trigger.chasers_1, "m12_start_chasers_1_cb", "") 
  1799. 	m12_setup_chaser_group(M12_groups.stag_chasers_002) 
  1800. 	m12_setup_trigger(M12_trigger.chasers_2, "m12_start_chasers_2_cb", "") 
  1801. end 
  1802.  
  1803. function m12_cleanup_escape_garage() 
  1804. 	-- Don't cleanup M12_groups.garage_cars.name here since we don't want to destory the 
  1805. 	-- players vehicle until we fade out (in m12_cleanup()) 
  1806.  
  1807. 	notoriety_set(M12_STAG_NOTORIETY, 0) 
  1808. 	notoriety_set_min(M12_STAG_NOTORIETY, 0) 
  1809. 	notoriety_set_max(M12_STAG_NOTORIETY, 5) 
  1810. 	 
  1811. 	on_vehicle_enter("", LOCAL_PLAYER) 
  1812. 	traffic_disable_lanes(M12_trigger.block_traffic, false) 
  1813. end 
  1814.  
  1815. -- Spawns and populate a group of chaser vehicles. 
  1816. -- 
  1817. function m12_setup_chaser_group(group_table) 
  1818. 	group_create(group_table.name) 
  1819. 	for key, vehicle_table in pairs(group_table.vehicles) do 
  1820. 		local vehicle	= vehicle_table.vehicle 
  1821. 		local driver	= vehicle_table.driver 
  1822. 		local gunner	= vehicle_table.gunner 
  1823. 		vehicle_suppress_npc_exit(vehicle) 
  1824. 		vehicle_enter_teleport(driver, vehicle, 0, true) 
  1825. 		if gunner ~= nil and gunner ~= "" then 
  1826. 			vehicle_enter_teleport(gunner, vehicle, 4, true) 
  1827. 		end 
  1828. 	end 
  1829. end 
  1830.  
  1831. function m12_hq_freeze_cb() 
  1832. 	on_trigger("", M12_trigger.saints_hq_freeze) 
  1833. 	trigger_enable(M12_trigger.saints_hq_freeze, false) 
  1834. 	M12_thread.stop_player_car = thread_new("m12_stop_player_car_thread") 
  1835. end 
  1836.  
  1837.  
  1838. -- Spawns and sets up Josh's behavior 
  1839. -- 
  1840. function m12_setup_josh() 
  1841. 	group_create(M12_groups.josh.name, true) 
  1842. 	 
  1843. 	-- make sure Josh has the proper persona 
  1844. 	character_set_persona(NPC_JOSH, "Josh") 
  1845. 	 
  1846. 	-- Josh is important to the mission, so check to make sure he does not die. 
  1847. 	on_death("m12_on_death", NPC_JOSH) 
  1848. 	 
  1849. 	-- Prevent Josh from attacking anyone 
  1850. 	set_attack_enemies_flag(NPC_JOSH, false) 
  1851. 	set_attack_peds_flag(NPC_JOSH, false) 
  1852. 	set_attack_player_flag(NPC_JOSH, false) 
  1853. 	 
  1854. 	-- Prevent Josh from being attacked 
  1855. 	set_dont_attack_me_on_sight_flag(NPC_JOSH, true) 
  1856. 	 
  1857. 	-- Mark Josh as a Over the Shoulder human shield 
  1858. 	character_set_over_the_shoulder(NPC_JOSH, true) 
  1859. 	 
  1860. 	-- Only allow Josh to be grabbed by the player 
  1861. 	character_set_only_player_grabs(NPC_JOSH, true) 
  1862. 	 
  1863. 	-- Make sure Josh doesn't have any weapons and attempt to attack someone 
  1864. 	inv_item_remove_all(NPC_JOSH) 
  1865. 	-- Do not disable all combat actions since fleeing/cowerig is considered a combat action 
  1866. 	--npc_combat_enable(NPC_JOSH, false) 
  1867. 	 
  1868. 	-- Wait until Josh is active; we can sometimes fail to take him as a human shield if 
  1869. 	-- he isn't activated before we get to that point. 
  1870. 	local delay_handle = thread_new("delay", 2.0) 
  1871. 	while character_is_ready(NPC_JOSH) == false and thread_check_done(delay_handle) == false do 
  1872. 		thread_yield() 
  1873. 	end 
  1874. 	 
  1875. 	-- Prevent the player from accidentally pwning Josh. 
  1876. 	set_suppress_synced_melee_attacks_flag(NPC_JOSH, true) 
  1877. end 
  1878.  
  1879. function m12_cleanup_josh() 
  1880. 	if not group_is_loaded(M12_groups.josh.name) then 
  1881. 		return 
  1882. 	end 
  1883. 	 
  1884. 	marker_remove(NPC_JOSH, SYNC_ALL)	 
  1885. 	on_death("", NPC_JOSH) 
  1886. 	on_vehicle_enter("", NPC_JOSH) 
  1887. 	on_vehicle_exit("", NPC_JOSH)	 
  1888. 	on_dismiss("", NPC_JOSH) 
  1889. 	 
  1890. 	party_dismiss(NPC_JOSH) 
  1891. 	 
  1892. 	group_destroy(M12_groups.josh.name) 
  1893. end 
  1894.  
  1895. -- Spawns and sets up Suko. 
  1896. -- 
  1897. function m12_setup_suko() 
  1898. 	group_create(M12_groups.homies.name, true) 
  1899. 	follower_set_can_abandon(NPC_SUKO, true) 
  1900. 	 
  1901. 	on_death("m12_on_death", NPC_SUKO) 
  1902. 	on_dismiss("m12_party_member_dismissed", NPC_SUKO) 
  1903. end 
  1904.  
  1905. function m12_cleanup_suko() 
  1906. 	on_death("", NPC_SUKO) 
  1907. 	on_dismiss("", NPC_SUKO) 
  1908. 	party_dismiss(NPC_SUKO) 
  1909.  
  1910. 	-- Suko should always be loaded 
  1911. 	group_destroy(M12_groups.homies.name) 
  1912. end 
  1913.  
  1914.  
  1915. -- *************************************************** 
  1916. -- Miscellaneous m12 Helper Functions 
  1917. -- *************************************************** 
  1918.  
  1919. -- Enables the specified trigger 
  1920. -- 
  1921. -- trigger   - Name of the trigger to enable 
  1922. -- on_enter  - call back function to call when the trigger is triggered. 
  1923. -- on_exit	 - call back function to call when the trigger is exited 
  1924. -- sync_type - (optional) how to sync the trigger_enable call. 
  1925. function m12_setup_trigger(trigger, on_enter, on_exit, sync_type) 
  1926. 	trigger_enable(trigger, true, sync_type) 
  1927. 	on_trigger(on_enter, trigger) 
  1928. 	on_trigger_exit(on_exit, trigger) 
  1929. end 
  1930.  
  1931. -- Disables the specified trigger 
  1932. -- 
  1933. -- trigger - Name of the trigger to disable 
  1934. function m12_cleanup_trigger(trigger) 
  1935. 	if trigger == nil or trigger == "" then 
  1936. 		return 
  1937. 	end 
  1938.  
  1939. 	if type(trigger) == "table" then 
  1940. 		if trigger.name ~= nil then 
  1941. 			m12_cleanup_trigger(trigger.name) 
  1942. 		else		 
  1943. 			for key, val in pairs(trigger) do 
  1944. 				m12_cleanup_trigger(val) 
  1945. 			end 
  1946. 		end 
  1947. 		return 
  1948. 	end 
  1949.  
  1950. 	on_trigger("", trigger) 
  1951. 	on_trigger_exit("", trigger) 
  1952. 	trigger_enable(trigger, false) 
  1953. end 
  1954.  
  1955. -- Sets up a spawn region, and starts spawning the specified groups. 
  1956. -- 
  1957. -- group         - Table with the following member tables 
  1958. --                 group.regions - Table of script region names 
  1959. --                 group.groups  - Table of group names to spawn 
  1960. -- respawn_delay - How long to wait (in seconds) to respawn a group after it was destroyed 
  1961. -- check_los     - false to disable line of sight checkes. Defaults to true (perform los checks) 
  1962. function m12_setup_spawn_group(group, respawn_delay, check_los) 
  1963. 	-- If a dealy is not provided, assume 10 seconds 
  1964. 	respawn_delay = respawn_delay or 10.0 
  1965. 	 
  1966. 	-- Enable the spawn region 
  1967. 	for i = 1, #group.regions do 
  1968. 		spawn_region_enable(group.regions[i], true) 
  1969. 	end 
  1970. 	 
  1971. 	-- Disable line of sight checks if requested. 
  1972. 	if check_los == false then 
  1973. 		for i = 1, #group.regions do 
  1974. 			spawn_region_enable_los(group.regions[i], false) 
  1975. 		end	 
  1976. 	end 
  1977. 	 
  1978. 	-- Start spawning the actual groups. 
  1979. 	for i = 1, #group.groups do 
  1980. 		continuous_spawn_start(group.groups[i], 0, respawn_delay) 
  1981. 	end 
  1982. end 
  1983.  
  1984. -- Disables the specified spawn groups and spawn regions 
  1985. -- 
  1986. -- group - Spawn group table (see m12_setup_spawn_group()) to disable 
  1987. function m12_cleanup_spawn_group(group) 
  1988. 	-- Stop spawning the actual groups. 
  1989. 	for i = 1, #group.groups do 
  1990. 		continuous_spawn_stop(group.groups[i]) 
  1991. 	end 
  1992. 	 
  1993. 	-- disable the spawn region 
  1994. 	for i = 1, #group.regions do 
  1995. 		local region = group.regions[i] 
  1996. 		spawn_region_enable(region, false) 
  1997. 		spawn_region_enable_los(region, true) 
  1998. 	end 
  1999. end 
  2000.  
  2001. -- Disables all spawn groups and regions. 
  2002. -- 
  2003. function m12_cleanup_all_spawn_groups()	 
  2004. 	for group in pairs(M12_spawn_groups) do 
  2005. 		m12_cleanup_spawn_group(M12_spawn_groups[group]) 
  2006. 	end 
  2007. end 
  2008.  
  2009. function m12_set_objective(obj) 
  2010. 	M12_current_obj = obj 
  2011. 	 
  2012. 	if M12_secondary_obj == "" then 
  2013. 		objective_text(0, obj.name, "", "", SYNC_ALL, obj.icon)	 
  2014. 		m12_add_icons_to_active_triggers() 
  2015. 	end 
  2016. end 
  2017.  
  2018. function m12_clear_objective() 
  2019. 	M12_current_obj = "" 
  2020. 	 
  2021. 	if M12_secondary_obj == "" then 
  2022. 		objective_text_clear(0) 
  2023. 	end 
  2024. 	 
  2025. 	m12_remove_icons_from_active_triggers() 
  2026. end 
  2027.  
  2028. function m12_set_seconodary_objective(obj) 
  2029. 	M12_secondary_obj = obj 
  2030. 	objective_text(0, obj.name, "", "", SYNC_ALL, obj.icon) 
  2031. 	m12_remove_icons_from_active_triggers() 
  2032. end 
  2033.  
  2034. function m12_clear_seconodary_objective() 
  2035. 	M12_secondary_obj = "" 
  2036. 	 
  2037. 	if M12_current_obj ~= "" then 
  2038. 		objective_text(0, M12_current_obj.name, "", "", SYNC_ALL, M12_current_obj.icon) 
  2039. 		m12_add_icons_to_active_triggers() 
  2040. 	else 
  2041. 		objective_text_clear(0) 
  2042. 	end 
  2043. end 
  2044.  
  2045. -- Setup an ambush group 
  2046. -- 
  2047. -- group_table:		Lua table defining the ambush group 
  2048. function m12_helper_setup_ambush_group(group_table) 
  2049. 	-- Register this ambush group 
  2050. 	M12_runtime.ambush_groups[#M12_runtime.ambush_groups + 1] = group_table 
  2051.  
  2052. 	-- Enable the trigger(s) 
  2053. 	for i, trigger in pairs(group_table.triggers) do 
  2054. 		trigger_enable(trigger, true) 
  2055. 		on_trigger("m12_ambush_triggered_cb", trigger) 
  2056. 	end 
  2057. end 
  2058.  
  2059. -- Cleanup an ambush group 
  2060. function m12_helper_cleanup_ambush_group(group_table, destroy) 
  2061. 	-- Find and un-register this ambush group 
  2062. 	for i, group in pairs(M12_runtime.ambush_groups) do 
  2063. 		if (M12_runtime.ambush_groups[i].name == group_table.name) then 
  2064. 			M12_runtime.ambush_groups[i] = M12_runtime.ambush_groups[#M12_runtime.ambush_groups] 
  2065. 			M12_runtime.ambush_groups[#M12_runtime.ambush_groups] = nil 
  2066. 			break 
  2067. 		end 
  2068. 	end 
  2069. 	 
  2070. 	-- Disabled the trigger(s) 
  2071. 	for i, trigger in pairs(group_table.triggers) do  
  2072. 		trigger_enable(trigger, false) 
  2073. 		on_trigger("", trigger) 
  2074. 	end 
  2075. end 
  2076.  
  2077. -- Callback when the player enters an ambush trigger 
  2078. -- 
  2079. -- triggerer:		Play that entered the trigger 
  2080. -- trigger:			Name of the trigger that was entered 
  2081. function m12_ambush_triggered_cb(triggerer, trigger) 
  2082. 	-- Look-up the script group for this trigger volume 
  2083. 	local group_table = nil 
  2084. 	for i, ambush_group in pairs(M12_runtime.ambush_groups) do 
  2085. 		for j, ambush_trigger in pairs(ambush_group.triggers) do 
  2086. 			if (ambush_trigger == trigger) then 
  2087. 				group_table = ambush_group 
  2088. 			end 
  2089. 		end 
  2090. 	end 
  2091. 	 
  2092. 	if (group_table ~= nil) then 
  2093. 		for i, char in pairs(group_table.chars) do 
  2094. 			if (char.behavior == "advance") then 
  2095. 				npc_leash_remove(char.name) 
  2096. 				ai_add_enemy_target(char.name, CLOSEST_PLAYER, ATTACK_ON_SIGHT, false) 
  2097. 				ai_do_scripted_move(char.name, char.nav, true, false) 
  2098. 			elseif (char.behavior == "attack_region") then 
  2099. 				npc_leash_remove(char.name) 
  2100. 				ai_add_enemy_target(char.name, CLOSEST_PLAYER, ATTACK_ON_SIGHT, false) 
  2101. 				ai_attack_region(char.name, char.nav, char.radius) 
  2102. 			elseif (char.behavior == "take_cover") then 
  2103. 				npc_leash_remove(char.name) 
  2104. 				ai_add_enemy_target(char.name, CLOSEST_PLAYER, ATTACK_ON_SIGHT, false) 
  2105. 				ai_do_scripted_take_cover(char.name) 
  2106. 			end 
  2107. 		end		 
  2108. 	end 
  2109. end 
  2110.  
  2111. -- ************************* 
  2112. -- 
  2113. -- Callback functions 
  2114. -- 
  2115. -- ************************* 
  2116.  
  2117. -- Generic trigger callback. Whenever the trigger is triggered by the player, the 
  2118. -- M12_trigger_reached flag is set. 
  2119. -- 
  2120. -- human   - Who triggered the trigger 
  2121. -- trigger - Name of the triggered trigger. 
  2122. function m12_trigger_cback(human, trigger) 
  2123. 	if human == LOCAL_PLAYER or human == REMOTE_PLAYER then 
  2124. 		M12_trigger_reached = true 
  2125. 	end 
  2126. end 
  2127.  
  2128. -- function m12_elev_persona_cb(human, trigger) 
  2129. -- 	m12_play_persona_line(M12_persona_line.up_on_floor_7) 
  2130. -- end 
  2131.  
  2132. -- Conversation that plays when the player tries to take upper elevators 
  2133. -- 
  2134. function m12_start_convo_elevator(human, trigger) 
  2135. 	m12_cleanup_trigger(trigger) 
  2136. 	m12_start_convo_thread(M12_convo.elevator) 
  2137. end 
  2138.  
  2139.  
  2140.  
  2141. -- Have some peds flee from a side room down a flight of stairs 
  2142. -- 
  2143. function m12_start_fleeing_peds_1(human, trigger) 
  2144. 	-- Only do this once. 
  2145. 	if M12_fleeing_peds_triggered then 
  2146. 		return 
  2147. 	end 
  2148. 	M12_fleeing_peds_triggered = true 
  2149. 	 
  2150. 	m12_cleanup_trigger(trigger) 
  2151. 	group_create(M12_groups.fleeing_peds_001.name) 
  2152. 	m12_move_members(M12_groups.fleeing_peds_001) 
  2153. end 
  2154.  
  2155. -- Called when a human enters a elevator. 
  2156. -- 
  2157. function m12_elevator_enter_cback(human, trigger) 
  2158. 	if human == LOCAL_PLAYER then 
  2159. 		M12_local_in_elevator = true 
  2160.  
  2161. 	elseif human == REMOTE_PLAYER then 
  2162. 		M12_remote_in_elevator = true 
  2163.  
  2164. 	elseif human == NPC_JOSH then 
  2165. 		M12_josh_in_elevator = true 
  2166.  
  2167. 	end 
  2168. 	 
  2169. 	M12_player_in_elevator = M12_local_in_elevator or M12_remote_in_elevator 
  2170. end 
  2171.  
  2172. -- Called when a human exits a elevator. 
  2173. -- 
  2174. function m12_elevator_exit_cback(human, trigger) 
  2175. 	if human == LOCAL_PLAYER then 
  2176. 		M12_local_in_elevator = false 
  2177. 		 
  2178. 	elseif human == REMOTE_PLAYER then 
  2179. 		M12_remote_in_elevator = false 
  2180. 		 
  2181. 	elseif human == NPC_JOSH then 
  2182. 		M12_josh_in_elevator = false 
  2183. 		 
  2184. 	end 
  2185. 	 
  2186. 	M12_player_in_elevator = M12_local_in_elevator or M12_remote_in_elevator 
  2187. end 
  2188.  
  2189. -- Ends the mission if an important human is killed. 
  2190. -- 
  2191. -- victim - Who was killed 
  2192. -- killer - The killer... 
  2193. function m12_on_death(victim, killer) 
  2194. 	if victim == NPC_SUKO then 
  2195. 		mission_end_failure("m12", M12_FAILURE_SUKO_DIED) 
  2196. 	elseif victim == NPC_JOSH then 
  2197. 		mission_end_failure("m12", M12_FAILURE_JOSH_DIED) 
  2198. 	end 
  2199. end 
  2200.  
  2201. function m12_party_member_dismissed(npc, leader) 
  2202. 	if npc == NPC_SUKO then 
  2203. 		mission_end_failure("m12", M12_FAILURE_SUKO_ABANDONED) 
  2204. 	elseif npc == NPC_JOSH then 
  2205. 		mission_end_failure("m12", M12_FAILURE_JOSH_ABANDONED) 
  2206. 	end 
  2207. end 
  2208.  
  2209. -- Cubical battle callback. When this trigger is reached, start spawning additional  
  2210. -- spawn groups. This is done to help balance the number of npcs and prevent the player 
  2211. -- from being overrun. 
  2212. -- 
  2213. -- human   - Who triggered the callback 
  2214. -- trigger - Name of the triggered trigger. 
  2215. function m12_start_spawning(human, trigger) 
  2216. 	if human == LOCAL_PLAYER or human == REMOTE_PLAYER then 
  2217. 		-- Cleanup this trigger since it should only fire once. 
  2218. 		m12_cleanup_trigger(M12_trigger.start_spawning) 
  2219. 		-- Start spawning the additional waves. 
  2220. 		m12_setup_spawn_group(M12_spawn_groups.cubical_wave_1, 10.0, true) 
  2221. 		m12_setup_spawn_group(M12_spawn_groups.cubical_wave_2, 25.0, true) 
  2222. 	end 
  2223. end 
  2224.  
  2225. -- Continuous spawn callback for the lobby area. 
  2226. function m12_lobby_spawn_cb() 
  2227. 	m12_cleanup_trigger(M12_trigger.lobby_spawn) 
  2228. 	m12_play_persona_line(M12_persona_line.ele_to_garage) 
  2229. 	m12_setup_spawn_group(M12_spawn_groups.lobby_escape, 25.0, true) 
  2230. end 
  2231.  
  2232. -- Called when a player equips a weapon, and sets M12_weapon_equipped to reflect 
  2233. -- the players weapon state. 
  2234. -- 
  2235. function m12_weapon_was_equipped(human, weapon) 
  2236. 	if human == LOCAL_PLAYER or human == REMOTE_PLAYER then 
  2237. 		if weapon ~= "Fist" then 
  2238. 			M12_weapon_equipped = true 
  2239. 		else 
  2240. 			M12_weapon_equipped = false 
  2241. 		end 
  2242. 	end 
  2243. end 
  2244.  
  2245. function m12_player_fired_weapon(human, weapon, attack_type) 
  2246. 	if weapon ~= "unarmed" and weapon ~= "Fist" then 
  2247. 		m12_exit_stealth_section() 
  2248. 		mission_end_failure("m12", M12_FAILURE_COVER_BLOWN) 
  2249. 	end 
  2250. end 
  2251.  
  2252. -- The player reverts to whatever weapon they had equipped when they entered the vehicle, 
  2253. -- so we need to re-unequip it when they exit the vehicle after the "hide the guns" line plays. 
  2254. -- 
  2255. function m12_remove_weapon_on_vehicle_exit(character) 
  2256. 	-- Only need to do this once. 
  2257. 	on_vehicle_exit("", character) 
  2258. 	 
  2259. 	-- Unequip their weapon again. 
  2260. 	inv_item_equip(nil, character) 
  2261. end 
  2262.  
  2263. -- Called when any notoriety based event is generated. Fail the mission on any 
  2264. -- NPC deaths or assaults. 
  2265. -- 
  2266. -- event		- Name of the event that occured 
  2267. -- police	- Increase in police notoriety 
  2268. -- gange		- Increase in gane notoriety 
  2269. -- team		- Name of the notoriety team that was effected 
  2270. function m12_notoriety_increased(event, police, gange, team) 
  2271. 	if event == "civilian kill"    or event == "gang kill"    or event == "police kill" or 
  2272. 	   event == "civilian assault" or event == "gang assault" or event == "police assault" then 
  2273. 		m12_exit_stealth_section() 
  2274. 		mission_end_failure("m12", M12_FAILURE_COVER_BLOWN) 
  2275. 	end 
  2276. end 
  2277.  
  2278. -- Callback for when a mission critical NPC takes damage during the stealth section; fails the mission. 
  2279. -- 
  2280. function m12_npc_damaged_fail() 
  2281. 	m12_exit_stealth_section() 
  2282. 	mission_end_failure("m12", M12_FAILURE_COVER_BLOWN) 
  2283. end 
  2284.  
  2285. -- Called when the player is leaving the garage. Have a few vehicles partly block the exit. 
  2286. -- 
  2287. function m12_block_garage_ramp_cb(human, trigger) 
  2288. 	m12_cleanup_trigger(trigger) 
  2289. 	for key, vehicle_table in pairs(M12_groups.stag_outside_garage.vehicle_paths) do 
  2290. 		vehicle_table.thread = thread_new("m12_thread_vehicle_pathfind_thread", vehicle_table) 
  2291. 	end 
  2292. 	notoriety_force_no_spawn(M12_STAG_NOTORIETY, false) 
  2293. 	notoriety_force_no_spawn("stag", false) 
  2294. end 
  2295.  
  2296. -- Called when the player passes a group of STAG vehicles sitting on the side of the road. 
  2297. -- Have them follow and attempt to ram the player. 
  2298. -- 
  2299. function m12_start_chasers_1_cb(human, trigger) 
  2300. 	m12_cleanup_trigger(trigger) 
  2301. 	for key, vehicle_table in pairs(M12_groups.stag_chasers_001.vehicles) do 
  2302. 		local vehicle = vehicle_table.vehicle 
  2303. 		local exit_on_stop = false 
  2304. 		local allow_ram = true 
  2305. 		vehicle_chase(vehicle, human, exit_on_stop, allow_ram) 
  2306. 		vehicle_set_crazy(vehicle, true) 
  2307. 	end 
  2308. end 
  2309.  
  2310. function m12_start_chasers_2_cb(human, trigger) 
  2311. 	m12_cleanup_trigger(trigger) 
  2312. 	for key, vehicle_table in pairs(M12_groups.stag_chasers_002.vehicles) do 
  2313. 		local vehicle = vehicle_table.vehicle 
  2314. 		local exit_on_stop = false 
  2315. 		local allow_ram = true 
  2316. 		vehicle_chase(vehicle, human, exit_on_stop, allow_ram) 
  2317. 		vehicle_set_crazy(vehicle, true) 
  2318. 	end 
  2319. end 
  2320.  
  2321. -- ************************* 
  2322. -- 
  2323. -- Thread functions 
  2324. -- 
  2325. -- ************************* 
  2326.  
  2327. -- Finds the member of a group nearest to the player and plays a line after a duration. 
  2328. -- 
  2329. function m12_find_nearest_guy_and_play_line(group, line, max_dist, delay_time) 
  2330. 	delay(delay_time) 
  2331. 	 
  2332. 	local all_dead = false 
  2333. 	 
  2334. 	while true do 
  2335. 		if group_is_loaded(group) == false then 
  2336. 			return 
  2337. 		end 
  2338. 		 
  2339. 		local nearest_dist = 999999 
  2340. 		local nearest_dude = "" 
  2341. 		for i, npc in pairs(group.chars) do 
  2342. 			if character_is_dead(npc.name) == false then 
  2343. 				local dist = get_dist(npc.name, LOCAL_PLAYER) 
  2344. 				if dist < nearest_dist then 
  2345. 					nearest_dist = dist 
  2346. 					nearest_dude = npc.name 
  2347. 				end 
  2348. 			end 
  2349. 		end 
  2350. 		 
  2351. 		if nearest_dude == "" then 
  2352. 			-- Couldn't find anyone, we're done. 
  2353. 			return 
  2354. 		end 
  2355. 		 
  2356. 		if max_dist > 0 and nearest_dist < max_dist then 
  2357. 			audio_play_persona_line(nearest_dude, M12_persona_line.secure_building.name) 
  2358. 			return 
  2359. 		end 
  2360. 		 
  2361. 		delay(0.25) 
  2362. 	end 
  2363. end 
  2364.  
  2365. -- Stops the player's car. 
  2366. -- 
  2367. function m12_stop_player_car_thread() 
  2368. 	-- Josh should be in the same car as the local player. 
  2369. 	if character_is_in_vehicle(LOCAL_PLAYER) then 
  2370. 		vehicle_max_speed(LOCAL_PLAYER, 0.0) 
  2371. 		while true do 
  2372. 			-- Continue stopping until we kill the thread in mission cleanup. 
  2373. 			vehicle_stop_do(LOCAL_PLAYER) 
  2374. 			thread_yield() 
  2375. 		end 
  2376. 	end 
  2377. end 
  2378.  
  2379. -- This function kills Josh if he is ever dropped as a human shield, failing the mission. 
  2380. -- 
  2381. function m12_handle_josh_dropped_thread() 
  2382. 	while true do 
  2383. 		-- Keep checking until this thread is killed. 
  2384. 		while character_has_specific_human_shield(LOCAL_PLAYER, NPC_JOSH) do  
  2385. 			thread_yield() 
  2386. 		end 
  2387. 		 
  2388. 		if character_is_dead(NPC_JOSH) then 
  2389. 			-- Well, that's it for Josh... 
  2390. 			return 
  2391. 		end 
  2392. 		 
  2393. 		-- If the host is incapacitated he can't take Josh as a human shield. 
  2394. 		-- Let's just kill Josh then; we don't have much other choice. 
  2395. 		if human_is_downed(LOCAL_PLAYER) then 
  2396. 			character_kill(NPC_JOSH, true) 
  2397. 			return 
  2398. 		end 
  2399. 		 
  2400. 		-- Woops!  Find the nearest nav in the current list and teleport the player and Josh there. 
  2401. 		local nearest_nav = nil 
  2402. 		local nearest_dist = nil 
  2403. 		local cur_dist = nil 
  2404. 		for i, cur_nav in pairs(M12_cur_josh_dropped_nav_list) do 
  2405. 			cur_dist = get_dist(LOCAL_PLAYER, cur_nav) 
  2406. 			if nearest_dist == nil or nearest_dist > cur_dist then 
  2407. 				nearest_nav = cur_nav 
  2408. 				nearest_dist = cur_dist 
  2409. 			end 
  2410. 		end 
  2411. 		 
  2412. 		if nearest_nav == nil then 
  2413. 			-- Well, somehow we failed to find a place to teleport to.  Josh dies as a result... poor Josh. 
  2414. 			character_kill(NPC_JOSH, true) 
  2415. 			return 
  2416. 		end 
  2417.  
  2418. 		fade_out(0.5, {0, 0, 0}, SYNC_LOCAL) 
  2419. 		fade_out_block() 
  2420. 		 
  2421. 		m12_cleanup_player_carrying_josh(false) 
  2422. 		 
  2423. 		teleport(LOCAL_PLAYER, nearest_nav) 
  2424. 		teleport(NPC_JOSH, nearest_nav) 
  2425. 		while teleport_check_done(LOCAL_PLAYER) == false do 
  2426. 			thread_yield() 
  2427. 		end 
  2428. 		while teleport_check_done(NPC_JOSH) == false do 
  2429. 			thread_yield() 
  2430. 		end 
  2431. 		 
  2432. 		-- Wait for Josh to be ready if necessary, but only wait so long. 
  2433. 		local wait_time = 0.0 
  2434. 		while (character_is_ready(NPC_JOSH) == false) and (wait_time < 5.0) do 
  2435. 			wait_time = wait_time + get_frame_time() 
  2436. 			thread_yield() 
  2437. 		end 
  2438. 		 
  2439. 		if character_is_ready(NPC_JOSH) then 
  2440. 			player_take_human_shield(LOCAL_PLAYER, NPC_JOSH) 
  2441. 			m12_setup_player_to_carry_josh(false) 
  2442. 		else 
  2443. 			character_kill(NPC_JOSH, true) 
  2444. 			return 
  2445. 		end 
  2446. 			 
  2447. 		fade_in(0.5, SYNC_LOCAL) 
  2448. 		fade_in_block() 
  2449. 	end 
  2450. end 
  2451.  
  2452. -- Populate a vehicle, have it follow a path, and then have all the npcs exit the vehicle. 
  2453. -- 
  2454. function m12_thread_vehicle_pathfind_thread(vehicle_table) 
  2455. 	vehicle_enter_group_teleport(vehicle_table.members, vehicle_table.vehicle) 
  2456. 	vehicle_pathfind_to(vehicle_table.vehicle, vehicle_table.path, true, true) 
  2457. 	vehicle_exit_group(vehicle_table.members) 
  2458. 	vehicle_table.thread = INVALID_THREAD_HANDLE 
  2459. end 
  2460.  
  2461. -- Instruct the player to remove their weapon, or fail the mission if they keep it out for to long 
  2462. -- 
  2463. function m12_thread_unequip_your_weapon() 
  2464. 	while true do 
  2465. 		while not M12_weapon_equipped do 
  2466. 			thread_yield() 
  2467. 		end 
  2468. 		 
  2469. 		-- Setup the HUD to display how much time the player has to unequip their weapon 
  2470. 		hud_timer_set(1, M12_WEAPON_UNEQUIP_TIME) 
  2471. 		m12_set_seconodary_objective(M12_OBJ_UNEQUIP_YOUR_WEAPON) 
  2472.  
  2473. 		while M12_weapon_equipped do 
  2474. 			if hud_timer_get_remainder(1) <= 0 then 
  2475. 				hud_timer_stop(1) 
  2476. 				m12_exit_stealth_section() 
  2477. 				mission_end_failure("m12", M12_FAILURE_COVER_BLOWN) 
  2478. 			end 
  2479.  
  2480. 			thread_yield() 
  2481. 		end 
  2482.  
  2483. 		hud_timer_stop(1) 
  2484. 		 
  2485. 		m12_clear_seconodary_objective() 
  2486. 	end 
  2487. end 
  2488.  
  2489. -- Taking a human shield does not generate a notoriety event. If a player takes a human sheild, 
  2490. -- instantly fail the mission. 
  2491. -- 
  2492. function m12_thread_human_shield_check() 
  2493. 	while true do 
  2494. 		if character_has_human_shield(LOCAL_PLAYER) then 
  2495. 			m12_exit_stealth_section() 
  2496. 			mission_end_failure("m12", M12_FAILURE_COVER_BLOWN) 
  2497. 		end 
  2498. 		 
  2499. 		if M12_in_coop then 
  2500. 			if character_has_human_shield(REMOTE_PLAYER) then 
  2501. 				m12_exit_stealth_section() 
  2502. 				mission_end_failure("m12", M12_FAILURE_COVER_BLOWN) 
  2503. 			end 
  2504. 		end 
  2505. 		 
  2506. 		thread_yield() 
  2507. 	end 
  2508. end 
  2509.  
  2510. -- Add a marker to pickup Josh whenever necessary 
  2511. -- 
  2512. function m12_thread_pickup_josh_marker() 
  2513. 	while true do 
  2514. 		while not character_is_in_vehicle(LOCAL_PLAYER) do 
  2515. 			thread_yield() 
  2516. 		end 
  2517. 		 
  2518. 		if not character_is_in_vehicle(NPC_JOSH) then 
  2519. 			m12_set_seconodary_objective(M12_OBJ_PICKUP_JOSH_BIRK) 
  2520. 			marker_add(NPC_JOSH, MINIMAP_ICON_USE, OI_ASSET_USE, OI_FLAGS_DEFAULT, SYNC_ALL) 
  2521. 			while character_is_in_vehicle(LOCAL_PLAYER) and not character_is_in_vehicle(NPC_JOSH) do 
  2522. 				thread_yield() 
  2523. 			end 
  2524. 			marker_remove(NPC_JOSH, SYNC_ALL) 
  2525. 			m12_clear_seconodary_objective() 
  2526. 		end 
  2527. 		 
  2528. 		thread_yield() 
  2529. 	end 
  2530. end 
  2531.  
  2532. -- ************************* 
  2533. -- 
  2534. -- Thread helper functions 
  2535. -- 
  2536. -- ************************* 
  2537.  
  2538. -- Kill all active threads. 
  2539. -- 
  2540. function m12_unload_all_threads() 
  2541. 	m12_unload_all_convos() 
  2542. 	 
  2543. 	if M12_thread.pickup_josh ~= INVALID_THREAD_HANDLE then 
  2544. 		thread_kill(M12_thread.pickup_josh) 
  2545. 		M12_thread.pickup_josh = INVALID_THREAD_HANDLE 
  2546. 	end 
  2547. 	 
  2548. 	for key, vehicle_table in pairs(M12_groups.stag_outside_garage.vehicle_paths) do 
  2549. 		 if vehicle_table.thread ~= INVALID_THREAD_HANDLE then 
  2550. 			thread_kill(vehicle_table.thread) 
  2551. 			vehicle_table.thread = INVALID_THREAD_HANDLE 
  2552. 		 end 
  2553. 	end 
  2554. end 
  2555.  
  2556.  
  2557. -- ************************* 
  2558. -- 
  2559. -- Conversation functions 
  2560. -- 
  2561. -- ************************* 
  2562.  
  2563. -- Plays a conversation 
  2564. -- 
  2565. -- convo: Conversation to play 
  2566. function m12_play_convo(convo) 
  2567. 	if convo.name ~= "" and convo.name ~= nil then 
  2568. 		if type(convo.name) == "table" then 
  2569. 			m12_play_persona_line(convo.name) 
  2570. 		else 
  2571. 			debug_print("MAD", "Playing Convo: " .. convo.name) 
  2572. 			convo.handle = audio_conversation_load(convo.name) 
  2573. 			audio_conversation_play(convo.handle) 
  2574. 			audio_conversation_wait_for_end(convo.handle) 
  2575. 			convo.handle = nil 
  2576. 			debug_print("MAD", "Ended Convo: " .. convo.name) 
  2577. 		end 
  2578. 	end 
  2579.  
  2580. 	if convo.delay ~= nil and convo.delay > 0.01 then 
  2581. 		delay(convo.delay) 
  2582. 	end 
  2583. end 
  2584.  
  2585. -- Unloads a conversation 
  2586. -- 
  2587. -- convo: Conversation to unload 
  2588. function m12_unload_convo(convo) 
  2589. 	if convo.handle == nil then 
  2590. 		return 
  2591. 	end 
  2592.  
  2593. 	audio_conversation_end(convo.handle) 
  2594. 	convo.handle = nil 
  2595. end 
  2596.  
  2597. -- Unloads all conversations from the convo table 
  2598. -- 
  2599. function m12_unload_all_convos() 
  2600. 	for convo_key, convo_set in pairs(M12_convo) do 
  2601. 		m12_unload_convo_set(convo_set) 
  2602.  
  2603. 		if convo_set.thread ~= INVALID_THREAD_HANDLE then 
  2604. 			thread_kill(convo_set.thread) 
  2605. 		end 
  2606. 	end 
  2607. end 
  2608.  
  2609. -- Iterates through a table of conversations and plays them. 
  2610. -- 
  2611. -- convo_set: Table of conversations 
  2612. -- 
  2613. function m12_play_convo_set(convo_set) 
  2614. 	for key, convo in pairs(convo_set.files) do 
  2615. 		m12_play_convo(convo) 
  2616. 	end 
  2617. end 
  2618.  
  2619. -- Unloads a convo table (array) 
  2620. -- 
  2621. -- convo_set Table of conversations to unload 
  2622. -- 
  2623. function m12_unload_convo_set(convo_set) 
  2624. 	for key, convo in pairs(convo_set.files) do 
  2625. 		m12_unload_convo(convo) 
  2626. 	end 
  2627. end 
  2628.  
  2629. -- Starts an audio conversation as a thread 
  2630. -- 
  2631. -- convo_table: Conversation to play 
  2632. -- 
  2633. function m12_start_convo_thread(convo_table) 
  2634. 	if M12_active_convo ~= "" then 
  2635. 		m12_unload_convo_set(M12_active_convo) 
  2636. 		M12_active_convo = "" 
  2637. 		delay(0.25) 
  2638. 	end 
  2639. 	convo_table.thread = thread_new("m12_audio_thread", convo_table) 
  2640. end 
  2641.  
  2642. -- Loads the necessary 2D personas for the heli rail sequence 
  2643. -- 
  2644. function m12_load_personas() 
  2645. 	for key, persona in pairs(M12_personas) do 
  2646. 		persona.handle = audio_persona_load_2d(persona.name) 
  2647. 	end 
  2648. end 
  2649.  
  2650. -- Unloads all 2d personas 
  2651. -- 
  2652. function m12_unload_personas() 
  2653. 	for key, persona in pairs(M12_personas) do 
  2654. 		if persona.handle ~= INVALID_PERSONA_HANDLE then 
  2655. 			audio_persona_remove_2d(persona.handle) 
  2656. 			persona.handle = INVALID_PERSONA_HANDLE 
  2657. 		end 
  2658. 	end 
  2659. end 
  2660.  
  2661. -- Gets the 2d persona handle from a character name 
  2662. -- 
  2663. function m12_get_persona_handle(line) 
  2664. 	for key, persona in pairs(M12_personas) do 
  2665. 		if persona.name == line.character then 
  2666. 			return persona.handle 
  2667. 		end 
  2668. 	end 
  2669.  
  2670. 	return nil 
  2671. end 
  2672.  
  2673. -- Plays a persona line. 
  2674. -- 
  2675. function m12_play_persona_line(line) 
  2676. 	debug_print("MAD", "Playing Persona Line: " .. line.name) 
  2677. 	 
  2678. 	if line.play_2d then 
  2679. 		audio_play_persona_line_2d(m12_get_persona_handle(line), line.name) 
  2680. 	else 
  2681. 		audio_play_persona_line(line.character, line.name) 
  2682. 	end 
  2683. end 
  2684.  
  2685.  
  2686.  
  2687. -- Play a audio conversation 
  2688. -- 
  2689. -- convo_table: Table of the audio conversation files to play 
  2690. -- 
  2691. function m12_audio_thread(convo_table) 
  2692. 	M12_active_convo = convo_table 
  2693. 	m12_play_convo_set(convo_table) 
  2694. 	convo_table.thread = INVALID_THREAD_HANDLE 
  2695. 	M12_active_convo = "" 
  2696. end 
  2697.