sr2lua/ep01.lua

  1. -- ep01.lua 
  2. -- SR2 mission script 
  3. -- 3/28/07 
  4.  
  5. -- Global constants ( ALL_CAPS means that they shouldn't be modified in running code, except for maybe	group_create_hidden(group) in a setup function ) 
  6.  
  7.  
  8.  
  9. 	-- KNOBS_TO_TURN -- 
  10.  
  11.  
  12. 			--[[ *** READ ME *** 
  13. 			 
  14. 				Whenever a script function looks up a wave parameter, a naming convention is used to select the appropriate value. 
  15. 				Parameter values for single player missions can use any name, say "PARAMETER_1" for example. If you wish to have 
  16. 				a different value for that parameter in coop, then prepend "COOP" to the parameter name. In this case, we get 
  17. 				"COOP_PARAMETER_1". 
  18.  
  19. 				When a mission function needs to access "PARAMETER_1", it will search for the appropriate overloaded values first: 
  20.  
  21. 					*	Single player will use the value stored in "PARAMETER_1". 
  22. 				 
  23. 					*	Coop will use the value stored in "COOP_PARAMETER_1", if it exists. Otherwise it will use the 
  24. 						default single player value stored in "PARAMETER_1". 
  25. 			 ]] 
  26.  
  27. 			-- Mission parameters 
  28. 			EP01_PARAMETERS	=  
  29. 				{	 
  30.  
  31. 					-- Stage 1, nightclub fight 
  32.  
  33. 						-- single-player values 
  34. 							["ULTOR_BLITZ_CHANCE"]				= .5,		-- chance that Ultor will charget the player 
  35. 							["ULTOR_ATTACK_NPC_CHANCE"]		= .2,		-- chance that Ultor will attack NPCs 
  36.  
  37. 						-- coop values 
  38.  
  39. 					-- Stage 2, save the ltnts 
  40. 					 
  41. 						-- single-player values 
  42. 							["MIN_POLICE_NOTORIETY"]			= 3,		-- Min Police/Ultor notoriety after leaving the nightclub. 
  43.  
  44. 							["PIERCE_MAX_HIT_POINTS"]			= 3000,	-- Max # hit points for pierce 
  45. 							["PIERCE_PERCENT_HEALTH"]			= 1.0,	-- Ratio of his hit points Pierce has when player(s) arrive. 
  46. 							["PIERCE_SURVIVAL_TICKS"]			= 20,		-- Number of times Pierce's health will tick down before he dies. 
  47. 							["PIERCE_SURVIVAL_TIME_S"]			= 90,		-- How long Pierce will survive 
  48. 			 
  49. 							["VAN_DRIVER_HIT_POINTS"]			= 4000,	-- Shaundi kidnapping van driver HP 
  50. 							["VAN_SHOTGUN_HIT_POINTS"]			= 4000,	-- HP of ultor riding shotgun in Shaundi kidnapping van 
  51. 							["VAN_HIT_POINTS"]					= 12000, -- Shaundi kidnapping van HP 
  52. 							["VAN_WARN_PERCENT_HEALTH"]		= .40,	-- Warn the player that the van is almost disabled 
  53. 							["VAN_DISABLED_PERCENT_HEALTH"]	= .30,	-- Van disabled @ this ratio health if not destroyed 
  54. 							["VAN_TORQUE_MODIFIER"]				= 1.4,	-- Increasing torque makes the van driver more erratic 
  55.  
  56. 							["VAN_MAX_SPEED_INITIAL"]			= 60,		-- Van's max speed at the start of its path. 
  57. 							["VAN_MAX_SPEED_DAMAGED"]			= 80,		-- Van's max speed after it takes damage. 
  58. 							["VAN_OUT_OF_RANGE_SPEED_RATIO"] = .6,		-- Van travels at this portion of max speed if players out of range. 
  59. 							["VAN_OUT_OF_RANGE_DIST_M"]      = 50,		-- Distance at which above ratio is applied. 
  60.  
  61. 						-- coop values 
  62.  
  63. 				} 
  64.  
  65. 	-- COOP MISSION? --  
  66. 		IN_COOP	= false 
  67.  
  68. 	-- CHARACTERS -- 
  69.  
  70. 		--CHARACTER_PIERCE			= "ep01_$Cpierce" 
  71. 		CHARACTER_PIERCE			= "ep01_$Cpierce2" 
  72. 		CHARACTER_SHAUNDI			= "ep01_$Cshaundi" 
  73.  
  74. 		CHARACTER_SHAUNDI_ULTOR_SHOTGUN	=	"ep01_$c031"	-- Sitting shotgun in the Shaundi-nabbing van 
  75. 		CHARACTER_SHAUNDI_ULTOR_DRIVER	=	"ep01_$c032"	-- Driving the van 
  76.  
  77. 	-- CHECKPOINTS 
  78. 		 
  79. 		CHECKPOINT_START			= MISSION_START_CHECKPOINT			-- defined in ug_lib.lua 
  80. 		CHECKPOINT_LEFT_CLUB		= "ep01_checkpoint_left_club"		-- player(s) made it out of the club 
  81. 		CHECKPOINT_LTNT_SAVED	= "ep01_checkpoint_ltnt_saved"	-- player has saved 1 ltnt (used in single player only) 
  82. 		 
  83. 	-- GROUPS -- 
  84.  
  85. 		GROUP_CLUB_ULTOR						= "ep01_$Gclub_ultor" 
  86. 		GROUP_CLUB_ULTOR_COOP				= "ep01_$Gclub_ultor_coop" 
  87. 		GROUP_CLUB_MASAKO_A					= "ep01_$Gmasako_team_a" 
  88. 		GROUP_CLUB_MASAKO_B					= "ep01_$Gmasako_team_b" 
  89. 		GROUP_CLUB_ULTOR_OUTSIDE			= "ep01_$Gclub_ultor_outside" 
  90. 		GROUP_CLUB_ULTOR_OUTSIDE_COOP		= "ep01_$Gclub_ultor_outside_coop" 
  91. 		GROUP_SHAUNDI							= "ep01_$Gshaundi" 
  92. 		GROUP_SHAUNDI_ULTOR					= "ep01_$Gshaundi_ultor" 
  93. 		GROUP_PIERCE							= "ep01_$Gpierce2" 
  94. 		GROUP_PIERCE_ULTOR					= "ep01_$Gpierce_ultor2" 
  95. 		GROUP_CTE								= "ep01_$GCTE" 
  96.  
  97. 	-- GROUP MEMBER TABLES --  
  98.  
  99. 		MEMBERS_GROUP_CLUB_ULTOR		=	{	"ep01_$c000", "ep01_$c001", "ep01_$c002", "ep01_$c003", "ep01_$c004", 
  100. 														"ep01_$c005", "ep01_$c006", "ep01_$c007", "ep01_$c013", "ep01_$c014", 
  101. 														"ep01_$c015", "ep01_$c045", "ep01_$c056"} 
  102.  
  103. 		MEMBERS_GROUP_CLUB_ULTOR_COOP =	{	"ep01_$c016", "ep01_$c017", "ep01_$c018", "ep01_$c019", "ep01_$c020"} 
  104.  
  105. 		MEMBERS_GROUP_PIERCE_ULTOR		=	{	"ep01_$c046", "ep01_$c047", "ep01_$c048", "ep01_$c049", "ep01_$c050", 
  106. 														"ep01_$c051", "ep01_$c052", "ep01_$c053", "ep01_$c054", "ep01_$c055"} 
  107.  
  108. 		MASAKO_STAIRS_UNLEASH			=	{	"ep01_$c013", "ep01_$c045", "ep01_$c056"} 
  109. 		MASAKO_STAIRS_UNLEASH_COOP		=	{	"ep01_$c017", "ep01_$c018", "ep01_$c019", "ep01_$c020"} 
  110.  
  111. 	-- HELPTEXT 
  112.  
  113. 		-- localized helptext messages 
  114.  
  115. 			-- Failure conditions 
  116. 			HELPTEXT_FAILURE_SHAUNDI_ABANDONED	= "ep01_failure_shaundi_abandoned" -- "Shaundi was abandoned" 
  117. 			HELPTEXT_FAILURE_SHAUNDI_DIED			= "ep01_failure_shaundi_died" -- "Shaundi died" 
  118. 			HELPTEXT_FAILURE_PIERCE_ABANDONED	= "ep01_failure_pierce_abandoned"  -- "Pierce was abandoned" 
  119. 			HELPTEXT_FAILURE_PIERCE_DIED			= "ep01_failure_pierce_died" -- "Pierce died" 
  120.  
  121. 			-- Hud 
  122. 			HELPTEXT_HUD_PIERCE_HEALTH				= "ep01_hud_pierce_health" -- "Pierce's health" 
  123. 			HELPTEXT_HUD_VAN_HEALTH					= "ep01_hud_van_health" -- "Van's condition" 
  124.  
  125. 			-- Prompts 
  126.  
  127. 			HELPTEXT_PROMPT_EXIT_CLUB				= "ep01_prompt_exit_club" -- "Fight your way out of the club!" 
  128. 			HELPTEXT_PROMPT_CHECK_LIEUTENANTS	= "ep01_prompt_check_lieutenants" -- "Make sure that Pierce and Shaundi are ok" 
  129.  
  130. 			HELPTEXT_PROMPT_SAVE_SHAUNDI			= "ep01_prompt_save_shaundi" -- "Stop the van before the Ultor kill Shaundi and dump her body" 
  131. 			--HELPTEXT_PROMPT_SAVE_PIERCE			= "ep01_prompt_save_pierce" -- "Save Pierce" 
  132. 			HELPTEXT_PROMPT_VAN_ALMOST_DISABLED = "ep01_prompt_van_almost_disabled" -- "Careful, the van is almost disabled" 
  133. 			HELPTEXT_PROMPT_KILL_ULTOR				= "ep01_prompt_kill_ultor" -- "Eliminate the Ultor before Pierce dies" 
  134.  
  135. 			HELPTEXT_PROMPT_CHECK_PIERCE			= "ep01_prompt_check_pierce" -- "Now check on Pierce" 
  136. 			HELPTEXT_PROMPT_CHECK_SHAUNDI			= "ep01_prompt_check_shaundi" -- "Now check on Shaundi" 
  137.  
  138. 			-- Objectives 
  139. 			HELPTEXT_OBJECTIVE_ULTOR				= "ep01_objective_ultor" -- "%s of %s Ultor remaining"	 
  140.  
  141. 		-- unlocalized helptext messages 
  142.  
  143. 	-- MOVERS 
  144. 		DOOR_MASAKO_TEAM_A_1	= "ep01_DoorMM010" 
  145. 		DOOR_MASAKO_TEAM_A_2	= "ep01_DoorMM020" 
  146. 		DOOR_MASAKO_TEAM_B_1 = "ep01_DoorMM030" 
  147. 		DOOR_IN_CLUB_1			= "ep01_$Door_in_club_1" 
  148. 		DOOR_IN_CLUB_2			= "ep01_$Door_in_club_2" 
  149.  
  150. 	-- NAVPOINTS 
  151.  
  152. 		NAVPOINT_LOCAL_PLAYER_START		= "ep01_$Nlocal_player_start" 
  153. 		NAVPOINT_REMOTE_PLAYER_START		= "ep01_$Nremote_player_start" 
  154.  
  155. 		SHAUNDI_VAN_TURRET_PATH				=	{	"ep01_$n006", "ep01_$n001"} 
  156. 		SHAUNDI_VAN_NAVMESH_PATH			=	{	"ep01_$n002", "ep01_$n003", "ep01_$n004"} 
  157.  
  158. 		NAVPOINT_PIERCE_LOCATION			= "ep01_$n_pierce_apt2" -- Target for Ultor "shooting at Pierce" 
  159. 		 
  160. 		NAVPOINT_LOCAL_SUCCESS				= "ep01_$Nlocal_player_finish" -- teleport nav for the end of the mission 
  161. 		NAVPOINT_REMOTE_SUCCESS				= "ep01_$Nremote_player_finish" -- teleport nav for the end of the mission 
  162.  
  163. 	-- TRIGGERS --  
  164.  
  165. 		TRIGGER_MASAKO_TEAM_A_1			= "ep01_$t000" 
  166. 		TRIGGER_MASAKO_TEAM_A_2			= "ep01_$t001" 
  167. 		TRIGGER_MASAKO_TEAM_B_1			= "ep01_$t002" 
  168. 		TRIGGER_CLUB_FRONT_EXIT			= "ep01_$Tclub_front_exit" 
  169. 		TRIGGER_CLUB_REAR_EXIT			= "ep01_$Tclub_rear_exit" 
  170. 		TRIGGER_CLUB_FRONT_ENTRANCE	= "ep01_$Tclub_front_entrance" 
  171. 		TRIGGER_CLUB_REAR_ENTRANCE		= "ep01_$Tclub_rear_entrance" 
  172. 		TRIGGER_PIERCE						= "ep01_$Tnear_pierce2" 
  173. 		TRIGGER_SHAUNDI					= "ep01_$Tnear_shaundi" 
  174. 		-- If the player entered this area w/ a vehicle, Pierce's cutscene path may be blocked. Don't play the cutscene. 
  175. 		TRIGGER_PIERCE_CUTSCENE_AREA	= "ep01_$Tpierce_cutscene_area"  
  176.  
  177. 		-- List of all triggers, makes cleaning up more convenient 
  178. 		TABLE_ALL_TRIGGERS		= {	TRIGGER_CLUB_FRONT_EXIT, TRIGGER_CLUB_REAR_EXIT, TRIGGER_CLUB_FRONT_ENTRANCE, 
  179. 												TRIGGER_CLUB_REAR_ENTRANCE, TRIGGER_PIERCE, TRIGGER_SHAUNDI, TRIGGER_MASAKO_TEAM_A_1, 
  180. 												TRIGGER_MASAKO_TEAM_A_2, TRIGGER_MASAKO_TEAM_B_1, TRIGGER_PIERCE_CUTSCENE_AREA}		 
  181.  
  182. 	-- VEHICLES -- 
  183.  
  184. 		VEHICLE_SHAUNDI_VAN	=	"ep01_$v002"	-- The van which takes Shaundi off to the remote kill spot 
  185.  
  186. 	-- MISC CONSTANTS 
  187.  
  188. 		HUD_BAR = {[LOCAL_PLAYER] = 0, [REMOTE_PLAYER] = 1} 
  189.  
  190. 		MASAKO_TEAM_INFO =  
  191. 		{ 
  192. 			{	 
  193. 				["group"]		= GROUP_CLUB_MASAKO_A, 
  194. 				["triggers"]	= {TRIGGER_MASAKO_TEAM_A_1, TRIGGER_MASAKO_TEAM_A_2}, 
  195. 				["doors"]		= {DOOR_MASAKO_TEAM_A_1, DOOR_MASAKO_TEAM_A_2}, 
  196. 				["members"]    = {"ep01_$c008", "ep01_$c009", "ep01_$c010", "ep01_$c033", "ep01_$c035", 
  197. 										"ep01_$c037", "ep01_$c039"}, 
  198. 				["callback"]	= "ep01_masako_team_a_attack", 
  199. 			}, 
  200. 			{	 
  201. 				["group"]		= GROUP_CLUB_MASAKO_B, 
  202. 				["triggers"]	= {TRIGGER_MASAKO_TEAM_B_1}, 
  203. 				["doors"]		= {DOOR_MASAKO_TEAM_B_1}, 
  204. 				["members"]    = {"ep01_$c011", "ep01_$c012", "ep01_$c034", "ep01_$c036", "ep01_$c038", 
  205. 										"ep01_$c040"}, 
  206. 				["callback"]	= "ep01_masako_team_b_attack", 
  207. 			}; 
  208. 		} 
  209.  
  210. 		OTHER_PLAYER	=	{	[LOCAL_PLAYER]	= REMOTE_PLAYER, 
  211. 									[REMOTE_PLAYER] = LOCAL_PLAYER, 
  212. 								} 
  213.  
  214. 		PLAYER_SYNC		=	{	[LOCAL_PLAYER]	= SYNC_LOCAL, 
  215. 									[REMOTE_PLAYER] = SYNC_REMOTE, 
  216. 								} 
  217.  
  218. 		LTNT_TRIGGER_MESSAGE		=	{	[TRIGGER_PIERCE]	= "", 
  219. 												[TRIGGER_SHAUNDI] = HELPTEXT_PROMPT_SAVE_SHAUNDI, 
  220. 											} 
  221. 		 
  222. 		LTNT_TRIGGER_FUNCTIONS	=	{	[TRIGGER_PIERCE]	= "ep01_save_pierce", 
  223. 												[TRIGGER_SHAUNDI] = "ep01_save_shaundi", 
  224. 											} 
  225.  
  226. 		LTNT_SETUP_FUNCTIONS		=	{	[TRIGGER_PIERCE]	= nil, 
  227. 												[TRIGGER_SHAUNDI] = "ep01_setup_shaundi", 
  228. 											} 
  229.  
  230. 		-- The join function for the save-shaundi sequence is intentionally left empty 
  231. 		-- even though there is an ep01_join_shaundi function. A separate thread is 
  232. 		-- set up to handle the second player joining this sequence . 
  233. 		LTNT_TRIGGER_JOIN_FUNCTIONS	=	{	[TRIGGER_PIERCE]	= "ep01_join_pierce", 
  234. 														[TRIGGER_SHAUNDI] = "", 
  235. 													} 
  236.  
  237. 		SHAUNDI_VAN_ESCORT		=	{	["ep01_$v010"]	=	{"ep01_$c043", "ep01_$c044"}, 
  238. 												["ep01_$v009"]	=	{"ep01_$c041", "ep01_$c042"} 
  239. 											} 
  240.  
  241. -- Progress flags 
  242. 	Player_sequence_begun			=	{	[LOCAL_PLAYER]	= "", 
  243. 													[REMOTE_PLAYER] = "" 
  244. 												} 
  245. 	Shaundi_van_disabled				= false 
  246. 	Shaundi_van_damaged				= false -- Has the Shaundi-knapping van been damaged yet? 
  247.  
  248. -- Threads 
  249. 	Thread_pierce_health				= -1 
  250.  
  251. -- Misc 
  252. 	Shaundi_saved						= false -- Has player rescued Shaundi? 
  253. 	Pierce_saved						= false -- Has player rescued Pierce? 
  254.  
  255. 	Pierce_cutscene_area_blocked	= false -- Did a player drive a vehicle into Pierce's cutscene area? 
  256.  
  257. 	Shaundi_escort_disabled	= {} 
  258. 	Shaundi_escort_driver	= {} 
  259. 	Num_escorts					= 0 
  260.  
  261. function ep01_start(ep01_checkpoint, opening_cutscene_played) 
  262.  
  263. 	if (ep01_checkpoint == CHECKPOINT_START) then 
  264.  
  265. 		-- Dismiss current party 
  266. 		party_dismiss_all() 
  267.  
  268. 		if (not opening_cutscene_played) then 
  269. 			cutscene_play("tsse01-01") 
  270. 		end 
  271. 		fade_out(0) 
  272. 	end 
  273.  
  274. 	ep01_initialize(ep01_checkpoint) 
  275.  
  276. 	local is_restart = (ep01_checkpoint ~= CHECKPOINT_START) 
  277.  
  278. 	-- Restarting, remind the players what they're supposed to be doing. 
  279. 	if (ep01_checkpoint == CHECKPOINT_LTNT_SAVED) then 
  280. 		if (Shaundi_saved) then 
  281. 			mission_help_table(HELPTEXT_PROMPT_CHECK_PIERCE) 
  282. 		end 
  283. 		if (Pierce_saved) then 
  284. 			mission_help_table(HELPTEXT_PROMPT_CHECK_SHAUNDI) 
  285. 		end 
  286. 	elseif (ep01_checkpoint == CHECKPOINT_LEFT_CLUB) then 
  287. 		mission_help_table(HELPTEXT_PROMPT_CHECK_LIEUTENANTS) 
  288. 	end 
  289.  
  290. 	-- Stage 1: Players exit the club 
  291. 	if(ep01_checkpoint == CHECKPOINT_START) then 
  292.  
  293. 		ep01_exit_club() 
  294.  
  295. 		-- CHECKPOINT! 
  296. 		mission_set_checkpoint(CHECKPOINT_LEFT_CLUB) 
  297. 		ep01_checkpoint = CHECKPOINT_LEFT_CLUB 
  298.  
  299. 	end -- ends CHECKPOINT_START 
  300.  
  301. 	-- Player rescues both Ltnts. 
  302. 	if ( (ep01_checkpoint == CHECKPOINT_LTNT_SAVED) or (ep01_checkpoint == CHECKPOINT_LEFT_CLUB)) then 
  303.  
  304. 		ep01_prepare_ltnt_triggers(is_restart) 
  305. 		if (is_restart) then 
  306. 			-- Display a waypoint when needed 
  307. 			thread_new("ep01_waypoint_thread")			 
  308. 		end 
  309.  
  310. 		-- Wait for the player to save both Shaundi and Pierce 
  311. 		while(not (Shaundi_saved and Pierce_saved)) do 
  312. 			thread_yield() 
  313. 		end 
  314. 	end 
  315.  
  316. 	ep01_complete() 
  317. end 
  318.  
  319. function ep01_initialize(checkpoint) 
  320.  
  321. 	mission_start_fade_out(0.0) 
  322.  
  323. 	ep01_initialize_common() 
  324.  
  325. 	ep01_initialize_checkpoint(checkpoint) 
  326.  
  327. 	mission_start_fade_in() 
  328.  
  329. end 
  330.  
  331. -- Initialization code shared by all checkpoints. 
  332. function ep01_initialize_common() 
  333.  
  334. 	-- Start trigger is hit...the activate button was hit 
  335. 	set_mission_author("Phillip Alexander") 
  336.  
  337. 	if coop_is_active() then 
  338. 		IN_COOP = true 
  339. 	end 
  340.  
  341. 	-- Get police notoriety level...   
  342. 	--Ep_starting_police_notoriety = notoriety_get_decimal("Police") 
  343. 	--notoriety_set_min("Police", 0) 
  344. 	--notoriety_set("Police", 0) 
  345. 	--notoriety_set_max("Police", 0) 
  346.  
  347. 	-- Disallow action node spawning throughout this mission... the framerate is 
  348. 	-- just too bad near Pierce. 
  349. 	action_nodes_enable(false) 
  350. 	 
  351. 	homie_mission_lock("Pierce") 
  352. 	homie_mission_lock("Shaundi") 
  353.  
  354. 	-- Bump up notoriety to the minimum level 
  355. 	notoriety_reset("Police") 
  356. 	notoriety_set_min("Police", ep01_get_parameter_value("MIN_POLICE_NOTORIETY")) 
  357.  
  358. 	-- Disable police notoriety while a save-ltnt sequence is active 
  359. 	thread_new("ep01_notoriety_thread") 
  360.  
  361. end 
  362.  
  363. -- Initialization code specific to the checkpoint. 
  364. function ep01_initialize_checkpoint(checkpoint) 
  365.  
  366. 	if(checkpoint == CHECKPOINT_START) then 
  367.  
  368. 		-- Start loading the ultor goons 
  369. 		ep01_group_create_maybe_coop(GROUP_CLUB_ULTOR, GROUP_CLUB_ULTOR_COOP, true) 
  370. 		ep01_group_create_maybe_coop(GROUP_CLUB_ULTOR_OUTSIDE, GROUP_CLUB_ULTOR_OUTSIDE_COOP, true) 
  371.  
  372. 		-- We haven't saved anybody yet. 
  373. 		Ep01_lieutenant_saved = "" 
  374.  
  375. 		-- Teleport players to start location 
  376. 		teleport_coop(NAVPOINT_LOCAL_PLAYER_START, NAVPOINT_REMOTE_PLAYER_START) 
  377.  
  378. 		-- Setup Ultor goons 
  379. 		local blitz_chance = ep01_get_parameter_value("ULTOR_BLITZ_CHANCE") 
  380. 		local attack_npc_chance = ep01_get_parameter_value("ULTOR_ATTACK_NPC_CHANCE") 
  381. 		local function setup_goon(goon) 
  382. 			local roll = rand_float(0.0,1.0) 
  383. 			if (roll < blitz_chance) then 
  384. 				set_blitz_flag(goon,true) 
  385. 			end 
  386. 			set_always_sees_player_flag(goon, true) 
  387. 			attack(goon) 
  388. 			 
  389. 		end 
  390. 		for i,goon in pairs(MEMBERS_GROUP_CLUB_ULTOR) do 
  391. 			setup_goon(goon)				 
  392. 		end 
  393. 		if (IN_COOP) then 
  394. 			for i,goon in pairs(MEMBERS_GROUP_CLUB_ULTOR_COOP) do 
  395. 				setup_goon(goon)				 
  396. 			end 
  397. 		end 
  398.  
  399. 		-- Make sure that the double doors near the starting area are open 
  400. 		door_open(DOOR_IN_CLUB_1) 
  401. 		door_open(DOOR_IN_CLUB_2) 
  402.  
  403. 		crouch_start(LOCAL_PLAYER) 
  404. 		if (IN_COOP) then 
  405. 			crouch_start(REMOTE_PLAYER) 
  406. 		end 
  407.  
  408. 		-- Give the players time to start crouching 
  409. 		delay(1.0) 
  410.  
  411. 	end 
  412.  
  413. 	-- In single player only, there is a checkpoint after one ltnt has been saved. 
  414. 	-- We can figure out which ltnt has been saved because they'll have been added 
  415. 	-- to the player's party as a follower. In coop, if a ltnt has been saved, then 
  416. 	-- we store their name in the mission_globals variable Ep01_lieutenant_saved. 
  417.  
  418. 	if ((checkpoint == CHECKPOINT_LTNT_SAVED) or (Ep01_lieutenant_saved ~= "")) then 
  419.  
  420. 		-- In coop, saved lieutenants won't have been in the player's party at the time of 
  421. 		-- the last checkpoint. Therefore, we need to spawn them ourselves. 
  422. 		if (IN_COOP) then 
  423. 			if (Ep01_lieutenant_saved == CHARACTER_SHAUNDI) then 
  424. 				Shaundi_saved = true 
  425. 				group_create(GROUP_SHAUNDI,true) 
  426. 				party_add(CHARACTER_SHAUNDI) 
  427. 				ep01_override_shaundi_persona() 
  428. 				teleport(CHARACTER_SHAUNDI, TRIGGER_CLUB_REAR_EXIT) 
  429. 			elseif (Ep01_lieutenant_saved == CHARACTER_PIERCE) then 
  430. 				Pierce_saved = true 
  431. 				group_create(GROUP_PIERCE,true) 
  432. 				party_add(CHARACTER_PIERCE) 
  433. 				teleport(CHARACTER_PIERCE, TRIGGER_CLUB_REAR_EXIT) 
  434. 			end 
  435. 		end 
  436.  
  437. 		-- TODO: check to see which ltnt is in the player's party 
  438. 		if (Ep01_lieutenant_saved == CHARACTER_SHAUNDI) then 
  439. 			Shaundi_saved = true 
  440. 			on_dismiss("ep01_failure_shaundi_abandoned",CHARACTER_SHAUNDI) 
  441. 			on_death("ep01_failure_shaundi_died",CHARACTER_SHAUNDI) 
  442. 		end 
  443.  
  444. 		if (Ep01_lieutenant_saved == CHARACTER_PIERCE) then 
  445. 			Pierce_saved = true 
  446. 			on_dismiss("ep01_failure_pierce_abandoned",CHARACTER_PIERCE) 
  447. 			on_death("ep01_failure_pierce_died",CHARACTER_PIERCE) 
  448. 		end 
  449. 		 
  450. 	end -- ends (checkpoint == CHECKPOINT_LTNT_SAVED) or (Ep01_lieutenant_saved ~= "") 
  451.  
  452. end 
  453.  
  454. -- Stage 1 functions 
  455.  
  456. function ep01_setup_masako_teams() 
  457.  
  458. 	for i, team_info in pairs(MASAKO_TEAM_INFO) do 
  459.  
  460. 		-- Start loading the Masako team 
  461. 		group_create(team_info["group"], false) 
  462.  
  463. 		-- Setup the trigger(s) 
  464. 		for i,trigger in pairs(team_info["triggers"]) do 
  465. 			trigger_enable(trigger, true) 
  466. 			on_trigger(team_info["callback"],trigger)  
  467. 		end 
  468.  
  469. 		-- Make sure they don't attack 
  470. 		for i,masako in pairs(team_info["members"]) do 
  471. 			npc_combat_enable(masako, false) 
  472. 		end 
  473.  
  474. 	end 
  475.  
  476. end 
  477.  
  478. function ep01_masako_team_a_attack() 
  479. 	ep01_masako_team_attack(1) 
  480. end 
  481.  
  482. function ep01_masako_team_b_attack() 
  483. 	ep01_masako_team_attack(2) 
  484.  
  485. 	-- Also unleash the Masako near the stairs 
  486. 	for i, masako in pairs(MASAKO_STAIRS_UNLEASH) do 
  487. 		if(not character_is_dead(masako)) then 
  488. 			set_blitz_flag(masako,true) 
  489. 			npc_leash_remove(masako) 
  490. 		end 
  491. 	end 
  492. 	if(IN_COOP) then 
  493. 		for i, masako in pairs(MASAKO_STAIRS_UNLEASH_COOP) do 
  494. 			if(not character_is_dead(masako)) then 
  495. 				set_blitz_flag(masako,true) 
  496. 				npc_leash_remove(masako) 
  497. 			end 
  498. 		end 
  499. 	end 
  500. end 
  501.  
  502. function ep01_masako_team_attack(index) 
  503.  
  504. 	-- disable triggers 
  505. 	for i,trigger in pairs(MASAKO_TEAM_INFO[index]["triggers"]) do 
  506. 		trigger_enable(trigger, false) 
  507. 		on_trigger("", trigger) 
  508. 	end 
  509.  
  510. 	-- Make sure group is loaded before doing anything else 
  511. 	if(group_is_loaded(MASAKO_TEAM_INFO[index]["group"])) then 
  512. 		-- Open doors 
  513. 		for i,door in pairs(MASAKO_TEAM_INFO[index]["doors"]) do 
  514. 			door_open(door) 
  515. 		end 
  516. 		-- Have team members attack 
  517. 		for i,member in pairs(MASAKO_TEAM_INFO[index]["members"]) do 
  518. 			npc_combat_enable(member, true) 
  519. 			set_blitz_flag(member,true) 
  520. 			attack(member) 
  521. 		end 
  522. 	end 
  523. end 
  524.  
  525. Player_outside_club =	{	[LOCAL_PLAYER]	= false, 
  526. 									[REMOTE_PLAYER] = false} 
  527. function ep01_exit_club() 
  528.  
  529. 	ep01_setup_masako_teams(); 
  530.  
  531. 	-- Tell player(s) to exit the club 
  532. 	mission_help_table(HELPTEXT_PROMPT_EXIT_CLUB) 
  533.  
  534. 	-- Enable exit triggers, place exits on the map 
  535. 	local function ep01_setup_club_trigger(trigger,callback,on_map) 
  536. 		trigger_enable(trigger,true) 
  537. 		if(on_map) then 
  538. 			marker_add_trigger(trigger,MINIMAP_ICON_LOCATION,INGAME_EFFECT_LOCATION) 
  539. 		end 
  540. 		trigger_set_delay_between_activations(trigger,0) 
  541. 		on_trigger(callback,trigger) 
  542. 	end 
  543. 	ep01_setup_club_trigger(TRIGGER_CLUB_FRONT_EXIT, "ep01_club_exited", true) 
  544. 	ep01_setup_club_trigger(TRIGGER_CLUB_REAR_EXIT, "ep01_club_exited", true) 
  545. 	if (IN_COOP) then 
  546. 		ep01_setup_club_trigger(TRIGGER_CLUB_FRONT_ENTRANCE, "ep01_club_entered", false) 
  547. 		ep01_setup_club_trigger(TRIGGER_CLUB_REAR_ENTRANCE, "ep01_club_entered", false) 
  548. 	else 
  549. 		Player_outside_club[REMOTE_PLAYER] = true 
  550. 	end 
  551.  
  552. 	while (not (Player_outside_club[LOCAL_PLAYER] and Player_outside_club[REMOTE_PLAYER])) do 
  553. 		thread_yield() 
  554. 	end 
  555.  
  556. 	-- Disable triggers, make sure that map icons aren't displayed 
  557. 	local function ep01_cleanup_club_trigger(trigger) 
  558. 		marker_remove_trigger(trigger) 
  559. 		on_trigger("",trigger) 
  560. 		trigger_enable(trigger,false) 
  561. 	end 
  562. 	ep01_cleanup_club_trigger(TRIGGER_CLUB_FRONT_EXIT) 
  563. 	ep01_cleanup_club_trigger(TRIGGER_CLUB_REAR_EXIT) 
  564. 	if (IN_COOP) then 
  565. 		ep01_cleanup_club_trigger(TRIGGER_CLUB_FRONT_ENTRANCE) 
  566. 		ep01_cleanup_club_trigger(TRIGGER_CLUB_REAR_ENTRANCE) 
  567. 	end 
  568.  
  569. 	-- Release the goons 
  570. 	ep01_release_to_world_maybe_coop(GROUP_CLUB_ULTOR, GROUP_CLUB_ULTOR_COOP) 
  571.  
  572. 	-- Start the phone call thread 
  573. 	thread_new("ep01_phone_call") 
  574.  
  575. end 
  576.  
  577. Ep01_call_received = false 
  578. function ep01_call_received() 
  579. 	Ep01_call_received = true 
  580. end 
  581.  
  582. function ep01_phone_call()	 
  583.  
  584. 	-- register the phone call 
  585. 	mid_mission_phonecall("ep01_call_received") 
  586.  
  587. 	-- had a player begun a sequence? 
  588. 	local function sequence_triggered() 
  589. 		if( (Player_sequence_begun[LOCAL_PLAYER] ~= "") or (Player_sequence_begun[REMOTE_PLAYER] ~= "") ) then 
  590. 			return true			 
  591. 		end 
  592. 	end 
  593.  
  594. 	while( (not Ep01_call_received) and (not sequence_triggered()) ) do 
  595. 		thread_yield() 
  596. 	end 
  597.  
  598. 	if (not sequence_triggered()) then 
  599.  
  600. 		local cell_conversation =  
  601. 		{ 
  602. 			{ "TSSE1_TROUBLE_L1", nil, 0 }, 
  603. 			{ "PLAYER_TSSE1_TROUBLE_L2", LOCAL_PLAYER, 0 }, 
  604. 			{ "TSSE1_TROUBLE_L3", nil, 0 }, 
  605. 			{ "PLAYER_TSSE1_TROUBLE_L4", LOCAL_PLAYER, 0 }, 
  606. 		} 
  607.  
  608. 		audio_play_conversation( cell_conversation, INCOMING_CALL) 
  609.  
  610. 		mission_help_table(HELPTEXT_PROMPT_CHECK_LIEUTENANTS) 
  611.  
  612. 	else 
  613. 		mid_mission_phonecall_reset() 
  614. 	end 
  615.  
  616. 	-- If no ltnt sequence has begun, then add markers 
  617. 	if (Player_sequence_begun[LOCAL_PLAYER] == "") then 
  618. 		marker_add_trigger(TRIGGER_SHAUNDI,MINIMAP_ICON_LOCATION,"", SYNC_LOCAL) 
  619. 		marker_add_trigger(TRIGGER_PIERCE,MINIMAP_ICON_LOCATION,"", SYNC_LOCAL) 
  620. 	end 
  621. 	if ( IN_COOP and (Player_sequence_begun[LOCAL_PLAYER] == "") ) then 
  622. 		marker_add_trigger(TRIGGER_SHAUNDI,MINIMAP_ICON_LOCATION,"", SYNC_REMOTE) 
  623. 		marker_add_trigger(TRIGGER_PIERCE,MINIMAP_ICON_LOCATION,"", SYNC_REMOTE) 
  624. 	end 
  625.  
  626. 	-- Display a waypoint when needed 
  627. 	thread_new("ep01_waypoint_thread") 
  628.  
  629. end 
  630.  
  631.  
  632. -- Player has exited the club. Turn map icons off. 
  633. function ep01_club_exited(triggerer, trigger) 
  634. 	Player_outside_club[triggerer] = true 
  635. 	marker_remove_trigger(TRIGGER_CLUB_FRONT_EXIT, PLAYER_SYNC[triggerer]) 
  636. 	marker_remove_trigger(TRIGGER_CLUB_REAR_EXIT, PLAYER_SYNC[triggerer]) 
  637. end 
  638.  
  639. -- Player has reentered the club. Turn exit icons back on. (For coop) 
  640. function ep01_club_entered(triggerer, trigger) 
  641. 	Player_outside_club[triggerer] = false 
  642. 	local sync_type = PLAYER_SYNC[triggerer] 
  643. 	marker_add_trigger(TRIGGER_CLUB_FRONT_EXIT,MINIMAP_ICON_LOCATION,INGAME_EFFECT_LOCATION,sync_type) 
  644. 	marker_add_trigger(TRIGGER_CLUB_REAR_EXIT,MINIMAP_ICON_LOCATION,INGAME_EFFECT_LOCATION,sync_type) 
  645. end 
  646.  
  647. -- Stage 2 functions 
  648. function	ep01_prepare_ltnt_triggers(add_markers) 
  649.  
  650. 	local function prepare_trigger(ltnt_group, ultor_group, trigger, add_markers) 
  651. 		-- Load ltnt 
  652. 		group_create_hidden(ltnt_group) 
  653.  
  654. 		if (ultor_group ~= "") then 
  655. 			group_create_hidden(ultor_group) 
  656. 		end 
  657.  
  658. 		-- Setup the trigger for the save Shaundi portion of the mission 
  659. 		trigger_enable(trigger,true) 
  660. 		if (add_markers) then 
  661. 			marker_add_trigger(trigger,MINIMAP_ICON_LOCATION,"") 
  662. 		end 
  663. 		on_trigger("ep01_enter_ltnt_trigger",trigger) 
  664.  
  665. 		if (LTNT_SETUP_FUNCTIONS[trigger] ~= nil) then 
  666. 			thread_new(LTNT_SETUP_FUNCTIONS[trigger]) 
  667. 		end 
  668. 	end 
  669.  
  670. 	-- If Shaundi hasn't already been saved, then setup her part of the mission 
  671. 	if(not Shaundi_saved) then 
  672. 		prepare_trigger(GROUP_SHAUNDI, GROUP_SHAUNDI_ULTOR, TRIGGER_SHAUNDI, add_markers) 
  673. 	end 
  674.  
  675. 	-- If Pierce hasn't already been saved, then setup his part of the mission 
  676. 	if(not Pierce_saved) then 
  677. 		prepare_trigger(GROUP_PIERCE, GROUP_PIERCE_ULTOR, TRIGGER_PIERCE, add_markers) 
  678. 	end 
  679.  
  680. end 
  681.  
  682. function ep01_waypoint_thread() 
  683.  
  684. 	local Player_waypoints =	{	[LOCAL_PLAYER]	= "", 
  685. 											[REMOTE_PLAYER] = "" 
  686. 										} 
  687.  
  688. 	local new_waypoints =	{	} 
  689.  
  690. 	-- Get the new waypoint for this player 
  691. 	local function get_new_player_waypoint(player) 
  692.  
  693. 		-- If the save-shaundi sequence has already been started, then the waypoint for that  
  694. 		-- sequence becomes the knappers' van. 
  695. 		local shaundi_waypoint = TRIGGER_SHAUNDI 
  696. 		if (Player_sequence_begun[LOCAL_PLAYER] == TRIGGER_SHAUNDI or Player_sequence_begun[REMOTE_PLAYER] == TRIGGER_SHAUNDI) then 
  697. 			shaundi_waypoint = VEHICLE_SHAUNDI_VAN 
  698. 		end 
  699.  
  700. 		-- Player isn't in the middle of saving someone, see which waypoint they are closest to 
  701. 		if (Player_sequence_begun[player] == "") then 
  702.  
  703. 			if(Shaundi_saved and Pierce_saved) then 
  704. 				return 
  705. 			elseif(Shaundi_saved) then 
  706. 				-- Shaundi has been saved, send to Pierce 
  707. 				new_waypoints[player] = TRIGGER_PIERCE 
  708. 			elseif (Pierce_saved) then 
  709. 				-- Pierce has been saved, send to Shaundi 
  710. 				new_waypoints[player] = shaundi_waypoint 
  711. 			else 
  712. 				-- No ltnts. saved yet, send to closest one 
  713. 				local dist_to_pierce = get_dist(player,TRIGGER_PIERCE) 
  714. 				local dist_to_shaundi = get_dist(player,shaundi_waypoint) 
  715. 				if (dist_to_pierce < dist_to_shaundi) then 
  716. 					new_waypoints[player] = TRIGGER_PIERCE 
  717. 				else 
  718. 					new_waypoints[player] = shaundi_waypoint 
  719. 				end 
  720. 			end -- (Shaundi_saved)	 
  721. 		-- Player is saving Shaundi 
  722. 		elseif (Player_sequence_begun[player] == TRIGGER_SHAUNDI) then 
  723. 			new_waypoints[player] = shaundi_waypoint 
  724. 		-- Player is saving Pierce, no waypoint 
  725. 		elseif (Player_sequence_begun[player] == TRIGGER_PIERCE) then 
  726. 			new_waypoints[player] = "" 
  727. 		end -- end if (Player_sequence_begun[player] == "") 
  728.  
  729. 	end -- end function get_player_waypoint 
  730.  
  731. 	-- Shaundi has some dialogue to say if she's in a vehicle w/ a player. 
  732. 	-- we keep track of the distance and only play those lines at certain 
  733. 	-- intervals 
  734. 	local shaundi_dialogue_dist = -1 
  735. 	local shaundi_dialogue_interval = -1 
  736.  
  737. 	while(true) do 
  738. 		 
  739. 		get_new_player_waypoint(LOCAL_PLAYER) 
  740. 		if (IN_COOP) then 
  741. 			get_new_player_waypoint(REMOTE_PLAYER) 
  742. 		end 
  743.  
  744. 		for player, waypoint in pairs (new_waypoints) do 
  745. 			-- If needed, change waypoint 
  746.  
  747. 			if(waypoint ~= Player_waypoints[player]) then 
  748. 				-- Waypoint has changed, remove possible old waypoint and add new one 
  749.  
  750. 				if(Player_waypoints[player] ~= "") then 
  751. 				-- Get rid of the old waypoint 
  752. 					mission_waypoint_remove(PLAYER_SYNC[player]) 
  753. 				end 
  754. 				if(waypoint ~= "") then 
  755. 					mission_waypoint_add(waypoint,PLAYER_SYNC[player]) 
  756. 				end 
  757. 				Player_waypoints[player] = waypoint 
  758. 			end 
  759. 		end 
  760. 		 
  761. 		-- Maybe play a dialogue line for Shaundi 
  762. 		if(Shaundi_saved and not Pierce_saved) then 
  763.  
  764. 			-- Get the current distance from Shaundi to Pierce 
  765. 			local cur_dist = get_dist(CHARACTER_SHAUNDI,CHARACTER_PIERCE) 
  766.  
  767. 			-- Initialize the stored distance if not yet done 
  768. 			if(shaundi_dialogue_dist == -1) then 
  769. 				shaundi_dialogue_dist = cur_dist 
  770. 				shaundi_dialogue_interval = cur_dist / 2.5 
  771. 			-- Otherwise, play dialogue if we've crossed a distance barrier and Shaundi is in a vehicle 
  772. 			-- w/ one of the players 
  773. 			else 
  774. 				if(cur_dist < shaundi_dialogue_dist - shaundi_dialogue_interval) then 
  775. 					shaundi_dialogue_dist = shaundi_dialogue_dist - shaundi_dialogue_interval 
  776.  
  777. 					-- Only play these lines if Shaundi is in a vehicle near a player that is driving a vehicle. 
  778. 					if(character_is_in_vehicle(CHARACTER_SHAUNDI)) then 
  779. 						local local_driving = (character_is_in_a_driver_seat(LOCAL_PLAYER)) 
  780. 						local remote_driving = (IN_COOP and character_is_in_a_driver_seat(REMOTE_PLAYER)) 
  781. 						local near_local = (get_dist(LOCAL_PLAYER, CHARACTER_SHAUNDI) < 5.0) 
  782. 						local near_remote = (IN_COOP and (get_dist(LOCAL_PLAYER, CHARACTER_SHAUNDI) < 5.0)) 
  783. 						if ( (local_driving and near_local) or (remote_driving and near_remote)) then 
  784. 							audio_play_for_character("TSSE01_SHAUNDI_DRIVING", CHARACTER_SHAUNDI, "voice", false, false) 
  785. 						end 
  786. 					end 
  787.  
  788. 				end 
  789. 			end 
  790. 		end 
  791.  
  792. 		thread_yield() 
  793.  
  794. 	end -- end while(true) 
  795. 	 
  796. end 
  797.  
  798. -- Sets police notoriety to 0 when either of the player is working on saving a LTNT, 0 the rest of the time 
  799. function ep01_notoriety_thread() 
  800.  
  801. 	notoriety_reset("Police") 
  802.  
  803. 	local saved_notoriety_level = ep01_get_parameter_value("MIN_POLICE_NOTORIETY") 
  804. 	local police_notoriety_active = true 
  805.  
  806. 	while (true) do 
  807. 	 
  808. 		-- Determine if either player is working on one of the ltnt-saving sequences 
  809. 		local sequence_begun = ( Player_sequence_begun[LOCAL_PLAYER] ~= "" or Player_sequence_begun[REMOTE_PLAYER] ~= "") 
  810.  
  811. 		-- If a sequence has been started since the last check, save current notoriety before setting it to 0 
  812. 		if (police_notoriety_active and sequence_begun) then 
  813. 			saved_notoriety_level = notoriety_get_decimal("Police") 
  814. 			notoriety_set_min("Police", 0) 
  815. 			notoriety_set("Police", 0) 
  816. 			notoriety_set_max("Police", 0) 
  817.  
  818. 			police_notoriety_active = false 
  819. 		end 
  820.  
  821. 		-- If the players were in a save sequence and aren't any more, restore the police notoriety 
  822. 		if ((not sequence_begun) and (not police_notoriety_active)) then 
  823. 			notoriety_reset("Police") 
  824. 			notoriety_set_min("Police", ep01_get_parameter_value("MIN_POLICE_NOTORIETY")) 
  825. 			notoriety_set("Police", saved_notoriety_level) 
  826.  
  827. 			police_notoriety_active = true 
  828. 		end 
  829.  
  830. 		thread_yield() 
  831.  
  832. 	end 
  833.  
  834. end 
  835.  
  836. -- Player has gotten near one of the ltnts, start the save-that-ltnt subsequence. 
  837. function ep01_enter_ltnt_trigger(triggerer, trigger) 
  838.  
  839. 	-- Player already started a sequence 
  840.  
  841. 	-- TODO: 
  842. 	-- what happens if player 1 has already started another sequence, and triggers this  
  843. 	-- sequence while player 2 is still far off? If we don't spawn the sequence npcs, 
  844. 	-- then player 1 will see them pop-in when player 2 reaches the area. grrr. 
  845.  
  846. 	-- has the sequence already begun? 
  847. 	local sequence_begun = ((Player_sequence_begun[LOCAL_PLAYER] == trigger) or 
  848. 									(Player_sequence_begun[REMOTE_PLAYER] == trigger)) 
  849.  
  850. 	-- This player is already working on a sequence, return 
  851. 	if (	Player_sequence_begun[triggerer] ~= "") then 
  852. 		return 
  853. 	end 
  854.  
  855. 	-- This function adds a player to this save-the-ltnt sequence.  
  856. 	local function player_begin_sequence(player) 
  857. 		local sync_type = PLAYER_SYNC[player] 
  858.  
  859. 		-- Remove ltnt sequence start markers 
  860. 		marker_remove_trigger(TRIGGER_PIERCE,sync_type) 
  861. 		marker_remove_trigger(TRIGGER_SHAUNDI,sync_type) 
  862.  
  863. 		-- Either start the seqence or add the player to the sequence 
  864. 		if (not sequence_begun) then 
  865.  
  866. 			-- Record that the player has begun this mission 
  867. 			Player_sequence_begun[player] = trigger 
  868.  
  869. 			sequence_begun = true 
  870. 			thread_new(LTNT_TRIGGER_FUNCTIONS[trigger], player, trigger)	 
  871.  
  872. 			-- Display the mission sequence helptext 
  873. 			if (LTNT_TRIGGER_MESSAGE[trigger] ~= "") then 
  874. 				mission_help_table(LTNT_TRIGGER_MESSAGE[trigger], "", "", sync_type) 
  875. 			end 
  876.  
  877. 		else 
  878. 			if (LTNT_TRIGGER_JOIN_FUNCTIONS[trigger] ~= "") then 
  879.  
  880. 				-- Record that the player has begun this mission 
  881. 				Player_sequence_begun[player] = trigger 
  882.  
  883. 				thread_new(LTNT_TRIGGER_JOIN_FUNCTIONS[trigger], player) 
  884. 			end 
  885. 		end 
  886. 	end 
  887.  
  888. 	player_begin_sequence(triggerer) 
  889.  
  890. 	-- If in COOP, other player joins the sequence as well if they are close enough 
  891. 	if (IN_COOP) then 
  892.  
  893. 		delay(2) 
  894.  
  895. 		local other_player = OTHER_PLAYER[triggerer] 
  896.  
  897. 		if (Player_sequence_begun[other_player] == "") then 
  898.  
  899. 			local dist = get_dist(other_player,trigger) 
  900. 			if(dist < 300) then 
  901. 				if (LTNT_TRIGGER_JOIN_FUNCTIONS[trigger] ~= "") then 
  902. 					player_begin_sequence(other_player) 
  903. 				end 
  904.  
  905. 			end 
  906.  
  907. 		end 
  908. 	end 
  909. end 
  910.  
  911. -- Stage 2: save Shaundi threads 
  912.  
  913. function ep01_setup_shaundi() 
  914.  
  915. 	-- Make sure that Shaundi isn't killed 
  916. 	turn_invulnerable(CHARACTER_SHAUNDI,false) 
  917.  
  918. 	-- Make Shaundi a Civilian for now so that the Ultor don't attack her 
  919. 	set_team(CHARACTER_SHAUNDI, "Civilian") 
  920.  
  921. 	-- Place Shaundi and the ultor in the van: 
  922. 	vehicle_enter_teleport(CHARACTER_SHAUNDI_ULTOR_DRIVER,VEHICLE_SHAUNDI_VAN,0) 
  923. 	vehicle_enter_teleport(CHARACTER_SHAUNDI_ULTOR_SHOTGUN,VEHICLE_SHAUNDI_VAN,1) 
  924. 	vehicle_enter_teleport(CHARACTER_SHAUNDI,VEHICLE_SHAUNDI_VAN,2) 
  925.  
  926. 	-- Set max hit points for the van, its driver, and the guy riding shotgun 
  927. 	set_max_hit_points(CHARACTER_SHAUNDI_ULTOR_DRIVER, ep01_get_parameter_value("VAN_DRIVER_HIT_POINTS")) 
  928. 	set_max_hit_points(CHARACTER_SHAUNDI_ULTOR_SHOTGUN, ep01_get_parameter_value("VAN_SHOTGUN_HIT_POINTS")) 
  929. 	set_max_hit_points(VEHICLE_SHAUNDI_VAN, ep01_get_parameter_value("VAN_HIT_POINTS")) 
  930.  
  931. 	-- Set a few flags on the van. 
  932. 	vehicle_prevent_explosion_fling(VEHICLE_SHAUNDI_VAN,true) 
  933. 	vehicle_set_allow_ram_ped(VEHICLE_SHAUNDI_VAN,true) 
  934. 	vehicle_infinite_mass(VEHICLE_SHAUNDI_VAN, true) 
  935. 	vehicle_suppress_npc_exit(VEHICLE_SHAUNDI_VAN, true) 
  936.  
  937. 	-- Put passenger into escort vehicles, setup callbacks 
  938. 	for escort,passengers in pairs(SHAUNDI_VAN_ESCORT) do 
  939. 		Num_escorts = Num_escorts + 1 
  940. 		Shaundi_escort_disabled[escort] = false 
  941.  
  942. 		vehicle_suppress_npc_exit(escort, true) 
  943. 		vehicle_set_allow_ram_ped(escort,true) 
  944. 		vehicle_set_crazy(escort,true) 
  945. 		vehicle_set_use_short_cuts(escort,true) 
  946. 		vehicle_max_speed(escort, ep01_get_parameter_value("VAN_MAX_SPEED_DAMAGED")+10) 
  947.  
  948. 		on_vehicle_destroyed("ep01_escort_vehicle_disabled",escort) 
  949. 		on_death("ep01_escort_driver_killed",passengers[1]) 
  950.  
  951. 		for i,passenger in pairs(passengers) do 
  952. 			vehicle_enter_teleport(passenger, escort, i-1) 
  953. 			npc_combat_enable(passenger,true) 
  954. 		end 
  955. 		Shaundi_escort_driver[passengers[1]] = escort 
  956. 	end 
  957.  
  958. 	-- If Shaundi dies, player loses the mission. 
  959. 	on_death("ep01_failure_shaundi_died", CHARACTER_SHAUNDI) 
  960.  
  961. end 
  962.  
  963. function ep01_save_shaundi(triggerer, trigger) 
  964.  
  965. 	group_show(GROUP_SHAUNDI) 
  966. 	group_show(GROUP_SHAUNDI_ULTOR) 
  967.  
  968. 	-- Players have to disable the Van before the Ultor kill Shaundi and dump her body 
  969. 	-- Start a thread that will add the other player to this sequence when they get close enough 
  970. 	if (IN_COOP) then 
  971. 		thread_new("ep01_join_shaundi_monitor", OTHER_PLAYER[triggerer]) 
  972. 	end 
  973. 	ep01_process_van_chase(triggerer) 
  974.  
  975. 	-- If Shaundi wasn't saved, ep01_process_van_chase will call a mission failure function 
  976. 	-- and there is nothing to do in this function. 
  977.  
  978. 	if (Shaundi_saved) then 
  979. 		-- Shaundi was saved 
  980.  
  981. 		if (not Pierce_saved) then 
  982.  
  983. 			-- Add Shaundi to the party 
  984. 			party_add(CHARACTER_SHAUNDI) 
  985.  
  986. 			on_dismiss("ep01_failure_shaundi_abandoned",CHARACTER_SHAUNDI) 
  987. 			on_death("ep01_failure_shaundi_died", CHARACTER_SHAUNDI) 
  988.  
  989. 			ep01_override_shaundi_persona() 
  990.  
  991. 			-- We have two conversations that seem to make sense, select one at random 
  992. 			if(rand_float(0.0,1.0) < 0.5) then 
  993. 				audio_play_for_character("TSSE01_SHAUNDI_RESCUED_1", CHARACTER_SHAUNDI, "voice", false, true) 
  994. 				audio_play_for_character("TSSE01_SHAUNDI_FINDPIERCE_1", CHARACTER_SHAUNDI, "voice", false, false) 
  995. 			else 
  996. 				audio_play_for_character("TSSE1_SHAUNDI_FIRST_L1", CHARACTER_SHAUNDI, "voice", false, true) 
  997. 				audio_play_for_character("TSSE1_SHAUNDI_FIRST_L2", CHARACTER_SHAUNDI, "voice", false, false) 
  998. 			end 
  999.  
  1000. 			-- Add marker for Pierce 
  1001. 			marker_add_trigger(TRIGGER_PIERCE,MINIMAP_ICON_LOCATION,"") 
  1002.  
  1003. 			-- Checkpoint here in single player. In COOP, just record that Sahundi was saved. 
  1004. 			if (not IN_COOP) then 
  1005. 				mission_set_checkpoint(CHECKPOINT_LTNT_SAVED) 
  1006. 			end 
  1007. 			Ep01_lieutenant_saved = CHARACTER_SHAUNDI 
  1008.  
  1009. 			local sync = ep01_get_sequence_sync(TRIGGER_SHAUNDI) 
  1010. 			mission_help_table(HELPTEXT_PROMPT_CHECK_PIERCE, "", "", sync) 
  1011.  
  1012. 		-- Else Pierce and Shaundi both saved., Shaundi thanks the pc(s) 
  1013. 		else 
  1014. 			audio_play_for_character("TSSE01_SHAUNDI_RESCUED_1", CHARACTER_SHAUNDI, "voice", false, true) 
  1015. 		end 
  1016.  
  1017. 		-- Disable Shaundi's trigger 
  1018. 		on_trigger("", TRIGGER_SHAUNDI) 
  1019. 		trigger_enable(TRIGGER_SHAUNDI, false) 
  1020.  
  1021. 		-- Nobody is working on this sequence any more 
  1022. 		for player, ltnt_sequence in pairs(Player_sequence_begun) do 
  1023. 			if (Player_sequence_begun[player] == trigger) then 
  1024. 				Player_sequence_begun[player] = "" 
  1025. 			end 
  1026. 		end 
  1027.  
  1028. 		marker_remove_trigger(trigger, SYNC_ALL) 
  1029.  
  1030. 		turn_vulnerable(CHARACTER_SHAUNDI) 
  1031.  
  1032. 	end 
  1033. end 
  1034.  
  1035. function ep01_join_shaundi(player) 
  1036.  
  1037. 	-- Add UI elements - van health bar and van kill markers 
  1038. 	if ( not Shaundi_van_disabled and not(vehicle_is_destroyed(VEHICLE_SHAUNDI_VAN)) ) then 
  1039.  
  1040. 		local sync = PLAYER_SYNC[player] 
  1041. 		local hud_bar = HUD_BAR[player] 
  1042.  
  1043. 		marker_remove_trigger(TRIGGER_PIERCE,sync) 
  1044. 		marker_remove_trigger(TRIGGER_SHAUNDI,sync) 
  1045.  
  1046. 		-- TODO: tell the player what they are supposed to be doing 
  1047. 		mission_help_table(HELPTEXT_PROMPT_SAVE_SHAUNDI, "", "", sync) 
  1048.  
  1049. 		marker_add_vehicle(VEHICLE_SHAUNDI_VAN,MINIMAP_ICON_KILL,INGAME_EFFECT_VEHICLE_KILL,sync) 
  1050. 		local van_disabled_health_percent = ep01_get_parameter_value("VAN_DISABLED_PERCENT_HEALTH") 
  1051. 		local van_max_hit_points = ep01_get_parameter_value("VAN_HIT_POINTS") 
  1052. 		hud_bar_on(hud_bar, "Health", HELPTEXT_HUD_VAN_HEALTH, van_max_hit_points, sync ) 
  1053. 		hud_bar_set_range(hud_bar, van_disabled_health_percent * van_max_hit_points, van_max_hit_points, SYNC_ALL) 
  1054. 		hud_bar_set_value(hud_bar, get_current_hit_points(VEHICLE_SHAUNDI_VAN), sync) 
  1055. 					 
  1056. 	end 
  1057. end 
  1058.  
  1059. -- Track a player's distance from the Shaundi-knappers van. When the player 
  1060. -- gets close enough, have them join the save-Shaundi sequence. 
  1061. function ep01_join_shaundi_monitor(player)  
  1062.  
  1063. 	-- Delay a little bit, we want to make sure that the triggering player doesn't join the sequence after 
  1064. 	-- the other player. 
  1065. 	delay(2) 
  1066.  
  1067. 	local sequence_joined = false 
  1068.  
  1069. 	local sync = PLAYER_SYNC[player] 
  1070. 	-- Place a location marker on the vehicle until the player is told to destroy it 
  1071. 	marker_remove_trigger(TRIGGER_SHAUNDI,sync) 
  1072. 	marker_add_vehicle(VEHICLE_SHAUNDI_VAN,MINIMAP_ICON_LOCATION,"",sync) 
  1073.  
  1074. 	while ( (not Shaundi_saved) and (not sequence_joined)) do 
  1075.  
  1076. 		-- If the player isn't already saving a ltnt., see if they are close enough 
  1077. 		-- to the van to join in on the save-Shaundi sequence. 
  1078. 		if ( (Player_sequence_begun[player] == "") and (Player_sequence_begun[OTHER_PLAYER[player]] == TRIGGER_SHAUNDI)) then 
  1079.  
  1080. 			local dist = get_dist(player,VEHICLE_SHAUNDI_VAN) 
  1081. 			if(dist < 250) then 
  1082. 				sequence_joined = true 
  1083. 				Player_sequence_begun[player] = TRIGGER_SHAUNDI 
  1084. 				-- Remove the "location" icon from the van, the join function will add the kill icon 
  1085. 				marker_remove_vehicle(VEHICLE_SHAUNDI_VAN, sync) 
  1086. 				ep01_join_shaundi(player) 
  1087. 			end 
  1088.  
  1089. 		end 
  1090.  
  1091. 		thread_yield() 
  1092.  
  1093. 	end 
  1094.  
  1095. end 
  1096.  
  1097. -- Stop the van (but don't destroy it) before the Ultor reach the beach where they will Execute Shaundi 
  1098. -- and dump her body. 
  1099. function ep01_process_van_chase(triggerer) 
  1100.  
  1101. 	-- Turn on the health bar hud for the player that triggered the sequence. 
  1102. 	local sync = PLAYER_SYNC[triggerer] 
  1103. 	local hud_bar = HUD_BAR[triggerer] 
  1104. 	local van_disabled_health_percent = ep01_get_parameter_value("VAN_DISABLED_PERCENT_HEALTH") 
  1105. 	local van_hit_points = ep01_get_parameter_value("VAN_HIT_POINTS") 
  1106.  
  1107. 	hud_bar_on(hud_bar, "Health", HELPTEXT_HUD_VAN_HEALTH, van_hit_points, sync) 
  1108. 	hud_bar_set_range(hud_bar, van_disabled_health_percent * van_hit_points, van_hit_points, SYNC_ALL) 
  1109. 	hud_bar_set_value(hud_bar, van_hit_points, sync) 
  1110.  
  1111. 	-- Setup the van. 
  1112. 	marker_add_vehicle(VEHICLE_SHAUNDI_VAN,MINIMAP_ICON_KILL,INGAME_EFFECT_VEHICLE_KILL,sync) 
  1113. 	vehicle_suppress_npc_exit(VEHICLE_SHAUNDI_VAN, true) 
  1114. 	on_death("ep01_van_disabled", CHARACTER_SHAUNDI_ULTOR_DRIVER) 
  1115. 	on_take_damage("ep01_van_damaged",VEHICLE_SHAUNDI_VAN) 
  1116. 	on_vehicle_destroyed("ep01_failure_shaundi_died", VEHICLE_SHAUNDI_VAN) 
  1117.  
  1118. 	-- Start up the thread for handling the escort vehicles 
  1119. 	for escort,passengers in pairs(SHAUNDI_VAN_ESCORT) do 
  1120. 		vehicle_chase(escort, CHARACTER_SHAUNDI_ULTOR_DRIVER, false, false, true)	 
  1121. 	end 
  1122. 	local escort_thread = thread_new("ep01_process_escort_2") 
  1123. 	set_cops_shooting_from_vehicles(true) 
  1124.  
  1125. 	-- Have shaundi complain about being taken prisoner 
  1126. 	audio_play_for_character("TSSE01_SHAUNDI_CAPTURED_1", CHARACTER_SHAUNDI, "voice", false, true) 
  1127.  
  1128. 	-- Keep the van's speed up-to-date 
  1129. 	local van_speed_thread = thread_new("ep01_van_speed") 
  1130.  
  1131. 	-- The van follows traffic splines until it nears the beach 
  1132. 	vehicle_turret_base_to(VEHICLE_SHAUNDI_VAN, SHAUNDI_VAN_TURRET_PATH, false) 
  1133.  
  1134. 	if (not (Shaundi_van_disabled or vehicle_is_destroyed(VEHICLE_SHAUNDI_VAN))) then 
  1135. 		-- Then it tries to navmesh pathfind to the dump site 
  1136. 		vehicle_pathfind_to(VEHICLE_SHAUNDI_VAN, SHAUNDI_VAN_NAVMESH_PATH, true, false) 
  1137. 	end 
  1138.  
  1139. 	thread_kill(escort_thread) 
  1140. 	thread_kill(van_speed_thread) 
  1141.  
  1142. 	-- Make Shaundi a Playa once again 
  1143. 	set_team(CHARACTER_SHAUNDI, "Playas") 
  1144.  
  1145.  
  1146. 	-- Vehicle pathfinding may have ended because...  
  1147. 	-- a) The vehicle reached its destination OR 
  1148. 	-- b) The vehicle was destroyed OR 
  1149. 	-- c) The vehicle's driver was killed OR 
  1150. 	-- d) THe vehicle's health dropped below a specified threshold 
  1151.  
  1152. 	-- if the van arrives at the beach, then Shaundi is shot, her body dumped, and the mission is lost. 
  1153. 	if (not Shaundi_van_disabled and not(vehicle_is_destroyed(VEHICLE_SHAUNDI_VAN))) then 
  1154.  
  1155. 		-- Get rid of the old callbacks 
  1156. 		on_death("", CHARACTER_SHAUNDI_ULTOR_DRIVER) 
  1157. 		on_take_damage("",VEHICLE_SHAUNDI_VAN) 
  1158. 		on_vehicle_destroyed("", VEHICLE_SHAUNDI_VAN) 
  1159.  
  1160. 		-- Make sure that the player can't kill the driver or destroy the van during this sequence 
  1161. 		turn_invulnerable(CHARACTER_SHAUNDI_ULTOR_DRIVER,false) 
  1162. 		turn_invulnerable(VEHICLE_SHAUNDI_VAN,false) 
  1163.  
  1164. 		-- Play a couple of gun shots 
  1165. 		audio_play("MAGNUM_FIRE_NPC") 
  1166. 		delay(0.4) 
  1167. 		audio_play("MAGNUM_FIRE_NPC") 
  1168.  
  1169. 		-- Kick Shaundi out, ragdoll her as though she is dead 
  1170. 		vehicle_exit_dive(CHARACTER_SHAUNDI) 
  1171. 		character_ragdoll(CHARACTER_SHAUNDI) 
  1172. 		set_ignore_ai_flag(CHARACTER_SHAUNDI, true) 
  1173. 		vehicle_speed_override(VEHICLE_SHAUNDI_VAN, 80) 
  1174.  
  1175. 		-- The van begins to flee 
  1176. 		local dist,player = get_dist_closest_player_to_object(VEHICLE_SHAUNDI_VAN) 
  1177. 		vehicle_flee(VEHICLE_SHAUNDI_VAN,player) 
  1178.  
  1179. 		-- Let the player see Shaundi fall from the van. 
  1180. 		vehicle_speed_cancel(VEHICLE_SHAUNDI_VAN) 
  1181. 		delay(5.0) 
  1182.  
  1183. 		-- You lose! 
  1184. 		ep01_failure_shaundi_died() 
  1185.  
  1186. 		Shaundi_saved =  false 
  1187.  
  1188. 	elseif(Shaundi_van_disabled) then 
  1189. 		-- Players must have saved Shaundi, remove map crap 
  1190. 		-- TODO: only remove for appropriate player in coop 
  1191.  
  1192. 		-- Get rid of the old callbacks 
  1193. 		on_death("", CHARACTER_SHAUNDI_ULTOR_DRIVER) 
  1194. 		on_take_damage("",VEHICLE_SHAUNDI_VAN) 
  1195. 		on_vehicle_destroyed("", VEHICLE_SHAUNDI_VAN) 
  1196.  
  1197. 		delay(1.0) 
  1198.  
  1199. 		local sync = ep01_get_sequence_sync(TRIGGER_SHAUNDI) 
  1200. 		if ( (sync == SYNC_LOCAL) or (sync == SYNC_ALL) ) then 
  1201. 			hud_bar_off(HUD_BAR[LOCAL_PLAYER]) 
  1202. 		end 
  1203. 		if ( (sync == SYNC_REMOTE) or (sync == SYNC_ALL) ) then 
  1204. 			hud_bar_off(HUD_BAR[REMOTE_PLAYER]) 
  1205. 		end 
  1206.  
  1207. 		marker_remove_vehicle(VEHICLE_SHAUNDI_VAN) 
  1208.  
  1209. 		-- Ultor can exit the van now. 
  1210. 		vehicle_suppress_npc_exit(VEHICLE_SHAUNDI_VAN, false) 
  1211.  
  1212. 		local van_speed = get_vehicle_speed(VEHICLE_SHAUNDI_VAN) 
  1213. 		while(van_speed > 1.0) do 
  1214. 			van_speed = get_vehicle_speed(VEHICLE_SHAUNDI_VAN) 
  1215. 			thread_yield() 
  1216. 		end 
  1217. 	 
  1218. 		vehicle_exit(CHARACTER_SHAUNDI) 
  1219.  
  1220. 		Shaundi_saved = true 
  1221. 	end 
  1222.  
  1223. end 
  1224.  
  1225. -- Continuously adjusts the kidnappers' van's speed. 
  1226. -- 
  1227. -- A base speed is determined based on whether the van has been damaged yet or not. 
  1228. -- If the players are too far from the van, then adjust the base speed downward so they can catch up. 
  1229. -- At first we only adjust max speed. After the van is damaged we start overriding the speed as well... 
  1230. -- this makes it act a bit more reckless. We can't just throw it in chase mode as it needs to follow a path. 
  1231. function ep01_van_speed() 
  1232.  
  1233. 	local speed_initial = ep01_get_parameter_value("VAN_MAX_SPEED_INITIAL") 
  1234. 	local speed_damaged = ep01_get_parameter_value("VAN_MAX_SPEED_DAMAGED") 
  1235. 	local range_ratio   = ep01_get_parameter_value("VAN_OUT_OF_RANGE_SPEED_RATIO") 
  1236. 	local range_dist_m  = ep01_get_parameter_value("VAN_OUT_OF_RANGE_DIST_M") 
  1237.  
  1238. 	local overriding_speed = false	-- Have we started overriding the van's speed yet? 
  1239. 	local current_speed = 0				-- The speed that we've set for the van, probably not the speed at which it is moving. 
  1240.  
  1241. 	while( not (Shaundi_van_disabled or vehicle_is_destroyed(VEHICLE_SHAUNDI_VAN)) ) do 
  1242.  
  1243. 		-- Get the base speed for the van 
  1244. 		local base_speed = speed_initial 
  1245. 		if(Shaundi_van_damaged) then 
  1246. 			base_speed = speed_damaged 
  1247. 		end 
  1248. 		local new_speed = base_speed 
  1249.  
  1250. 		-- Modify the speed if the players are too far from the van 
  1251. 		local dist,player = get_dist_closest_player_to_object(VEHICLE_SHAUNDI_VAN) 
  1252. 		if (dist > range_dist_m) then 
  1253. 			new_speed = new_speed * range_ratio 
  1254. 		end 
  1255.  
  1256. 		-- Update the van's max speed if it has changed. 
  1257. 		local speed_changed = (new_speed ~= current_speed) 
  1258. 		if (speed_changed) then 
  1259. 			vehicle_max_speed(VEHICLE_SHAUNDI_VAN, new_speed) 
  1260. 			current_speed = new_speed 
  1261. 		end 
  1262. 		 
  1263. 		-- Override the vehicle's speed if 
  1264. 		-- 1) (speed changed and van has been damaged) AND/OR 
  1265. 		-- 2) van was just damaged - we need to make sure that the speed is overriden even if the 
  1266. 		-- new speed hasn't changed. 
  1267. 		local start_override = (Shaundi_van_damaged ~= overriding_speed) 
  1268. 		if ( (speed_changed and Shaundi_van_damaged) or start_override ) then 
  1269. 			vehicle_speed_override(VEHICLE_SHAUNDI_VAN, new_speed)			 
  1270. 			overriding_speed = true			 
  1271. 		end 
  1272.  
  1273. 		thread_yield() 
  1274. 	end 
  1275.  
  1276. 	-- After vehicle is destroyed, set its speed to 0 and exit. 
  1277. 	if ( not vehicle_is_destroyed(VEHICLE_SHAUNDI_VAN) ) then 
  1278. 		vehicle_speed_override(VEHICLE_SHAUNDI_VAN, 0) 
  1279. 		vehicle_stop(VEHICLE_SHAUNDI_VAN,true) 
  1280. 	end 
  1281. end 
  1282.  
  1283. function ep01_van_disabled() 
  1284. 	Shaundi_van_disabled = true; 
  1285. end 
  1286.  
  1287. -- Escort vehicles follow the Shaundi-knappers until a player approaches too close. 
  1288. -- At this point, one of the vans will start chasing the player and not stop. 
  1289. function ep01_process_escort_2() 
  1290.  
  1291. 	local attack_dist = 50 
  1292. 	local total_num_escorts = Num_escorts 
  1293. 	local escort_targets = {}		-- maps from escort -> player the escort is targeting 
  1294. 	local player_attackers = {}	-- maps from player -> the escort currently attacking the player 
  1295.  
  1296. 	-- Make sure that at escort is attacking the player 
  1297. 	local function escort_attack(player) 
  1298.  
  1299. 		-- See which escort is currently attacking the player 
  1300. 		local current_attacker = player_attackers[player] 
  1301.  
  1302. 		-- Is a new attacker neeeded? 
  1303. 		local need_attacker = false 
  1304.  
  1305. 		if( current_attacker == nil) then 
  1306. 			-- No one is attacking this player yet 
  1307. 			need_attacker = true	 
  1308. 		elseif (Shaundi_escort_disabled[current_attacker]) then 
  1309. 			-- The player's previous attacker was disabled 
  1310. 			need_attacker = true 
  1311. 		end 
  1312.  
  1313. 		if (need_attacker) then 
  1314. 			-- Find a new escort to attack the player 
  1315. 			local closest = 0 
  1316. 			local new_attacker = "" 
  1317. 			for escort,disabled in pairs(Shaundi_escort_disabled) do 
  1318.  
  1319. 				if (	(not disabled) and  
  1320. 						(player_attackers[OTHER_PLAYER[player]] ~= escort) ) then 
  1321. 					-- This escort is not disabled or attacking anyone 
  1322.  
  1323. 					local dist = get_dist(escort,player) 
  1324.  
  1325. 					if( (new_attacker == "") or (dist < closest)) then 
  1326. 						-- This escort is the best one we've found so far. 
  1327. 						new_attacker = escort 
  1328. 						closest = dist 
  1329. 					end							 
  1330. 				end 
  1331. 			end 
  1332.  
  1333. 			if ((new_attacker ~= "") and (closest < attack_dist)) then 
  1334. 				-- We found a new escort to attack the player 
  1335.  
  1336. 				player_attackers[player] = new_attacker 
  1337. 				-- Stop chasing the knapper mobile and start chasing the player 
  1338. 				vehicle_chase(new_attacker, player, false, true, true) 
  1339. 			end 
  1340.  
  1341. 		end 
  1342. 	end 
  1343.  
  1344. 	while(Num_escorts > 0) do 
  1345.  
  1346. 		-- For each player in range, have an escort attack them 
  1347. 		local local_dist = get_dist(LOCAL_PLAYER,VEHICLE_SHAUNDI_VAN) 
  1348. 		if(local_dist < attack_dist) then 
  1349. 			escort_attack(LOCAL_PLAYER) 
  1350. 		end 
  1351.  
  1352. 		if(IN_COOP) then 
  1353. 			local remote_dist = get_dist(REMOTE_PLAYER,VEHICLE_SHAUNDI_VAN) 
  1354. 			if(remote_dist < attack_dist) then 
  1355. 				escort_attack(REMOTE_PLAYER) 
  1356. 			end 
  1357. 		end 
  1358.  
  1359. 		thread_yield() 
  1360.  
  1361. 	end 
  1362.  
  1363. end 
  1364.  
  1365. function ep01_escort_driver_killed(driver) 
  1366. 	ep01_escort_vehicle_disabled(Shaundi_escort_driver[driver]) 
  1367. end 
  1368.  
  1369. function ep01_escort_vehicle_disabled(vehicle) 
  1370. 	Num_escorts = Num_escorts - 1 
  1371. 	Shaundi_escort_disabled[vehicle] = true 
  1372. end 
  1373.  
  1374. -- Called when the Shaundinapping van is damaged. 
  1375. -- damage_percent is the van's health fraction on (0,1) after the attack 
  1376. function ep01_van_damaged(van, attacker, damage_percent) 
  1377.  
  1378. 	-- Once the van has taken damage for the first time, the driver goes into crazy 
  1379. 	-- driver mode. They enjoy running over peds and are just all around 
  1380. 	-- bad drivers with no respect for your lawn. 
  1381. 	if (not Shaundi_van_damaged) then 
  1382. 		vehicle_set_allow_ram_ped(VEHICLE_SHAUNDI_VAN,true) 
  1383. 		vehicle_set_crazy(VEHICLE_SHAUNDI_VAN,true) 
  1384. 		vehicle_set_use_short_cuts(VEHICLE_SHAUNDI_VAN,true) 
  1385. 		vehicle_set_torque_multiplier(VEHICLE_SHAUNDI_VAN, ep01_get_parameter_value("VAN_TORQUE_MODIFIER")) 
  1386. 		Shaundi_van_damaged = true 
  1387. 	end 
  1388.  
  1389. 	if (damage_percent <= 0) then 
  1390. 		-- van has been destroyed with Shaundi still inside ... failure! 
  1391. 		ep01_failure_shaundi_died() 
  1392. 	else 
  1393. 		 
  1394. 		-- Update the health bar: 
  1395. 		local van_max_hit_points = ep01_get_parameter_value("VAN_HIT_POINTS") 
  1396. 		local van_disabled_health_percent = ep01_get_parameter_value("VAN_DISABLED_PERCENT_HEALTH") 
  1397. 		local van_hit_points = ep01_get_parameter_value("VAN_HIT_POINTS")		 
  1398.  
  1399. 		local van_cur_hit_points = van_max_hit_points * damage_percent		 
  1400. 		local van_min_hit_points = van_disabled_health_percent * van_hit_points 
  1401.  
  1402. 		if (van_cur_hit_points <= van_min_hit_points) then 
  1403. 			van_cur_hit_points = van_min_hit_points + 1 
  1404. 		end 
  1405.  
  1406. 		local sync = ep01_get_sequence_sync(TRIGGER_SHAUNDI) 
  1407. 		if ( (sync == SYNC_LOCAL) or (sync == SYNC_ALL) ) then 
  1408. 			hud_bar_set_value(HUD_BAR[LOCAL_PLAYER],van_cur_hit_points, SYNC_LOCAL) 
  1409. 		end 
  1410. 		if ( (sync == SYNC_REMOTE) or (sync == SYNC_ALL) ) then 
  1411. 			hud_bar_set_value(HUD_BAR[REMOTE_PLAYER],van_cur_hit_points, SYNC_REMOTE) 
  1412. 		end		 
  1413.  
  1414. 		if (damage_percent <= van_disabled_health_percent) then 
  1415. 			ep01_van_disabled() 
  1416. 		end 
  1417.  
  1418. 	end 
  1419. end 
  1420.  
  1421. -- Setup Shaundi's persona overrides 
  1422. function ep01_override_shaundi_persona() 
  1423. 	persona_override_character_start(CHARACTER_SHAUNDI, POT_SITUATIONS[POT_ATTACK], "TSSE01_SHAUNDI_ATTACK") 
  1424. 	persona_override_character_start(CHARACTER_SHAUNDI, POT_SITUATIONS[POT_PRAISED_BY_PC], "TSSE01_SHAUNDI_PRAISED") 
  1425. 	persona_override_character_start(CHARACTER_SHAUNDI, POT_SITUATIONS[POT_TAUNTED_BY_PC], "TSSE01_SHAUNDI_TAUNT") 
  1426. end 
  1427.  
  1428. -- Stage 2, "Save Pierce" functions 
  1429. function ep01_save_pierce(triggerer, trigger) 
  1430.  
  1431. 	-- Start checking for players driving vehicles into Pierce's cutscene area. 
  1432. 	on_trigger("ep01_player_entered_pierce_cutscene_area",TRIGGER_PIERCE_CUTSCENE_AREA)  
  1433. 	trigger_enable(TRIGGER_PIERCE_CUTSCENE_AREA, true) 
  1434.  
  1435. 	--group_show(GROUP_PIERCE) 
  1436. 	group_show(GROUP_PIERCE_ULTOR) 
  1437.  
  1438. 	-- When not in coop, we can also disallow ped spawning 
  1439. 	if (not IN_COOP) then 
  1440. 		spawning_pedestrians(false, false) 
  1441. 	end 
  1442.  
  1443. 	-- Have existing peds flee 
  1444. 	city_chunk_set_all_civilians_fleeing("sr2_chunk104", true) 
  1445. 	city_chunk_set_all_civilians_fleeing("sr2_chunk105", true) 
  1446.  
  1447. 	-- Display Pierce's health trickling away 
  1448. 	Thread_pierce_health = thread_new("ep01_display_pierce_health") 
  1449.  
  1450. 	-- Wait for the player(s) to kill off the Ultor goons 
  1451. 	for i,goon in pairs(MEMBERS_GROUP_PIERCE_ULTOR) do 
  1452. 		attack(goon) 
  1453. 	end 
  1454.  
  1455. 	vehicle_set_sirens("ep01_$v016",true) 
  1456. 	vehicle_set_sirenlights("ep01_$v016",true) 
  1457. 	vehicle_set_sirens("ep01_$v017",true) 
  1458. 	vehicle_set_sirenlights("ep01_$v017",true) 
  1459.  
  1460. 	ep01_process_enemy_set(	MEMBERS_GROUP_PIERCE_ULTOR,  
  1461. 									HELPTEXT_PROMPT_KILL_ULTOR, 
  1462. 									HELPTEXT_OBJECTIVE_ULTOR,  
  1463. 									PLAYER_SYNC[triggerer]) 
  1464.  
  1465. 	-- Stop displaying Pierce's health 
  1466. 	thread_kill(Thread_pierce_health) 
  1467.  
  1468. 	-- Pierce has been saved! 
  1469. 	Pierce_saved = true; 
  1470.  
  1471. 	-- Stop displaying Pierce's health 
  1472. 	local sync = ep01_get_sequence_sync(TRIGGER_PIERCE) 
  1473. 	if ( (sync == SYNC_LOCAL) or (sync == SYNC_ALL) ) then 
  1474. 		hud_bar_off(HUD_BAR[LOCAL_PLAYER]) 
  1475. 	end 
  1476. 	if ( (sync == SYNC_REMOTE) or (sync == SYNC_ALL) ) then 
  1477. 		hud_bar_off(HUD_BAR[REMOTE_PLAYER]) 
  1478. 	end 
  1479.  
  1480. 	-- Reallow ped spawning 
  1481. 	spawning_pedestrians(true) 
  1482.  
  1483. 	-- Stop having existing peds flee 
  1484. 	city_chunk_set_all_civilians_fleeing("sr2_chunk104", false) 
  1485. 	city_chunk_set_all_civilians_fleeing("sr2_chunk105", false) 
  1486.  
  1487. 	-- No point in adding Pierce to the party if the mission is complete 
  1488. 	if(not Shaundi_saved) then 
  1489.  
  1490. 		-- Fade out of the game 
  1491. 		local fade_out_dist = 100 
  1492. 		local fade_local = ((not IN_COOP) or (get_dist(CHARACTER_PIERCE, LOCAL_PLAYER) < fade_out_dist) ) 
  1493. 		local fade_remote = (IN_COOP and (get_dist(CHARACTER_PIERCE, LOCAL_PLAYER) < fade_out_dist)) 
  1494. 		if(fade_local) then 
  1495. 			fade_out(1.0,{0,0,0}, SYNC_LOCAL) 
  1496. 		end 
  1497. 		if(fade_remote) then 
  1498. 			fade_out(1.0,{0,0,0}, SYNC_REMOTE) 
  1499. 		end 
  1500. 		delay(1) 
  1501.  
  1502. 		-- Determine if we should play the cutscene 
  1503. 		local play_cutscene = true 
  1504. 		if (Pierce_cutscene_area_blocked) then 
  1505. 			-- Don't play the cutscene if the area is blocked. 
  1506. 			play_cutscene = false 
  1507. 		end 
  1508. 		if ( IN_COOP and (not (fade_local and fade_remote)) ) then 
  1509. 			-- Don't play the cutscene in Coop unless all players are being faded out. (No way to play for just one person) 
  1510. 			play_cutscene = false 
  1511. 		end 
  1512.  
  1513. 		-- Maybe play the cutscene 
  1514. 		if (play_cutscene) then 
  1515. 			cutscene_play("IG_ep01_scene1", "", "", false) 
  1516. 			group_destroy(GROUP_CTE) 
  1517. 		end 
  1518.  
  1519. 		-- Add pierce to the closest player's party. 
  1520. 		character_show(CHARACTER_PIERCE) 
  1521. 		party_add(CHARACTER_PIERCE) 
  1522. 		on_dismiss("ep01_failure_pierce_abandoned",CHARACTER_PIERCE) 
  1523. 		on_death("ep01_failure_pierce_died", CHARACTER_PIERCE) 
  1524.  
  1525. 		-- Reset Pierce's health to full 
  1526. 		set_current_hit_points(CHARACTER_PIERCE, ep01_get_parameter_value("PIERCE_MAX_HIT_POINTS")) 
  1527.  
  1528. 		if(fade_local) then 
  1529. 			fade_in(1.0, SYNC_LOCAL) 
  1530. 		end 
  1531. 		if(fade_remote) then 
  1532. 			fade_in(1.0, SYNC_REMOTE) 
  1533. 		end 
  1534.  
  1535. 		delay(1) 
  1536. 		clear_animation_state(CHARACTER_PIERCE) 
  1537.  
  1538. 		-- Add marker for Shaundi 
  1539. 		marker_add_trigger(TRIGGER_SHAUNDI,MINIMAP_ICON_LOCATION,"") 
  1540.  
  1541. 		-- Checkpoint here in single player. In COOP, just record that Pierce was saved. 
  1542. 		if (not IN_COOP) then 
  1543. 			mission_set_checkpoint(CHECKPOINT_LTNT_SAVED) 
  1544. 		end	 
  1545. 		Ep01_lieutenant_saved = CHARACTER_PIERCE 
  1546.  
  1547. 		local sync = ep01_get_sequence_sync(TRIGGER_PIERCE) 
  1548. 		mission_help_table(HELPTEXT_PROMPT_CHECK_SHAUNDI, "", "", sync) 
  1549.  
  1550. 		audio_play_for_character("TSSE1_PIERCE_FIRST_L1", CHARACTER_PIERCE, "voice", false, true) 
  1551. 		audio_play_for_character("TSSE1_PIERCE_FIRST_L2", LOCAL_PLAYER, "voice", false, false)		 
  1552.  
  1553. 	else 
  1554. 		if(get_dist(CHARACTER_SHAUNDI, CHARACTER_PIERCE) < 10) then 
  1555. 			audio_play_for_character("TSSE01_SHAUNDI_SEESPIERCE_1", CHARACTER_SHAUNDI, "voice", false, false) 
  1556. 		end 
  1557. 	end 
  1558.  
  1559. 	-- Nobody is working on this sequence any more 
  1560. 	trigger_enable(trigger,false) 
  1561. 	on_trigger("",trigger) 
  1562. 	for player, ltnt_sequence in pairs(Player_sequence_begun) do 
  1563. 		if (Player_sequence_begun[player] == trigger) then 
  1564. 			Player_sequence_begun[player] = "" 
  1565. 		end 
  1566. 	end 
  1567.  
  1568. 	marker_remove_trigger(trigger, SYNC_ALL) 
  1569.  
  1570. end 
  1571.  
  1572. -- A second player is joining the save-Pierce sequence. 
  1573. function ep01_join_pierce(triggerer) 
  1574. 	-- Setup HUD: 
  1575. 		local sync = PLAYER_SYNC[triggerer] 
  1576.  
  1577. 		-- Objective display handled by ep01_process_enemy_set 
  1578. 		objective_text(0, ep01_enemy_set_objective_helptext, ep01_enemies_to_kill - ep01_enemies_living, ep01_enemies_to_kill, sync) 
  1579.  
  1580. 		-- Add markers to living goons 
  1581. 		for i,goon in pairs(MEMBERS_GROUP_PIERCE_ULTOR) do 
  1582. 			if	(not character_is_dead(goon)) then 
  1583. 				marker_add_npc(goon, MINIMAP_ICON_KILL, INGAME_EFFECT_KILL, PLAYER_SYNC[triggerer])  
  1584. 			end 
  1585. 		end 
  1586.  
  1587. 		-- Place Pierce's health on the hud. 
  1588. 		local pierce_max_hit_points = ep01_get_parameter_value("PIERCE_MAX_HIT_POINTS") 
  1589. 		local hud_bar = HUD_BAR[triggerer] 
  1590. 		hud_bar_on(hud_bar, "Health", HELPTEXT_HUD_PIERCE_HEALTH, pierce_max_hit_points, sync) 
  1591. 		local hit_points = Ep01_pierce_current_health 
  1592. 		if (hit_points == -1) then 
  1593. 			hit_points = pierce_max_hit_points * ep01_get_parameter_value("PIERCE_PERCENT_HEALTH") 
  1594. 		end 
  1595. 		hud_bar_set_value(hud_bar, hit_points, sync ) 
  1596.  
  1597. 	-- Tell the player what to do 
  1598. 	mission_help_table(HELPTEXT_PROMPT_KILL_ULTOR) 
  1599. end 
  1600.  
  1601. -- This function is called when a player enters the area where Pierce's cutscene will take place. If they're 
  1602. -- driving a vehicle, it may be blocking Pierce's path so don't play the cutscene. 
  1603. function ep01_player_entered_pierce_cutscene_area(triggerer, trigger) 
  1604. 	if (character_is_in_vehicle(triggerer)) then 
  1605. 		Pierce_cutscene_area_blocked = true 
  1606. 		on_trigger("", trigger) 
  1607. 		trigger_enable(trigger, false) 
  1608. 	end 
  1609. end 
  1610.  
  1611. -- The goon wanders around and occasionally takes a shot at Pierce 
  1612. function ep01_pierce_ultor_patrol(goon) 
  1613.  
  1614. 	local next_action_cumulative_chances = { 
  1615. 		["wander"]			= 0.3,	-- Goon wanders around a bit 
  1616. 		["attack player"]	= 0.55,	-- Goon attacks the player 
  1617. 		["taunt"]			= 0.80,	-- Goon taunts Pierce; says something or makes a rude gesture. 
  1618. 		["attackpierce"]	= 1.0,	-- Goon attacks Pierce  
  1619. 	} 
  1620.  
  1621. 	local taunt_actions = {	"talk yell", "Insult A", "Insult B"} 
  1622.  
  1623. 	while(1) do 
  1624. 		local roll = rand_float(0.0,1.0) 
  1625. 		local attack_player_range = 50.0 
  1626.  
  1627. 		local dist,player = get_dist_closest_player_to_object(goon) 
  1628.  
  1629. 		-- Goon might wander around a bit as long as the player isn't too close 
  1630. 		if (	(roll < next_action_cumulative_chances["wander"]) and 
  1631. 				(dist >= attack_player_range) 
  1632. 			) then 
  1633. 			-- Goon wanders around a bit 
  1634.  
  1635. 			-- Looks odd because I use the goon's starting navpoint, which has the same 
  1636. 			-- name as the goon itself. 
  1637. 			wander_start(goon,goon,rand_float(6,12)) 
  1638. 			delay(rand_float(4,8)) 
  1639. 			wander_stop(goon) 
  1640. 		elseif (roll < next_action_cumulative_chances["attack player"]) then 
  1641. 			-- Have the npc attack the player as long as the player is close to the 
  1642. 			-- goon. If the player gets too far away, then go back 
  1643. 			-- and attack Pierce before getting back into the normal routine. 
  1644. 			if (dist < attack_player_range) then 
  1645. 				while (dist < attack_player_range) do 
  1646. 					npc_combat_enable(goon,true) 
  1647. 					attack(goon,player) 
  1648. 					delay(rand_int(10,15)) 
  1649. 					dist,player = get_dist_closest_player_to_object(goon) 
  1650. 				end 
  1651. 				-- Start moving back to original spot... can still attack  
  1652. 				move_to(goon,goon,2,false, false) 
  1653. 				-- Attack Pierce once 
  1654. 				force_fire(goon, NAVPOINT_PIERCE_LOCATION, true) 
  1655. 				--ep01_pierce_maybe_damaged() 
  1656.  
  1657. 				-- Remove from combat, go back into the normal loop 
  1658. 				npc_combat_enable(goon,false) 
  1659. 			end 
  1660.  
  1661. 		elseif (roll < next_action_cumulative_chances["taunt"]) then 
  1662. 			-- Goon engages in rudeness 
  1663.  
  1664. 			-- Put up weapon so taunt doesn't look dumb 
  1665. 			npc_holster(goon) 
  1666. 			turn_to(goon, NAVPOINT_PIERCE_LOCATION, false) 
  1667. 			local insult = taunt_actions[rand_int(1,sizeof_table(taunt_actions))] 
  1668. 			action_play(goon, insult, nil, true, nil, true) 
  1669. 			npc_unholster_best_weapon(goon) 
  1670. 		else 
  1671. 			-- Fire once at Pierce's location 
  1672. 			npc_combat_enable(goon,true) 
  1673. 			force_fire(goon, NAVPOINT_PIERCE_LOCATION, true) 
  1674. 			npc_combat_enable(goon,false) 
  1675. 			--ep01_pierce_maybe_damaged() 
  1676. 		end 
  1677. 		thread_yield() 
  1678. 	end 
  1679. end 
  1680.  
  1681. Ep01_pierce_current_health = -1 
  1682. function ep01_display_pierce_health() 
  1683.  
  1684. 	-- Set and display Pierce's health 
  1685.  
  1686. 		local pierce_max_hit_points = ep01_get_parameter_value("PIERCE_MAX_HIT_POINTS") 
  1687. 		local pierce_percent_health = ep01_get_parameter_value("PIERCE_PERCENT_HEALTH") 
  1688. 		local pierce_start_hit_points = pierce_max_hit_points * pierce_percent_health 
  1689.  
  1690. 		-- Set Pierce's max and current hit points 
  1691. 		set_max_hit_points(CHARACTER_PIERCE, pierce_max_hit_points) 
  1692. 		set_current_hit_points(CHARACTER_PIERCE, pierce_start_hit_points) 
  1693.  
  1694. 		-- Turn on the health bar hud 
  1695. 		local sync = ep01_get_sequence_sync(TRIGGER_PIERCE) 
  1696. 		local sync = ep01_get_sequence_sync(TRIGGER_PIERCE) 
  1697. 		if ( (sync == SYNC_LOCAL) or (sync == SYNC_ALL) ) then 
  1698. 			local hud_bar = HUD_BAR[LOCAL_PLAYER] 
  1699. 			hud_bar_on(hud_bar, "Health", HELPTEXT_HUD_PIERCE_HEALTH, pierce_max_hit_points, SYNC_LOCAL) 
  1700. 			hud_bar_set_range(hud_bar, 0, pierce_max_hit_points, SYNC_ALL) 
  1701. 			hud_bar_set_value(hud_bar, pierce_start_hit_points, SYNC_LOCAL) 
  1702. 		end 
  1703. 		if ( (sync == SYNC_REMOTE) or (sync == SYNC_ALL) ) then 
  1704. 			local hud_bar = HUD_BAR[REMOTE_PLAYER] 
  1705. 			hud_bar_on(hud_bar, "Health", HELPTEXT_HUD_PIERCE_HEALTH, pierce_max_hit_points, SYNC_REMOTE) 
  1706. 			hud_bar_set_range(hud_bar, 0, pierce_max_hit_points, SYNC_ALL) 
  1707. 			hud_bar_set_value(hud_bar, pierce_start_hit_points, SYNC_REMOTE) 
  1708. 		end 
  1709.  
  1710. 	-- Initialize time and damage dividers for health ticks 
  1711. 	local tick_time		=	{} 
  1712. 	local tick_amount		=	{} 
  1713.  
  1714. 	-- Grab some mission parameter values 
  1715. 	local survival_ticks = ep01_get_parameter_value("PIERCE_SURVIVAL_TICKS") 
  1716. 	local survival_time_s= ep01_get_parameter_value("PIERCE_SURVIVAL_TIME_S") 
  1717.  
  1718. 	-- Determine when to apply damage 
  1719. 	tick_time[100]	= true	-- always have the last interval end after the last segment 
  1720. 	local num_dividers	=	1 
  1721. 	while(num_dividers < survival_ticks) do 
  1722. 		local rand_divider = rand_int(1,99) 
  1723. 		if(tick_time[rand_divider] == nil) then 
  1724. 			tick_time[rand_divider] = 1 
  1725. 			num_dividers = num_dividers+1 
  1726. 		end 
  1727. 	end 
  1728.  
  1729. 	-- Determine amount of damage to apply 
  1730. 	tick_amount[100]	= true; 
  1731. 	num_dividers				= 1 
  1732. 	while(num_dividers < survival_ticks) do 
  1733. 		local rand_divider = rand_int(1,99) 
  1734. 		if(tick_amount[rand_divider] == nil) then 
  1735. 			tick_amount[rand_divider] = 1 
  1736. 			num_dividers = num_dividers+1 
  1737. 		end 
  1738. 	end 
  1739. 	 
  1740. 	local summed_damage = 0	-- cumulative damage percent (relative to starting health) 
  1741. 	local summed_time	  = 0 -- cumulative time 
  1742.  
  1743. 	for i=1, num_dividers, 1 do 
  1744.  
  1745. 		summed_damage = summed_damage +1 
  1746. 		summed_time	= summed_time + 1 
  1747. 		local tick_duration = 1 
  1748.  
  1749. 		-- Calculate the percent of time before damage is applied during this tick 
  1750. 		while(tick_time[summed_time] == nil) do 
  1751. 			tick_duration = tick_duration + 1 
  1752. 			summed_time = summed_time + 1 
  1753. 		end		 
  1754.  
  1755. 		-- Calculate the cumulative damage total after this tick is applied 
  1756. 		while(tick_amount[summed_damage] == nil) do 
  1757. 			summed_damage = summed_damage + 1 
  1758. 		end 
  1759.  
  1760. 		-- Delay until the interval has passed 
  1761. 		delay (.01 * tick_duration * survival_time_s) 
  1762.  
  1763. 		local new_health = pierce_start_hit_points * (100 - summed_damage)/100 
  1764. 		if (i ~= num_dividers and new_health < 1) then 
  1765. 			new_healh = 1 
  1766. 		end 
  1767. 		if (i == num_dividers) then 
  1768. 			new_health = 0 
  1769. 		end 
  1770.  
  1771. 		Ep01_pierce_current_health = new_health 
  1772.  
  1773. 		set_current_hit_points(CHARACTER_PIERCE,new_health) 
  1774.  
  1775.  
  1776. 		local sync = ep01_get_sequence_sync(TRIGGER_PIERCE) 
  1777. 		if ( (sync == SYNC_LOCAL) or (sync == SYNC_ALL) ) then 
  1778. 			hud_bar_set_value(HUD_BAR[LOCAL_PLAYER], new_health, SYNC_LOCAL ) 
  1779. 		end 
  1780. 		if ( (sync == SYNC_REMOTE) or (sync == SYNC_ALL) ) then 
  1781. 			hud_bar_set_value(HUD_BAR[REMOTE_PLAYER], new_health, SYNC_REMOTE ) 
  1782. 		end 
  1783.  
  1784. 	end 
  1785.  
  1786. 	-- If we've gotten here, all intervals are processed. Pierce is dead! 
  1787. 	local sync = ep01_get_sequence_sync(TRIGGER_PIERCE) 
  1788. 	if ( (sync == SYNC_LOCAL) or (sync == SYNC_ALL) ) then 
  1789. 		hud_bar_off(HUD_BAR[LOCAL_PLAYER]) 
  1790. 	end 
  1791. 	if ( (sync == SYNC_REMOTE) or (sync == SYNC_ALL) ) then 
  1792. 		hud_bar_off(HUD_BAR[REMOTE_PLAYER]) 
  1793. 	end 
  1794. 	ep01_failure_pierce_died() 
  1795. end 
  1796.  
  1797. function ep01_pierce_maybe_damaged() 
  1798. 	local damaged_chance = .6 
  1799. 	local min_damage = 60 
  1800. 	local max_damage = 100 
  1801. 	local roll = rand_float(0.0,1.0) 
  1802. 	if (roll <= damaged_chance) then 
  1803. 		local new_health = get_current_hit_points(CHARACTER_PIERCE) - rand_int(min_damage, max_damage) 
  1804. 		if (new_health < 0) then 
  1805. 			ep01_failure_pierce_died() 
  1806. 		else 
  1807. 			set_current_hit_points(CHARACTER_PIERCE,new_health) 
  1808. 			local sync = ep01_get_sequence_sync(TRIGGER_PIERCE) 
  1809. 			if ( (sync == SYNC_LOCAL) or (sync == SYNC_ALL) ) then 
  1810. 				hud_bar_set_value(HUD_BAR[LOCAL_PLAYER], new_health, SYNC_LOCAL ) 
  1811. 			end 
  1812. 			if ( (sync == SYNC_REMOTE) or (sync == SYNC_ALL) ) then 
  1813. 				hud_bar_set_value(HUD_BAR[REMOTE_PLAYER], new_health, SYNC_REMOTE ) 
  1814. 			end 
  1815. 		end 
  1816. 	end 
  1817. end 
  1818.  
  1819. ep01_enemies_to_kill = 0 
  1820. ep01_enemies_living = 0 
  1821. ep01_enemy_set_objective_helptext = "" 
  1822.  
  1823. -- Wait for the player to kill a group of enemies 
  1824. --  
  1825. -- enemy_table				A table containing the names of the enemies that need to be killed 
  1826. -- mission_helptext		The helptext message that will prompt the player(s) to kill the enemies 
  1827. -- objective_helptext	The objective text displayed in the hud, needs to be in the format %s of %s remaining 
  1828. -- sync						The initial sync type for hud elements 
  1829. function ep01_process_enemy_set(enemy_table, mission_helptext, objective_helptext, sync) 
  1830.  
  1831. 	-- Assign enemy callbacks, add markers 
  1832. 	for i, enemy in pairs(enemy_table) do 
  1833. 		on_death("ep01_enemy_killed", enemy) 
  1834. 		marker_add_npc(enemy, MINIMAP_ICON_KILL, INGAME_EFFECT_KILL, sync)  
  1835. 	end 
  1836.  
  1837. 	-- Setup kill tracking numbers 
  1838. 	ep01_enemies_to_kill = sizeof_table(enemy_table) 
  1839. 	ep01_enemies_living =  ep01_enemies_to_kill 
  1840.  
  1841. 	-- Display the objective text 
  1842. 	if(objective_helptext) then 
  1843. 		ep01_enemy_set_objective_helptext = objective_helptext 
  1844. 		objective_text(0, ep01_enemy_set_objective_helptext, ep01_enemies_to_kill - ep01_enemies_living, ep01_enemies_to_kill, sync) 
  1845. 	end 
  1846.  
  1847. 	-- Display the help text 
  1848. 	if(mission_helptext) then 
  1849. 		mission_help_table(mission_helptext, "", "", sync) 
  1850. 	end 
  1851.  
  1852. 	while (ep01_enemies_living > 0) do 
  1853. 		thread_yield() 
  1854. 	end 
  1855.  
  1856. end 
  1857.  
  1858. function ep01_enemy_killed(enemy) 
  1859. 	marker_remove_npc(enemy) 
  1860. 	on_death("",enemy) 
  1861. 	ep01_enemies_living = ep01_enemies_living - 1 
  1862. 	if (ep01_enemies_living < 1) then 
  1863. 		objective_text_clear(0) 
  1864. 		ep01_enemy_set_objective_helptext = "" 
  1865. 	else 
  1866. 		if (ep01_enemy_set_objective_helptext ~= "") then 
  1867. 			local sync = ep01_get_sequence_sync(TRIGGER_PIERCE) 
  1868. 			objective_text(0, ep01_enemy_set_objective_helptext, ep01_enemies_to_kill - ep01_enemies_living, ep01_enemies_to_kill, sync) 
  1869. 		end 
  1870. 	end 
  1871. end 
  1872.  
  1873. -- Other functions 
  1874.  
  1875. function ep01_cleanup() 
  1876.  
  1877. 	IN_COOP = coop_is_active() 
  1878.  
  1879. 	hud_bar_off(HUD_BAR[LOCAL_PLAYER]) 
  1880. 	if (IN_COOP) then 
  1881. 		hud_bar_off(HUD_BAR[REMOTE_PLAYER]) 
  1882. 	end 
  1883.  
  1884. 	-- Reallow action spawning 
  1885. 	action_nodes_enable(true) 
  1886.  
  1887. 	-- Reallow ped spawning (may be disabled in single-player) 
  1888. 	spawning_pedestrians(true) 
  1889.  
  1890. 	-- Stop having existing peds flee 
  1891. 	city_chunk_set_all_civilians_fleeing("sr2_chunk104", false) 
  1892. 	city_chunk_set_all_civilians_fleeing("sr2_chunk105", false) 
  1893.  
  1894. 	-- Allow Shaundi and Pierce to be summoned via the cell phone again. 
  1895. 	homie_mission_unlock("Pierce") 
  1896. 	homie_mission_unlock("Shaundi") 
  1897.  
  1898. 	-- Get rid of the any mid-mission phone calls 
  1899. 	mid_mission_phonecall_reset() 
  1900.  
  1901. 	-- Make the players vulnerable again 
  1902. 	turn_vulnerable(LOCAL_PLAYER) 
  1903. 	if (IN_COOP) then 
  1904. 		turn_vulnerable(REMOTE_PLAYER) 
  1905. 	end 
  1906.  
  1907. 	-- Kill threads 
  1908. 		thread_kill(Thread_pierce_health) 
  1909.  
  1910. 	-- reset global variables 
  1911.  
  1912. 	-- reset notoriety 
  1913. 		 
  1914. 		-- Reset min/max Police notoriety 
  1915. 		notoriety_reset("Police") 
  1916.  
  1917. 		-- Set player's police notoriety back to the level it was at when the mission started. 
  1918. 		--notoriety_set("Police", Ep_starting_police_notoriety) 
  1919.  
  1920. 	-- remove markers 
  1921.  
  1922. 	-- remove callbacks 
  1923.  
  1924. 		-- disable all triggers, remove callbacks, remove from map 
  1925. 		for i, trigger in pairs(TABLE_ALL_TRIGGERS) do 
  1926. 			on_trigger("",trigger) 
  1927. 			trigger_enable(trigger,false) 
  1928. 			marker_remove_trigger(trigger) 
  1929. 		end 
  1930. 	 
  1931. end 
  1932.  
  1933. function ep01_success() 
  1934. 	-- Called when the mission has ended with success 
  1935. end 
  1936.  
  1937. function ep01_complete() 
  1938.  
  1939. 	-- Play the outro cutscene 
  1940. 	--bink_play_movie("tsse01-2.bik") 
  1941.  
  1942. 	-- End the mission with success 
  1943. 	mission_end_success("ep01", "tsse01_02", {NAVPOINT_LOCAL_SUCCESS,NAVPOINT_REMOTE_SUCCESS}) 
  1944. end 
  1945.  
  1946. -- Get the value of the sync type for a sequence 
  1947. -- 
  1948. -- sequence The name of the sequence (name of the start trigger) 
  1949. -- 
  1950. -- Returns mission paramater value. 
  1951. function ep01_get_sequence_sync(sequence) 
  1952.  
  1953. 	local should_sync_local		= (Player_sequence_begun[LOCAL_PLAYER] == sequence) 
  1954. 	local should_sync_remote	= (Player_sequence_begun[REMOTE_PLAYER] == sequence) 
  1955.  
  1956. 	if(should_sync_local and should_sync_remote) then 
  1957. 		return SYNC_ALL 
  1958. 	elseif (should_sync_remote) then 
  1959. 		return SYNC_REMOTE 
  1960. 	else 
  1961. 		return SYNC_LOCAL 
  1962. 	end 
  1963.  
  1964. end 
  1965.  
  1966. -- Get the value of the mission parameter. 
  1967. -- 
  1968. -- parameter	Mission parameter whose value the function should return 
  1969. --	i				If the parameter is a table, then i indexes the entry that should be returned 
  1970. -- 
  1971. -- Returns mission paramater value. 
  1972. function ep01_get_parameter_value(parameter, i) 
  1973.  
  1974. 	local return_val = nil 
  1975.  
  1976. 	-- Check for a coop value: 
  1977. 	if (IN_COOP) then 
  1978. 		if (i) then 
  1979. 			if (EP01_PARAMETERS["COOP_" .. parameter] ~= nil) then 
  1980. 				return_val = EP01_PARAMETERS["COOP_" .. parameter][i] 
  1981. 			end 
  1982. 		else 
  1983. 			return_val = EP01_PARAMETERS["COOP_" .. parameter] 
  1984. 		end 
  1985. 	end 
  1986.  
  1987. 	-- Get the standard value 
  1988. 	if (return_val == nil) then 
  1989. 		if (i) then 
  1990. 			if (EP01_PARAMETERS[parameter] ~= nil) then 
  1991. 				return_val = EP01_PARAMETERS[parameter][i] 
  1992. 			end 
  1993. 		else 
  1994. 			return_val = EP01_PARAMETERS[parameter] 
  1995. 		end 
  1996. 	end 
  1997.  
  1998. 	return return_val 
  1999. end 
  2000.  
  2001. function ep01_group_create_maybe_coop(group_always, group_coop, blocking) 
  2002. 	group_create(group_always, blocking) 
  2003. 	if (IN_COOP) then 
  2004. 		group_create(group_coop, blocking) 
  2005. 	end 
  2006. end 
  2007.  
  2008. function ep01_release_to_world_maybe_coop(always, coop) 
  2009. 	release_to_world(always) 
  2010. 	if (IN_COOP) then 
  2011. 		release_to_world(coop) 
  2012. 	end 
  2013. end 
  2014.  
  2015. -- MISSION FAILURE FUNCTIONS -------------------------------- 
  2016.  
  2017. function ep01_failure_shaundi_abandoned() 
  2018. 	-- End the mission, Shaundi abandoned 
  2019. 	mission_end_failure("ep01", HELPTEXT_FAILURE_SHAUNDI_ABANDONED) 
  2020. end 
  2021.  
  2022. function ep01_failure_shaundi_died() 
  2023. 	-- End the mission, Shaundi died 
  2024. 	mission_end_failure("ep01", HELPTEXT_FAILURE_SHAUNDI_DIED) 
  2025. end 
  2026.  
  2027. function ep01_failure_pierce_abandoned() 
  2028. 	-- End the mission, Pierce abandoned 
  2029. 	mission_end_failure("ep01", HELPTEXT_FAILURE_PIERCE_ABANDONED) 
  2030. end 
  2031.  
  2032. function ep01_failure_pierce_died() 
  2033. 	-- End the mission, Pierce died 
  2034. 	mission_end_failure("ep01", HELPTEXT_FAILURE_PIERCE_DIED) 
  2035. end 
  2036.