sr2lua/rn04.lua

  1. -- rn04.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. 	DEBUG_TEXT_NUM_LIVING			= 1 
  8. 	DEBUG_TEXT_RESPAWN_COUNT		= 2 
  9. 	DEBUG_TEXT_RESPAWN_LOCATION	= 3	 
  10.  
  11. 	DEBUG_TEXT_ENABLED = { 
  12. 		[DEBUG_TEXT_NUM_LIVING]			=	false, 
  13. 		[DEBUG_TEXT_RESPAWN_COUNT]		=	false, 
  14. 		[DEBUG_TEXT_RESPAWN_LOCATION] =	false, 
  15. 	} 
  16. 	 
  17. 	DEBUG_SKIP_CHURCH_JUMP  = false -- If true, church jump is skipped 
  18.  
  19. 	-- KNOBS_TO_TURN -- 
  20.  
  21.  
  22. 			--[[ *** READ ME *** 
  23. 			 
  24. 				Whenever a script function looks up a wave parameter, a naming convention is used to select the appropriate value. 
  25. 				Parameter values for single player missions can use any name, say "PARAMETER_1" for example. If you wish to have 
  26. 				a different value for that parameter in coop, then prepend "COOP" to the parameter name. In this case, we get 
  27. 				"COOP_PARAMETER_1". 
  28.  
  29. 				When a mission function needs to access "PARAMETER_1", it will search for the appropriate overloaded values first: 
  30.  
  31. 					*	Single player will use the value stored in "PARAMETER_1". 
  32. 				 
  33. 					*	Coop will use the value stored in "COOP_PARAMETER_1", if it exists. Otherwise it will use the 
  34. 						default single player value stored in "PARAMETER_1". 
  35. 			 ]] 
  36.  
  37. 			-- Mission parameters 
  38. 			RN04_PARAMETERS	=  
  39. 				{	 
  40. 					-- Parameters used in both stages 
  41. 							["HOMIE_VEHICLE_SPEED_OVERRIDE"]		= 65,		-- Speed of the homie's vehicle 
  42. 							["HOMIE_VEHICLE_HEALTH_MULTIPLIER"]	= 4,	-- Health multiplier of the homie's vehicle 
  43.  
  44. 					-- Stage 1, defend the house 
  45.  
  46. 						-- single-player values 
  47. 							["GAT_HIT_POINTS"]				= 5000,	-- How many hit points Gat has 
  48. 							["MIN_RONIN_NOTORIETY"]			= 2,		-- Minimum Ronin notoriety during the defend Gat stage 
  49. 							["MAX_RONIN_NOTORIETY"]			= 2,		-- Maximum Ronin notoriety during the defend Gat stage 
  50. 							["PLAYER_DIALOGUE_DELAY_S"]	= 45,		-- 60 Delay before player says "Where the hell is that ambulance!"  
  51. 							["CELL_PHONE_DELAY_S"]			= 5,		-- Delay between player's dialogue and phone call 
  52. 							["WAVE_MIN_SIZE"]					= 2,		-- Min number of Ronin to attack in one wave 
  53. 							["WAVE_MAX_SIZE"]					= 3,		-- Max number of Ronin to attack in one wave 
  54. 							["WAVE_MIN_DELAY_S"]				= 6,		-- Min delay between waves 
  55. 							["WAVE_MAX_DELAY_S"]				= 10,		-- Max delay between waves 
  56. 							["MAX_LIVING"]						= 6,		-- Maximum number of Ronin that can be alive at one time 
  57.  
  58. 						-- coop values 
  59. 							["COOP_MIN_RONIN_NOTORIETY"]			= 3, 
  60. 							["COOP_MAX_RONIN_NOTORIETY"]			= 3, 
  61. 							["COOP_WAVE_MIN_SIZE"]					= 3, 
  62. 							["COOP_WAVE_MAX_SIZE"]					= 5, 
  63. 							["COOP_WAVE_MIN_DELAY_S"]				= 2, 
  64. 							["COOP_WAVE_MAX_DELAY_S"]				= 4, 
  65. 							["COOP_MAX_LIVING"]						= 10, 
  66.  
  67. 					-- Stage 2, hospital drive part 1 
  68. 					 
  69. 						-- single-player values 
  70. 							["MIN_RONIN_NOTORIETY_DRIVE"]	= 3,		-- Minimum Ronin notoriety while driving to the hospital 
  71. 							["MAX_RONIN_NOTORIETY_DRIVE"]	= 4,		-- Maximum Ronin notoriety while driving to the hospital 
  72. 							["BIKE_CHASE_SPEED"]				= 75,		-- Speed of Ronin chasing the players on bikes 
  73. 							["CAR_CHASE_SPEED"]				= 75,		-- Speed of Ronin chasing the players in cars 
  74. 							["BIKE_CHASE_HP"]					= 800,	-- Speed of Ronin chasing the players on bikes 
  75. 							["CAR_CHASE_HP"]					= 1600,	-- Speed of Ronin chasing the players in cars 
  76. 							["MAX_CHASE_VEHICLES"]			= 5,		-- Limits # vehicles chasing players at any time 
  77. 							["CHASE_TRAFFIC_DENSITY"]		= .40,	-- Traffic desnity during the chase 
  78.  
  79. 						-- coop values 
  80. 							["COOP_MIN_RONIN_NOTORIETY_DRIVE"]	= 4, 
  81. 							["COOP_MAX_RONIN_NOTORIETY_DRIVE"]	= 5, 
  82. 							["COOP_BIKE_CHASE_HP"]			= 1200,	-- Speed of Ronin chasing the players on bikes 
  83. 							["COOP_CAR_CHASE_HP"]			= 2400,	-- Speed of Ronin chasing the players in cars 
  84. 							["COOP_MAX_CHASE_VEHICLES"]	= 8 
  85. 				} 
  86.  
  87. 	-- COOP MISSION? --  
  88. 		IN_COOP	= false 
  89.  
  90. 	-- CHARACTERS -- 
  91.  
  92. 		CHARACTER_GAT		= "rn04_$Cgat" 
  93. 		CHARACTER_HOMIE	= "rn04_$Chomie" 
  94.  
  95. 	-- CONVERSATIONS 
  96. 	   DELIRIOUS_CONVERSATION = 
  97. 		{ 
  98. 			{ "RON4_DELERIUM_L1", CHARACTER_GAT, 1 }, 
  99. 			{ "PLAYER_RON4_DELERIUM_L2", LOCAL_PLAYER, 1 }, 
  100. 			{ "RON4_DELERIUM_L3", CHARACTER_GAT, 1 }, 
  101. 			{ "RON4_DELERIUM_L4", CHARACTER_HOMIE, 1 }, 
  102. 			{ "PLAYER_RON4_DELERIUM_L5", LOCAL_PLAYER, 1 }, 
  103. 		} 
  104.  
  105. 	   HOMIE_PHONE_CONVERSATION = 
  106. 		{ 
  107. 			{ "PLAYER_RON4_COME_L1", LOCAL_PLAYER, 1 }, 
  108. 			{ "RON4_COME_L2", CELLPHONE_CHARACTER, 1 }, 
  109. 		} 
  110.  
  111.  
  112. 	-- CHECKPOINTS 
  113. 		 
  114. 		CHECKPOINT_START						= MISSION_START_CHECKPOINT			-- defined in ug_lib.lua 
  115. 		CHECKPOINT_DRIVE					= "rn04_checkpoint_drive" 
  116. 		 
  117. 	-- GROUPS -- 
  118.  
  119. 		GROUP_GAT							= "rn04_$Ggat" 
  120. 		GROUP_START_VEHICLES				= "rn04_$Gstart_vehicles" 
  121. 		GROUP_HOMIE							= "rn04_$Ghomie" 
  122. 		GROUP_STAGE_1_RONIN				= "rn04_$Gstage_1_ronin" 
  123. 		GROUP_STAGE_1_RONIN_VEHICLES	= "rn04_$Gstage_1_ronin_vehicles" 
  124. 		GROUP_CHASE_0						= "rn04_$Gchase_0" 
  125. 		GROUP_CHASE_1						= "rn04_$Gchase_1" 
  126. 		GROUP_ROADBLOCK_1					= "rn04_$Groadblock_1" 
  127. 		GROUP_ROADBLOCK_2					= "rn04_$Groadblock_2" 
  128. 		GROUP_ROADBLOCK_3					= "rn04_$Groadblock_3" 
  129.  
  130.  
  131. 	-- GROUP MEMBER TABLES --  
  132. 	 
  133. 		MEMBERS_GROUP_STAGE_1_RONIN		=	{	"rn04_$c000", "rn04_$c001", "rn04_$c002", "rn04_$c003", "rn04_$c004", 
  134. 															"rn04_$c005", "rn04_$c006", "rn04_$c007", "rn04_$c008", "rn04_$c009", 
  135. 															"rn04_$c010", "rn04_$c011", "rn04_$c012", "rn04_$c013", "rn04_$c014", 
  136. 															"rn04_$c015"} 
  137. 	-- HELPTEXT 
  138.  
  139. 		-- Failure conditions 
  140.  
  141. 			HELPTEXT_FAILURE_CAR_DESTROYED	= "rn04_failure_car_destroyed"	-- "Car destroyed." 
  142. 			HELPTEXT_FAILURE_GAT_DIED			= "rn04_failure_gat_died"		 
  143. 			HELPTEXT_FAILURE_GAT_ABANDONED	= "rn04_failure_gat_abandoned" 
  144.  
  145. 		-- Stage 1  
  146.  
  147. 			HELPTEXT_PROMPT_DEFEND_GAT			= "rn04_prompt_defend_gat"			-- "Protect Gat til the ambulance arrives." 
  148.  
  149. 			--HELPTEXT_DIALOGUE_PLAYER_WHERE	= "rn04_dialogue_player_where"	-- "Playa: What the fuck is taking so long?" X 
  150. 			--HELPTEXT_DIALOGUE_GAT_HEALTH_80	= "rn04_dialogue_gat_health_80"	-- "Gat: Tis but a flesh wound." X 
  151. 			--HELPTEXT_DIALOGUE_GAT_HEALTH_40	= "rn04_dialogue_gat_health_40"	-- "Gat: Johnny Gat always triumphs! Have at you! Come on then." X 
  152. 			--HELPTEXT_DIALOGUE_GAT_HEALTH_10	= "rn04_dialogue_gat_health_10"	-- "Gat: I'll bite your les off!." X 
  153.  
  154. 			HELPTEXT_HUD_AMBULANCE_TIMER		= "rn04_hud_ambulance_timer"		-- "Time until ambulance arrival" X 
  155. 			HELPTEXT_HUD_GAT_HEALTH				= "rn07_hud_gat_health"				-- "Johnny Gat's Health" 
  156.  
  157. 			HELPTEXT_PROMPT_KEEP_WAITING		= "rn04_prompt_keep_waiting"		-- "Keep waiting til help comes." X 
  158. 			HELPTEXT_PROMPT_GAT_HEALTH_50		= "rn04_prompt_gat_health_50"		-- "Gat is not looking good." X 
  159. 			HELPTEXT_PROMPT_GAT_HEALTH_30		= "rn04_prompt_gat_health_30"		-- "Gat is barely hanging on." X 
  160. 			HELPTEXT_PROMPT_CLEAR_AREA			= "rn04_prompt_clear_area"			-- "Clear out the area before help arrives." X 
  161. 			HELPTEXT_PROMPT_CAR_ARIIVAL		= "rn04_prompt_car_arrival"		-- "Help has arrived." X 
  162.  
  163. 		-- Stage 2 
  164.  
  165. 			HELPTEXT_HUD_CAR_HEALTH				= "rn04_hud_car_health"				-- "Car Health" 
  166.  
  167. 			HELPTEXT_PROMPT_DEFEND_CAR			= "rn04_prompt_defend_car"			-- "Protect the car from Ronin until you get to the hospital." X 
  168. 			HELPTEXT_PROMPT_GAT_DELIRIOUS		= "rn04_prompt_gat_delirious"		-- "Hurry, Gat's becoming delirious!" X 
  169.  
  170. 		-- UNLOCALIZED !! 
  171. 			HELPTEXT_OBJECTIVE_CLEAR			= "rn05_objective_ltnts"			-- "%s of %s Ronin lieutenants killed"	 
  172.  
  173. 	-- MISC CONSTANTS 
  174. 		RONIN_SAFE_SPAWN_DIST			= 100	 -- Distance at which we can safely spawn Ronin 
  175. 		RONIN_RESPAWN_TIME_MS			= 250  -- Time in MS before respawning 
  176. 		RONIN_RESPAWN_DISTANCE			= 0.01 -- Distance corpse must be from player in order to respawn 
  177.  
  178. 		WAVE_INITIAL_SPAWN_LOCATIONS =  
  179. 			{	 
  180. 				"rn04_$n100", "rn04_$n101", "rn04_$n102", "rn04_$n103", "rn04_$n104", 
  181. 				"rn04_$n105", "rn04_$n106", "rn04_$n107", "rn04_$n108", "rn04_$n109" 
  182. 			} 
  183.  
  184. 		WAVE_SPAWN_LOCATIONS =  
  185. 			{	 
  186. --				{"rn04_$n000", "rn04_$n001", "rn04_$n002", "rn04_$n003", "rn04_$n004"}; 
  187. 				{"rn04_$n005", "rn04_$n006", "rn04_$n007", "rn04_$n008", "rn04_$n009"}; 
  188. 				{"rn04_$n010", "rn04_$n011", "rn04_$n012", "rn04_$n013", "rn04_$n014"}; 
  189. 				{"rn04_$n015", "rn04_$n016", "rn04_$n017", "rn04_$n018", "rn04_$n019"};				 
  190. 				{"rn04_$n068", "rn04_$n069", "rn04_$n070", "rn04_$n071", "rn04_$n072"};		 
  191. 			} 
  192.  
  193. 		LOCAL_PLAYER_WEAPON				= "rpg_launcher" 
  194. 		REMOTE_PLAYER_WEAPON				= "rpg_launcher" 
  195.  
  196. 		ESCAPE_PATH_PART1	=	{	"rn04_$n074", "rn04_$n033", "rn04_$n034"} 
  197. 		ESCAPE_PATH_PART2 =	{	"rn04_$n035", "rn04_$n036", "rn04_$n039", "rn04_$n040", "rn04_$n041", "rn04_$n042"} 
  198. 		ESCAPE_PATH_PART3	=	{	"rn04_$n043", "rn04_$n044", "rn04_$n045"} 
  199. 		ESCAPE_PATH_PART4 =  {	"rn04_$n046"} 
  200. 		ESCAPE_PATH_PART5	=	{	"rn04_$n047"} 
  201. 		ESCAPE_PATH_PART5b=	{	"rn04_$n110", "rn04_$n111", "rn04_$n112", "rn04_$n113", "rn04_$n114", "rn04_$n115", "rn04_$n116"} 
  202. 		ESCAPE_PATH_PART5c =	{	"rn04_$n052", "rn04_$n021"} 
  203. 		ESCAPE_PATH_PART6 =	{	"rn04_$n022", "rn04_$n023"} 
  204. 		ESCAPE_PATH_PART6a=	{	"rn04_$n067", "rn04_$n117", "rn04_$n118"} 
  205. 		ESCAPE_PATH_PART6b=	{	"rn04_$n119", "rn04_$n120", "rn04_$n121", "rn04_$n122", "rn04_$n123", "rn04_$n124", "rn04_$n125"} 
  206. 		ESCAPE_PATH_PART6c=	{	"rn04_$n126", "rn04_$n127", "rn04_$n128", "rn04_$n129", "rn04_$n130", "rn04_$n131"} 
  207. 		ESCAPE_PATH_PART6d=	{	"rn04_$n132", "rn04_$n133", "rn04_$n134", "rn04_$n135", "rn04_$n136", "rn04_$n137"} 
  208. 		ESCAPE_PATH_PART6e=	{	"rn04_$n138", "rn04_$n139", "rn04_$n140", "rn04_$n141", "rn04_$n142", "rn04_$n143"} 
  209. 		ESCAPE_PATH_PART7 =	{	"rn04_$n144", "rn04_$n145", "rn04_$n146", "rn04_$n032"} 
  210.  
  211. 		HOMIE_ARRIVAL_PATH = {	"rn04_$n073", "rn04_$n024"} 
  212.  
  213. 	-- MOVERS 
  214.  
  215. 	-- NAVPOINTS 
  216. 	 
  217. 		NAVPOINT_ATTACK_LOCATION 		= "rn04_$n147" 
  218.  
  219. 		NAVPOINT_LOCAL_PLAYER_START		= "rn04_$Nlocal_player_start" 
  220. 		NAVPOINT_REMOTE_PLAYER_START		= "rn04_$Nremote_player_start" 
  221.  
  222. 		--NAVPOINT_HOMIE_ARRIVAL				= "rn04_$n024"	-- Where the homies park to pick up player(s) & Gat 
  223. 		NAVPOINT_HOSPITAL_PARKING			= "rn04_$n048" -- Where the homie parks in the hospital parking lot to end the mission. 
  224.  
  225. 	-- TRIGGERS --  
  226. 	 
  227. 		TRIGGER_CHASE_1			= "rn04_$t000" 
  228. 		TRIGGER_ROADBLOCK_1		= "rn04_$t001" 
  229. 		TRIGGER_ROADBLOCK_2		= "rn04_$t002" 
  230. 		TRIGGER_ROADBLOCK_3		= "rn04_$t004" 
  231.  
  232. 		-- List of all triggers, makes cleaning up more convenient 
  233. 		TABLE_ALL_TRIGGERS		= {	TRIGGER_CHASE_1, TRIGGER_ROADBLOCK_1, TRIGGER_ROADBLOCK_2, 
  234. 												TRIGGER_ROADBLOCK_3}		 
  235.  
  236. 	-- VEHICLES -- 
  237. 		VEHICLE_HOMIE_CHOICES	= {	"rn04_$Vhomie1", "rn04_$Vhomie2", "rn04_$Vhomie3", "rn04_$Vhomie4", "rn04_$Vhomie5"} 
  238. 		--Rn04_vehicle_homie				= "rn04_$Vhomie_new" 
  239.  
  240. 	-- VEHICLE SPAWN LOCATIONS (for first sequence attacks) 
  241.  
  242. 		VEHICLE_SPAWN_LOCATIONS =  
  243. 			{ 
  244. 				{ 
  245. 					["navpoint"] = "rn04_$n076", 
  246. 					["torque multiplier"] = 2, 
  247. 					["jump speed"] = 70, 
  248. 					["jump path"] = {"rn04_$n079"}, 
  249. 					["destination path"] = {"rn04_$n082", "rn04_$n097"}, 
  250. 					["vehicle"] = "rn04_$v014", 
  251. 				}, 
  252. 				{ 
  253. 					["navpoint"] = "rn04_$n083", 
  254. 					["destination path"] = {"rn04_$n084", "rn04_$n085", "rn04_$n086", "rn04_$n098"}, 
  255. 					["vehicle"] = "rn04_$v015", 
  256. 				}, 
  257. 				{ 
  258. 					["navpoint"] = "rn04_$n087", 
  259. 					["destination path"] = {"rn04_$n088", "rn04_$n089", "rn04_$n090", "rn04_$n091"}, 
  260. 					["vehicle"] = "rn04_$v016", 
  261. 				}, 
  262. 				{	 
  263. 					["navpoint"] = "rn04_$n075", 
  264. 					["torque multiplier"] = 2, 
  265. 					["jump speed"] = 55, 
  266. 					["jump path"] = {"rn04_$n080"}, 
  267. 					["destination path"] = {"rn04_$n081"}, 
  268. 					["vehicle"] = "rn04_$v017", 
  269. 				}, 
  270. 				{ 
  271. 					["navpoint"] = "rn04_$n092", 
  272. 					["destination path"] = {"rn04_$n093", "rn04_$n094", "rn04_$n099"}, 
  273. 					["vehicle"] = "rn04_$v018", 
  274. 				}, 
  275. 				{ 
  276. 					["navpoint"] = "rn04_$n095", 
  277. 					["destination path"] = {"rn04_$n096"}, 
  278. 					["vehicle"] = "rn04_$v019", 
  279. 				}, 
  280. 			} 
  281.  
  282. 	-- CHASE / AMBUSHES 
  283.  
  284. 		CHASES_AND_AMBUSHES =  
  285. 		{	 
  286. 		 
  287. 		["chase_0"]	=	 
  288. 			{	["type"]			=	"chase", 
  289. 				["vehicles"]	=	{	["rn04_$v006"]		=	{	["passengers"]	= {	"rn04_$c029"},  
  290. 																			["type"]			= "bike" 
  291. 																		}, 
  292. 											["rn04_$v007"]		=	{	["passengers"]	= {	"rn04_$c030"},  
  293. 																			["type"]			= "bike" 
  294. 																		}, 
  295. 										}, 
  296. 				["on_foot"]		=	{}, 
  297. 				-- No trigger, we start this chase immediately 
  298. 			}, 
  299.  
  300. 		 
  301. 		 
  302. 			["chase_1"]	=	 
  303. 			{	["type"]			=	"chase", 
  304. 				["group"]		=	GROUP_CHASE_1, 
  305. 				["vehicles"]	=	{	["rn04_$v001 (0)"] =	{	["passengers"]	= {	"rn04_$c017 (0)"},  
  306. 																			["type"]			= "car", 
  307. 																			["jump"]			= true, 
  308. 																			["delay_s"]		= 2.0, 
  309. 																		}, 
  310. 											["rn04_$v000"]		=	{	["passengers"]	= {	"rn04_$c016",	"rn04_$c017"},  
  311. 																			["type"]			= "car" 
  312. 																		}, 
  313. 											["rn04_$v001"]		=	{	["passengers"]	= {	"rn04_$c018"},  
  314. 																			["type"]			= "car" 
  315. 																		}, 
  316. 										}, 
  317. 				["on_foot"]		= {	"rn04_$c019",	"rn04_$c020"}, 
  318. 				["trigger"]		= TRIGGER_CHASE_1 
  319. 			}, 
  320.  
  321. 			["roadblock_1"]	=	 
  322. 			{	["type"]			=	"roadblock", 
  323. 				["group"]		=	GROUP_ROADBLOCK_1, 
  324. 				["vehicles"]	=	{	["rn04_$v002"]	=	{	["passengers"]	= {	"rn04_$c023",	"rn04_$c024"},  
  325. 																		["type"]			= "car" 
  326. 																	}, 
  327. 											["rn04_$v003"] =	{	["passengers"]	= {	"rn04_$c026"},  
  328. 																		["type"]			= "car" 
  329. 																	}, 
  330. 											["rn04_$v004"] =	{	["passengers"]	= {	"rn04_$c022",	"rn04_$c025"},  
  331. 																		["type"]			= "car" 
  332. 																	}, 
  333. 											["rn04_$v005"] =	{	["passengers"]	= {	"rn04_$c028"},  
  334. 																		["type"]			= "bike" 
  335. 																	}, 
  336. 										}, 
  337. 				["on_foot"]		=	{	"rn04_$c021",	"rn04_$c022",	"rn04_$c023",	"rn04_$c024",	"rn04_$c025", 
  338. 											"rn04_$c026",	"rn04_$c027",	"rn04_$c028" 
  339. 										}, 
  340. 				["misfire"]		=	{	["rn04_$c027"]	= "rn04_$n038" 
  341. 										}, 
  342. 				["trigger"]		=	TRIGGER_ROADBLOCK_1, 
  343. 			}, 
  344.  
  345. 			["roadblock_2"]	=	 
  346. 			{	["type"]			=	"roadblock", 
  347. 				["group"]		=	GROUP_ROADBLOCK_2, 
  348. 				["vehicles"]	=	{	["rn04_$v008"]	=	{	["passengers"]	= {	"rn04_$c031"},  
  349. 																		["type"]			= "car" 
  350. 																	}, 
  351. 											["rn04_$v009"] =	{	["passengers"]	= {	"rn04_$c032",	"rn04_$c033"},  
  352. 																		["type"]			= "car" 
  353. 																	}, 
  354. 										}, 
  355. 				["on_foot"]		=	{	 
  356. 										}, 
  357. 				["trigger"]		=	TRIGGER_ROADBLOCK_2, 
  358. 			}, 
  359.  
  360. 			["roadblock_3"]	=	 
  361. 			{	["type"]			=	"roadblock", 
  362. 				["group"]		=	GROUP_ROADBLOCK_3, 
  363. 				["vehicles"]	=	{	["rn04_$v010"]	=	{	["passengers"]	= {	"rn04_$c034", "rn04_$c035"},  
  364. 																		["type"]			= "car" 
  365. 																	}, 
  366. 											["rn04_$v011"] =	{	["passengers"]	= {	"rn04_$c036", "rn04_$c037"},  
  367. 																		["type"]			= "car" 
  368. 																	}, 
  369. 											["rn04_$v012"] =	{	["passengers"]	= {	"rn04_$c038"},  
  370. 																		["type"]			= "bike" 
  371. 																	}, 
  372. 											["rn04_$v013"] =	{	["passengers"]	= {	"rn04_$c039", "rn04_$c040"},  
  373. 																		["type"]			= "bike" 
  374. 																	}, 
  375. 										}, 
  376. 				["on_foot"]		=	{	"rn04_$c034", "rn04_$c035", "rn04_$c036", "rn04_$c037", "rn04_$c038",  
  377. 											"rn04_$c039", "rn04_$c040", 
  378. 										}, 
  379. 				["misfire"]		=	{	["rn04_$c038"]	= "rn04_$n020" 
  380. 										}, 
  381. 				["trigger"]		=	TRIGGER_ROADBLOCK_3, 
  382. 			}, 
  383. 		} 
  384.  
  385.  
  386. -- Progress flags 
  387. 	Ambulance_timer_expired					= false 
  388. 	Clearing_ronin								= false -- Are players clearing out Ronin? 
  389. 	Chase_or_ambush_sent						= false 
  390.  
  391. -- Misc 
  392. 	Spawning_initial_ronin					= true 
  393. 	Ronin_to_clear								= 0 
  394. 	Ronin_cleared								= 0 
  395. 	Vehicles_attacking						= 0 
  396. 	Last_complication							= "" 
  397. 	Spawnable_ronin							= {} 
  398. 	Spawnable_vehicle							= {} 
  399. 	Spawn_area_navpoint_index				= {} 
  400. 	Vehicle_navpoint_index					= 1 
  401. 	Ragdolling_gat								= true 
  402. 	Thread_ragdoll_gat						= -1 
  403. 	Temp_weapons_given						= false 
  404.  
  405. 	-- There is a lot of random helptext and I don't want messages to get overriden. 
  406. 	-- So, I'm queing up messages to be displayed and have a separate thread that  
  407. 	-- handles printing to the screen. There are two queuess, one for important 
  408. 	-- prompts and dialogue and another for the random lines. Messages in the 2nd 
  409. 	-- queue are only displayed if the first queue is empty. 
  410. 	Helptext_queue_high_priority			= {} 
  411. 	Helptext_queue_high_priority_first	= 1	-- Index of the next message to display (Will index a nil value if no messages in queue) 
  412. 	Helptext_queue_high_priority_last	= 0	-- Index of the last message currently in the queue (Same warning) 
  413. 	Helptext_queue_low_priority			= {} 
  414. 	Helptext_queue_low_priority_first	= 1 
  415. 	Helptext_queue_low_priority_last		= 0 
  416. 	Last_message_displayed					= "" 
  417.  
  418. function rn04_start(rn04_checkpoint, is_restart) 
  419.  
  420. 	mission_start_fade_out() 
  421.  
  422. 	if(rn04_checkpoint == CHECKPOINT_START) then 
  423.  
  424. 		local start_groups = {GROUP_GAT, GROUP_START_VEHICLES, GROUP_STAGE_1_RONIN, GROUP_STAGE_1_RONIN_VEHICLES} 
  425.  
  426. 		if (is_restart) then 
  427.  
  428. 			-- Load starting groups 
  429. 			for i,group in pairs(start_groups) do 
  430. 				group_create_hidden(group, true) 
  431. 			end 
  432.  
  433. 			-- Teleport players to the start location 
  434. 			teleport_coop(NAVPOINT_LOCAL_PLAYER_START, NAVPOINT_REMOTE_PLAYER_START, true) 
  435.  
  436. 		else 
  437. 			-- Play the intro cutscene 
  438. 			cutscene_play("ro04-01", start_groups, {NAVPOINT_LOCAL_PLAYER_START, NAVPOINT_REMOTE_PLAYER_START}, false) 
  439. 		end 
  440.  
  441. 		group_show(GROUP_GAT) 
  442. 		group_show(GROUP_START_VEHICLES) 
  443.  
  444. 	end 
  445.  
  446. 	rn04_initialize(rn04_checkpoint) 
  447.  
  448. 	-- Stage 1: Player(s) defend Gat from waves of attacking Ronin 
  449. 	if(rn04_checkpoint == CHECKPOINT_START) then 
  450.  
  451. 		-- Start loading in the homie 
  452. 		group_create_hidden(GROUP_HOMIE, true) 
  453.  
  454. 		turn_vulnerable(CHARACTER_GAT) 
  455. 		turn_vulnerable(LOCAL_PLAYER) 
  456. 		if (IN_COOP) then 
  457. 			turn_vulnerable(REMOTE_PLAYER) 
  458. 		end		 
  459.  
  460. 		rn04_defend_gat() 
  461.  
  462. 		-- CHECKPOINT! 
  463. 		delay(1.0) 
  464.  
  465. 		-- Make sure that the homie and his vehicle will be saved by the checkpoint system 
  466. 		vehicle_mark_as_players(Rn04_vehicle_homie, LOCAL_PLAYER) 
  467. 		party_dismiss_all()  
  468. 		party_add(CHARACTER_HOMIE, LOCAL_PLAYER) 
  469.  
  470. 		mission_set_checkpoint(CHECKPOINT_DRIVE) 
  471. 		rn04_checkpoint = CHECKPOINT_DRIVE 
  472.  
  473. 		-- Fade out and disable player controls 
  474. 		fade_out(0.0,{0,0,0}, SYNC_ALL) 
  475. 		fade_out_block() 
  476.  
  477. 		player_controls_disable(LOCAL_PLAYER) 
  478. 		if (IN_COOP) then 
  479. 			player_controls_disable(REMOTE_PLAYER) 
  480. 		end 
  481.  
  482. 		-- Create the chase group... this needs to happen before the teleport_coop in rn04_setup_vehicle_occupants 
  483. 		group_create(GROUP_CHASE_0, true) 
  484.  
  485. 		-- Place the correct people in the vehicle 
  486. 		rn04_setup_vehicle_occupants() 
  487.  
  488. 		-- Prepare for the drive to the hospital 
  489. 		rn04_setup_hospital_drive() 
  490.  
  491. 		-- Fade into the game 
  492. 		fade_in(1.0, SYNC_ALL) 
  493. 		fade_in_block() 
  494.  
  495. 		-- Reenable player controls 
  496. 		player_controls_enable(LOCAL_PLAYER) 
  497. 		if (IN_COOP) then 
  498. 			player_controls_enable(REMOTE_PLAYER) 
  499. 		end 
  500.  
  501.  
  502. 	end -- ends CHECKPOINT_START 
  503.  
  504. 	-- Stage 2 
  505. 	if (rn04_checkpoint == CHECKPOINT_DRIVE) then 
  506.  
  507. 		rn04_drive_to_hospital() 
  508. 		 
  509. 	end -- ends CHECKPOINT_DRIVE 
  510.  
  511. 	-- Don't have the mission succeed if we didn't arrive at the destination. 
  512. 	if (vehicle_is_destroyed(Rn04_vehicle_homie) or get_dist(Rn04_vehicle_homie, NAVPOINT_HOSPITAL_PARKING) > 15) then 
  513. 		rn04_failure_car_destroyed() 
  514. 		while(true) do 
  515. 			thread_yield() 
  516. 		end 
  517. 	else 
  518. 		-- Mission end 
  519. 		rn04_complete() 
  520. 	end 
  521.  
  522. end 
  523.  
  524. function rn04_initialize(checkpoint) 
  525.  
  526. 	rn04_initialize_common() 
  527.  
  528. 	rn04_initialize_checkpoint(checkpoint) 
  529.  
  530. 	rn04_initialize_common_post() 
  531.  
  532. 	mission_start_fade_in() 
  533. end 
  534.  
  535. function rn04_initialize_common() 
  536.  
  537. 	-- Start trigger is hit...the activate button was hit 
  538. 	set_mission_author("Phillip Alexander") 
  539.  
  540. 	if (coop_is_active()) then 
  541. 		IN_COOP	= true 
  542. 	end 
  543.  
  544. 	-- Start the thread that will display helptext 
  545. 	thread_new("rn04_display_helptext") 
  546.  
  547. 	notoriety_set("Police",0) 
  548. 	notoriety_set_max("Police", 0) 
  549. end 
  550.  
  551. function rn04_initialize_common_post() 
  552.  
  553. 	npc_suppress_persona(CHARACTER_GAT, true) 
  554. 	character_prevent_flinching(CHARACTER_GAT, true) 
  555. 	character_disallow_ragdoll(CHARACTER_GAT) 
  556.  
  557. end 
  558.  
  559.  
  560. function rn04_initialize_checkpoint(checkpoint) 
  561.  
  562. 	if(checkpoint == CHECKPOINT_START) then 
  563.  
  564. 		-- Make sure that no one is damaged before we fade in 
  565. 		turn_invulnerable(CHARACTER_GAT, false) 
  566. 		turn_invulnerable(LOCAL_PLAYER, false) 
  567. 		if (IN_COOP) then 
  568. 			turn_invulnerable(REMOTE_PLAYER, false) 
  569. 		end 
  570.  
  571. 		-- Don't allow the player to dial 911 
  572. 		cell_spawns_enable(false) 
  573.  
  574. 		-- Setup Gat. 
  575. 		on_death("rn04_failure_gat_died", CHARACTER_GAT) 
  576. 		on_dismiss("rn04_failure_gat_abandoned", CHARACTER_GAT) 
  577. 		character_make_priority_target(CHARACTER_GAT, true, 10) 
  578. 		set_unrecruitable_flag(CHARACTER_GAT, true) 
  579. 		inv_item_remove_all(CHARACTER_GAT) 
  580. 		npc_combat_enable(CHARACTER_GAT, false) 
  581.  
  582. 		-- Eliminate ambient gang spawning and set notoriety levels 
  583. 		ambient_gang_spawn_enable(false) 
  584. 		spawning_allow_cop_ambient_spawns(false) 
  585. 		notoriety_set_max("Ronin",rn04_get_parameter_value("MAX_RONIN_NOTORIETY"))		 
  586. 		notoriety_set_min("Ronin",rn04_get_parameter_value("MIN_RONIN_NOTORIETY"))	 
  587.  
  588. 		-- Turn off notoriety spawning 
  589. 		notoriety_force_no_spawn("Ronin", true)  
  590. 		 
  591. 		-- Make sure Johnny Gat stays ragdolled 
  592. 		Thread_ragdoll_gat = thread_new("rn04_ragdoll_johnny_gat") 
  593.  
  594. 		-- Play messages/dialogue when Gat's health drops below certain levels 
  595. 		thread_new("rn04_display_gat_health_messages") 
  596.  
  597. 		-- Override the respawn distance for Ronin soldiers 
  598. 		npc_respawn_dist_override(RONIN_RESPAWN_DISTANCE) 
  599.  
  600. 		-- Have Ronin attack the player(s), wait for initial group to spawn 
  601. 		thread_new("rn04_attack_in_waves") 
  602. 		while(Spawning_initial_ronin) do 
  603. 			thread_yield() 
  604. 		end 
  605.  
  606. 		city_chunk_set_all_civilians_fleeing("sr2_chunk182", true) 
  607. 		spawning_pedestrians(false, false) 
  608. 		action_nodes_enable(false) 
  609. 	end 
  610.  
  611. 	if (checkpoint == CHECKPOINT_DRIVE) then 
  612.  
  613. 		group_create(GROUP_GAT, true) 
  614. 		teleport(CHARACTER_HOMIE, NAVPOINT_LOCAL_PLAYER_START) 
  615. 		character_show(CHARACTER_HOMIE) 
  616.  
  617. 		spawning_allow_cop_ambient_spawns(false) 
  618.  
  619. 		-- Create the chase group... this needs to happen before the teleport_coop in rn04_setup_vehicle_occupants 
  620. 		group_create(GROUP_CHASE_0, true) 
  621.  
  622. 		-- Place the correct people in the vehicle 
  623. 		rn04_setup_vehicle_occupants() 
  624.  
  625. 		-- Prepare for the drive to the hospital 
  626. 		rn04_setup_hospital_drive() 
  627.  
  628.  
  629. 	end 
  630.  
  631. end 
  632.  
  633. function rn04_defend_gat() 
  634.  
  635. 	-- Gat grunts when taking damage 
  636. 	local thread_gat_grunt = thread_new("rn04_gat_grunt_damage") 
  637.  
  638. 	-- Tell the player to defend Gat 
  639. 	rn04_add_high_priority_helptext(HELPTEXT_PROMPT_DEFEND_GAT) 
  640. 	marker_add_npc(CHARACTER_GAT, MINIMAP_ICON_PROTECT_ACQUIRE, INGAME_EFFECT_PROTECT_ACQUIRE, SYNC_ALL) 
  641. 	set_max_hit_points(CHARACTER_GAT,rn04_get_parameter_value("GAT_HIT_POINTS")) 
  642. 	damage_indicator_on(1, CHARACTER_GAT,0.0, HELPTEXT_HUD_GAT_HEALTH) 
  643.  
  644. 	-- Delay, then play Player dialogue 
  645. 	hud_timer_set(0, rn04_get_parameter_value("PLAYER_DIALOGUE_DELAY_S")*1000,"rn04_ambulance_timer_expired") 
  646. 	while(not Ambulance_timer_expired) do 
  647. 		thread_yield() 
  648. 	end 
  649.  
  650. 	-- Player wonders what is taking so long 
  651. 	audio_play_for_character("PLAYER_RON4_FIRST_WAVE_01", LOCAL_PLAYER, "voice", false, true) 
  652. 	delay(2) 
  653. 	rn04_add_high_priority_helptext(HELPTEXT_PROMPT_KEEP_WAITING) 
  654.  
  655. 	-- Homie calls the player after a bit 
  656. 	delay(rn04_get_parameter_value("CELL_PHONE_DELAY_S")) 
  657.  
  658. 	rn04_homie_phone_call() 
  659.  
  660. 	-- Tell the player to clear out the Ronin before the homie arrives 
  661. 	rn04_add_high_priority_helptext(HELPTEXT_PROMPT_CLEAR_AREA) 
  662. 	Clearing_ronin = true 
  663. 	marker_remove_npc(CHARACTER_GAT, SYNC_ALL) 
  664.  
  665. 	-- Add markers on on_death callbacks to all of the Ronin that are still attacking 
  666. 	for i,ronin in pairs(MEMBERS_GROUP_STAGE_1_RONIN) do 
  667. 		if ( (Spawnable_ronin[ronin] == false) and (not character_is_dead(ronin)) and (not character_hidden(ronin))) then 
  668. 			Ronin_to_clear = Ronin_to_clear + 1	 
  669. 			marker_add_npc(ronin, MINIMAP_ICON_KILL, INGAME_EFFECT_KILL, SYNC_ALL) 
  670. 			on_death("rn04_ronin_killed", ronin) 
  671. 		end 
  672. 	end 
  673.  
  674. 	-- Wait for all of the Ronin to be killed before sending in the Homie 
  675. 	if (Ronin_to_clear > 0) then 
  676. 		objective_text(0, HELPTEXT_OBJECTIVE_CLEAR, Ronin_cleared, Ronin_to_clear) 
  677. 		while (Ronin_to_clear > Ronin_cleared)  do 
  678. 			thread_yield() 
  679. 		end 
  680. 	end 
  681. 	objective_text_clear(0) 
  682.  
  683. 	thread_kill(thread_gat_grunt) 
  684.  
  685. 	-- Homie to the rescue 
  686.  
  687. 		-- Get the closest vehicle that is out of sight of the player 
  688. 		-- (If none in sight, get the furthest) 
  689. 		local max_dist = -1 
  690. 		local min_dist = 5000 
  691. 		local far_vehicle = "" 
  692. 		local near_vehicle = "" 
  693. 		for i,vehicle in pairs(VEHICLE_HOMIE_CHOICES) do 
  694.  
  695. 			local dist = get_dist_closest_player_to_object(vehicle) 
  696.  
  697. 			-- Is this the furthest vehicle that we've found? 
  698. 			if (dist > max_dist) then 
  699. 				max_dist = dist 
  700. 				far_vehicle = vehicle 
  701. 			end 
  702.  
  703. 			-- Is it the closest out of sight vehicle that we've found? 
  704. 			if((not rn04_navpoint_in_fov(vehicle,3)) and (dist < min_dist)) then 
  705. 				min_dist = dist 
  706. 				near_vehicle = vehicle 
  707. 			end 
  708. 		end 
  709.  
  710. 		if(near_vehicle ~= "") then 
  711. 			Rn04_vehicle_homie = near_vehicle 
  712. 		else 
  713. 			Rn04_vehicle_homie = far_vehicle 
  714. 		end 
  715.  
  716. 		-- Destroy other vehicles in the group to the world 
  717. 		for i,vehicle in pairs(VEHICLE_HOMIE_CHOICES) do 
  718. 			if (Rn04_vehicle_homie ~= vehicle) then 
  719. 				object_destroy(vehicle) 
  720. 			end 
  721. 		end 
  722.  
  723. 		-- Place the homie in the vehicle 
  724. 		vehicle_enter_teleport(CHARACTER_HOMIE,Rn04_vehicle_homie,0) 
  725. 		set_seatbelt_flag(CHARACTER_HOMIE,true) 
  726.  
  727. 		-- make them visible 
  728. 		vehicle_show(Rn04_vehicle_homie) 
  729. 		character_show(CHARACTER_HOMIE) 
  730.  
  731. 		-- Don't let the vehicle/homie be destroyed before the player(s) knows that it is mission-critical 
  732. 		turn_invulnerable(CHARACTER_HOMIE, false) 
  733. 		turn_invulnerable(Rn04_vehicle_homie, false) 
  734. 		vehicle_prevent_explosion_fling(Rn04_vehicle_homie, true)  
  735.  
  736. 		-- prepare for turret base driving 
  737. 		rn04_setup_homie_car(Rn04_vehicle_homie) 
  738.  
  739. 		-- Send homie to Aisha's place 
  740. 		vehicle_turret_base_to(Rn04_vehicle_homie, HOMIE_ARRIVAL_PATH,true) 
  741. 		audio_play_for_character("BMTSS1_RON4_SECOND_WAVE_01", CHARACTER_HOMIE, "voice", false, true) 
  742.  
  743. 		-- Gat's damage indicator is no longer needed. 
  744. 		damage_indicator_off(1) 
  745.  
  746. 	-- Make the homie and his vehicle vulnerable again. 
  747. 		turn_vulnerable(Rn04_vehicle_homie) 
  748.  
  749. end 
  750.  
  751. function rn04_gat_grunt_damage() 
  752.  
  753. 	delay(10) 
  754.  
  755. 	local gat_max_hit_points = rn04_get_parameter_value("GAT_HIT_POINTS") 
  756.  
  757. 	local function gat_health_ratio() 
  758. 		if (character_is_dead(CHARACTER_GAT)) then 
  759. 			return 0 
  760. 		end 
  761. 		local gat_hit_points = get_current_hit_points(CHARACTER_GAT) 
  762. 		return gat_hit_points / gat_max_hit_points 
  763. 	end 
  764.  
  765. 	while (gat_health_ratio() > .90) do 
  766. 		thread_yield() 
  767. 	end 
  768. 	if (not character_is_dead(CHARACTER_GAT)) then 
  769. 		audio_play_persona_line(CHARACTER_GAT, "voice - pain shout", 50) 
  770. 	end 
  771.  
  772. 	while (gat_health_ratio() > .8) do 
  773. 		thread_yield() 
  774. 	end 
  775. 	if (not character_is_dead(CHARACTER_GAT)) then 
  776. 		audio_play_for_character("GAT_RON4_RANDOM_DELERIUM", CHARACTER_GAT, "voice", false, true) 
  777. 	end 
  778.  
  779. 	while (gat_health_ratio() > .60) do 
  780. 		thread_yield() 
  781. 	end 
  782. 	if (not character_is_dead(CHARACTER_GAT)) then 
  783. 		audio_play_persona_line(CHARACTER_GAT, "voice - pain shout", 50) 
  784. 	end 
  785.  
  786. 	while (gat_health_ratio() > .40) do 
  787. 		thread_yield() 
  788. 	end 
  789. 	if (not character_is_dead(CHARACTER_GAT)) then 
  790. 		audio_play_for_character("GAT_RON4_RANDOM_DELERIUM", CHARACTER_GAT, "voice", false, true) 
  791. 	end 
  792.  
  793. 	while (gat_health_ratio() > .25) do 
  794. 		thread_yield() 
  795. 	end 
  796. 	if (not character_is_dead(CHARACTER_GAT)) then 
  797. 		audio_play_persona_line(CHARACTER_GAT, "voice - death scream", 50) 
  798. 	end 
  799.  
  800. end 
  801.  
  802. function rn04_setup_vehicle_occupants() 
  803.  
  804. 	-- Make sure that no random ped or vehicle spawns obstruct our vehicle 
  805. 	spawning_pedestrians(false, true) 
  806. 	spawning_vehicles(false) 
  807.  
  808. 	-- Teleport players to the start location 
  809. 	teleport_coop(NAVPOINT_LOCAL_PLAYER_START, NAVPOINT_REMOTE_PLAYER_START, true) 
  810.  
  811. 	-- Dismiss any extra followers and put Johnny Gat and the homie in the player's party 
  812. 	party_dismiss_all()  
  813. 	party_add(CHARACTER_HOMIE, LOCAL_PLAYER) 
  814.  
  815. 	if (IN_COOP) then 
  816. 		party_add(CHARACTER_GAT, REMOTE_PLAYER) 
  817. 	else 
  818. 		party_add(CHARACTER_GAT, LOCAL_PLAYER) 
  819. 	end 
  820. 	 
  821. 	thread_kill(Thread_ragdoll_gat) 
  822. 	Ragdolling_gat = false 
  823.  
  824. 	-- First make sure that the players aren't already in a vehicle 
  825. 	character_evacuate_from_all_vehicles(LOCAL_PLAYER) 
  826. 	if IN_COOP then 
  827. 		character_evacuate_from_all_vehicles(REMOTE_PLAYER) 
  828. 	end 
  829. 	character_evacuate_from_all_vehicles(CHARACTER_HOMIE) 
  830.  
  831. 	-- Kick everyone out of the homie's vehicle 
  832. 	vehicle_evacuate(Rn04_vehicle_homie) 
  833.  
  834. 	delay(0.5) 
  835.  
  836. 	-- Stop allowing npcs to exit the vehicle 
  837. 	vehicle_suppress_npc_exit(Rn04_vehicle_homie, true) 
  838. 	set_seatbelt_flag(CHARACTER_HOMIE,true) 
  839.  
  840. 	-- Then place everyone inside 
  841. 	set_unjackable_flag(Rn04_vehicle_homie, false) 
  842. 	follower_make_independent(CHARACTER_HOMIE, true) 
  843. 	follower_make_independent(CHARACTER_GAT, true) 
  844. 	vehicle_enter_teleport(CHARACTER_HOMIE,Rn04_vehicle_homie,0) 
  845. 	vehicle_enter_teleport(CHARACTER_GAT,Rn04_vehicle_homie,2) 
  846. 	vehicle_enter_teleport(LOCAL_PLAYER,Rn04_vehicle_homie,1) 
  847. 	set_unjackable_flag(Rn04_vehicle_homie, true) 
  848. 	if IN_COOP then 
  849. 		vehicle_enter_teleport(REMOTE_PLAYER,Rn04_vehicle_homie,3) 
  850. 	end 
  851.  
  852. 	while( not character_is_in_vehicle(CHARACTER_GAT, Rn04_vehicle_homie) ) do 
  853. 		thread_yield() 
  854. 	end 
  855. 	while( not character_is_in_vehicle(CHARACTER_HOMIE, Rn04_vehicle_homie) ) do 
  856. 		thread_yield() 
  857. 	end 
  858. 	while( not character_is_in_vehicle(LOCAL_PLAYER,Rn04_vehicle_homie)) do 
  859. 		thread_yield() 
  860. 	end 
  861. 	if (IN_COOP) then 
  862. 		local teleport_attempts = 1 
  863. 		while( (not character_is_in_vehicle(REMOTE_PLAYER,Rn04_vehicle_homie)) and (teleport_attempts < 5) ) do 
  864. 			set_unjackable_flag(Rn04_vehicle_homie, false) 
  865. 			vehicle_enter_teleport(REMOTE_PLAYER, Rn04_vehicle_homie, 2) 
  866. 			set_unjackable_flag(Rn04_vehicle_homie, true) 
  867. 			teleport_attempts = teleport_attempts + 1 
  868. 			delay(1.0) 
  869. 		end 
  870. 		-- Delay 1 more second or the client has a tendency to see themselves spawn outside of the car. 
  871. 		delay(1.0) 
  872. 	end 
  873.  
  874. 	character_set_injured(CHARACTER_GAT, true) 
  875.  
  876. 	-- Allow vehicle spawning 
  877. 	spawning_vehicles(true) 
  878.  
  879. end 
  880.  
  881. function rn04_setup_hospital_drive() 
  882.  
  883. 	-- Set the min/max Ronin notoriety 
  884. 	notoriety_set_max("Ronin",rn04_get_parameter_value("MAX_RONIN_NOTORIETY_DRIVE")) 
  885. 	notoriety_set_min("Ronin",rn04_get_parameter_value("MIN_RONIN_NOTORIETY_DRIVE")) 
  886.  
  887. 	-- set traffic density 
  888. 	set_traffic_density(rn04_get_parameter_value("CHASE_TRAFFIC_DENSITY")) 
  889.  
  890. 	-- give the player(s) better weapon 
  891. 	inv_weapon_add_temporary(LOCAL_PLAYER, LOCAL_PLAYER_WEAPON, 1, true) 
  892. 	inv_item_equip(LOCAL_PLAYER_WEAPON,LOCAL_PLAYER) 
  893. 	if (IN_COOP) then 
  894. 		inv_weapon_add_temporary(REMOTE_PLAYER, REMOTE_PLAYER_WEAPON, 1, true) 
  895. 		inv_item_equip(REMOTE_PLAYER_WEAPON,REMOTE_PLAYER) 
  896. 	end 
  897. 	Temp_weapons_given = true 
  898.  
  899. 	-- Get Gat ready 
  900. 	inv_item_remove_all(CHARACTER_GAT) 
  901. 	npc_combat_enable(CHARACTER_GAT, false) 
  902. 	character_set_injured(CHARACTER_GAT, true) 
  903.  
  904. 	-- Prepare homie 
  905. 	set_seatbelt_flag(CHARACTER_HOMIE,true) 
  906. 	character_set_injured(CHARACTER_GAT, true) 
  907.  
  908. 	-- Start the first chase 
  909. 	rn04_complication("chase_0") 
  910.  
  911. 	-- Prepare the vehicle for turret mode 
  912. 	rn04_setup_homie_car(Rn04_vehicle_homie) 
  913. 	on_vehicle_destroyed("rn04_failure_car_destroyed", Rn04_vehicle_homie) 
  914. 	set_unjackable_flag(Rn04_vehicle_homie, true) 
  915.  
  916. 	-- Player(s) can not enter/exit vehicles 
  917. 	set_player_can_enter_exit_vehicles(LOCAL_PLAYER, false) 
  918. 	if (IN_COOP) then 
  919. 		set_player_can_enter_exit_vehicles(REMOTE_PLAYER, false) 
  920. 	end 
  921.  
  922. 	-- Allow spawning 
  923. 	spawning_pedestrians(true) 
  924. 	action_nodes_enable(true) 
  925. 	spawning_vehicles(true) 
  926.  
  927. 	-- Start spawning Ronin and cops again 
  928. 	ambient_gang_spawn_enable(true) 
  929. 	spawning_allow_cop_ambient_spawns(true) 
  930. 	notoriety_force_no_spawn("Ronin", false) 
  931.  
  932. end 
  933.  
  934. function rn04_drive_to_hospital() 
  935.  
  936. 	-- start the thread that will release the initial Ronin vehicles 
  937. 	thread_new("rn04_initial_ronin_release") 
  938.  
  939. 	-- start the chase and ambush thread 
  940. 	thread_new("rn04_chase_and_ambush") 
  941.  
  942. 	-- Gat is getting loopy! 
  943. 	thread_new("rn04_play_gat_delirious_conversation") 
  944.  
  945. 	-- Turret base away! 
  946. 	roadblocks_enable(false) 
  947.  
  948. 	-- Tell the player to defend the car. 
  949. 	rn04_add_high_priority_helptext(HELPTEXT_PROMPT_DEFEND_CAR) 
  950.  
  951. 	-- Head to roadblock 
  952. 	vehicle_turret_base_to(Rn04_vehicle_homie, ESCAPE_PATH_PART1, false) 
  953. 	audio_play_for_character("BMTSS1_RON4_ROADBLOCK_01", CHARACTER_HOMIE, "voice", false, false) 
  954.  
  955. 	-- Make a u-turn and leave the roadblock 
  956. 	--rn04_add_high_priority_helptext(HELPTEXT_DIALOGUE_HOMIE_U_TURN) 
  957. 	thread_new("rn04_homie_vehicle_speed_spurt",Rn04_vehicle_homie, 4, 70) 
  958.  
  959. 	-- Start pathfinding to the jump location 
  960. 	vehicle_turret_base_to(Rn04_vehicle_homie, ESCAPE_PATH_PART2, false) 
  961.  
  962. 	-- Ignore repulsors for the remainder of the path to the jump 
  963. 	vehicle_ignore_repulsors(Rn04_vehicle_homie, true) 
  964. 	vehicle_turret_base_to(Rn04_vehicle_homie, ESCAPE_PATH_PART3, false) 
  965. 	vehicle_turret_base_to(Rn04_vehicle_homie, ESCAPE_PATH_PART4, false) 
  966.  
  967. 	-- Increase speed to the ramp. 
  968. 	vehicle_max_speed(Rn04_vehicle_homie,80) 
  969. 	vehicle_speed_override(Rn04_vehicle_homie,80) 
  970.  
  971. 	if ( not DEBUG_SKIP_CHURCH_JUMP) then 
  972. 		-- Switch to navmesh pathfinding before the church jump. Otherwise the ai will turn 
  973. 		-- back onto a traffic spline before completing the jump. 
  974. 		vehicle_set_torque_multiplier(Rn04_vehicle_homie, 1.5) 
  975. 		vehicle_set_script_hard_goto(Rn04_vehicle_homie,true) 
  976. 		turn_invulnerable(Rn04_vehicle_homie, false) 
  977.  
  978. 		audio_play_for_character("BMTSS1_RON4_CHURCH_JUMP_01", CHARACTER_HOMIE, "voice", false, false) 
  979.  
  980. 		vehicle_pathfind_to(Rn04_vehicle_homie,ESCAPE_PATH_PART5, true, false) 
  981. 		--thread_new("rn04_homie_vehicle_speed_spurt",Rn04_vehicle_homie, 5, 86) 
  982.  
  983. 		-- Wait until we're airborne before Gat mouths off any more. 
  984. 		local became_airborne = false 
  985. 		local airborne_checks = 0 
  986. 		local max_airborne_checks = 60 
  987. 		while ( (not vehicle_in_air(Rn04_vehicle_homie)) and (airborne_checks < max_airborne_checks) ) do 
  988. 			airborne_checks = airborne_checks + 1 
  989. 			thread_yield() 
  990. 		end 
  991. 		if (airborne_checks < max_airborne_checks) then 
  992. 			became_airborne = true 
  993. 		end 
  994.  
  995. 		-- If we didn't get airborne, we're going to skip some stuff	 
  996. 		if (became_airborne) then 
  997. 			--rn04_add_high_priority_helptext(HELPTEXT_DIALOGUE_GAT_JUMP) 
  998. 			delay(4.0) 
  999. 		end 
  1000.  
  1001. 		vehicle_set_torque_multiplier(Rn04_vehicle_homie, 1.2) 
  1002. 	end 
  1003.  
  1004. 	-- Make sure that we've landed before calling pathfinding code again. 
  1005. 	while (vehicle_in_air(Rn04_vehicle_homie)) do 
  1006. 		thread_yield() 
  1007. 	end 
  1008. 	delay(0.25) 
  1009. 	turn_vulnerable(Rn04_vehicle_homie) 
  1010. 	vehicle_speed_cancel(Rn04_vehicle_homie) 
  1011. 	vehicle_ignore_repulsors(Rn04_vehicle_homie, false) 
  1012.  
  1013. 	-- Head to the ditch 
  1014. 	audio_play_for_character("BMTSS1_RON4_DITCH_JUMP_01", CHARACTER_HOMIE, "voice", false, false) 
  1015. 	vehicle_turret_base_to(Rn04_vehicle_homie, ESCAPE_PATH_PART5b, false) 
  1016. 	vehicle_turret_base_to(Rn04_vehicle_homie, ESCAPE_PATH_PART5c, false) 
  1017.  
  1018. 	-- Say something about the roadblock 
  1019. 	audio_play_for_character("BMTSS1_RON4_DITCH_JUMP_01", CHARACTER_HOMIE, "voice", false, false) 
  1020. 	-- Use navmesh pathfinding up to the roadblock, only have gps-only splines in this area.  
  1021. 	-- Also stop at the splines end so that we don't end up in the agua  
  1022. 	vehicle_pathfind_to(Rn04_vehicle_homie,ESCAPE_PATH_PART6, true, true) 
  1023. 	audio_play_for_character("BMTSS1_RON4_AROUND_DITCH_01", CHARACTER_HOMIE, "voice", false, false) 
  1024.  
  1025. 	-- Play random dialogue for Gat: 
  1026. 	thread_new("rn04_play_gat_delirious_messages") 
  1027.  
  1028. 	-- Do a u-turn to exit the ditch. Run over anyone in our way 
  1029. 	vehicle_ignore_repulsors(Rn04_vehicle_homie, true) 
  1030. 	vehicle_pathfind_to(Rn04_vehicle_homie,ESCAPE_PATH_PART6a, true, false) 
  1031. 	vehicle_ignore_repulsors(Rn04_vehicle_homie, false) 
  1032.  
  1033. 	vehicle_set_use_short_cuts(Rn04_vehicle_homie, false) 
  1034.  
  1035. 	vehicle_turret_base_to(Rn04_vehicle_homie, ESCAPE_PATH_PART6b, false) 
  1036. 	vehicle_turret_base_to(Rn04_vehicle_homie, ESCAPE_PATH_PART6c, false) 
  1037. 	vehicle_turret_base_to(Rn04_vehicle_homie, ESCAPE_PATH_PART6d, false) 
  1038. 	vehicle_turret_base_to(Rn04_vehicle_homie, ESCAPE_PATH_PART6e, false) 
  1039.  
  1040. 	-- Make a u-turn and leave the roadblock 
  1041. 	--thread_new("rn04_homie_vehicle_speed_spurt",Rn04_vehicle_homie, 4, 70) 
  1042.  
  1043. 	vehicle_turret_base_to(Rn04_vehicle_homie, ESCAPE_PATH_PART7, false) 
  1044.  
  1045. 	-- Pathfind into the parking lot 
  1046. 	vehicle_pathfind_to(Rn04_vehicle_homie,NAVPOINT_HOSPITAL_PARKING, true, true) 
  1047.  
  1048. 	-- Thank the homie 
  1049. 	audio_play_for_character("PLAYER_RON4_HOSPITAL_01", LOCAL_PLAYER, "voice", false, true) 
  1050.  
  1051. end 
  1052.  
  1053. function rn04_initial_ronin_release() 
  1054.  
  1055. 	delay(30) 
  1056. 	release_to_world(GROUP_START_VEHICLES) 
  1057. 	release_to_world(GROUP_STAGE_1_RONIN) 
  1058. 	release_to_world(GROUP_STAGE_1_RONIN_VEHICLES) 
  1059.  
  1060. end 
  1061.  
  1062. -- Spawn waves of ronin to attack ceiling supports that the player(s) is(are) defending 
  1063. Num_living_attackers = 0 
  1064. Num_ronin_spawned = 0 
  1065. Spawnable_ronin = {} 
  1066. Spawn_locations_next_navpoint_index	= {} 
  1067. function rn04_attack_in_waves() 
  1068.  
  1069. 	-- Set respawn dist threshold very low. 
  1070. 	npc_respawn_dist_override(RONIN_RESPAWN_DISTANCE) 
  1071. 	 
  1072. 	-- All ronin are initially spawnable 
  1073. 	for i, ronin in pairs(MEMBERS_GROUP_STAGE_1_RONIN) do 
  1074. 		Spawnable_ronin[ronin] = true 
  1075. 	end 
  1076.  
  1077. 	-- Convenience variables for wave size parameters. 
  1078. 	local min_wave_size = rn04_get_parameter_value("WAVE_MIN_SIZE") 
  1079. 	local max_wave_size = rn04_get_parameter_value("WAVE_MAX_SIZE") 
  1080. 	local max_attackers = rn04_get_parameter_value("MAX_LIVING") 
  1081.  
  1082. 	local min_wave_delay = rn04_get_parameter_value("WAVE_MIN_DELAY_S") 
  1083. 	local max_wave_delay = rn04_get_parameter_value("WAVE_MAX_DELAY_S") 
  1084.  
  1085. 	-- Returns the next wave size 
  1086. 	local function get_next_wave_size() 
  1087. 		local next_wave_size = rand_int(min_wave_size, max_wave_size) 
  1088. 		rn04_debug_text("Next wave size = " .. next_wave_size, DEBUG_TEXT_RESPAWN_COUNT) 
  1089. 		return next_wave_size 
  1090. 	end 
  1091.  
  1092. 	-- Size of the next wave to spawn 
  1093. 	local next_wave_size = get_next_wave_size() 
  1094.  
  1095. 	-- Continuously check the number of Ronin attacking, spawn more if needed. 
  1096. 	while(not Clearing_ronin) do 
  1097.  
  1098. 		-- Spawn the next wave if there is room. 
  1099. 		if (next_wave_size + Num_living_attackers <= max_attackers) then 
  1100.  
  1101. 			local num_ronin_in_wave = rn04_send_wave(next_wave_size) 
  1102. 			Num_ronin_spawned = Num_ronin_spawned + num_ronin_in_wave 
  1103. 			Num_living_attackers = Num_living_attackers + num_ronin_in_wave 
  1104. 			rn04_debug_text("Ronin spawned, Num_living_attackers = " .. Num_living_attackers, DEBUG_TEXT_NUM_LIVING) 
  1105. 			next_wave_size =  get_next_wave_size() 
  1106.  
  1107. 			if(not Spawning_initial_ronin) then 
  1108. 				delay(rand_float(min_wave_delay, max_wave_delay)) 
  1109. 			end 
  1110.  
  1111. 		else 
  1112.  
  1113. 		-- If there isn't enough room, we can't be on the initial wave anymore 
  1114. 			Spawning_initial_ronin = false 
  1115. 		end 
  1116.  
  1117. 		thread_yield() 
  1118.  
  1119. 	end -- end while(true) 
  1120.  
  1121. end 
  1122.  
  1123. -- Send a wave of ronin to attack the players 
  1124. -- 
  1125. -- wave_size: number of attackers to send 
  1126. -- 
  1127. -- returns number of attackers successfully spawned 
  1128. function rn04_send_wave(wave_size) 
  1129.  
  1130. 	local num_ronin_spawned = 0 
  1131. 	num_ronin_spawned = rn04_maybe_send_wave_vehicle(wave_size) 
  1132. 	local peds_to_spawn = wave_size - num_ronin_spawned 
  1133.  
  1134. 	-- For each Ronin to be spawned 
  1135. 	for i=1, peds_to_spawn, 1 do 
  1136.  
  1137. 		-- Get a ronin to spawn and a safe spawning location.  
  1138. 		local ronin = rn04_get_spawnable_ronin() 
  1139. 		local spawn_navpoint = rn04_get_safe_spawn() 
  1140.  
  1141. 		-- If either one not found, return # ronin already spawned. 
  1142. 		if ( spawn_navpoint == nil ) then 
  1143. 			return num_ronin_spawned 
  1144. 		end 
  1145.  
  1146. 		-- Teleport to the spawn navpoint 
  1147. 		teleport(ronin, spawn_navpoint) 
  1148.  
  1149. 		-- We're gonna spawn this guy, do some book keeping and start its patrol 
  1150. 		num_ronin_spawned = num_ronin_spawned + 1 
  1151. 		rn04_ronin_was_spawned(ronin) 
  1152.  
  1153. 		-- Show the ronin and start its patrol 
  1154. 		character_show(ronin) 
  1155. 		rn04_ronin_attack(ronin) 
  1156.  
  1157. 		-- Delay a little bit, gives the ronin time to leave the spawn area and keeps congestion down. 
  1158. 		if (not 	Spawning_initial_ronin ) then 
  1159. 			delay(.2,.5) 
  1160. 		end 
  1161.  
  1162. 	end 
  1163.  
  1164. 	-- Return num of ronin spawned 
  1165. 	return num_ronin_spawned 
  1166.  
  1167. end 
  1168.  
  1169. function rn04_ronin_was_spawned(ronin) 
  1170.  
  1171. 	-- Tell the ronin to respawn, override default respawn time 
  1172. 	Spawnable_ronin[ronin] = false 
  1173. 	npc_respawn_after_death(ronin, true) 
  1174. 	npc_respawn_after_death_time_override(ronin, RONIN_RESPAWN_TIME_MS, true) 
  1175. 	on_respawn("rn04_respawn_ronin",ronin) 
  1176.  
  1177.  
  1178. end 
  1179.  
  1180. function rn04_maybe_send_wave_vehicle(wave_size) 
  1181.  
  1182. 	if ( Spawning_initial_ronin ) then 
  1183. 		return 0 
  1184. 	end 
  1185.  
  1186. 	local safe_vehicle_spawn_location = rn04_get_safe_wave_vehicle_spawn_location() 
  1187. 	local num_ronin_spawned = 0 
  1188.  
  1189. 	if (safe_vehicle_spawn_location) then 
  1190.  
  1191. 		local vehicle_entrance = VEHICLE_SPAWN_LOCATIONS[safe_vehicle_spawn_location] 
  1192. 		local vehicle = vehicle_entrance["vehicle"] 
  1193.  
  1194. 		Sent_wave_vehicles[vehicle] = true 
  1195.  
  1196. 		-- Place the passengers in the vehicles 
  1197. 		local num_seats = vehicle_get_num_seats(vehicle) 
  1198. 		local num_passengers = min(num_seats, wave_size) 
  1199. 		local passengers = {} 
  1200. 		for i = 1, num_passengers, 1 do 
  1201. 			local ronin = rn04_get_spawnable_ronin() 
  1202. 			if ( (ronin ~= nil) and (vehicle ~= nil) ) then 
  1203. 				passengers[i] = ronin 
  1204. 				vehicle_enter_teleport(ronin, vehicle, i-1) 
  1205. 				num_ronin_spawned = num_ronin_spawned + 1 
  1206. 				character_show(ronin) 
  1207. 				rn04_ronin_was_spawned(ronin) 
  1208. 			end 
  1209. 		end 
  1210.  
  1211. 		-- If we couldn't find any Ronin to place in the vehicle, then we won't 
  1212. 		-- be able to send the vehicle 
  1213. 		if (num_ronin_spawned == 0) then 
  1214. 			return num_ronin_spawned 
  1215. 		end 
  1216.  
  1217. 		thread_new("rn04_send_wave_vehicle", safe_vehicle_spawn_location, passengers) 
  1218. 		 
  1219. 	end 
  1220.  
  1221. 	return num_ronin_spawned 
  1222.  
  1223. end 
  1224.  
  1225. function rn04_send_wave_vehicle(spawn_location, passengers) 
  1226.  
  1227. 	local vehicle_entrance = VEHICLE_SPAWN_LOCATIONS[spawn_location] 
  1228. 	local navpoint = vehicle_entrance["navpoint"] 
  1229. 	local vehicle = vehicle_entrance["vehicle"] 
  1230. 	local jump_speed = vehicle_entrance["jump speed"] 
  1231. 	local jump_path = vehicle_entrance["jump path"] 
  1232. 	local dest_path = vehicle_entrance["destination path"] 
  1233. 	local torque_multiplier = vehicle_entrance["torque multiplier"] 
  1234.  
  1235. 	Sent_wave_vehicles[vehicle] = true 
  1236.  
  1237. 	delay(1.0) 
  1238. 	if navpoint then 
  1239. 		teleport_vehicle(vehicle, navpoint) 
  1240. 	end 
  1241. 	delay(3.0) 
  1242.  
  1243. 	vehicle_show(vehicle) 
  1244. 	for i, passenger in pairs(passengers) do 
  1245. 		character_show(passenger) 
  1246. 	end 
  1247.  
  1248. 	vehicle_infinite_mass(vehicle, true) 
  1249. 	vehicle_ignore_repulsors(vehicle, true) 
  1250. 	vehicle_set_allow_ram_ped(vehicle,true) 
  1251. 	 
  1252. 	if jump_path then 
  1253.  
  1254. 		vehicle_speed_override(vehicle, jump_speed) 
  1255. 		if torque_multiplier then 
  1256. 			vehicle_set_torque_multiplier(vehicle, torque_multiplier) 
  1257. 		end 
  1258.  
  1259. 		vehicle_pathfind_to(vehicle, jump_path, true, false) 
  1260.  
  1261. 		-- Wait for take off 
  1262. 		while (not vehicle_in_air(vehicle)) do 
  1263. 			thread_yield() 
  1264. 		end 
  1265. 		-- Wait for landing 
  1266. 		while (vehicle_in_air(vehicle)) do 
  1267. 			thread_yield() 
  1268. 		end 
  1269.  
  1270. 		-- Cancel vehicle overrides 
  1271. 		vehicle_speed_cancel(vehicle) 
  1272. 		vehicle_set_torque_multiplier(vehicle, 1.0) 
  1273. 	end 
  1274.  
  1275. 	vehicle_pathfind_to(vehicle, dest_path, true, true) 
  1276.  
  1277. 	vehicle_infinite_mass(vehicle, false) 
  1278. 	vehicle_ignore_repulsors(vehicle, false) 
  1279. 	vehicle_set_allow_ram_ped(vehicle,false) 
  1280. 	 
  1281. 	for i, passenger in pairs(passengers) do 
  1282. 		set_attack_enemies_flag(passenger, true) 
  1283. 		vehicle_exit(passenger) 
  1284. 		if(rand_float(0.0,1.0) < .70) then 
  1285. 			attack(passenger, CHARACTER_GAT) 
  1286. 		else 
  1287. 			attack(passenger, LOCAL_PLAYER) 
  1288. 		end 
  1289. 	end 
  1290. end 
  1291.  
  1292. Sent_wave_vehicles = {} 
  1293. function rn04_get_safe_wave_vehicle_spawn_location() 
  1294.  
  1295. 	for i, vehicle_info in pairs (VEHICLE_SPAWN_LOCATIONS) do 
  1296. 		local already_sent = ( Sent_wave_vehicles[vehicle_info["vehicle"]] == true) 
  1297. 		local in_fov = rn04_navpoint_in_fov(vehicle_info["navpoint"], 5) 
  1298. 		if ( (not already_sent) and (not in_fov) ) then 
  1299. 			Sent_wave_vehicles[vehicle_info["vehicle"]] = true 
  1300. 			return i 
  1301. 		end 
  1302. 	end 
  1303.  
  1304. 	return nil 
  1305.  
  1306. end 
  1307.  
  1308. function rn04_test_vehicle_entrances() 
  1309.  
  1310. 	for i,vehicle_entrance in pairs (VEHICLE_SPAWN_LOCATIONS) do 
  1311. 		 
  1312. 		local navpoint = vehicle_entrance["navpoint"] 
  1313. 		local driver = vehicle_entrance["driver"] 
  1314. 		local vehicle = vehicle_entrance["vehicle"] 
  1315. 		local jump_speed = vehicle_entrance["jump speed"] 
  1316. 		local jump_path = vehicle_entrance["jump path"] 
  1317. 		local dest_path = vehicle_entrance["destination path"] 
  1318. 		local torque_multiplier = vehicle_entrance["torque multiplier"] 
  1319.  
  1320. 		vehicle_enter_teleport(driver, vehicle) 
  1321. 		delay(1.0) 
  1322. 		if navpoint then 
  1323. 			teleport_vehicle(vehicle, navpoint) 
  1324. 		end 
  1325. 		delay(3.0) 
  1326.  
  1327. 		vehicle_show(vehicle) 
  1328. 		character_show(driver) 
  1329. 		if jump_path then 
  1330.  
  1331. 			vehicle_infinite_mass(vehicle, true) 
  1332. 			vehicle_ignore_repulsors(vehicle, true) 
  1333. 			vehicle_speed_override(vehicle, jump_speed) 
  1334. 			if torque_multiplier then 
  1335. 				vehicle_set_torque_multiplier(vehicle, torque_multiplier) 
  1336. 			end 
  1337.  
  1338. 			vehicle_pathfind_to(vehicle, jump_path, true, false) 
  1339.  
  1340. 			-- Wait for take off 
  1341. 			while (not vehicle_in_air(vehicle)) do 
  1342. 				thread_yield() 
  1343. 			end 
  1344. 			-- Wait for landing 
  1345. 			while (vehicle_in_air(vehicle)) do 
  1346. 				thread_yield() 
  1347. 			end 
  1348.  
  1349. 			-- Cancel vehicle overrides 
  1350. 			vehicle_speed_cancel(vehicle) 
  1351. 			vehicle_set_torque_multiplier(vehicle, 1.0) 
  1352. 			vehicle_infinite_mass(vehicle, false) 
  1353. 			vehicle_ignore_repulsors(vehicle, false) 
  1354. 		end 
  1355.  
  1356. 		vehicle_pathfind_to(vehicle, dest_path, true, true) 
  1357. 		vehicle_exit(driver) 
  1358. 		attack(driver) 
  1359.  
  1360. 	end 
  1361.  
  1362. 	while 1 do  
  1363. 		thread_yield() 
  1364. 	end 
  1365.  
  1366. end 
  1367.  
  1368. -- Returns a spawnable ronin if one is available, nil else. 
  1369. function rn04_get_spawnable_ronin() 
  1370.  
  1371. 	for i, ronin in pairs(MEMBERS_GROUP_STAGE_1_RONIN) do 
  1372. 		if (Spawnable_ronin[ronin] == true) then 
  1373. 			return ronin 
  1374. 		end 
  1375. 	end 
  1376.  
  1377. 	return nil 
  1378.  
  1379. end 
  1380.  
  1381. -- Handle the respawning of an attacking Ronin. 
  1382. function rn04_respawn_ronin(ronin) 
  1383.  
  1384. 	-- Update the count of living ronin 
  1385. 	Num_living_attackers = Num_living_attackers - 1 
  1386. 	rn04_debug_text("Respawn, New num_living_attackers = " .. Num_living_attackers, DEBUG_TEXT_NUM_LIVING) 
  1387.  
  1388. 	-- keep the ronin hidden for now 
  1389. 	character_hide(ronin) 
  1390.  
  1391. 	-- Make this ronin available for spawning again 
  1392. 	delay(.5) 
  1393. 	Spawnable_ronin[ronin] = true 
  1394.  
  1395. end 
  1396.  
  1397. function rn04_ronin_attack(ronin) 
  1398. 	-- setup respawning 
  1399. 	npc_respawn_after_death(ronin, true) 
  1400. 	on_respawn("rn04_respawn_ronin", ronin) 
  1401. 	on_take_damage("rn04_ronin_damaged", ronin) 
  1402.  
  1403. 	if (not 	Spawning_initial_ronin ) then 
  1404. 		move_to(ronin, NAVPOINT_ATTACK_LOCATION, 2, false, true) 
  1405. 	end 
  1406. 	 
  1407. 	if(rand_float(0.0,1.0) < .70) then 
  1408. 		attack(ronin, CHARACTER_GAT) 
  1409. 	else 
  1410. 		attack(ronin, LOCAL_PLAYER) 
  1411. 	end 
  1412. end 
  1413.  
  1414. function rn04_ronin_damaged(ronin, attacker, damage_percent) 
  1415. 	on_take_damage("", ronin) 
  1416.  
  1417. 	if(attacker == LOCAL_PLAYER) then 
  1418. 		attack(ronin, LOCAL_PLAYER) 
  1419. 	elseif(attacker == REMOTE_PLAYER) then 
  1420. 		attack(ronin, REMOTE_PLAYER) 
  1421. 	end 
  1422. 	local new_health = damage_percent*get_max_hit_points(ronin) 
  1423. 	set_current_hit_points(ronin, new_health) 
  1424.  
  1425. end 
  1426.  
  1427. function rn04_ronin_killed(ronin) 
  1428.  
  1429. 	Ronin_cleared = Ronin_cleared + 1 
  1430. 	objective_text(0, HELPTEXT_OBJECTIVE_CLEAR, Ronin_cleared, Ronin_to_clear) 
  1431.  
  1432. 	marker_remove_npc(ronin) 
  1433. 	on_death("", ronin) 
  1434. end 
  1435.  
  1436.  
  1437. -- TODO: have the following function use the preferred starting location for the initial spawns. 
  1438.  
  1439. -- Find a navpoint at which we can safely (without popping) spawn a Ronin. 
  1440. -- 
  1441. -- The search for a safe navpoint has 2 stages: 
  1442. -- 1) Try to return a navpoint from the hint location 
  1443. -- 2) Try to return a navpoint that is a certain minimum distance from the players 
  1444. -- 
  1445. -- Parameters: 
  1446. --		hint_location: location at which we'd like to spawn the npc 
  1447. -- 
  1448. --	Returns: 
  1449. --		spawn_navpoint: navpoint at which to spawn 
  1450. Rn04_initial_spawn_index = 0 
  1451. function rn04_get_safe_spawn(hint_location) 
  1452.  
  1453. 	-- The initial allotment of Ronin is spawned at a special set of nav points right in front of the 
  1454. 	-- player. We aren't doing fov checks for these, they're spawned during a fade out. 
  1455. 	if (Spawning_initial_ronin) then 
  1456. 		Rn04_initial_spawn_index = Rn04_initial_spawn_index + 1 
  1457. 		return WAVE_INITIAL_SPAWN_LOCATIONS[Rn04_initial_spawn_index] 
  1458. 	end 
  1459.  
  1460. 	-- 1) Try to return a navpoint from the preferred location: 
  1461. 	if (hint_location ~= nil) then 
  1462. 		if (rn04_location_is_safe(hint_location)) then 
  1463. 			return rn04_return_location(hint_location) 
  1464. 		end 
  1465. 	end 
  1466.  
  1467. 	-- 2) Try to return a navpoint that is a certain minimum distance from the players 
  1468.  
  1469. 	local safe_spawn_location_indices = {} 
  1470. 	local num_safe_spawn_locations = 0; 
  1471.  
  1472. 	-- Add safe spawn locations to the list 
  1473. 	for i=1, sizeof_table(WAVE_SPAWN_LOCATIONS), 1 do 
  1474.  
  1475. 		if (rn04_location_is_safe(i)) then 
  1476.  
  1477. 			num_safe_spawn_locations = num_safe_spawn_locations + 1 
  1478. 			safe_spawn_location_indices[num_safe_spawn_locations] = i 
  1479.  
  1480. 		end 
  1481.  
  1482. 	end 
  1483.  
  1484. 	-- Can't do anything if there are no safe spawn areas. 
  1485. 	if (num_safe_spawn_locations == 0) then 
  1486. 		return nil 
  1487. 	end 
  1488.  
  1489. 	-- Select a random safe spawn area 
  1490. 	return rn04_return_location(safe_spawn_location_indices[rand_int(1,num_safe_spawn_locations)])  
  1491.  
  1492. end 
  1493.  
  1494. function rn04_return_location(location_index)  
  1495.  
  1496. 	-- Get current navpoint index 
  1497. 	local current_navpoint_index = Spawn_locations_next_navpoint_index[location_index] 
  1498. 	if (current_navpoint_index == nil) then 
  1499. 		current_navpoint_index = 0 
  1500. 	end 
  1501.  
  1502. 	-- Get the navpoint that we are going to return 
  1503. 	local navpoint = WAVE_SPAWN_LOCATIONS[location_index][current_navpoint_index] 
  1504.  
  1505. 	-- Do a modular ncrement the navpoint index for this location 
  1506. 	local next_navpoint_index = current_navpoint_index + 1 
  1507. 	local max_navpoint_index = sizeof_table(WAVE_SPAWN_LOCATIONS[location_index]) 
  1508. 	if (next_navpoint_index > max_navpoint_index) then 
  1509. 		next_navpoint_index = 1 
  1510. 	end 
  1511. 	Spawn_locations_next_navpoint_index[location_index] = next_navpoint_index 
  1512.  
  1513. 	-- return the navpoint and location index 
  1514. 	return navpoint, next_navpoint_index 
  1515.  
  1516. end 
  1517.  
  1518. function rn04_location_is_safe(location_index) 
  1519.  
  1520. 	-- Get the next navpoint at this location 
  1521. 	local navpoint_index = Spawn_locations_next_navpoint_index[location_index] 
  1522. 	if (navpoint_index == nil) then 
  1523. 		navpoint_index = 1 
  1524. 	end 
  1525. 	local navpoint = WAVE_SPAWN_LOCATIONS[location_index][navpoint_index] 
  1526.  
  1527. 	-- See if the navpoint is distance-safe 
  1528. 	local dist, closest_player = get_dist_closest_player_to_object(navpoint) 
  1529. 	if (dist < 10.0 or dist > 150.0) then 
  1530. 		return false 
  1531. 	end 
  1532.  
  1533. 	if (not rn04_navpoint_in_fov(navpoint)) then 
  1534. 		return true 
  1535. 	end 
  1536. 	return false 
  1537.  
  1538. end 
  1539.  
  1540. function rn04_navpoint_in_fov(navpoint, radius) 
  1541.  
  1542. 	local navpoint_in_local_fov = navpoint_in_player_fov(navpoint, LOCAL_PLAYER, radius) 
  1543. 	local navpoint_in_remote_fov = false 
  1544. 	if (IN_COOP) then 
  1545. 		navpoint_in_remote_fov = navpoint_in_player_fov(navpoint, REMOTE_PLAYER, radius) 
  1546. 	end 
  1547.  
  1548. 	return (navpoint_in_local_fov or navpoint_in_remote_fov) 
  1549.  
  1550. end 
  1551.  
  1552. function rn04_play_gat_delirious_conversation() 
  1553. 	-- Wait a bit 
  1554. 	delay(10) 
  1555. 	audio_play_conversation( DELIRIOUS_CONVERSATION) 
  1556. end 
  1557.  
  1558. -- During stage 2, Gat becomes delirious and starts spouting nonsense. 
  1559. function rn04_play_gat_delirious_messages() 
  1560.  
  1561. 	-- Chance that Gat will talk, how often we check. 
  1562. 	local talk_chance = .50 
  1563. 	local talk_interval = 15 
  1564.  
  1565. 	-- Gat says something odd every once in a while 
  1566. 	while(true) do 
  1567. 		 
  1568. 		delay(talk_interval) 
  1569.  
  1570. 		if (not character_is_dead(CHARACTER_GAT) ) then 
  1571. 			local talk_roll = rand_float(0.0,1.0) 
  1572. 			if (talk_roll < talk_chance) then 
  1573. 				audio_play_for_character("GAT_RON4_RANDOM_DELERIUM", CHARACTER_GAT, "voice", false, true) 
  1574. 			end 
  1575. 		end 
  1576.  
  1577. 		thread_yield() 
  1578. 	end 
  1579.  
  1580. end 
  1581.  
  1582. -- When Gat's health reaches certain levels, plays dialogue lines for Gat or  
  1583. -- displays a warning prompt for the player. 
  1584. function rn04_display_gat_health_messages() 
  1585.  
  1586. 	-- Prompts given to the player to indicate that Gat's health is deteriorating 
  1587. 	local gat_health_prompts =  
  1588. 		{ 
  1589. 			{.50,	HELPTEXT_PROMPT_GAT_HEALTH_50}, 
  1590. 			{.30,	HELPTEXT_PROMPT_GAT_HEALTH_30}, 
  1591. 		} 
  1592. 	 
  1593. 	local num_health_prompts		= sizeof_table(gat_health_prompts) 
  1594. 	local next_prompt					= 1 
  1595.  
  1596. 	while	( (next_prompt <= num_health_prompts) and (not character_is_dead(CHARACTER_GAT)) )  do 
  1597. 	 
  1598. 		-- Calculate Gat's current health level on [0,1] 
  1599. 		local gat_current_health = get_current_hit_points(CHARACTER_GAT) 
  1600. 		local gat_health_ratio = get_current_hit_points(CHARACTER_GAT)/get_max_hit_points(CHARACTER_GAT) 
  1601.  
  1602. 		-- Display prompt? 
  1603. 		if( (next_prompt <= num_health_prompts) and (gat_health_ratio < gat_health_prompts[next_prompt][1]) ) then 
  1604. 			rn04_add_high_priority_helptext(gat_health_prompts[next_prompt][2])			 
  1605. 			next_prompt = next_prompt + 1 
  1606. 		end 
  1607.  
  1608. 		thread_yield() 
  1609. 	end 
  1610.  
  1611. end 
  1612.  
  1613. -- Plays dialogue lines for the Homie when his vehicle reaches certain levels of damage 
  1614. function rn04_display_homie_car_health_messages() 
  1615.  
  1616. 	-- Gat's dialogue that is played when certain damage thresholds are reached 
  1617. 	local homie_dialogue_lines =  
  1618. 		{ 
  1619. 			{.65,	"BMTSS1_RON4_VEHICLE_65DAMAGE_01"}, 
  1620. 		} 
  1621. 		 
  1622. 	local num_dialogue_lines		= sizeof_table(homie_dialogue_lines) 
  1623. 	local next_dialogue				= 1 
  1624.  
  1625. 	while	(	(next_dialogue <= num_dialogue_lines) and  
  1626. 				(not character_is_dead(CHARACTER_HOMIE)) and 
  1627. 				(not vehicle_is_destroyed(Rn04_vehicle_homie)) )  do 
  1628. 	 
  1629. 		-- Calculate car's current health level on [0,1] 
  1630. 		local health_ratio = get_current_hit_points(Rn04_vehicle_homie)/get_max_hit_points(Rn04_vehicle_homie) 
  1631.  
  1632. 		-- Play dialogue helptext? 
  1633. 		if( (next_dialogue <= num_dialogue_lines) and (health_ratio < homie_dialogue_lines[next_dialogue][1]) ) then 
  1634. 			audio_play_for_character(homie_dialogue_lines[next_dialogue][2], CHARACTER_HOMIE, "voice", false, false) 
  1635. 		end 
  1636.  
  1637. 		thread_yield() 
  1638. 	end 
  1639.  
  1640. end 
  1641.  
  1642. function rn04_ambulance_timer_expired() 
  1643. 	Ambulance_timer_expired = true 
  1644. 	--hud_timer_hide(0, true) 
  1645. 	hud_timer_stop(0) 
  1646. end 
  1647.  
  1648. function rn04_ragdoll_johnny_gat() 
  1649.  
  1650. 	local anim_name = "Gat Injured" 
  1651. 	while(true) do 
  1652. 		if (not check_animation_state(CHARACTER_GAT, anim_name)) then 
  1653. 			set_animation_state(CHARACTER_GAT, anim_name) 
  1654. 		end 
  1655. 		thread_yield() 
  1656. 	end 
  1657. end 
  1658.  
  1659. function rn04_homie_vehicle_speed_spurt(vehicle, time_s, speed) 
  1660. 	vehicle_ignore_repulsors(vehicle, true) 
  1661. 	vehicle_max_speed(vehicle,speed) 
  1662. 	vehicle_speed_override(vehicle, speed) 
  1663. 	delay(time_s) 
  1664. 	--vehicle_speed_override(vehicle, rn04_get_parameter_value("HOMIE_VEHICLE_SPEED_OVERRIDE")) 
  1665. 	vehicle_speed_cancel(vehicle) 
  1666. 	vehicle_max_speed(vehicle, rn04_get_parameter_value("HOMIE_VEHICLE_SPEED_OVERRIDE")) 
  1667. 	vehicle_ignore_repulsors(vehicle, false) 
  1668. end 
  1669.  
  1670. function rn04_chase_and_ambush() 
  1671. 	rn04_complication("chase_1") 
  1672. 	rn04_complication("roadblock_1") 
  1673. 	rn04_complication("roadblock_2") 
  1674. 	rn04_complication("roadblock_3") 
  1675. end 
  1676.  
  1677. function rn04_complication(complication_name) 
  1678.  
  1679. 	local complication = CHASES_AND_AMBUSHES[complication_name] 
  1680. 	local complication_type = complication["type"] 
  1681.  
  1682. 	-- Arm the trigger if it exists, otherwise we'll call the on_trigger_hit function immediately 
  1683. 	if(complication["trigger"]) then 
  1684. 		trigger_enable(complication["trigger"],true) 
  1685. 		on_trigger("rn04_chase_or_ambush_location_reached",complication["trigger"]) 
  1686. 	else 
  1687. 		Chase_or_ambush_sent = true; 
  1688. 	end 
  1689.  
  1690. 	-- create the group 
  1691. 	if (complication["group"]) then 
  1692. 		group_create(complication["group"]) 
  1693. 	end 
  1694.  
  1695. 	-- complication-type-specific preparation 
  1696. 	if (complication_type == "chase") then 
  1697. 		rn04_chase_prepare(complication_name) 
  1698. 	elseif (complication_type == "roadblock") then 
  1699. 		rn04_roadblock_prepare(complication_name) 
  1700. 	end 
  1701.  
  1702. 	-- wait for the complication trigger to be hit 
  1703. 	while (not Chase_or_ambush_sent) do 
  1704. 		thread_yield() 
  1705. 	end 
  1706.  
  1707. 	-- Reset the trigger 
  1708. 	if (complication["trigger"]) then 
  1709. 		trigger_enable(complication["trigger"],false) 
  1710. 		on_trigger("",complication["trigger"]) 
  1711. 	end 
  1712. 	Chase_or_ambush_sent = false 
  1713.  
  1714. 	-- complication-type-specific trigger-hit function 
  1715. 	if (complication_type == "chase") then 
  1716. 		rn04_chase_trigger_hit(complication_name) 
  1717. 	elseif (complication_type == "roadblock") then 
  1718. 		rn04_roadblock_trigger_hit(complication_name) 
  1719. 	end 
  1720.  
  1721. 	-- complication-type-specific cleanup for the last complication 
  1722. 	-- Release the on_foot Ronin from the last group 
  1723. 	if (Last_complication ~= "") then 
  1724. 		local last_complication_type = CHASES_AND_AMBUSHES["Last_complication"] 
  1725. 		if (last_complication_type == "chase") then 
  1726. 			rn04_chase_cleanup(Last_complication) 
  1727. 		elseif (last_complication_type == "roadblock") then 
  1728. 			rn04_roadblock_cleanup(Last_complication) 
  1729. 		end 
  1730. 	end 
  1731.  
  1732. 	Last_complication = complication_name 
  1733. end 
  1734.  
  1735. function rn04_chase_prepare(chase_name) 
  1736. 	local chase = CHASES_AND_AMBUSHES[chase_name] 
  1737.  
  1738. 		-- prepare vehicles 
  1739. 	for vehicle,vehicle_data in pairs(chase["vehicles"]) do 
  1740.  
  1741. 		-- place driver/passengers in the vehicle 
  1742. 		for i,passenger in pairs(vehicle_data["passengers"]) do 
  1743. 			vehicle_enter_teleport(passenger,vehicle,i-1) 
  1744. 			set_seatbelt_flag(passenger,true) 
  1745. 		end 
  1746.  
  1747. 		-- get ready to chase 
  1748. 		vehicle_suppress_npc_exit(vehicle, true) 
  1749. 		vehicle_set_allow_ram_ped(vehicle,true) 
  1750. 		vehicle_set_crazy(vehicle,true) 
  1751. 		vehicle_set_use_short_cuts(vehicle,true) 
  1752.  
  1753. 		-- Set vehicle class specific parameters 
  1754. 		-- (speed override is set later or vehicles will begin driving immediately) 
  1755. 		if (vehicle_data["type"] == "car") then 
  1756. 			set_max_hit_points(vehicle, 	rn04_get_parameter_value("CAR_CHASE_HP")) 
  1757.  
  1758. 		elseif (vehicle_data["type"] == "bike") then 
  1759. 			set_max_hit_points(vehicle, 	rn04_get_parameter_value("BIKE_CHASE_HP")) 
  1760. 		end 
  1761.  
  1762. 		-- add callback to update count of vehicles attacking 
  1763. 		on_vehicle_destroyed("rn04_chase_vehicle_destroyed", vehicle) 
  1764.  
  1765. 	end 
  1766. end 
  1767.  
  1768. -- Vehicles attack if doing so won't cause us to excede the threshold, otherwise they are destroyed 
  1769. -- peds attack 
  1770. function rn04_chase_trigger_hit(chase_name) 
  1771. 	 
  1772. 	local chase = CHASES_AND_AMBUSHES[chase_name] 
  1773.  
  1774. 	-- Have vehicles enter chase mode 
  1775. 	for vehicle,vehicle_data in pairs(chase["vehicles"]) do 
  1776.  
  1777. 		-- get the maximum number of vehicles that can chasing the players 
  1778. 		local max_vehicles	= rn04_get_parameter_value("MAX_CHASE_VEHICLES") 
  1779.  
  1780. 		-- have the vehicle attack if we won't excede the max 
  1781. 		if (Vehicles_attacking < max_vehicles and not vehicle_is_destroyed(vehicle)) then 
  1782.  
  1783. 			-- Set vehicle class specific parameters 
  1784. 			-- (speed override is set later or vehicles will begin driving immediately) 
  1785. 			if (vehicle_data["type"] == "car") then 
  1786. 				vehicle_max_speed(vehicle, rn04_get_parameter_value("CAR_CHASE_SPEED")) 
  1787. 			elseif (vehicle_data["type"] == "bike") then 
  1788. 				vehicle_max_speed(vehicle, rn04_get_parameter_value("BIKE_CHASE_SPEED")) 
  1789. 			end 
  1790. 				 
  1791. 			-- Set vehicle class specific parameters 
  1792. 			local speed_override = 0 
  1793. 			if (vehicle_data["type"] == "car") then 
  1794. 				speed_override = rn04_get_parameter_value("CAR_CHASE_SPEED") 
  1795. 			elseif (vehicle_data["type"] == "bike") then 
  1796. 				speed_override = rn04_get_parameter_value("BIKE_CHASE_SPEED") 
  1797. 			end 
  1798.  
  1799. 			thread_new("rn04_vehicle_chase_maybe_jump",vehicle,vehicle_data["jump"], speed_override, vehicle_data["delay_s"]) 
  1800.  
  1801. 			-- increment attacking count 
  1802. 			Vehicles_attacking = Vehicles_attacking + 1 
  1803. 		else 
  1804.  
  1805. 			-- release vehicles that we can't have attack 
  1806. 			on_vehicle_destroyed("", vehicle) 
  1807. 			release_to_world(vehicle) 
  1808. 			 
  1809. 		end 
  1810.  
  1811. 	end 
  1812.  
  1813. 	-- Have npcs attack 
  1814. 	for i,npc in pairs(chase["on_foot"]) do 
  1815. 		attack(npc,LOCAL_PLAYER,true) 
  1816. 	end 
  1817. end 
  1818.  
  1819. -- Have a vehicle possibly delay a bit and then enter chase mode 
  1820. function rn04_vehicle_chase_maybe_jump(vehicle,jump,speed_override, delay_s) 
  1821.  
  1822. 	-- Maybe wait a bit 
  1823. 	if(delay_s) then 
  1824. 		vehicle_speed_override(vehicle, 0) 
  1825. 		delay(delay_s) 
  1826. 	end 
  1827. 	vehicle_speed_cancel(vehicle) 
  1828.  
  1829. 	-- If jumping, wait for the vehicle to become airborn and then land 
  1830. 	if(jump) then 
  1831. 		vehicle_speed_override(vehicle, vehicle_get_max_speed(vehicle)) 
  1832. 		while( not vehicle_in_air(vehicle) ) do 
  1833. 			thread_yield() 
  1834. 		end 
  1835. 		delay(1.5) 
  1836. 		while( vehicle_in_air(vehicle) ) do 
  1837. 			thread_yield() 
  1838. 		end 
  1839. 		vehicle_speed_cancel(vehicle) 
  1840. 	end 
  1841. 	vehicle_chase(vehicle, LOCAL_PLAYER, true, true, true) 
  1842. end 
  1843.  
  1844. -- Tidy up a chase complication by releasing the on-foot attackers 
  1845. -- vehicles and their passengers are cleaned up as the vehicles are destroyed 
  1846. function rn04_chase_cleanup(chase_name) 
  1847. 	for i,npc in pairs(CHASES_AND_AMBUSHES[chase_name]["on_foot"]) do 
  1848. 		release_to_world(npc) 
  1849. 	end 
  1850. end 
  1851.  
  1852. function rn04_chase_vehicle_destroyed(vehicle) 
  1853. 	Vehicles_attacking = Vehicles_attacking - 1 
  1854. 	on_vehicle_destroyed("",vehicle) 
  1855. 	local num_seats = vehicle_get_num_seats(vehicle) 
  1856. 	for i=1, num_seats, 1 do 
  1857. 		local passenger = get_char_in_vehicle(vehicle,i) 
  1858. 		if (passenger) then 
  1859. 			release_to_world(passenger) 
  1860. 		end 
  1861. 	end 
  1862. 	release_to_world(vehicle) 
  1863. end 
  1864.  
  1865. -- Peds attack, vehicles prepared in case they'll have to attack 
  1866. function rn04_roadblock_prepare(roadblock_name) 
  1867.  
  1868. 	local roadblock = CHASES_AND_AMBUSHES[roadblock_name] 
  1869.  
  1870. 	for vehicle,vehicle_data in pairs(roadblock["vehicles"]) do 
  1871.  
  1872. 		-- set potential passengers to use their seat belts 
  1873. 		for i,passenger in pairs(vehicle_data["passengers"]) do 
  1874. 			set_seatbelt_flag(passenger,true) 
  1875. 		end 
  1876.  
  1877. 		-- prepare vehicle for chase 
  1878. 		vehicle_suppress_npc_exit(vehicle, true) 
  1879. 		vehicle_set_allow_ram_ped(vehicle,true) 
  1880. 		vehicle_set_crazy(vehicle,true) 
  1881. 		vehicle_set_use_short_cuts(vehicle,true) 
  1882.  
  1883. 		-- Set hit points 
  1884. 		if (vehicle_data["type"] == "car") then 
  1885. 			set_max_hit_points(vehicle, 	rn04_get_parameter_value("CAR_CHASE_HP")) 
  1886. 		elseif (vehicle_data["type"] == "bike") then 
  1887. 			set_max_hit_points(vehicle, 	rn04_get_parameter_value("BIKE_CHASE_HP")) 
  1888. 		end 
  1889.  
  1890. 	end 
  1891.  
  1892. 	-- Guys on foot can start attacking 
  1893. 	local check_misfires = roadblock["misfire"] ~= nil 
  1894. 	for i,npc in pairs(roadblock["on_foot"]) do 
  1895. 		-- Check if this npc should misfire 
  1896. 		local target = nil 
  1897. 		if(check_misfires) then 
  1898. 			local target = roadblock["misfire"][npc] 
  1899. 		end 
  1900. 		if (target) then 
  1901. 			patrol("rn04_npc_misfire",npc,target) 
  1902. 		else 
  1903. 			attack(npc,LOCAL_PLAYER,true) 
  1904. 		end 
  1905. 	end 
  1906. end 
  1907.  
  1908. function rn04_npc_misfire(npc,target) 
  1909. 	local dist = 	get_dist(npc,Rn04_vehicle_homie) 
  1910. 	while(dist > 60) do 
  1911. 		dist = 	get_dist(npc,Rn04_vehicle_homie) 
  1912. 		thread_yield() 
  1913. 	end	 
  1914. 	force_fire(npc, target, true)  
  1915. 	attack(npc,LOCAL_PLAYER,true) 
  1916. end 
  1917.  
  1918. -- Roadblock triggers are placed after the roadblock. When they are hit, the roadblockers 
  1919. -- realize that their trap failed. Those that are still alive get in their vehicles and 
  1920. -- join the chase. Npcs and vehicles which can't join the chase are released because 
  1921. -- the player may not be that far away. 
  1922. function rn04_roadblock_trigger_hit(roadblock_name) 
  1923. 	 
  1924. 	local roadblock = CHASES_AND_AMBUSHES[roadblock_name] 
  1925.  
  1926. 	-- Have vehicles enter chase mode 
  1927. 	for vehicle,vehicle_data in pairs(roadblock["vehicles"]) do 
  1928.  
  1929. 		-- get the maximum number of vehicles that can chasing the players 
  1930. 		local max_vehicles	= rn04_get_parameter_value("MAX_CHASE_VEHICLES") 
  1931.  
  1932. 		-- have the vehicle attack if we won't excede the max 
  1933. 		if ( (Vehicles_attacking < max_vehicles) and (not vehicle_is_destroyed(vehicle)) ) then 
  1934.  
  1935. 			-- Set vehicle class specific parameters 
  1936. 			-- (speed override is set later or vehicles will begin driving immediately) 
  1937. 			if (vehicle_data["type"] == "car") then 
  1938. 				vehicle_max_speed(vehicle, rn04_get_parameter_value("CAR_CHASE_SPEED")) 
  1939. 			elseif (vehicle_data["type"] == "bike") then 
  1940. 				vehicle_max_speed(vehicle, rn04_get_parameter_value("BIKE_CHASE_SPEED")) 
  1941. 			end 
  1942.  
  1943. 			thread_new("rn04_roadblock_vehicle_attack",roadblock_name,vehicle) 
  1944.  
  1945. 		else 
  1946.  
  1947. 			-- If a vehicle can't attack, release it and its potentail passengers. 
  1948. 			on_vehicle_destroyed("", vehicle) 
  1949. 			release_to_world(vehicle) 
  1950. 			for i,passenger in pairs(vehicle_data["passengers"]) do 
  1951. 				if (not character_is_dead(passenger)) then 
  1952. 					release_to_world(passenger) 
  1953. 				end 
  1954. 			end 
  1955. 							 
  1956. 		end 
  1957.  
  1958. 	end 
  1959.  
  1960. end 
  1961.  
  1962. function rn04_roadblock_vehicle_attack(roadblock_name, vehicle) 
  1963. 	 
  1964. 	local vehicle_data = CHASES_AND_AMBUSHES[roadblock_name]["vehicles"][vehicle] 
  1965.  
  1966. 	-- See which of the potential passengers are still alive 
  1967. 	local passengers = {} 
  1968. 	local next_seat = 1 
  1969. 	for i,passenger in pairs(vehicle_data["passengers"]) do 
  1970. 		if (not character_is_dead(passenger)) then 
  1971. 			passengers[next_seat] = passenger 
  1972. 			next_seat = next_seat +1 
  1973. 		end 
  1974. 	end 
  1975.  
  1976. 	-- If someone was alive to enter the vehicle, have it attack 
  1977. 	if (next_seat ~= 1) then 
  1978.  
  1979. 		-- tell everyone to get in the vehicle 
  1980. 		vehicle_enter_group(passengers, vehicle) 
  1981.  
  1982. 		-- set some flags 
  1983. 		vehicle_set_crazy(vehicle,true) 
  1984. 		vehicle_set_use_short_cuts(vehicle, true) 
  1985.  
  1986. 		-- vroom vroom vroom 
  1987. 		vehicle_chase(vehicle, LOCAL_PLAYER, true, true, true) 
  1988.  
  1989. 		-- add callback to update count of vehicles attacking 
  1990. 		on_vehicle_destroyed("rn04_chase_vehicle_destroyed", vehicle) 
  1991.  
  1992. 		-- increment attacking count 
  1993. 		Vehicles_attacking = Vehicles_attacking + 1 
  1994. 	 
  1995. 	else 
  1996. 		 
  1997. 		-- If none of the potential passengers are alive, then release the vehicle 
  1998. 		release_to_world(vehicle) 
  1999.  
  2000. 	end 
  2001.  
  2002. end 
  2003.  
  2004. -- Tidy up a roadblock complication. 
  2005. -- Releases npcs which aren't in a vehicle, and are far from the player(s) they were probably left behind. 
  2006. function rn04_roadblock_cleanup(roadblock_name) 
  2007. 	for i,npc in pairs(CHASES_AND_AMBUSHES[roadblock_name]["on_foot"]) do 
  2008. 		if (not character_is_in_vehicle(npc)) then 
  2009. 			release_to_world(npc) 
  2010. 		end 
  2011. 	end 
  2012. end 
  2013.  
  2014. function rn04_chase_or_ambush_location_reached() 
  2015. 	Chase_or_ambush_sent = true 
  2016. end 
  2017.  
  2018. -- Get the value of the mission parameter. 
  2019. -- 
  2020. -- parameter	Mission parameter whose value the function should return 
  2021. --	i				If the parameter is a table, then i indexes the entry that should be returned 
  2022. -- 
  2023. -- Returns mission paramater value. 
  2024. function rn04_get_parameter_value(parameter, i) 
  2025.  
  2026. 	local return_val = nil 
  2027.  
  2028. 	-- Check for an overloaded value for coop missions. 
  2029. 	if (IN_COOP and return_val == nil) then 
  2030. 		if (i) then 
  2031. 			if (RN04_PARAMETERS["COOP_" .. parameter] ~= nil) then 
  2032. 				return_val = RN04_PARAMETERS["COOP_" .. parameter][i] 
  2033. 			end 
  2034. 		else 
  2035. 			return_val = RN04_PARAMETERS["COOP_" .. parameter] 
  2036. 		end 
  2037. 	end 
  2038.  
  2039. 	-- Get the standard value 
  2040. 	if (return_val == nil) then 
  2041. 		if (i) then 
  2042. 			if (RN04_PARAMETERS[parameter] ~= nil) then 
  2043. 				return_val = RN04_PARAMETERS[parameter][i] 
  2044. 			end 
  2045. 		else 
  2046. 			return_val = RN04_PARAMETERS[parameter] 
  2047. 		end 
  2048. 	end 
  2049.  
  2050. --	cash_add(1,return_val) 
  2051. 	return return_val 
  2052. end 
  2053.  
  2054. -- Helptext functions 
  2055. function rn04_add_high_priority_helptext(helptext) 
  2056. 	if (helptext ~= nil) then 
  2057. 		Helptext_queue_high_priority_last = Helptext_queue_high_priority_last + 1 
  2058. 		Helptext_queue_high_priority[Helptext_queue_high_priority_last] = helptext 
  2059. 	end	 
  2060. end 
  2061.  
  2062. function rn04_add_low_priority_helptext(helptext) 
  2063. 	if (helptext ~= nil) then 
  2064. 		Helptext_queue_low_priority_last = Helptext_queue_low_priority_last + 1 
  2065. 		Helptext_queue_low_priority[Helptext_queue_low_priority_last] = helptext 
  2066. 	end	 
  2067. end 
  2068.  
  2069. -- Display queued helptext 
  2070. function rn04_display_helptext() 
  2071.  
  2072. 	while(true) do 
  2073.  
  2074. 		-- If there is a high priority message queued up, display it 
  2075. 		if ( Helptext_queue_high_priority_last >= Helptext_queue_high_priority_first) then 
  2076. 			local high_priority_message = Helptext_queue_high_priority[Helptext_queue_high_priority_first] 
  2077. 			Helptext_queue_high_priority[Helptext_queue_high_priority_first] = nil 
  2078. 			Helptext_queue_high_priority_first = Helptext_queue_high_priority_first + 1 
  2079. 			mission_help_table(high_priority_message) 
  2080. 			delay(5.0) 
  2081. 			Last_message_displayed = high_priority_message 
  2082. 		-- Otherwise, if there is a low priority message in the queue, display it 
  2083. 		elseif ( Helptext_queue_low_priority_last >= Helptext_queue_low_priority_first) then 
  2084. 			local low_priority_message = Helptext_queue_low_priority[Helptext_queue_low_priority_first] 
  2085. 			Helptext_queue_low_priority[Helptext_queue_low_priority_first] = nil 
  2086. 			Helptext_queue_low_priority_first = Helptext_queue_low_priority_first + 1 
  2087. 			mission_help_table(low_priority_message) 
  2088. 			delay(5.0) 
  2089. 			Last_message_displayed = low_priority_message 
  2090. 		end 
  2091. 		thread_yield() 
  2092.  
  2093. 	end 
  2094. end 
  2095.  
  2096. function rn04_cleanup() 
  2097.  
  2098. 	IN_COOP = coop_is_active() 
  2099.  
  2100. 	turn_vulnerable(LOCAL_PLAYER) 
  2101. 	if (IN_COOP) then 
  2102. 		turn_vulnerable(REMOTE_PLAYER) 
  2103. 	end		 
  2104.  
  2105. 	--cellphone_remove(persona_trigger_get_player_prefix(LOCAL_PLAYER).."PLAYER_RON4_COME_L1") 
  2106.  
  2107. 	-- Reenable cell phone spawns 
  2108. 		cell_spawns_enable(true) 
  2109.  
  2110. 	-- Clear the hud timer 
  2111. 		hud_timer_stop(0) 
  2112.  
  2113. 	-- Allow normal spawning 
  2114. 		roadblocks_enable(true) 
  2115. 		ambient_gang_spawn_enable(true) 
  2116. 		spawning_allow_cop_ambient_spawns(true) 
  2117. 		spawning_pedestrians(true) 
  2118. 		spawning_vehicles(true) 
  2119. 		action_nodes_enable(true) 
  2120. 		city_chunk_set_all_civilians_fleeing("sr2_chunk182", false) 
  2121.  
  2122. 	-- reset global variables 
  2123.  
  2124. 		-- Reset the respawn distance 
  2125. 		npc_respawn_dist_reset() 
  2126.  
  2127. 		-- Reset traffic density 
  2128. 		set_traffic_density(1.00) 
  2129.  
  2130. 		-- Player(s) can enter/exit vehicles 
  2131. 		set_player_can_enter_exit_vehicles(LOCAL_PLAYER, true) 
  2132. 		if (IN_COOP) then 
  2133. 			set_player_can_enter_exit_vehicles(REMOTE_PLAYER, true) 
  2134. 		end 
  2135.  
  2136. 	-- reset notoriety 
  2137. 		notoriety_reset("Ronin") 
  2138. 		notoriety_set("Ronin",0) 
  2139. 		notoriety_force_no_spawn("Ronin", false)  
  2140. 		notoriety_reset("Police") 
  2141.  
  2142. 	-- remove markers and callbacks 
  2143.  
  2144. 		-- Ronin in stage 1 
  2145. 		for i,ronin in pairs (MEMBERS_GROUP_STAGE_1_RONIN) do 
  2146. 			on_death("", ronin) 
  2147. 			on_respawn("", ronin) 
  2148. 			marker_remove_npc(ronin, SYNC_ALL) 
  2149. 		end 
  2150.  
  2151. 		-- GPS 
  2152. 		mission_waypoint_remove() 
  2153.  
  2154. 		-- Gat callbacks 
  2155. 		on_incapacitated("", CHARACTER_GAT) 
  2156. 		on_death("", CHARACTER_GAT) 
  2157. 		on_dismiss("", CHARACTER_GAT) 
  2158.  
  2159. 		-- Homie's vehice 
  2160. 		if ( (Rn04_vehicle_homie ~= "") and (vehicle_exists(Rn04_vehicle_homie) and (not vehicle_is_destroyed(Rn04_vehicle_homie)))) then 
  2161. 			on_vehicle_destroyed("",Rn04_vehicle_homie) 
  2162. 			vehicle_set_untowable(Rn04_vehicle_homie, false) 
  2163. 			vehicle_evacuate(Rn04_vehicle_homie) 
  2164. 		end 
  2165. 		group_destroy(GROUP_HOMIE) 
  2166.  
  2167. 	-- Remove followers 
  2168. 		if (npc_is_in_party(CHARACTER_GAT)) then 
  2169. 			npc_stop_following(CHARACTER_GAT) 
  2170. 		end 
  2171.  
  2172. 	-- Remove temporary weapon(s) 
  2173. 	if (Temp_weapons_given) then 
  2174. 		inv_weapon_remove_temporary(LOCAL_PLAYER, LOCAL_PLAYER_WEAPON) 
  2175. 		if (IN_COOP) then 
  2176. 			inv_weapon_remove_temporary(REMOTE_PLAYER, REMOTE_PLAYER_WEAPON) 
  2177. 		end 
  2178. 	end 
  2179. end 
  2180.  
  2181. function rn04_success() 
  2182. 	-- Called when the mission has ended with success 
  2183. end 
  2184.  
  2185. -- setup_homie_car 
  2186. -- 
  2187. -- Prepares homie's vehicle for turret mode 
  2188. -- 
  2189. function rn04_setup_homie_car(vehicle_homie) 
  2190. 		local hit_points = get_max_hit_points(vehicle_homie) 
  2191. 		 
  2192. 		vehicle_set_torque_multiplier(vehicle_homie, 1.2) 
  2193. 		vehicle_never_flatten_tires(vehicle_homie, true) 
  2194. 		set_max_hit_points(vehicle_homie, hit_points*rn04_get_parameter_value("HOMIE_VEHICLE_HEALTH_MULTIPLIER")) 
  2195. 		vehicle_max_speed(vehicle_homie, rn04_get_parameter_value("HOMIE_VEHICLE_SPEED_OVERRIDE")) 
  2196. 		vehicle_suppress_npc_exit(vehicle_homie, true) 
  2197. 		vehicle_prevent_explosion_fling(vehicle_homie,true) 
  2198. 		vehicle_set_allow_ram_ped(vehicle_homie,true) 
  2199. 		vehicle_set_crazy(vehicle_homie,true) 
  2200. 		vehicle_set_use_short_cuts(vehicle_homie, true) 
  2201. 		vehicle_infinite_mass(vehicle_homie, true) 
  2202. 		set_unjackable_flag(vehicle_homie, true) 
  2203. 		vehicle_set_untowable(vehicle_homie, true) 
  2204. 		vehicle_suppress_flipping(vehicle_homie, true) 
  2205. 		--vehicle_ignore_repulsors(vehicle_homie, true) 
  2206. 		--vehicle_disable_flee(vehicle_homie, true) 
  2207. 		--vehicle_disable_chase(vehicle_homie, true) 
  2208. end 
  2209.  
  2210. function rn04_complete() 
  2211.  
  2212. 	-- End the mission with success 
  2213. 	mission_end_success("rn04", "ro04-02", {"player_respawns_$DT_hospital", "player_respawns_$DT_hospital"}) 
  2214. end 
  2215.  
  2216. function rn04_homie_phone_call() 
  2217.  
  2218. 	audio_play_conversation( HOMIE_PHONE_CONVERSATION, OUTGOING_CALL ) 
  2219.  
  2220. end 
  2221.  
  2222. -- MISSION FAILURE FUNCTIONS -------------------------------- 
  2223.  
  2224. function rn04_failure_car_destroyed() 
  2225. 	-- End the mission, player's car destroyed 
  2226. 	mission_end_failure("rn04", HELPTEXT_FAILURE_CAR_DESTROYED) 
  2227. end 
  2228.  
  2229. function rn04_failure_gat_abandoned() 
  2230. 	-- End the mission, Gat abandoned 
  2231. 	mission_end_failure("rn04", HELPTEXT_FAILURE_GAT_ABANDONED) 
  2232. end 
  2233.  
  2234. function rn04_failure_gat_died() 
  2235. 	-- End the mission, Gat died 
  2236. 	mission_end_failure("rn04", HELPTEXT_FAILURE_GAT_DIED) 
  2237. end 
  2238.  
  2239. function rn04_debug_text(text, debug_type) 
  2240.  
  2241. 	if(DEBUG_TEXT_ENABLED[debug_type]) then 
  2242. 		mission_debug(text, 10, debug_type) 
  2243. 	end 
  2244.  
  2245. end