sr2lua/tss04.lua

  1. -- tss04.lua 
  2. -- SR2 mission script 
  3. -- 3/27/08 
  4.  
  5. -- Global Variables -- 
  6.  
  7. -- This factor is applied to player damage in single player.  
  8. SINGLE_PLAYER_DAMAGE_MULTIPLIER = 0.50 
  9.  
  10. -- This factor is applied to player damage in co-op. 
  11. COOP_DAMAGE_MULTIPLIER = 0.75 
  12.  
  13. CHARACTER_SHAUNDI					= "tss04_$Shaundi" 
  14. CHARACTER_CARLOS					= "tss04_$Carlos" 
  15. CHARACTER_PIERCE					= "tss04_$Pierce" 
  16.  
  17. -- Index/Trigger --> Character, Checkpoing Name, Completed 
  18. Tss04_3_phase_table				= {{CHARACTER_SHAUNDI,	"Shaundi",	false, INVALID_THREAD_HANDLE, INVALID_THREAD_HANDLE},  
  19. 											{CHARACTER_CARLOS,	"Carlos",	false, INVALID_THREAD_HANDLE, INVALID_THREAD_HANDLE},  
  20. 											{CHARACTER_PIERCE,	"Pierce",	false, INVALID_THREAD_HANDLE, INVALID_THREAD_HANDLE}} 
  21.  
  22. Tss04_recruit_table_index		= {[CHARACTER_SHAUNDI] = 1, [CHARACTER_CARLOS] = 2, [CHARACTER_PIERCE] = 3} 
  23.  
  24. Tss04_3_phase_table_size		= 3 
  25.  
  26. -- This needs to come after Shaundi, Carlos, and Pierce being defined... 
  27. Tss04_carlos_reacquaint			= {{"TSSP4_REACQUAINT_L1",				CHARACTER_CARLOS,	0.2}, 
  28. 											{"PLAYER_TSSP4_REACQUAINT_L2",	LOCAL_PLAYER,		0.2}, 
  29. 											{"TSSP4_REACQUAINT_L3",				CHARACTER_CARLOS,	0.2}, 
  30. 											{"PLAYER_TSSP4_REACQUAINT_L4",	LOCAL_PLAYER,		0.2}, 
  31. 											{"TSSP4_REACQUAINT_L5",				CHARACTER_CARLOS,	0.2}, 
  32. 											{"PLAYER_TSSP4_REACQUAINT_L6",	LOCAL_PLAYER,		0.2}} 
  33.  
  34. Tss04_carlos_phone_call			= {{"CARLOS_TSSP4_RANDOM_CALL_01",	CELLPHONE_CHARACTER,	0}, 
  35. 											{"CARLOS_TSSP4_RANDOM_CALL_02",	CELLPHONE_CHARACTER,	1}, 
  36. 											{"CARLOS_TSSP4_RANDOM_CALL_03",	CELLPHONE_CHARACTER,	2}} 
  37.  
  38. Tss04_shaundi_in_exchange		= {{"TSSP04_SHAUNDI_FINISHED_1",	CHARACTER_SHAUNDI, 0.25, "talk with respect" }} 
  39.  
  40. Tss04_carlos_in_exchange		= {{"TSSP4_CARLOS_IN_L1",			CHARACTER_CARLOS,		0.25, "talk submissive" }, 
  41. 											{"PLAYER_TSSP4_CARLOS_IN_L2",	LOCAL_PLAYER,			rand_int(0.1, 0.25)}, 
  42. 											{"TSSP4_CARLOS_IN_L3",			CHARACTER_CARLOS,		rand_int(0.1, 0.25) }} 
  43.  
  44. Tss04_pierce_in_exchange		= {{"TSSP4_PIERCE_IN_L1",			CHARACTER_PIERCE,		0.25, "talk yes" }, 
  45. 											{"PLAYER_TSSP4_PIERCE_IN_L2",	LOCAL_PLAYER,			rand_int(0.1, 0.25)}, 
  46. 											{"TSSP4_PIERCE_IN_L3",			CHARACTER_PIERCE,		rand_int(0.1, 0.25)}} 
  47.  
  48. Tss04_in_saints_exchange		= {[CHARACTER_SHAUNDI]	= Tss04_shaundi_in_exchange,  
  49. 											[CHARACTER_CARLOS]	= Tss04_carlos_in_exchange,  
  50. 											[CHARACTER_PIERCE]	= Tss04_pierce_in_exchange} 
  51.  
  52. Tss04_shaundi_back_exchange	= {{"PLAYER_TSSP4_SHAUNDI_BACK_L1",	LOCAL_PLAYER,			0.25}, 
  53. 											{"TSSP4_SHAUNDI_BACK_L2",			CHARACTER_SHAUNDI,	0.25, "talk yes" }} 
  54.  
  55. Tss04_carlos_back_exchange		= {{"PLAYER_TSSP4_CARLOS_BACK_L1",	LOCAL_PLAYER,			0.25}, 
  56. 											{"TSSP4_CARLOS_BACK_L2",			CHARACTER_CARLOS,		0.25, "talk yes" }} 
  57.  
  58. Tss04_pierce_back_exchange		= {{"PLAYER_TSSP4_PIERCE_BACK_L1",	LOCAL_PLAYER,			0.25}, 
  59. 											{"TSSP4_PIERCE_BACK_L2",			CHARACTER_PIERCE,		0.25, "talk yes" }} 
  60.  
  61. Tss04_back_to_hq_exchange		= {[CHARACTER_SHAUNDI]	= Tss04_shaundi_back_exchange,  
  62. 											[CHARACTER_CARLOS]	= Tss04_carlos_back_exchange,  
  63. 											[CHARACTER_PIERCE]	= Tss04_pierce_back_exchange} 
  64.  
  65. SHAUNDI_PERSONA_OVERRIDES = { { POT_SITUATIONS[POT_ATTACK], "SHAUNDI_TSSP4_ATTACK" }, 
  66. 										{ POT_SITUATIONS[POT_TAKE_DAMAGE], "SHAUNDI_TSSP4_TAKDAM" }, 
  67. 										{ POT_SITUATIONS[POT_PRAISED_BY_PC], "TSSP04_SHAUNDI_PRAISED" }, 
  68. 										{ POT_SITUATIONS[POT_TAUNTED_BY_PC], "TSSP04_SHAUNDI_TAUNT" }, 
  69. 										{ POT_SITUATIONS[POT_BARTER], "TSSP04_SHAUNDI_BARTER" }, 
  70. 										{ POT_SITUATIONS[POT_HIT_CAR], "TSSP04_SHAUNDI_HITCAR" }, 
  71. 										{ POT_SITUATIONS[POT_HIT_OBJ], "TSSP04_SHAUNDI_HITOBJ" }, 
  72. 										{ POT_SITUATIONS[POT_HIT_PED], "TSSP04_SHAUNDI_HITPED" } } 
  73.  
  74. CARLOS_PERSONA_OVERRIDES = { { POT_SITUATIONS[POT_ATTACK], "CARLOS_TSSP4_ATTACK" }, 
  75. 									  { POT_SITUATIONS[POT_TAKE_DAMAGE], "CARLOS_TSSP4_TAKDAM" }, 
  76. 									  { POT_SITUATIONS[POT_PRAISED_BY_PC], "CARLOS_TSSP4_PRAISE" }, 
  77. 									  { POT_SITUATIONS[POT_TAUNTED_BY_PC], "CARLOS_TSSP4_TAUNT" }, 
  78. 									  { POT_SITUATIONS[POT_BARTER], "CARLOS_TSSP4_BARTER" }, 
  79. 									  { POT_SITUATIONS[POT_HIT_CAR], "CARLOS_TSSP4_HITCAR" }, 
  80. 									  { POT_SITUATIONS[POT_HIT_OBJ], "CARLOS_TSSP4_HITOBJ" }, 
  81. 									  { POT_SITUATIONS[POT_HIT_PED], "CARLOS_TSSP4_HITPED" } } 
  82.  
  83. PIERCE_PERSONA_OVERRIDES = { { POT_SITUATIONS[POT_ATTACK], "PIERCE_TSSP4_ATTACK" }, 
  84. 									  { POT_SITUATIONS[POT_TAKE_DAMAGE], "PIERCE_TSSP4_TAKDAM" }, 
  85. 									  { POT_SITUATIONS[POT_PRAISED_BY_PC], "PIERCE_TSSP4_PRAISE" }, 
  86. 									  { POT_SITUATIONS[POT_TAUNTED_BY_PC], "PIERCE_TSSP4_TAUNT" }, 
  87. 									  { POT_SITUATIONS[POT_BARTER], "PIERCE_TSSP4_BARTER" }, 
  88. 									  { POT_SITUATIONS[POT_HIT_CAR], "PIERCE_TSSP4_HITCAR" }, 
  89. 									  { POT_SITUATIONS[POT_HIT_OBJ], "PIERCE_TSSP4_HITOBJ" }, 
  90. 									  { POT_SITUATIONS[POT_HIT_PED], "PIERCE_TSSP4_HITPED" }, 
  91. 									  { POT_SITUATIONS[POT_GRATS_PC], "PIERCE_TSSP4_GRATS" } } 
  92.  
  93. Tss04_lieutenant_persona_overrides = { [CHARACTER_SHAUNDI] = SHAUNDI_PERSONA_OVERRIDES,  
  94. 													[CHARACTER_CARLOS] = CARLOS_PERSONA_OVERRIDES,  
  95. 													[CHARACTER_PIERCE] = PIERCE_PERSONA_OVERRIDES } 
  96.  
  97. Tss04_mourners						= {"tss04_$c000", "tss04_$c000 (0)", "tss04_$c001", "tss04_$c001 (0)", "tss04_$c002"} 
  98. Tss04_trash							= {"tss04_$c003", "tss04_$c003 (0)", "tss04_$c003 (1)", "tss04_$c004", "tss04_$c004 (0)"} 
  99.  
  100. Num_tss04_mourners				= sizeof_table(Tss04_mourners) 
  101. Num_tss04_trash					= sizeof_table(Tss04_trash) 
  102.  
  103. Tss04_ronin							= {"tss04_$ronin_sl1", "tss04_$ronin_sl2", "tss04_$ronin_sl3",  
  104. 											"tss04_$ronin_lt1", "tss04_$ronin_sl2 (0)", "tss04_$ronin_sl3 (0)",  
  105. 											"tss04_$ronin_lt1 (0)", "tss04_$ronin_sl3 (1)", "tss04_$ronin_lt1 (1)"} 
  106. Num_tss04_ronin					= sizeof_table(Tss04_ronin) 
  107.  
  108. Tss04_ronin_group1				= {"tss04_$ronin_lt1 (1)", "tss04_$ronin_sl3 (1)"}  
  109. Tss04_ronin_group2				= {"tss04_$ronin_lt1 (0)", "tss04_$ronin_sl2 (0)", "tss04_$ronin_sl3 (0)"}  
  110. Tss04_ronin_group3				= {"tss04_$ronin_lt1", "tss04_$ronin_sl1", "tss04_$ronin_sl2", "tss04_$ronin_sl3"}  
  111.  
  112. Num_tss04_ronin_group1			= sizeof_table(Tss04_ronin_group1) 
  113. Num_tss04_ronin_group2			= sizeof_table(Tss04_ronin_group2) 
  114. Num_tss04_ronin_group3			= sizeof_table(Tss04_ronin_group3) 
  115.  
  116. Tss04_tow_trucks					= {"tss04_$towtruck1", "tss04_$towtruck2"} 
  117. Num_tss04_tow_trucks				= sizeof_table(Tss04_tow_trucks) 
  118.  
  119. Tss01_tow_truck_entered			= {["tss04_$towtruck1"] = false, ["tss04_$towtruck2"] = false} 
  120. Tss04_carlos_has_phoned_buddy = false 
  121.  
  122. Tss04_player1_kills				= 0 
  123. Tss04_player2_kills				= 0 
  124.  
  125. Tss04_ronin_kills             = 0 
  126.  
  127. Tss04_stunt_jumps					= {"tss04_$t002", "tss04_$t003", "tss04_$t004"} 
  128. Tss04_stunt_jumps_idx			= {["tss04_$t002"] = 1, ["tss04_$t003"] = 2, ["tss04_$t004"] = 3} 
  129. Num_tss04_stunt_jumps			= sizeof_table(Tss04_stunt_jumps) 
  130.  
  131. Tss04_player1_jump				= 0 
  132. Tss04_player2_jump				= 0 
  133.  
  134. Tss04_coop_winner					= "" 
  135.  
  136. STUNT_JUMP_EFFECT					= "icon_race_empty" 
  137.  
  138. LOCATION_START						= "mission_start_sr2_city_$tss04" 
  139. LOCATION_START_PLAYER_2			= "tss04_$remote_player_start" 
  140.  
  141. IN_COOP								= false 
  142. PHASE_ACTIVE						= false 
  143. PLAYER_IN_STUNT_AREA				= false 
  144.  
  145. GROUP_START_VEHICLES				= "tss04_$start_vehicles" 
  146. GROUP_STUNT_VEHICLES				= "tss04_$stunt_vehicles" 
  147. GROUP_TOWTRUCK_1					= "tss04_$towtruck1" 
  148. GROUP_TOWTRUCK_2					= "tss04_$towtruck2" 
  149. GROUP_TOWED_VEHICLE				= "tss04_$towed_vehicle" 
  150. GROUP_TOWED_VEHICLE_COOP		= "tss04_$towed_vehicle_coop" 
  151. GROUP_RONIN							= "tss04_$ronin" 
  152.  
  153. STUNTS_INDEX						= 1 
  154. TOWTRUCK_INDEX						= 2 
  155. KILLING_INDEX						= 3 
  156. LT_ACTIVATION_DISTANCE			= 4 
  157.  
  158. CHARACTER_INDEX					= 1 
  159. CHECKPOINT_INDEX					= 2 
  160. COMPLETED_INDEX					= 3 
  161. LOAD_THREAD_INDEX					= 4 
  162. MOVE_THREAD_INDEX					= 5 
  163.  
  164. LOCAL_TOWED_VEHICLE				= "tss04_$v005" 
  165. REMOTE_TOWED_VEHICLE				= "tss04_$v008" 
  166. TOWED_VEHICLE_TRIGGER			= "tss04_$in_garage" 
  167. GARAGE_OPEN_TRIGGER				= "tss04_$open_garage" 
  168. TOWED_COMPLETE_TRIGGER			= "tss04_$tow_finished" 
  169. SUBURBS_TRIGGER					= "tss04_$suburbs" 
  170.  
  171. GARAGE_DOOR_MOVER					= "garage_sr2_city_SU_mech_door" 
  172.  
  173. TRIGGER_DISABLED_1				= "garage_sr2_city_$SU_mech_ext" 
  174. TRIGGER_DISABLED_2				= "garage_sr2_city_$SU_mech_store" 
  175.  
  176. MISSION_FINISHED_TRIGGER		= "tss04_$finish" 
  177.  
  178. START_PHASE_THREAD				= INVALID_THREAD_HANDLE 
  179. TOWTRUCK_REGENERATE				= INVALID_THREAD_HANDLE 
  180.  
  181. CT_INTRO = "tssp04-01" 
  182. CT_OUTRO = "tssp04-02" 
  183.  
  184. LIEUTENANT_LEAVE_VEHICLE_MAX_SPEED_MPH = 5 
  185.  
  186. Correct_vehicle_hitched = { [LOCAL_PLAYER] = false, [REMOTE_PLAYER] = false } 
  187.  
  188. function tss04_start(checkpoint, is_restart) 
  189. 	-- Start trigger is hit...the activate button was hit  
  190. 	set_mission_author("Ryan Spencer") 
  191.  
  192. 	-- Check for coop being active 
  193. 	if (coop_is_active()) then 
  194. 		IN_COOP	= true 
  195. 	end 
  196.  
  197. 	-- Reduce the amount of damage applied to the players 
  198. 	if (IN_COOP) then 
  199. 		character_set_damage_multiplier(REMOTE_PLAYER, COOP_DAMAGE_MULTIPLIER) 
  200. 		character_set_damage_multiplier(LOCAL_PLAYER, COOP_DAMAGE_MULTIPLIER) 
  201. 	else 
  202. 		character_set_damage_multiplier(LOCAL_PLAYER, SINGLE_PLAYER_DAMAGE_MULTIPLIER) 
  203. 	end 
  204.  
  205. 	notoriety_force_no_spawn("Ronin", true) 
  206. 	ambient_gang_spawn_enable(false) 
  207. 	notoriety_set_max("Police", 2) 
  208. 	notoriety_set_max("Ronin", 2) 
  209.  
  210.    mission_start_fade_out() 
  211.    if ( checkpoint == MISSION_START_CHECKPOINT ) then 
  212. 	if (not is_restart) then 
  213. 		cutscene_play( CT_INTRO, "", "", true ) 
  214. 	end 
  215.    end 
  216.  
  217. 	-- Check to see if we are starting from the beginning 
  218. 	if (checkpoint == MISSION_START_CHECKPOINT) then 
  219. 		-- Teleport the player(s) to where they will need to be 
  220. 		teleport_coop(LOCATION_START, LOCATION_START_PLAYER_2) 
  221.  
  222. 		-- We need to create both of these groups since the mission is starting from the beginning 
  223. 		group_create(GROUP_START_VEHICLES, true) 
  224. 		group_create(GROUP_STUNT_VEHICLES, false) 
  225.  
  226. 		-- Always be looking to regenerate the tow trucks 
  227. 		TOWTRUCK_REGENERATE = thread_new("tss04_regenerate_towtrucks") 
  228.  
  229. 		-- Add a minimap icon 
  230. 		minimap_icon_add_navpoint(SUBURBS_TRIGGER, MINIMAP_ICON_LOCATION, "", SYNC_ALL) 
  231. 		trigger_enable(SUBURBS_TRIGGER, true) 
  232. 		on_trigger("tss04_recruit_lieutenants", SUBURBS_TRIGGER) 
  233.  
  234. 		-- Add a waypoint 
  235. 		waypoint_add(SUBURBS_TRIGGER, SYNC_ALL) 
  236. 	else 
  237.       -- There is at least one phase that still needs to be completed 
  238.       for i = 1, Tss04_3_phase_table_size, 1 do 
  239.          if (strstr(checkpoint, Tss04_3_phase_table[i][CHECKPOINT_INDEX])) then 
  240.             -- Mark the checkpoint as complete 
  241.             Tss04_3_phase_table[i][COMPLETED_INDEX] = true 
  242.          else 
  243.             -- Add a minimap icon 
  244.             --marker_add_npc( Tss04_3_phase_table[i][CHARACTER_INDEX], MINIMAP_ICON_PROTECT_ACQUIRE, INGAME_EFFECT_PROTECT_ACQUIRE, SYNC_ALL ) 
  245.             minimap_icon_add_navpoint(Tss04_3_phase_table[i][CHARACTER_INDEX], MINIMAP_ICON_PROTECT_ACQUIRE, "", SYNC_ALL) 
  246.             --mission_debug( "Start: added minimap icon for "..Tss04_3_phase_table[i][CHARACTER_INDEX], 20 ) 
  247.             -- Create the load thread 
  248.             Tss04_3_phase_table[i][LOAD_THREAD_INDEX] = thread_new("tss04_load_lieutenant", Tss04_3_phase_table[i][CHARACTER_INDEX], 270.0) 
  249.  
  250.             -- Check to see if we need to create any of the vehicle groups 
  251.             if (i == STUNTS_INDEX) then 
  252.                -- We need these vehicles for stunts 
  253.                group_create(GROUP_STUNT_VEHICLES, true) 
  254.             elseif (i == TOWTRUCK_INDEX) then 
  255.                -- Always be looking to regenerate the tow trucks 
  256.                TOWTRUCK_REGENERATE = thread_new("tss04_regenerate_towtrucks") 
  257.             end 
  258.          end 
  259.       end 
  260. 	end 
  261.  
  262. 	-- Reset the garage door 
  263. 	mesh_mover_reset(GARAGE_DOOR_MOVER) 
  264.  
  265. 	-- Disable the Rim Job triggers for Carlos' activity 
  266. 	trigger_enable(TRIGGER_DISABLED_1, false) 
  267. 	trigger_enable(TRIGGER_DISABLED_2, false) 
  268.  
  269.    mission_start_fade_in() 
  270.  
  271. 	START_PHASE_THREAD = thread_new("tss04_start_phase_try") 
  272.  
  273. 	-- Tell the player(s) what to do 
  274. 	if (checkpoint == MISSION_START_CHECKPOINT) then 
  275. 		delay(2.0) 
  276. 		-- Tell the player(s) to go to the suburbs 
  277. 		mission_help_table("tss04_suburbs") 
  278. 	elseif (checkpoint == "ShaundiCarlosPierce") then 
  279. 		delay(2.0) 
  280. 		-- Tell the player(s) to go back to the headquarters 
  281. 		mission_help_table("tss04_back_to_hq") 
  282. 	end 
  283. end 
  284.  
  285. function tss04_cleanup() 
  286. 	-- Cleanup mission here 
  287.  
  288. 	ambient_gang_spawn_enable(true) 
  289.  
  290. 	-- Reset IN_COOP in case mission end was triggered by a disconnect 
  291. 	IN_COOP = coop_is_active() 
  292.  
  293. 	-- Reset the amount of damage applied to the players 
  294. 	character_set_damage_multiplier(LOCAL_PLAYER, 1.0) 
  295. 	if (IN_COOP) then 
  296. 		character_set_damage_multiplier(REMOTE_PLAYER, 1.0) 
  297. 	end 
  298.  
  299. 	-- Kill the start phase thread 
  300. 	thread_kill(START_PHASE_THREAD) 
  301. 	thread_kill(TOWTRUCK_REGENERATE) 
  302.  
  303. 	-- Remove the waypoint if it still exists 
  304. 	waypoint_remove(SYNC_ALL) 
  305.  
  306. 	-- Cleanup the phase table 
  307. 	for i = 1, Tss04_3_phase_table_size, 1 do 
  308. 		local lieutenant_name = Tss04_3_phase_table[i][CHARACTER_INDEX] 
  309.  
  310.       --marker_remove_npc( Tss04_3_phase_table[i][CHARACTER_INDEX], SYNC_ALL ) 
  311. 		minimap_icon_remove_navpoint( lieutenant_name, SYNC_ALL ) 
  312. 		-- Remove the on death 
  313. 		on_death("", lieutenant_name ) 
  314.  
  315. 		if (character_exists(lieutenant_name)) then 
  316. 			for index, override in pairs( Tss04_lieutenant_persona_overrides[lieutenant_name] ) do 
  317. 				persona_override_character_stop( lieutenant_name, override[1] ) 
  318. 			end 
  319. 		end 
  320. 	end 
  321.  
  322. 	-- Reset notoriety 
  323. 	notoriety_reset("Police") 
  324. 	notoriety_reset("Ronin") 
  325. 	notoriety_force_no_spawn("Ronin", false) 
  326.  
  327.  
  328. 	-- Remove the markers 
  329. 	minimap_icon_remove_navpoint(SUBURBS_TRIGGER) 
  330.  
  331. 	marker_remove_group(GROUP_RONIN, SYNC_ALL) 
  332. 	marker_remove_vehicle(LOCAL_TOWED_VEHICLE, SYNC_LOCAL) 
  333.   
  334. 	for index, truck_name in pairs( Tss04_tow_trucks ) do 
  335. 		marker_remove_vehicle( truck_name, SYNC_ALL ) 
  336. 	end 
  337.  
  338. 	if (IN_COOP) then 
  339. 		marker_remove_vehicle(REMOTE_TOWED_VEHICLE, SYNC_REMOTE) 
  340. 	end 
  341. 	marker_remove_trigger(TOWED_VEHICLE_TRIGGER, SYNC_ALL) 
  342.  
  343. 	-- Remove any callbacks 
  344. 	for i = 1, Num_tss04_ronin, 1 do 
  345. 		on_death("", Tss04_ronin[i]) 
  346. 	end 
  347.  
  348. 	if (IN_COOP) then 
  349. 		on_random_human_killed("", "tss04") 
  350. 	end 
  351.  
  352. 	on_vehicle_destroyed("", LOCAL_TOWED_VEHICLE) 
  353. 	if (IN_COOP) then 
  354. 		on_vehicle_destroyed("", REMOTE_TOWED_VEHICLE) 
  355. 	end 
  356.  
  357. 	-- Enable the Rim Job triggers that were disabled for Carlos' activity 
  358. 	trigger_enable(TRIGGER_DISABLED_1, true) 
  359. 	trigger_enable(TRIGGER_DISABLED_2, true) 
  360.  
  361. 	-- Disable any triggers that may have been enabled 
  362. 	trigger_enable(MISSION_FINISHED_TRIGGER, false) 
  363. 	trigger_enable(TOWED_VEHICLE_TRIGGER, false) 
  364. 	trigger_enable(GARAGE_OPEN_TRIGGER, false) 
  365.    trigger_type_enable( "car mechanic", true ) 
  366.  
  367. 	-- Release the groups to the world		 
  368. 	release_to_world(GROUP_START_VEHICLES) 
  369. 	release_to_world(GROUP_STUNT_VEHICLES) 
  370. 	release_to_world(GROUP_TOWTRUCK_1) 
  371. 	release_to_world(GROUP_TOWTRUCK_2) 
  372. 	release_to_world(GROUP_TOWED_VEHICLE) 
  373. 	release_to_world(GROUP_TOWED_VEHICLE_COOP) 
  374. 	release_to_world(GROUP_RONIN) 
  375.  
  376.    hud_timer_stop( 0 ) 
  377.  
  378.    mission_cleanup_maybe_reenable_player_controls() 
  379. end 
  380.  
  381. function tss04_success() 
  382. 	-- Called when the mission has ended with success 
  383.  
  384. 	-- Post the news event 
  385. 	radio_post_event("JANE_NEWS_TSSP04", true) 
  386.  
  387. 	-- Unlock heli activities. Both instances include cutscenes w/ Shaundi and Pierce who 
  388. 	-- aren't introduced until this mission. Most activities are unlocked after tss02. 
  389. 	mission_unlock("heli_br") 
  390. 	mission_unlock("heli_tp") 
  391.  
  392. 	-- Let players recruit again 
  393. 	party_set_recruitable(true) 
  394. end 
  395.  
  396. function tss04_recruit_lieutenants() 
  397. 	-- Disable this trigger 
  398. 	trigger_enable(SUBURBS_TRIGGER, false) 
  399.  
  400. 	-- Remove a minimap icon 
  401. 	minimap_icon_remove_navpoint(SUBURBS_TRIGGER, SYNC_ALL) 
  402. 	-- Remove the waypoint 
  403. 	waypoint_remove(SYNC_ALL) 
  404.  
  405. 	-- Tell the player(s) to recruit 
  406. 	mission_help_table("tss04_recruit") 
  407.  
  408. 	-- Show the lieutenants 
  409. 	for i = 1, Tss04_3_phase_table_size, 1 do 
  410. 		-- Add a minimap icon 
  411.       --marker_add_npc( Tss04_3_phase_table[i][CHARACTER_INDEX], MINIMAP_ICON_PROTECT_ACQUIRE, INGAME_EFFECT_PROTECT_ACQUIRE, SYNC_ALL ) 
  412. 		minimap_icon_add_navpoint(Tss04_3_phase_table[i][CHARACTER_INDEX], MINIMAP_ICON_PROTECT_ACQUIRE, "", SYNC_ALL) 
  413.       --mission_debug( "Recruit: added minimap icon for "..Tss04_3_phase_table[i][CHARACTER_INDEX], 20 ) 
  414. 		-- Create the load thread 
  415. 		Tss04_3_phase_table[i][LOAD_THREAD_INDEX] = thread_new("tss04_load_lieutenant", Tss04_3_phase_table[i][CHARACTER_INDEX], 270.0) 
  416. 	end 
  417.  
  418. 	-- We do not need these vehicles anymore =P 
  419. 	release_to_world(GROUP_START_VEHICLES) 
  420. end 
  421.  
  422. function tss04_load_lieutenant(human, dist) 
  423. 	-- Now continuously look to load this human if we are close enough 
  424. 	while (1) do 
  425. 		thread_yield() 
  426.  
  427. 		-- Only process this if the player is looking for another phase to participate in 
  428. 		if (not PHASE_ACTIVE) then 
  429. 			local		load_human = false 
  430.  
  431. 			-- We need to make sure one of the players is close enough 
  432. 			if (get_dist_char_to_nav(LOCAL_PLAYER, human) < dist) then 
  433. 				load_human = true 
  434. 			elseif (IN_COOP) then 
  435. 				if (get_dist_char_to_nav(REMOTE_PLAYER, human) < dist) then 
  436. 					load_human = true 
  437. 				end 
  438. 			end 
  439.  
  440. 			-- Is the human already loaded? 
  441. 			local		human_loaded = group_is_loaded(human) 
  442.  
  443. 			-- Create the human or destory him 
  444. 			if (load_human and not human_loaded) then 
  445. 				group_create(human, true) 
  446.             ingame_effect_add_npc( human, INGAME_EFFECT_PROTECT_ACQUIRE, SYNC_ALL ) 
  447. 				-- Do not let the player recruit the lieutenants 
  448. 				set_unrecruitable_flag(human, true) 
  449. 			elseif (not load_human and human_loaded) then 
  450. 				-- Since we are going to unload this character, remove his death function 
  451. 				on_death("", human) 
  452.             ingame_effect_remove_npc( human, SYNC_ALL ) 
  453. 				group_destroy(human) 
  454. 			end 
  455.  
  456. 			-- The lieutenants cannot die at anytime 
  457. 			if ( human_loaded and character_is_dead( human ) == false ) then 
  458. 				on_death("tss04_phase_lieutenant_died", human) 
  459. 			end 
  460. 		end 
  461. 	end 
  462. end 
  463.  
  464. function tss04_start_phase_try() 
  465. 	-- Now continuously look for one of the lieutenants to recriut 
  466. 	while (1) do 
  467. 		thread_yield() 
  468.  
  469. 		-- Loop through each character 
  470. 		for i = 1, Tss04_3_phase_table_size, 1 do 
  471. 			local		human_is_loaded = character_check_resource_loaded(Tss04_3_phase_table[i][CHARACTER_INDEX]) 
  472. 			local		phase_is_complete = Tss04_3_phase_table[i][COMPLETED_INDEX] 
  473.  
  474. 			-- Make the phase can be activiated 
  475. 			if (not PHASE_ACTIVE and not phase_is_complete and human_is_loaded) then 
  476. 				local		activating_player = "" 
  477.  
  478. 				-- We are so we need to make sure the two players are close enough... 
  479. 				if (get_dist_char_to_char(LOCAL_PLAYER, Tss04_3_phase_table[i][CHARACTER_INDEX]) < LT_ACTIVATION_DISTANCE) then 
  480. 					activating_player = LOCAL_PLAYER 
  481. 				elseif (IN_COOP) then 
  482. 					if (get_dist_char_to_char(REMOTE_PLAYER, Tss04_3_phase_table[i][CHARACTER_INDEX]) < LT_ACTIVATION_DISTANCE) then 
  483. 						activating_player = REMOTE_PLAYER 
  484. 					end 
  485. 				end 
  486.  
  487. 				if (not (activating_player == "")) then 
  488. 					-- Try to start the phase associated with this character 
  489. 					PHASE_ACTIVE = tss04_start_phase(activating_player, Tss04_3_phase_table[i][CHARACTER_INDEX]) 
  490. 				                
  491. 					if (not PHASE_ACTIVE) then 
  492. 						-- Starting the phase failed so delay a little while 
  493. 						delay(5.0) 
  494. 					end 
  495. 				end 
  496. 			end 
  497. 		end 
  498. 	end 
  499. end 
  500.  
  501. function tss04_start_phase(human, lieutenant) 
  502. 	-- Check to see if we are in coop... 
  503. 	if (IN_COOP) then 
  504. 		-- We are so we need to make sure the two players are close enough... 
  505. 		if (get_dist_char_to_char(LOCAL_PLAYER, REMOTE_PLAYER) > 8.0) then 
  506. 			-- The players are too far apart, output a message to the users 
  507. 			mission_help_table_nag("tss04_too_far_apart") 
  508. 			-- The start phase failed 
  509. 			return false 
  510. 		end 
  511. 	end 
  512.  
  513. 	-- Disable the other active triggers and remove their icons 
  514. 	for i = 1, Tss04_3_phase_table_size, 1 do 
  515. 		-- If the phase is complete then do nothing 
  516. 		if (not Tss04_3_phase_table[i][COMPLETED_INDEX]) then 
  517. 			-- Remove the minimap icon 
  518.          --marker_remove_npc( Tss04_3_phase_table[i][CHARACTER_INDEX], SYNC_ALL ) 
  519. 			minimap_icon_remove_navpoint(Tss04_3_phase_table[i][CHARACTER_INDEX], SYNC_ALL) 
  520.  
  521.          --mission_debug( "Start phase: Removed marker from "..Tss04_3_phase_table[i][CHARACTER_INDEX], 20 ) 
  522. 		end 
  523. 	end 
  524.  
  525.    ingame_effect_remove_npc( lieutenant, SYNC_ALL ) 
  526.  
  527. 	-- The lieutenant is now recruitable 
  528. 	set_unrecruitable_flag(lieutenant, false) 
  529. 	-- Add the character to the player's party 
  530.    npc_go_idle( lieutenant ) 
  531.  
  532. 	-- The mission's already over. Don't bother trying to start the phase 
  533. 	if ( character_is_dead( lieutenant ) ) then 
  534. 		return 
  535. 	end 
  536. 	party_add(lieutenant, human) 
  537.    npc_leash_remove( lieutenant ) 
  538.  
  539. 	-- Kill this parties load thread 
  540. 	thread_kill(Tss04_3_phase_table[Tss04_recruit_table_index[lieutenant]][LOAD_THREAD_INDEX]) 
  541.  
  542. 	-- Figure out what we need to do now 
  543. 	-- 
  544. 	-- "tss04_$Shaundi"  
  545. 	-- "tss04_$Carlos" 
  546. 	-- "tss04_$Pierce" 
  547. 	-- 
  548.  
  549. 	-- Override personas for this lieutenant 
  550. 	for index, override in pairs( Tss04_lieutenant_persona_overrides[lieutenant] ) do 
  551. 		persona_override_character_start( lieutenant, override[1], override[2] ) 
  552. 	end 
  553.  
  554. 	if (lieutenant == Tss04_3_phase_table[STUNTS_INDEX][CHARACTER_INDEX]) then 
  555. 		-- Stunts 
  556. 		thread_new("tss04_intro_line_and_objective", "TSSP04_SHAUNDI_SEEPLAYER_1", lieutenant, "tss04_shaundi_start", "tss04_stunts_phase") 
  557. 	elseif (lieutenant == Tss04_3_phase_table[TOWTRUCK_INDEX][CHARACTER_INDEX]) then 
  558. 		-- Towing 
  559. 		thread_new("tss04_intro_line_and_objective", "CARLOS_TSSP4_IMPRESS_01", lieutenant, "tss04_carlos_start", "tss04_towtruck_phase") 
  560. 	else 
  561. 		-- Killing 
  562. 		thread_new("tss04_intro_line_and_objective", "PIERCE_TSSP4_INTRO_01", lieutenant, "tss04_pierce_start", "tss04_killing_phase") 
  563. 	end 
  564.  
  565. 	-- The start phase was setup correctly 
  566. 	return true 
  567. end 
  568.  
  569. function tss04_intro_line_and_objective(line, lieutenant, objective, setup) 
  570. 	-- Play the audio line 
  571. 	audio_play_for_character(line, lieutenant, "voice", false, true) 
  572. 	-- Show the objective 
  573. 	mission_help_table(objective) 
  574. 	-- Spawn a thread to do the setup 
  575. 	thread_new(setup) 
  576. end 
  577.  
  578. function tss04_phase_lieutenant_died(human) 
  579. 	if (Tss04_3_phase_table[STUNTS_INDEX][CHARACTER_INDEX] == human) then 
  580. 		-- Shaundi 
  581. 		mission_end_failure("tss04", "tss04_shaundi_died") 
  582. 	elseif (Tss04_3_phase_table[TOWTRUCK_INDEX][CHARACTER_INDEX] == human) then 
  583. 		-- Carlos 
  584. 		mission_end_failure("tss04", "tss04_carlos_died") 
  585. 	else 
  586. 		-- Pierce 
  587. 		mission_end_failure("tss04", "tss04_pierce_died") 
  588. 	end 
  589. end 
  590.  
  591. function tss04_phase_lieutenant_abandoned(human) 
  592. 	if (Tss04_3_phase_table[STUNTS_INDEX][CHARACTER_INDEX] == human) then 
  593. 		-- Shaundi 
  594. 		mission_end_failure("tss04", "tss04_shaundi_abandoned") 
  595. 	elseif (Tss04_3_phase_table[TOWTRUCK_INDEX][CHARACTER_INDEX] == human) then 
  596. 		-- Carlos 
  597. 		mission_end_failure("tss04", "tss04_carlos_abandoned") 
  598. 	else 
  599. 		-- Pierce 
  600. 		mission_end_failure("tss04", "tss04_pierce_abandoned") 
  601. 	end 
  602. end 
  603.  
  604. function tss04_phase_completed(player, lieutenant) 
  605. 	-- Clear the HUD of the current objectives 
  606. 	hud_timer_stop(0) 
  607. 	objective_text_clear(0) 
  608. 	objective_text_clear(1) 
  609.  
  610.    --mission_debug( lieutenant.." phase completed.", 20 ) 
  611.  
  612. 	local		all_phases_complete = true 
  613. 	-- Mark this part as finished 
  614. 	for i = 1, Tss04_3_phase_table_size, 1 do 
  615. 		-- Look for the matching human 
  616. 		if (Tss04_3_phase_table[i][CHARACTER_INDEX] == lieutenant) then 
  617. 			-- Mark completed 
  618. 			Tss04_3_phase_table[i][COMPLETED_INDEX] = true 
  619. 		end 
  620.  
  621. 		-- Are all phases complete 
  622. 		if (not Tss04_3_phase_table[i][COMPLETED_INDEX]) then 
  623. 			all_phases_complete = false 
  624. 		end 
  625.    end 
  626.  
  627. 	-- If we are not finished then handle the other phases and dismiss the current party member 
  628. 	if (not all_phases_complete) then 
  629. 		-- Enable the other active triggers and remove their icons 
  630. 		for i = 1, Tss04_3_phase_table_size, 1 do 
  631. 			-- If the phase is complete then do nothing 
  632. 			if (not Tss04_3_phase_table[i][COMPLETED_INDEX]) then 
  633. 				-- Add a minimap icon 
  634.             --marker_add_npc( Tss04_3_phase_table[i][CHARACTER_INDEX], MINIMAP_ICON_PROTECT_ACQUIRE, INGAME_EFFECT_PROTECT_ACQUIRE, SYNC_ALL ) 
  635. 				minimap_icon_add_navpoint(Tss04_3_phase_table[i][CHARACTER_INDEX], MINIMAP_ICON_PROTECT_ACQUIRE, "", SYNC_ALL) 
  636.             --mission_debug( "Phase completed: added minimap icon for "..Tss04_3_phase_table[i][CHARACTER_INDEX], 20 ) 
  637. 			end 
  638. 		end 
  639.  
  640. 		-- Revive the follower if they are incapacitated 
  641. 		if (follower_is_unconscious(lieutenant)) then 
  642. 			npc_revive(lieutenant) 
  643. 		end 
  644.  
  645. 		-- Remove the on death 
  646. 		on_death("", lieutenant) 
  647. 		-- Remove the on abandon 
  648. 		on_dismiss("", lieutenant) 
  649. 		-- Remove from the party 
  650. 		party_dismiss(lieutenant) 
  651. 		-- Don't allow this character to be recruitable 
  652. 		set_unrecruitable_flag(lieutenant, true) 
  653. 		-- Make them invulnerable so they can't be killed 
  654. 		turn_invulnerable(lieutenant, false) 
  655.  
  656. 		-- Setup the checkpoint... 
  657. 		local		checkpoint_string = "" 
  658.  
  659. 		for i = 1, Tss04_3_phase_table_size, 1 do 
  660. 			-- If the phase is complete then add its signature 
  661. 			if (Tss04_3_phase_table[i][COMPLETED_INDEX]) then 
  662. 				checkpoint_string = checkpoint_string .. Tss04_3_phase_table[i][CHECKPOINT_INDEX] 
  663. 			end 
  664. 		end 
  665.  
  666. 		-- Instruct the player(s) what to do next 
  667. 		if (lieutenant == Tss04_3_phase_table[STUNTS_INDEX][CHARACTER_INDEX]) then 
  668. 			mission_help_table("tss04_shaundi_complete") 
  669. 		elseif (lieutenant == Tss04_3_phase_table[TOWTRUCK_INDEX][CHARACTER_INDEX]) then 
  670. 			mission_help_table("tss04_carlos_complete") 
  671. 		else 
  672. 			mission_help_table("tss04_pierce_complete") 
  673. 		end 
  674.  
  675. 		-- Play the in Saints conversation 
  676. 		audio_play_conversation(Tss04_in_saints_exchange[lieutenant]) 
  677. 		-- Have them pathfind back to their original positions... 
  678. 		Tss04_3_phase_table[Tss04_recruit_table_index[lieutenant]][MOVE_THREAD_INDEX] = thread_new("tss04_lieutenant_done", lieutenant) 
  679. 		-- Look for an opportunity to release the lieutenant 
  680. 		thread_new("tss04_release_human_to_world", lieutenant, 100.0, true) 
  681.  
  682.       notoriety_set( "brotherhood", 0 ) 
  683.       notoriety_set( "ronin", 0 ) 
  684.       notoriety_set( "samedi", 0 ) 
  685.       notoriety_set( "police", 0 ) 
  686.  
  687.       thread_yield() 
  688.  
  689.       -- Set the checkpoint string data 
  690. 		mission_set_checkpoint(checkpoint_string) 
  691. 	else 
  692. 		-- Make them invulnerable so they can't be killed 
  693. 		turn_invulnerable(lieutenant ) 
  694.       turn_invulnerable( LOCAL_PLAYER ) 
  695.       if ( coop_is_active() ) then 
  696.          turn_invulnerable( REMOTE_PLAYER ) 
  697.       end 
  698. 		-- Play the back to HQ conversation 
  699. 		audio_play_conversation(Tss04_back_to_hq_exchange[lieutenant]) 
  700.  
  701.       -- End the mission with success 
  702.       mission_end_success( "tss04", CT_OUTRO, { LOCATION_START, LOCATION_START_PLAYER_2 } ) 
  703. 	end 
  704.  
  705. 	-- Handle coop reward stuff here based upon the phase completed... it is by lieutenant 
  706. 	if (IN_COOP) then 
  707. 		-- Give out the bonus... 
  708. 		if (lieutenant == Tss04_3_phase_table[STUNTS_INDEX][CHARACTER_INDEX]) then 
  709. 			-- Stunts reward 
  710. 			cash_add(300, player) 
  711. 		elseif (lieutenant == Tss04_3_phase_table[TOWTRUCK_INDEX][CHARACTER_INDEX]) then 
  712. 			-- Tow truck reward 
  713. 			cash_add(300, player) 
  714. 		else 
  715. 			-- Killing reward 
  716. 			cash_add(300, player) 
  717. 		end 
  718. 	end 
  719.  
  720. 	-- The phase is no longer active 
  721. 	PHASE_ACTIVE = false 
  722. end 
  723.  
  724. function tss04_lieutenant_done(human) 
  725.    while ( character_is_in_vehicle( human ) ) do 
  726.       local cur_speed = get_vehicle_speed( human ) 
  727.       if ( get_char_vehicle_is_in_air( human ) == false and cur_speed <= LIEUTENANT_LEAVE_VEHICLE_MAX_SPEED_MPH ) then 
  728.          delay( 2.0 ) 
  729.          cur_speed = get_vehicle_speed( human ) 
  730.          if ( get_char_vehicle_is_in_air( human ) == false and cur_speed <= LIEUTENANT_LEAVE_VEHICLE_MAX_SPEED_MPH ) then 
  731.             vehicle_exit( human ) 
  732.          end 
  733.          delay( 2.0 ) 
  734.       end 
  735.       thread_yield() 
  736.    end 
  737.  
  738. 	-- Have a human run back to their spawning position 
  739. 	move_to_safe(human, human, 3, true, true) 
  740. 	turn_to_orient(human, human) 
  741. end 
  742.  
  743. function tss04_release_human_to_world(human, dist, kill_move_thread) 
  744. 	-- Now continuously look to release the human to the world 
  745. 	while (1) do 
  746. 		thread_yield() 
  747.  
  748. 		local		human_in_range = false 
  749.  
  750. 		-- We need to make sure one of the players is close enough 
  751. 		if (get_dist_char_to_nav(LOCAL_PLAYER, human) < dist) then 
  752. 			human_in_range = true 
  753. 		elseif (IN_COOP) then 
  754. 			if (get_dist_char_to_nav(REMOTE_PLAYER, human) < dist) then 
  755. 				human_in_range = true 
  756. 			end 
  757. 		end 
  758.  
  759. 		-- The human is no longer in range so release it... 
  760. 		if (not human_in_range) then 
  761. 			if (kill_move_thread) then 
  762. 				-- Kill the move and orient thread 
  763. 				thread_kill(Tss04_3_phase_table[Tss04_recruit_table_index[human]][MOVE_THREAD_INDEX]) 
  764. 			end 
  765.          mission_debug( "releasing "..human.." to world.", 3600 ) 
  766. 			-- Release to the world 
  767.          if ( character_is_released( human ) == false ) then 
  768.    			release_to_world(human) 
  769.          end 
  770. 			return 
  771. 		end 
  772. 	end 
  773. end 
  774.  
  775. function tss04_stunts_phase() 
  776. 	-- Shaundi cannot be abandoned 
  777. 	on_dismiss("tss04_phase_lieutenant_abandoned", Tss04_3_phase_table[STUNTS_INDEX][CHARACTER_INDEX]) 
  778.  
  779. 	-- Add the stunts callbacks 
  780. 	if (not IN_COOP) then 
  781. 		objective_text(0, "tss04_stunt", Tss04_player1_jump, Num_tss04_stunt_jumps) 
  782.  
  783. 		-- Enable all of the stunt jump triggers and their callbacks 
  784. 		for i = 1, Num_tss04_stunt_jumps, 1 do 
  785. 			trigger_enable(Tss04_stunt_jumps[i], true) 
  786. 			on_trigger("tss04_stunt_jump", Tss04_stunt_jumps[i]) 
  787. 		end 
  788. 	else		 
  789. 		-- In coop there is a timer 
  790. 		hud_timer_set(0, 1000 * 60 * 3, "tss04_stunt_timer_expired") 
  791.  
  792. 		objective_text(0, "tss04_stunt", Tss04_player1_jump, Num_tss04_stunt_jumps, SYNC_LOCAL) 
  793. 		objective_text(1, "tss04_stunt", Tss04_player2_jump, Num_tss04_stunt_jumps, SYNC_REMOTE) 
  794.  
  795. 		-- Enable all of the stunt jump triggers and their callbacks 
  796. 		for i = 1, Num_tss04_stunt_jumps, 1 do 
  797. 			trigger_enable(Tss04_stunt_jumps[i], true) 
  798. 			on_trigger("tss04_stunt_jump_coop", Tss04_stunt_jumps[i]) 
  799. 		end 
  800. 	end 
  801.  
  802. 	marker_add_trigger(Tss04_stunt_jumps[1], MINIMAP_ICON_LOCATION, STUNT_JUMP_EFFECT) 
  803.  
  804. 	-- We have a driving stunts tutorial 
  805. 	if ( tutorial_completed( "driving_stunts" ) == false ) then 
  806. 		tutorial_start("driving_stunts", 3000, true) 
  807. 	end 
  808. end 
  809.  
  810. function tss04_stunt_jump(human, trigger) 
  811.    -- If Shaundi is not in a vehicle...this will not count 
  812.    if (not character_is_in_vehicle(CHARACTER_SHAUNDI)) then 
  813.       return 
  814.    end 
  815.  
  816. 	-- Needs to be the local player... 
  817. 	if (not (human == LOCAL_PLAYER)) then 
  818. 		return 
  819. 	end 
  820.  
  821. 	-- Get the trigger index 
  822. 	local		index = Tss04_stunt_jumps_idx[trigger] 
  823. 	 
  824. 	-- Check to see if we went through a trigger the we are not suppose to 
  825. 	if (index > (Tss04_player1_jump + 1)) then 
  826. 		-- We cannot go through this one yet 
  827. 		return 
  828. 	end 
  829.  
  830. 	-- Increment the count 
  831. 	Tss04_player1_jump = Tss04_player1_jump + 1 
  832.  
  833.    if ( Tss04_player1_jump == 1 ) then 
  834.       if ( tutorial_completed( "hud_text" ) == false ) then 
  835. 		   tutorial_start("hud_text", 15000, true) 
  836.       end 
  837.    end 
  838.  
  839. 	-- Check for player completion (removal of effect) 
  840. 	marker_remove_trigger(Tss04_stunt_jumps[index], SYNC_LOCAL) 
  841. 	if (Tss04_player1_jump < Num_tss04_stunt_jumps) then 
  842. 		marker_add_trigger(Tss04_stunt_jumps[index + 1], MINIMAP_ICON_LOCATION, STUNT_JUMP_EFFECT) 
  843. 	end 
  844.  
  845. 	-- Disable the trigger 
  846. 	trigger_enable(Tss04_stunt_jumps[index], false) 
  847. 	-- for_cutscene = false, blocking = false 
  848. 	audio_play_for_character( "SYS_RACE_CHECKPOINT", human, "foley", false, false ) 
  849.  
  850.  
  851. 	-- Update the objective status 
  852. 	objective_text(0, "tss04_stunt", Tss04_player1_jump, Num_tss04_stunt_jumps) 
  853.  
  854. 	-- Has player 1 or 2 reached the required cash amount? 
  855. 	if (Tss04_player1_jump == Num_tss04_stunt_jumps) then 
  856. 		-- We do not need these vehicles anymore =P 
  857. 		release_to_world(GROUP_STUNT_VEHICLES) 
  858.  
  859. 		tss04_phase_completed(human, Tss04_3_phase_table[STUNTS_INDEX][CHARACTER_INDEX]) 
  860. 	end 
  861. end 
  862.  
  863. function tss04_stunt_jump_coop(human, trigger) 
  864. 	-- Needs to be the local or remote player... 
  865. 	if (not (human == LOCAL_PLAYER) and not (human == REMOTE_PLAYER)) then 
  866. 		return 
  867. 	end 
  868.  
  869. 	-- Get the trigger index 
  870. 	local		index = Tss04_stunt_jumps_idx[trigger] 
  871. 	 
  872. 	if (human == LOCAL_PLAYER) then 
  873. 		-- Check to see if we went through a trigger the we are not suppose to 
  874. 		if (index <= Tss04_player1_jump) then 
  875. 			-- We already went through these 
  876. 			return 
  877. 		elseif (index > (Tss04_player1_jump + 1)) then 
  878. 			-- We cannot go through this one yet 
  879. 			return 
  880. 		end 
  881.  
  882. 		-- Increment the count 
  883. 		Tss04_player1_jump = Tss04_player1_jump + 1 
  884.  
  885. 		-- Check for player completion (removal of effect) 
  886. 		marker_remove_trigger(Tss04_stunt_jumps[index], SYNC_LOCAL) 
  887. 		if (Tss04_player1_jump < Num_tss04_stunt_jumps) then 
  888. 			marker_add_trigger(Tss04_stunt_jumps[index + 1], MINIMAP_ICON_LOCATION, STUNT_JUMP_EFFECT, SYNC_LOCAL) 
  889. 		end 
  890. 	else 
  891. 		-- Check to see if we went through a trigger the we are not suppose to 
  892. 		if (index <= Tss04_player2_jump) then 
  893. 			-- We already went through these 
  894. 			return 
  895. 		elseif (index > (Tss04_player2_jump + 1)) then 
  896. 			-- We cannot go through this one yet 
  897. 			return 
  898. 		end 
  899.  
  900. 		-- Increment the count 
  901. 		Tss04_player2_jump = Tss04_player2_jump + 1 
  902.  
  903. 		-- Check for player completion (removal of effect) 
  904. 		marker_remove_trigger(Tss04_stunt_jumps[index], SYNC_REMOTE) 
  905. 		if (Tss04_player2_jump < Num_tss04_stunt_jumps) then 
  906. 			marker_add_trigger(Tss04_stunt_jumps[index + 1], MINIMAP_ICON_LOCATION, STUNT_JUMP_EFFECT, SYNC_REMOTE) 
  907. 		end 
  908. 	end 
  909. 	-- for_cutscene = false, blocking = false 
  910. 	audio_play_for_character( "SYS_RACE_CHECKPOINT", human, "foley", false, false ) 
  911.  
  912. 	-- Check for trigger disable 
  913. 	if ((Tss04_player1_jump >= index) and (Tss04_player2_jump >= index)) then 
  914. 		-- Both players have passed through this trigger so disable it 
  915. 		trigger_enable(Tss04_stunt_jumps[index], false) 
  916. 	end 
  917.  
  918. 	-- Update the objective status 
  919. 	objective_text(0, "tss04_stunt", Tss04_player1_jump, Num_tss04_stunt_jumps, SYNC_LOCAL) 
  920. 	objective_text(1, "tss04_stunt", Tss04_player2_jump, Num_tss04_stunt_jumps, SYNC_REMOTE) 
  921.  
  922. 	-- Check to see if we need to set who the winner is 
  923. 	if (Tss04_coop_winner == "") then 
  924. 		if (Tss04_player1_jump == Num_tss04_stunt_jumps) then 
  925. 			Tss04_coop_winner = LOCAL_PLAYER 
  926. 		elseif (Tss04_player2_jump == Num_tss04_stunt_jumps) then 
  927. 			Tss04_coop_winner = REMOTE_PLAYER 
  928. 		end 
  929. 	end 
  930.  
  931. 	-- Has player 1 or 2 reached the required cash amount? 
  932. 	if ((Tss04_player1_jump == Num_tss04_stunt_jumps) and (Tss04_player2_jump == Num_tss04_stunt_jumps)) then 
  933. 		-- We do not need these vehicles anymore =P 
  934. 		release_to_world(GROUP_STUNT_VEHICLES) 
  935.  
  936. 		tss04_phase_completed(Tss04_coop_winner, Tss04_3_phase_table[STUNTS_INDEX][CHARACTER_INDEX]) 
  937. 		-- Reset the coop winner 
  938. 		Tss04_coop_winner = "" 
  939. 	end 
  940. end 
  941.  
  942. function tss04_stunt_timer_expired() 
  943. 	-- The stunt timer elapsed 
  944. 	mission_end_failure("tss04", "tss04_stunt_timer") 
  945. end 
  946.  
  947. function tss04_mark_tow_target( player_name ) 
  948.    if ( player_name == LOCAL_PLAYER ) then 
  949.    	marker_add_vehicle(LOCAL_TOWED_VEHICLE, MINIMAP_ICON_PROTECT_ACQUIRE, INGAME_EFFECT_VEHICLE_PROTECT_ACQUIRE, SYNC_LOCAL) 
  950. 		waypoint_add(LOCAL_TOWED_VEHICLE, SYNC_LOCAL) 
  951.    elseif ( player_name == REMOTE_PLAYER ) then 
  952. 		marker_add_vehicle(REMOTE_TOWED_VEHICLE, MINIMAP_ICON_PROTECT_ACQUIRE, INGAME_EFFECT_VEHICLE_PROTECT_ACQUIRE, SYNC_REMOTE) 
  953. 		waypoint_add(REMOTE_TOWED_VEHICLE, SYNC_REMOTE) 
  954.    end 
  955. end 
  956.  
  957. function tss04_unmark_tow_target( player_name ) 
  958.    if ( player_name == LOCAL_PLAYER ) then 
  959.    	marker_remove_vehicle(LOCAL_TOWED_VEHICLE, SYNC_LOCAL) 
  960. 		waypoint_remove(SYNC_LOCAL) 
  961.    elseif ( player_name == REMOTE_PLAYER ) then 
  962. 		marker_remove_vehicle(REMOTE_TOWED_VEHICLE, SYNC_REMOTE) 
  963. 		waypoint_remove(SYNC_REMOTE) 
  964.    end 
  965. end 
  966.  
  967. function tss04_towtruck_phase() 
  968. 	-- Create the towed vehicle 
  969. 	group_create(GROUP_TOWED_VEHICLE) 
  970. 	if (IN_COOP) then 
  971. 		group_create(GROUP_TOWED_VEHICLE_COOP) 
  972. 	end 
  973.  
  974. 	-- Carlos cannot be abandoned 
  975. 	on_dismiss("tss04_phase_lieutenant_abandoned", Tss04_3_phase_table[TOWTRUCK_INDEX][CHARACTER_INDEX]) 
  976.    trigger_type_enable( "car mechanic", false ) 
  977.  
  978. 	-- The towed vehicle cannot die 
  979. 	on_vehicle_destroyed("tss04_towed_vehicle_destroyed", LOCAL_TOWED_VEHICLE) 
  980. 	-- Set the hit points...the base hitpoints are weak 
  981. 	set_max_hit_points(LOCAL_TOWED_VEHICLE, (get_max_hit_points(LOCAL_TOWED_VEHICLE) * 2.5)) 
  982. 	-- Add an on vehicle hitched callback 
  983. 	on_vehicle_hitched("tss04_towed_vehicle_hitched", LOCAL_TOWED_VEHICLE) 
  984. 	-- Add an on vehicle unhitched callback 
  985. 	on_vehicle_unhitched("tss04_towed_vehicle_unhitched", LOCAL_TOWED_VEHICLE) 
  986. 	-- Lock the vehicle towed vehicle 
  987. 	set_unjackable_flag(LOCAL_TOWED_VEHICLE, true) 
  988.  
  989. 	if (IN_COOP) then 
  990. 		-- Carlos needs to be independent 
  991. 		follower_make_independent(Tss04_3_phase_table[TOWTRUCK_INDEX][CHARACTER_INDEX], true) 
  992. 		-- We need to move Carlos out of the way 
  993. 		thread_new("tss04_move_carlos", Tss04_3_phase_table[TOWTRUCK_INDEX][CHARACTER_INDEX]) 
  994.  
  995. 		-- The towed vehicle cannot die 
  996. 		on_vehicle_destroyed("tss04_towed_vehicle_destroyed", REMOTE_TOWED_VEHICLE) 
  997. 		-- Set the hit points...the base hitpoints are weak 
  998. 		set_max_hit_points(REMOTE_TOWED_VEHICLE, (get_max_hit_points(REMOTE_TOWED_VEHICLE) * 2.5)) 
  999. 		-- Add an on vehicle hitched callback 
  1000. 		on_vehicle_hitched("tss04_towed_vehicle_hitched", REMOTE_TOWED_VEHICLE) 
  1001. 		-- Add an on vehicle unhitched callback 
  1002. 		on_vehicle_unhitched("tss04_towed_vehicle_unhitched", REMOTE_TOWED_VEHICLE) 
  1003. 		-- Lock the vehicle towed vehicle 
  1004. 		set_unjackable_flag(REMOTE_TOWED_VEHICLE, true) 
  1005. 	end 
  1006.  
  1007. 	-- Show the towed vehicle 
  1008. 	group_show(GROUP_TOWED_VEHICLE) 
  1009. 	if (IN_COOP) then 
  1010. 		group_show(GROUP_TOWED_VEHICLE_COOP) 
  1011. 	end 
  1012.  
  1013. 	-- Enable the drop off trigger... 
  1014. 	on_trigger("tss04_towtruck_parked", TOWED_VEHICLE_TRIGGER) 
  1015. 	trigger_enable(TOWED_VEHICLE_TRIGGER, true) 
  1016.  
  1017.    -- Start a new thread to watch for showing the tow message 
  1018. 	thread_new("tss04_tow_truck_message") 
  1019.  
  1020. 	-- Kill the regenerate thread...it is no longer needed 
  1021. 	thread_kill(TOWTRUCK_REGENERATE) 
  1022.  
  1023. 	for i = 1, Num_tss04_tow_trucks, 1 do 
  1024. 		if (vehicle_exists(Tss04_tow_trucks[i]) and not vehicle_hidden(Tss04_tow_trucks[i])) then 
  1025. 			-- Setup the on vehicle enter 
  1026. 			on_vehicle_enter("tss02_towtruck_entered", Tss04_tow_trucks[i]) 
  1027.  
  1028.          vehicle_infinite_mass( Tss04_tow_trucks[i], false ) 
  1029.          vehicle_prevent_explosion_fling( Tss04_tow_trucks[i], false ) 
  1030.          turn_vulnerable( Tss04_tow_trucks[i] ) 
  1031. 			on_vehicle_destroyed("tss04_towtruck_destroyed_failure", Tss04_tow_trucks[i]) 
  1032.          set_unjackable_flag( Tss04_tow_trucks[i], false ) 
  1033.  
  1034. 			if (not Tss01_tow_truck_entered[Tss04_tow_trucks[i]]) then 
  1035. 				-- Add a marker to the tow truck 
  1036.             marker_add_vehicle( Tss04_tow_trucks[i], MINIMAP_ICON_LOCATION, INGAME_EFFECT_VEHICLE_INTERACT, SYNC_ALL ) 
  1037. 			else  
  1038. 				-- Setup the on vehicle exit 
  1039. 				on_vehicle_exit("tss02_towtruck_exited", Tss04_tow_trucks[i]) 
  1040. 			end 
  1041. 		end 
  1042. 	end 
  1043.  
  1044. 	-- In coop, Carlos does not ride in a vehicle 
  1045. 	if (not IN_COOP) then 
  1046. 		-- Play the Carlos conversation 
  1047. 		thread_new("tss04_carlos_conversation") 
  1048. 	end 
  1049. end 
  1050.  
  1051. function tss04_carlos_conversation() 
  1052. 	delay(2.0) 
  1053. 	-- Play the reacquaintance conversation...in the tow truck 
  1054. 	audio_play_conversation_in_vehicle(Tss04_carlos_reacquaint) 
  1055. end 
  1056.  
  1057. function tss04_move_carlos(human) 
  1058. 	-- Move Carlos to the navpoint 
  1059. 	move_to_safe(human, "tss04_$n000", 3, true, false) 
  1060. 	-- Orient Carlos 
  1061. 	turn_to_orient(human, "tss04_$n000") 
  1062. end 
  1063.  
  1064. function tss04_tow_truck_message() 
  1065. 	local		local_player = false 
  1066. 	local		remote_player = false 
  1067.  
  1068. 	if (not IN_COOP) then 
  1069. 		remote_player = true 
  1070. 	end 
  1071.  
  1072. 	-- Check to see if we need to show the player the tow truck message 
  1073. 	while (not local_player or not remote_player) do 
  1074. 		thread_yield() 
  1075.  
  1076. 		if (not local_player and get_dist_char_to_vehicle(LOCAL_PLAYER, LOCAL_TOWED_VEHICLE) < 20.0) then 
  1077. 			mission_help_table_nag("tss04_tow_truck", nil, nil, SYNC_LOCAL) 
  1078. 			waypoint_remove(SYNC_LOCAL) 
  1079. 			local_player = true 
  1080. 		end 
  1081.  
  1082. 		if (not remote_player and get_dist_char_to_vehicle(REMOTE_PLAYER, REMOTE_TOWED_VEHICLE) < 20.0) then 
  1083. 			mission_help_table_nag("tss04_tow_truck", nil, nil, SYNC_REMOTE) 
  1084. 			waypoint_remove(SYNC_REMOTE) 
  1085. 			remote_player = true 
  1086. 		end 
  1087. 	end 
  1088. end 
  1089.  
  1090. function tss04_towed_vehicle_destroyed() 
  1091. 	-- The towed vehicle was destroyed 
  1092. 	mission_end_failure("tss04", "tss04_towed_destroyed") 
  1093. end 
  1094.  
  1095. function tss04_towed_vehicle_hitched(hitched, towtruck) 
  1096. 	local		is_local_player = character_is_in_vehicle(LOCAL_PLAYER, towtruck) 
  1097. 	local		is_remote_player = character_is_in_vehicle(REMOTE_PLAYER, towtruck) 
  1098.  
  1099. 	-- As a safety check verify that one of these guys is in the towtruck 
  1100. 	if (not is_local_player and not is_remote_player) then 
  1101. 		return 
  1102. 	end 
  1103.  
  1104. 	local		towed_vehicle = REMOTE_TOWED_VEHICLE 
  1105. 	local		sync_type = SYNC_REMOTE 
  1106.    local player_name = REMOTE_PLAYER 
  1107.  
  1108. 	-- Are we looking for the remote towed vehicle? 
  1109. 	if (is_local_player) then 
  1110. 		towed_vehicle = LOCAL_TOWED_VEHICLE 
  1111. 		sync_type = SYNC_LOCAL 
  1112.       player_name = LOCAL_PLAYER 
  1113. 	end  
  1114.  
  1115. 	-- It must be the correct towtruck and towed vehicle 
  1116. 	if (not (hitched == towed_vehicle)) then 
  1117. 		return 
  1118. 	end 
  1119.  
  1120.    Correct_vehicle_hitched[player_name] = true 
  1121.  
  1122. 	-- Remove the towed vehicle marker 
  1123.    tss04_unmark_tow_target( player_name ) 
  1124. 	 
  1125. 	-- Add the dropoff trigger as the objective 
  1126.    marker_add_trigger(TOWED_VEHICLE_TRIGGER, MINIMAP_ICON_LOCATION, INGAME_EFFECT_VEHICLE_LOCATION, sync_type) 
  1127.  
  1128. 	-- Add callback if it is a scripted tow truck 
  1129. 	if (not (towtruck == nil)) then 
  1130. 		-- We might add something here in the future...just don't want to remove it for now 
  1131. 	end 
  1132.  
  1133. 	-- Add a waypoint back to the garage 
  1134. 	waypoint_add(TOWED_VEHICLE_TRIGGER, sync_type) 
  1135.  
  1136. 	-- Have the appropriate group attack 
  1137. 	if (is_local_player) then 
  1138. 		for i = 1, Num_tss04_mourners, 1 do 
  1139. 			if (not character_is_dead(Tss04_mourners[i])) then 
  1140. 				set_blitz_flag(Tss04_mourners[i], true) 
  1141. 				set_cant_flee_flag(Tss04_mourners[i], true)  
  1142. 				attack(Tss04_mourners[i], LOCAL_PLAYER) 
  1143.  
  1144. 				-- Look for an opportunity to release the mourners 
  1145. 				thread_new("tss04_release_human_to_world", Tss04_mourners[i], 60.0, false) 
  1146. 			end 
  1147. 		end 
  1148.  
  1149. 		-- In coop, Carlos does not ride in a vehicle 
  1150. 		if (not IN_COOP and not Tss04_carlos_has_phoned_buddy) then 
  1151. 			-- Carlos will now phone his buddy 
  1152. 			thread_new("tss04_carlos_phones_buddy") 
  1153. 			-- Mark it as having been played... 
  1154. 			Tss04_carlos_has_phoned_buddy = true 
  1155. 		end 
  1156. 	elseif (is_remote_player) then 
  1157. 		for i = 1, Num_tss04_trash, 1 do 
  1158. 			if (not character_is_dead(Tss04_trash[i])) then 
  1159. 				set_blitz_flag(Tss04_trash[i], true) 
  1160. 				set_cant_flee_flag(Tss04_trash[i], true)  
  1161. 				attack(Tss04_trash[i], REMOTE_PLAYER) 
  1162.  
  1163. 				-- Look for an opportunity to release the trash 
  1164. 				thread_new("tss04_release_human_to_world", Tss04_trash[i], 60.0, false) 
  1165. 			end 
  1166. 		end 
  1167. 	end 
  1168.  
  1169. 	-- Delay a moment so that police notoriety doesn't happen right away 
  1170. 	delay(5.0) 
  1171. 	-- Once we are considered hitched, set police notoriety 
  1172. 	notoriety_set_max("Police", 1) 
  1173. 	notoriety_set_min("Police", 1) 
  1174. end 
  1175.  
  1176. function tss04_carlos_phones_buddy() 
  1177. 	-- Carlos has a one man conversation with his buddy... 
  1178. 	audio_play_conversation(Tss04_carlos_phone_call, OUTGOING_CALL) 
  1179. end 
  1180.  
  1181. function tss04_towed_vehicle_unhitched(unhitched, towtruck) 
  1182. 	local		is_local_player = character_is_in_vehicle(LOCAL_PLAYER, towtruck) 
  1183. 	local		is_remote_player = character_is_in_vehicle(REMOTE_PLAYER, towtruck) 
  1184.  
  1185. 	-- As a safety check verify that one of these guys is in the towtruck 
  1186. 	if (not is_local_player and not is_remote_player) then 
  1187. 		return 
  1188. 	end 
  1189.  
  1190. 	local		towed_vehicle = REMOTE_TOWED_VEHICLE 
  1191. 	local		sync_type = SYNC_REMOTE 
  1192.    local player_name = REMOTE_PLAYER 
  1193.  
  1194. 	-- Are we looking for the local towed vehicle? 
  1195. 	if (is_local_player) then 
  1196. 		towed_vehicle = LOCAL_TOWED_VEHICLE 
  1197. 		sync_type = SYNC_LOCAL 
  1198.       player_name = LOCAL_PLAYER 
  1199. 	end  
  1200.  
  1201. 	-- It must be the correct towtruck and towed vehicle 
  1202. 	if (not (unhitched == towed_vehicle)) then 
  1203. 		return 
  1204. 	end 
  1205.  
  1206.    Correct_vehicle_hitched[player_name] = false 
  1207.  
  1208. 	-- Add the marker 
  1209. 	waypoint_remove( sync_type ) 
  1210.    tss04_mark_tow_target( player_name ) 
  1211.     
  1212. 	-- Remove the garage open trigger as the objective 
  1213.    marker_remove_trigger( TOWED_VEHICLE_TRIGGER, sync_type ) 
  1214.  
  1215. 	-- Add callback if it is a scripted tow truck 
  1216. 	if (not (towtruck == nil)) then 
  1217. 		-- We might add something here in the future...just don't want to remove it for now 
  1218. 	end 
  1219.  
  1220. 	-- Add callback if it is a scripted tow truck 
  1221. 	if (not (towtruck == nil)) then 
  1222. 		-- We might add something here in the future...just don't want to remove it for now 
  1223. 	end 
  1224. end 
  1225.  
  1226. function tss04_towtruck_destroyed(vehicle) 
  1227. 	-- Release this vehicle (group) to the world so it can regenerate 
  1228. 	release_to_world(vehicle) 
  1229. end 
  1230.  
  1231. function tss02_towtruck_entered(human, vehicle) 
  1232. 	-- Needs to be the local or remote player... 
  1233. 	if (not (human == LOCAL_PLAYER) and not (human == REMOTE_PLAYER)) then 
  1234. 		return 
  1235. 	end 
  1236.  
  1237. 	local		sync_type = SYNC_REMOTE 
  1238.  
  1239. 	-- Are we looking for the local towed vehicle? 
  1240. 	if (human == LOCAL_PLAYER) then 
  1241. 		sync_type = SYNC_LOCAL 
  1242. 	end  
  1243.  
  1244.    -- Guide the player to the objective now that he's in the truck 
  1245. 	for index, truck_name in pairs( Tss04_tow_trucks ) do 
  1246. 		marker_remove_vehicle( truck_name, sync_type ) 
  1247. 	end 
  1248.    if ( Correct_vehicle_hitched[human] ) then 
  1249.       marker_add_trigger(TOWED_VEHICLE_TRIGGER, MINIMAP_ICON_LOCATION, INGAME_EFFECT_VEHICLE_LOCATION, sync_type) 
  1250.    else 
  1251.       tss04_mark_tow_target( human ) 
  1252.    end 
  1253.  
  1254. 	on_vehicle_exit("tss02_towtruck_exited", vehicle) 
  1255. end 
  1256.  
  1257. function tss02_towtruck_exited(human, vehicle) 
  1258. 	-- Needs to be the local or remote player... 
  1259. 	if (not (human == LOCAL_PLAYER) and not (human == REMOTE_PLAYER)) then 
  1260. 		return 
  1261. 	end 
  1262.  
  1263. 	local		sync_type = SYNC_REMOTE 
  1264.  
  1265. 	-- Are we looking for the local towed vehicle? 
  1266. 	if (human == LOCAL_PLAYER) then 
  1267. 		sync_type = SYNC_LOCAL 
  1268. 	end  
  1269.  
  1270. 	-- Remove the objective for now and add a marker for the tow truck 
  1271.    if ( Correct_vehicle_hitched[human] ) then 
  1272.       marker_remove_trigger(TOWED_VEHICLE_TRIGGER, sync_type) 
  1273.       waypoint_remove( sync_type ) 
  1274.    else 
  1275.       tss04_unmark_tow_target( human ) 
  1276.    end 
  1277. 	marker_add_vehicle(vehicle, MINIMAP_ICON_PROTECT_ACQUIRE, INGAME_EFFECT_VEHICLE_PROTECT_ACQUIRE, sync_type) 
  1278. end 
  1279.  
  1280. function tss04_towtruck_destroyed_failure() 
  1281. 	-- The mission ends in failure since the tow truck is required 
  1282. 	mission_end_failure("tss04", "tss04_tow_truck_destroyed") 
  1283. end 
  1284.  
  1285. function tss04_regenerate_towtrucks() 
  1286. 	-- Only use one tow truck unless we are in coop 
  1287. 	local	num_tow_truck = 1 
  1288.  
  1289. 	if (IN_COOP) then 
  1290. 		num_tow_truck = Num_tss04_tow_trucks 
  1291. 	end 
  1292.  
  1293. 	-- While in this mission 
  1294. 	while (1) do 
  1295. 		-- Loop through the towtrucks and check for revival 
  1296. 		for i = 1, num_tow_truck, 1 do 
  1297. 			-- When a group is no longer loaded and is dead, recreate the group 
  1298. 			if (not group_is_loaded(Tss04_tow_trucks[i])) then 
  1299. 				-- Create the group, hidden 
  1300. 				group_create_hidden(Tss04_tow_trucks[i]) 
  1301. 			end 
  1302.  
  1303. 			-- If the current towtruck is hidden then see if we can reveal it 
  1304. 			if (vehicle_hidden(Tss04_tow_trucks[i])) then 
  1305. 				local local_can_show		= not navpoint_in_player_fov(Tss04_tow_trucks[i], LOCAL_PLAYER, 3.0) 
  1306. 				local remote_can_show	= true 
  1307.  
  1308. 				if (IN_COOP) then 
  1309. 					remote_can_show = not navpoint_in_player_fov(Tss04_tow_trucks[i], REMOTE_PLAYER, 3.0) 
  1310. 				end 
  1311.  
  1312. 				if (local_can_show and remote_can_show) then 
  1313. 					-- Show the towtruck 
  1314. 					group_show(Tss04_tow_trucks[i]) 
  1315. 					-- Setup the death callback 
  1316. 					on_vehicle_destroyed("tss04_towtruck_destroyed", Tss04_tow_trucks[i]) 
  1317. 					-- Setup our enter callback 
  1318. 					on_vehicle_enter("tss02_towtruck_enter", Tss04_tow_trucks[i]) 
  1319. 					-- Adjust the hitpoints 
  1320. 					set_max_hit_points(Tss04_tow_trucks[i], get_max_hit_points(Tss04_tow_trucks[i]) * 1.5) 
  1321.  
  1322.                vehicle_infinite_mass( Tss04_tow_trucks[i], true ) 
  1323.                vehicle_prevent_explosion_fling( Tss04_tow_trucks[i], false ) 
  1324.                turn_invulnerable( Tss04_tow_trucks[i] ) 
  1325.                set_unjackable_flag( Tss04_tow_trucks[i], true ) 
  1326. 				end 
  1327. 			end 
  1328.  
  1329. 			-- Yield and check the next tow truck in the next frame 
  1330. 			thread_yield() 
  1331. 		end 
  1332. 	end 
  1333. end 
  1334.  
  1335. function tss04_towtruck_parked(human) 
  1336. 	local		is_local_player = (human == LOCAL_PLAYER) 
  1337. 	local		is_remote_player = (human == REMOTE_PLAYER) 
  1338.  
  1339.    --mission_debug( "tow truck parked called" ) 
  1340.  
  1341. 	-- Must be one of the players and must be in the tow truck with the hitched vehicle 
  1342. 	if (not is_local_player and not is_remote_player) then 
  1343.       --mission_debug( "fell through because was not player" ) 
  1344. 		return 
  1345. 	elseif (not (get_char_vehicle_special_type(human) == VST_TOW_TRUCK)) then 
  1346. 		-- Must be in a tow truck 
  1347.       --mission_debug( "fell through because player was not in tow truck" ) 
  1348. 		return 
  1349. 	else 
  1350. 		local		towed_vehicle = REMOTE_TOWED_VEHICLE 
  1351. 		local		sync_type = SYNC_REMOTE 
  1352.  
  1353. 		-- Are we looking for the local towed vehicle? 
  1354. 		if (is_local_player) then 
  1355. 			towed_vehicle = LOCAL_TOWED_VEHICLE 
  1356. 			sync_type = SYNC_LOCAL 
  1357. 		end 
  1358.  
  1359. 		-- Must be towing the correct vehicle 
  1360. 		if (not (get_char_vehicle_towed_vehicle(human) == towed_vehicle)) then 
  1361. 			return 
  1362. 		end 
  1363.  
  1364. 		-- Reset the police min notoriety 
  1365. 		notoriety_reset("Police") 
  1366. 		notoriety_set_max("Police", 2) 
  1367.  
  1368.       local cur_tow_truck_name = get_char_vehicle_name( human ) 
  1369.       for index, tow_truck_name in pairs( Tss04_tow_trucks ) do 
  1370.          if ( cur_tow_truck_name == tow_truck_name ) then 
  1371.             on_vehicle_enter( "", cur_tow_truck_name ) 
  1372.             on_vehicle_exit( "", cur_tow_truck_name ) 
  1373.             marker_remove_vehicle( cur_tow_truck_name ) 
  1374. 		      set_unjackable_flag( cur_tow_truck_name, true ) 
  1375.          end 
  1376.       end 
  1377.  
  1378. 		-- Force the vehicle to stop 
  1379. 		vehicle_stop(human) 
  1380. 		-- Force the player out of the vehicle...don't allow the vehicle to be enterable 
  1381. 		vehicle_exit(human, true) 
  1382. 		-- Lock the vehicle towed vehicle 
  1383. 		set_unjackable_flag(towed_vehicle, true) 
  1384.  
  1385. 		-- Remove the trigger effect from the person who has made it here 
  1386. 		marker_remove_trigger(TOWED_VEHICLE_TRIGGER, sync_type) 
  1387. 		-- Direct the player to his next goal of being outside of the garage 
  1388. 		minimap_icon_add_trigger(TOWED_COMPLETE_TRIGGER, MINIMAP_ICON_LOCATION, "", sync_type) 
  1389.  
  1390.       -- Release the mourners and trash to the world so it can be populated 
  1391.       for i = 1, Num_tss04_mourners, 1 do 
  1392.          if (not character_is_released(Tss04_mourners[i])) then 
  1393.             release_to_world(Tss04_mourners[i]) 
  1394.          end 
  1395.       end 
  1396.  
  1397.       if (IN_COOP) then 
  1398.          -- Only do these when in coop 
  1399.          for i = 1, Num_tss04_trash, 1 do 
  1400.             if (not character_is_released(Tss04_trash[i])) then 
  1401.                release_to_world(Tss04_trash[i]) 
  1402.             end 
  1403.          end 
  1404.       end 
  1405.  
  1406.       tss04_towtruck_complete( human ) 
  1407. 	end 
  1408. end 
  1409.  
  1410. function tss04_towtruck_complete(human) 
  1411. 	local		is_local_player = (human == LOCAL_PLAYER) 
  1412. 	local		is_remote_player = (human == REMOTE_PLAYER) 
  1413.  
  1414. 	-- Must be one of the players and must be in the tow truck with the hitched vehicle 
  1415. 	if (not is_local_player and not is_remote_player) then 
  1416. 		return 
  1417. 	elseif (character_is_in_vehicle(human)) then 
  1418. 		return 
  1419. 	end 
  1420.  
  1421. 	-- Kill the regenerate thread...it is no longer needed 
  1422. 	thread_kill(TOWTRUCK_REGENERATE) 
  1423.  
  1424. 	-- Remove the callback functions 
  1425. 	on_vehicle_destroyed("", LOCAL_TOWED_VEHICLE) 
  1426. 	-- Remove the on vehicle hitched callback 
  1427. 	on_vehicle_hitched("", LOCAL_TOWED_VEHICLE) 
  1428. 	-- Remove the on vehicle unhitched callback 
  1429. 	on_vehicle_unhitched("", LOCAL_TOWED_VEHICLE) 
  1430. 	-- Remove the towed vehicle marker 
  1431. 	marker_remove_vehicle(LOCAL_TOWED_VEHICLE, SYNC_LOCAL) 
  1432.  
  1433.    for index, tow_truck_name in pairs( Tss04_tow_trucks ) do 
  1434.       marker_remove_vehicle( tow_truck_name, SYNC_ALL ) 
  1435.       on_vehicle_exit( "", tow_truck_name ) 
  1436.       on_vehicle_enter( "", tow_truck_name ) 
  1437.       set_unjackable_flag( tow_truck_name, false ) 
  1438.    end 
  1439.  
  1440. 	-- We do not need these vehicles anymore 
  1441. 	release_to_world(GROUP_TOWTRUCK_1) 
  1442. 	release_to_world(GROUP_TOWTRUCK_2) 
  1443. 	release_to_world(GROUP_TOWED_VEHICLE) 
  1444. 	tss04_unmark_tow_target( LOCAL_PLAYER ) 
  1445.  
  1446. 	if (IN_COOP) then 
  1447. 		tss04_unmark_tow_target( REMOTE_PLAYER ) 
  1448. 		-- Remove the callback functions 
  1449. 		on_vehicle_destroyed("", REMOTE_TOWED_VEHICLE) 
  1450. 		-- Remove the on vehicle hitched callback 
  1451. 		on_vehicle_hitched("", REMOTE_TOWED_VEHICLE) 
  1452. 		-- Remove the on vehicle unhitched callback 
  1453. 		on_vehicle_unhitched("", REMOTE_TOWED_VEHICLE) 
  1454. 		-- Remove the towed vehicle marker 
  1455. 		marker_remove_vehicle(REMOTE_TOWED_VEHICLE, SYNC_REMOTE) 
  1456.  
  1457. 		-- We do not need these vehicles anymore 
  1458. 		release_to_world(GROUP_TOWED_VEHICLE_COOP) 
  1459.  
  1460. 		-- Carlos needs to be dependent 
  1461. 		follower_make_independent(Tss04_3_phase_table[TOWTRUCK_INDEX][CHARACTER_INDEX], false) 
  1462. 	end 
  1463.  
  1464. 	-- Disable all of the towed to trigger stuff 
  1465. 	on_trigger("", TOWED_VEHICLE_TRIGGER) 
  1466. 	trigger_enable(TOWED_VEHICLE_TRIGGER, false) 
  1467. 	marker_remove_trigger(TOWED_VEHICLE_TRIGGER, SYNC_ALL) 
  1468.  
  1469. 	-- Disable all of the towed to trigger stuff 
  1470. 	on_trigger("", TOWED_COMPLETE_TRIGGER) 
  1471. 	trigger_enable(TOWED_COMPLETE_TRIGGER, false) 
  1472. 	minimap_icon_remove_trigger(TOWED_COMPLETE_TRIGGER, SYNC_ALL) 
  1473.  
  1474. 	-- Remove the waypoints that were added 
  1475. 	waypoint_remove(SYNC_ALL) 
  1476.    trigger_type_enable( "car mechanic", true ) 
  1477.  
  1478.    -- Clear notoriety here to fix a TDL 
  1479.    notoriety_set( "brotherhood", 0 ) 
  1480.    notoriety_set( "ronin", 0 ) 
  1481.    notoriety_set( "samedi", 0 ) 
  1482.    notoriety_set( "police", 0 ) 
  1483.  
  1484. 	tss04_phase_completed(human, Tss04_3_phase_table[TOWTRUCK_INDEX][CHARACTER_INDEX]) 
  1485. end 
  1486.  
  1487. function tss04_killing_phase() 
  1488. 	-- Create the three groups of 2, 3, and 4 Ronin 
  1489. 	group_create(GROUP_RONIN, false) 
  1490.  
  1491. 	-- Pierce cannot be abandoned 
  1492. 	on_dismiss("tss04_phase_lieutenant_abandoned", Tss04_3_phase_table[KILLING_INDEX][CHARACTER_INDEX]) 
  1493.  
  1494. 	if (IN_COOP) then 
  1495. 		-- Set max notoriety 
  1496. 		notoriety_set_max("Ronin", 3) 
  1497.  
  1498. 		-- In coop there is a timer 
  1499. 		hud_timer_set(0, 1000 * 60 * 2, "tss04_killing_timer_expired") 
  1500.    end 
  1501.  
  1502.    -- Add on_death function for the scripted characters... 
  1503.    for i = 1, Num_tss04_ronin, 1 do 
  1504.       on_death("tss04_ronin_killed", Tss04_ronin[i]) 
  1505.    end 
  1506.  
  1507.    -- Mark the group of npcs 
  1508.    marker_add_group(GROUP_RONIN, MINIMAP_ICON_KILL, INGAME_EFFECT_KILL, SYNC_ALL) 
  1509.  
  1510.    -- Soldiers follow the lieutenants 
  1511.    for i = 2, Num_tss04_ronin_group1, 1 do 
  1512.       npc_follow_npc(Tss04_ronin_group1[i], Tss04_ronin_group1[1]) 
  1513.    end 
  1514.  
  1515.    for i = 2, Num_tss04_ronin_group2, 1 do 
  1516.       npc_follow_npc(Tss04_ronin_group2[i], Tss04_ronin_group2[1]) 
  1517.    end 
  1518.  
  1519.    for i = 2, Num_tss04_ronin_group3, 1 do 
  1520.       npc_follow_npc(Tss04_ronin_group3[i], Tss04_ronin_group3[1]) 
  1521.    end 
  1522.  
  1523.    -- Have the lieutenants wander 
  1524.    wander_start(Tss04_ronin_group1[1], Tss04_ronin_group1[1], 10.0) 
  1525.    wander_start(Tss04_ronin_group2[1], Tss04_ronin_group2[1], 10.0) 
  1526.    wander_start(Tss04_ronin_group3[1], Tss04_ronin_group3[1], 30.0) 
  1527.  
  1528.    -- Set max notoriety 
  1529.    notoriety_set_max("Ronin", 2) 
  1530.    -- Disable notoriety spawning 
  1531.    notoriety_force_no_spawn("Ronin", true) 
  1532.  
  1533.    objective_text(0, "tss04_killing", Tss04_ronin_kills, Num_tss04_ronin) 
  1534.  
  1535. 	-- Make sure the group is visible 
  1536. 	group_show(GROUP_RONIN) 
  1537.  
  1538. 	-- Show the shooting stunts tutorial 
  1539.    if ( tutorial_completed( "shooting_stunts" ) == false ) then 
  1540.    	tutorial_start("shooting_stunts", 5000, true) 
  1541.    end 
  1542. end 
  1543.  
  1544. function tss04_ronin_killed(victim, attacker) 
  1545. 	on_death("", victim) 
  1546. 	marker_remove_npc(victim, SYNC_ALL) 
  1547.  
  1548. 	Tss04_ronin_kills = Tss04_ronin_kills + 1 
  1549.  
  1550. 	objective_text(0, "tss04_killing", Tss04_ronin_kills, Num_tss04_ronin) 
  1551.  
  1552. 	-- Have all of the scripted enemies died? 
  1553. 	if (Tss04_ronin_kills >= Num_tss04_ronin) then 
  1554. 		-- Release the ronin group to the world 
  1555. 		release_to_world(GROUP_RONIN) 
  1556. 		-- We need notoriety spawning to continue 
  1557. 		notoriety_force_no_spawn("Ronin", false) 
  1558.  
  1559. 		tss04_phase_completed(attacker, Tss04_3_phase_table[KILLING_INDEX][CHARACTER_INDEX]) 
  1560. 	end 
  1561. end 
  1562.  
  1563. function tss04_killing_timer_expired() 
  1564. 	-- The stunt timer elapsed 
  1565. 	mission_end_failure("tss04", "tss04_killing_timer") 
  1566. end