sr2lua/rn01.lua

  1. -- rn01.lua 
  2. -- SR2 mission script 
  3. -- 3/28/07 
  4.  
  5. DEBUG_SKIP_GUARDS				= false	-- Skip the security guard fight stage?	 
  6.  
  7. --[[	***** NOTES ***** 
  8. 		In stage 4 of this mission, we need to spawn Ronin in waves to attack the players. To do this without 
  9. 		the player seeing the enemies popping into existence, I've divided the the city into 6 areas. I keep 
  10. 		track of which area each player is in. When a new enemy needs to be spawned, I select an area whose 
  11. 		spawn locations can not be seen from the areas which contain players. Here are the areas: 
  12.  
  13. 		"area_1":	Hallway along the N-pointing corner of the 1st floor, runs from near reception desk to elevator. 
  14. 		"area_2":	Hallway along the E-pointing corner of the 1st floor, runs from near reception desk to elevator. 
  15. 		"area_3":	Counting room/safes. 
  16. 		"area_4":	Casino's 2nd floor. 
  17. 		"area_5":	Portion of Casino's first floor not already accounted for. 
  18. 		"area_6":	Anywhere outside of the Casino. 
  19. 		]] 
  20.  
  21. -- Global constants ( ALL_CAPS means that they shouldn't be modified in running code, except for maybe in a setup function ) 
  22.  
  23. 	-- COOP MISSION? --  
  24. 		IN_COOP	= false 
  25.  
  26. 	-- KNOBS_TO_TURN -- 
  27.  
  28. 		-- All stages 
  29. 			MAX_RONIN_NOTORIETY				= 2 
  30. 			MAX_POLICE_NOTORIETY			= 2 
  31.  
  32. 		-- Stage 1 
  33. 		-- Stage 2 
  34.  
  35. 			-- Security guards that wander. 
  36. 			WANDERING_GUARDS = {"rn01_$c002", "rn01_$c003", "rn01_$c004", "rn01_$c006"} 
  37.  
  38. 			MIN_RONIN_NOTORIETY			= 2 -- Minimum ronin notoriety after a security guard is attacked in single player. 
  39. 			COOP_MIN_RONIN_NOTORIETY	= 2 -- Minimum ronin notoriety after a security guard is attacked in coop. 
  40.  
  41. 		-- Stage 3 
  42. 		-- Stage 4, Defend homies while they load cash boxes 
  43.  
  44. 			TRUCK_HEALTH_MULTIPLIER			= 2.0  -- Hit point multiplier for the heist truck 
  45.  
  46. 		-- Stage 5 
  47.  
  48. 			MIN_POLICE_NOTORIETY			= 2 -- Minimum police notoriety for drive home in single player. 
  49. 			COOP_MIN_POLICE_NOTORIETY	= 2 -- Minimum police notoriety for drive home in coop. 
  50.  
  51. 	-- CHARACTERS -- 
  52. 		CHARACTER_GAT				= "rn01_$Cgat" 
  53. 		CHARACTER_HELPER		= "rn01_$Chelper_1" 
  54. 		CHARACTER_PIERCE			= "rn01_$Cpierce" 
  55.  
  56. 	-- CHECKPOINTS 
  57. 		 
  58. 		CHECKPOINT_START						= MISSION_START_CHECKPOINT			-- defined in ug_lib.lua 
  59. 		CHECKPOINT_CASINO						= "rn01_checkpoint_casino"			-- players arrived at Casino 
  60. 		CHECKPOINT_LOAD_BOXES				= "rn01_checkpoint_load_boxes"	-- after counting room unlocked 
  61. 		--CHECKPOINT_DRIVE_HOME				= "rn01_checkpoint_drive_home"	-- boxes loaded, ready to head back to sr_hq 
  62.  
  63. 	-- GROUPS -- 
  64.  
  65. 		GROUP_TRUCK						= "rn01_$Gtruck" 
  66. 		GROUP_START_CAR				= "rn01_$Gstart_car" 
  67. 		GROUP_START_CAR_COOP			= "rn01_$Gstart_car_coop" 
  68. 		GROUP_GAT						= "rn01_$Ggat" 
  69. 		GROUP_CASINO_GUARDS			= "rn01_$Gcasino_guards"		-- Security guards inside the casino 
  70. 		GROUP_COOP_CASINO_GUARDS	= "rn01_$Gcoop_casino_guards" -- As ^, but only used in coop. 
  71. 		GROUP_RONIN_WAVES				= "rn01_$Gronin_waves"			-- Ronin that spawn in waves during stage 4 
  72.  
  73. 	-- GROUP MEMBER TABLES --  
  74. 	 
  75. 		MEMBERS_GROUP_CASINO_GUARDS		=	{	"rn01_$c000", "rn01_$c001", "rn01_$c002", "rn01_$c003", "rn01_$c004", 
  76. 															"rn01_$c006", "rn01_$c008", "rn01_$c009", "rn01_$c011", "rn01_$c012", 
  77. 															"rn01_$c013", "rn01_$c014", "rn01_$c015", "rn01_$c016", "rn01_$c017"} 
  78.  
  79. 		MEMBERS_GROUP_COOP_CASINO_GUARDS =	{	"rn01_$c005", "rn01_$c007", "rn01_$c010"} 
  80.  
  81. 	-- HELPTEXT 
  82.  
  83. 		HELPTEXT_PROMPT_REENTER_TRUCK		= "rn01_prompt_reenter_truck"		-- Get back in the truck! 
  84. 		HELPTEXT_PROMPT_ENTER_TRUCK		= "rn01_prompt_enter_truck"		-- The boxes are loaded, get in the truck! 
  85. 		HELPTEXT_PROMPT_CASINO				= "rn01_prompt_casino"				-- "Head to the casino." 
  86. 		HELPTEXT_PROMPT_GUARDS				= "rn01_prompt_guards"				-- "Take out all the security guards." 
  87. 		HELPTEXT_PROMPT_HEAD_HOME			= "rn01_prompt_head_home"			-- "Get the loot back to Saints headquarters." 
  88. 		HELPTEXT_PROMPT_NOTORIETY_ZERO	= "rn01_prompt_notoriety_zero"	-- Eliminate your notoriety before heading to the hideout. 
  89. 		HELPTEXT_PROMPT_POLICE_CALLED		= "rn01_prompt_police_called"		-- “The Ronin called in the police for help!”  
  90. 		HELPTEXT_PROMPT_BOMB_WARNING		= "rn01_prompt_bomb_warning" 
  91.  
  92. 		HELPTEXT_OBJECTIVE_GUARDS			= "rn01_objective_guards"			-- "%s of %s guards killed." 
  93. 		HELPTEXT_OBJECTIVE_NEAR_CASINO	= "rn01_objective_near_casino"	-- "Get closer to the casino" 
  94.  
  95. 		HELPTEXT_FAILURE_GAT_DIED			= "rn01_failure_gat_died"			-- "Johnny Gat died." 
  96. 		HELPTEXT_FAILURE_GAT_ABANDONED	= "rn01_failure_gat_abandoned"	-- "Johnny Gat was abandoned." 
  97. 		HELPTEXT_FAILURE_PIERCE_DIED		= "rn01_failure_pierce_died"		-- "Pierce died." 
  98. 		HELPTEXT_FAILURE_PIERCE_ABANDONED= "rn01_failure_pierce_abandoned" -- "Pierce was abandoned." 
  99. 		HELPTEXT_FAILURE_HOMIE_KILLED		= "rn01_failure_homie_killed"		-- "Homie killed" 
  100. 		HELPTEXT_FAILURE_TRUCK_DESTROYED = "rn01_failure_truck_destroyed"	-- "The heist truck was destroyed." 
  101.  
  102. 		HELPTEXT_PROMPT_PLANT_BOMBS		= "rn01_prompt_plant_bombs"		-- "Guard Gat while he rigs the doors with explosives" 
  103. 		HELPTEXT_PROMPT_USE_DETONATOR		= "rn01_prompt_use_detonator"		-- "Use the detonator to set off the bombs from a safe distance." 
  104.  
  105. 		HELPTEXT_HUD_GAT_PROGRESS			= "rn01_hud_gat_progress" 
  106.  
  107. 	-- MOVERS 
  108. 		DOOR_CASINO_MAIN_1					= "rn01_Dcasino_main_1" 
  109. 		DOOR_CASINO_MAIN_2					= "rn01_Dcasino_main_2" 
  110. 		DOOR_CASINO_REAR_1					= "rn01_Dcasino_rear_1" 
  111. 		DOOR_CASINO_REAR_2					= "rn01_Dcasino_rear_2" 
  112. 		DOOR_CASINO_REAR_3					= "rn01_Dcasino_rear_3" 
  113. 		DOOR_CASINO_AREA_1					= "rn01_Dcasino_area_1" 
  114. 		DOOR_CASINO_AREA_2					= "rn01_Dcasino_area_2" 
  115. 		DOOR_COUNTING_ROOM_1					= "rn01_Dcounting_room_1" 
  116. 		DOOR_COUNTING_ROOM_2					= "rn01_Dcounting_room_2" 
  117.  
  118. 	-- GUARD PATROL ROUTES 
  119.  
  120. 		DIR_FORWARD = 1 
  121. 		DIR_REVERSE = 2 
  122. 		DIR_EITHER = 3 
  123.  
  124. 		-- Rather than define separate routes for each guard, I've setup interconnecting segments of 
  125. 		-- patrol routes. Segments can transition onto other segments at any point. If a guard reaches 
  126. 		-- the end of a segment, then they'll return to their original spawn location. 
  127. 		CASINO_GUARD_INITIAL_PATH_SEGMENTS =  
  128. 		{	["rn01_$c000"] =	{	{1,DIR_FORWARD,1}, 
  129. 										{1,DIR_REVERSE,4}, 
  130. 										{2,DIR_REVERSE,6}, 
  131. 									}, 
  132. 			["rn01_$c001"] =	{	{1,DIR_FORWARD,4}, 
  133. 										{1,DIR_REVERSE,3}, 
  134. 										{2,DIR_FORWARD,1}, 
  135. 									}, 
  136. 		} 
  137.  
  138. 		-- Note, each navpoint can only belong to one path segment. 
  139. 		CASINO_GUARD_PATH_SEGMENTS =  
  140. 		{	[1] = {"rn01_$n045", "rn01_$n046", "rn01_$n047", "rn01_$n048"}, 
  141. 			[2] = {"rn01_$n049", "rn01_$n050", "rn01_$n051", "rn01_$n052", "rn01_$n053", "rn01_$n054"}, 
  142. 		} 
  143.  
  144. 		-- ["current_node"] = {[current_direction] = {{next_path, direction, index of first node on next path, }} 
  145. 		CASINO_GUARD_SEGMENT_TRANSITIONS =  
  146. 		{	["rn01_$n045"]	=	{	[DIR_REVERSE]	=	{	{2, DIR_FORWARD, 1}, 
  147. 																}, 
  148. 									}, 
  149. 			["rn01_$n047"]	=	{	[DIR_FORWARD]	=	{	{2, DIR_REVERSE, 6}, 
  150. 																}, 
  151. 									}, 
  152. 			["rn01_$n048"]	=	{	[DIR_EITHER]	=	{	{2, DIR_FORWARD, 1}, 
  153. 																	{2, DIR_REVERSE, 6}, 
  154. 																}, 
  155. 									}, 
  156. 			["rn01_$n049"]	=	{	[DIR_REVERSE]	=	{	{1, DIR_FORWARD, 1}, 
  157. 																	{1, DIR_FORWARD, 4}, 
  158. 																	{1, DIR_REVERSE, 3}, 
  159. 																}, 
  160. 									}, 
  161. 			["rn01_$n054"]	=	{	[DIR_FORWARD]	=	{	{1, DIR_FORWARD, 1}, 
  162. 																	{1, DIR_REVERSE, 4}, 
  163. 																	{1, DIR_REVERSE, 3}, 
  164. 																}, 
  165. 									}, 
  166. 		} 
  167.  
  168.  
  169. 	-- NAVPOINTS 
  170.  
  171. 		NAVPOINT_REMOTE_PLAYER_START		= "rn01_$Nremote_player_start" 
  172. 		NAVPOINT_LOCAL_PLAYER_START		= "mission_start_sr2_city_$rn01" 
  173. 		NAVPOINT_HELPER_ARRIVAL				= "rn01_$Nhelper_arrival"				-- Where Pierce and the homies vehicle arrives 
  174. 		NAVPOINT_CHANDELIER					= "rn01_$Nchandelier" 
  175. 		NAVPOINT_OCTO_1						= "rn01_$Nocto_1" 
  176. 		NAVPOINT_OCTO_2						= "rn01_$Nocto_2" 
  177.  
  178. 		NAVPOINT_CASINO_LOCAL_START		= "rn01_$Ncasino_local_start" 
  179. 		NAVPOINT_CASINO_REMOTE_START		= "rn01_$Ncasino_remote_start" 
  180.  
  181.  
  182. 	-- TRIGGERS --  
  183. 		 
  184. 		TRIGGER_CASINO_ARRIVAL			= "rn01_$Tcasino_arrival" 
  185. 		TRIGGER_COUNTING_ROOM_DOOR_1	= "rn01_$Tcounting_room_door_1" 
  186. 		TRIGGER_COUNTING_ROOM_DOOR_2	= "rn01_$Tcounting_room_door_2" 
  187. 		TRIGGER_AISHAS						= "rn01_$Taishas" 
  188.  
  189. 		-- List of all triggers, makes cleaning up more convenient 
  190. 		TABLE_ALL_TRIGGERS		= {	TRIGGER_CASINO_ARRIVAL, TRIGGER_COUNTING_ROOM_DOOR_1, TRIGGER_COUNTING_ROOM_DOOR_2,  
  191. 												TRIGGER_AISHAS}		 
  192.  
  193. 	-- VEHICLES -- 
  194.  
  195. 		VEHICLE_TRUCK				= "rn01_$v000"					-- Delivery truck 
  196.  
  197. 	-- CONVERSATIONS -- 
  198. 	   INTRO_CONVERSATION = 
  199. 		{ 
  200. 			{ "RON1_INTRO_L1", CHARACTER_GAT, 0.5 }, 
  201. 			{ "PLAYER_RON1_INTRO_L2", LOCAL_PLAYER, 1 }, 
  202. 			{ "RON1_INTRO_L3", CHARACTER_GAT, 1 }, 
  203. 			{ "PLAYER_RON1_INTRO_L4", LOCAL_PLAYER, 1 }, 
  204. 			{ "RON1_INTRO_L5", CHARACTER_GAT, 1 }, 
  205. 		} 
  206.  
  207. 	   LAUNDER_CONVERSATION = 
  208. 		{ 
  209. 			{ "PLAYER_RON1_LAUNDER_L1", LOCAL_PLAYER, 1 }, 
  210. 			{ "RON1_LAUNDER_L2", CHARACTER_GAT, 1 }, 
  211. 			{ "PLAYER_RON1_LAUNDER_L3", LOCAL_PLAYER, 1 }, 
  212. 			{ "RON1_LAUNDER_L4", CHARACTER_GAT, 1 }, 
  213. 			{ "PLAYER_RON1_LAUNDER_L5", LOCAL_PLAYER, 1 }, 
  214. 			{ "RON1_LAUNDER_L6", CHARACTER_GAT, 1 }, 
  215. 		} 
  216.  
  217. 	   LAUNDER_CONVERSATION_COOP = 
  218. 		{ 
  219. 			{ "PLAYER_RON1_LAUNDER_L1", LOCAL_PLAYER, 1 }, 
  220. 			{ "RON1_LAUNDER_L2_PHONE", CELLPHONE_CHARACTER, 1 }, 
  221. 			{ "PLAYER_RON1_LAUNDER_L3", LOCAL_PLAYER, 1 }, 
  222. 			{ "RON1_LAUNDER_L4_PHONE", CELLPHONE_CHARACTER, 1 }, 
  223. 			{ "PLAYER_RON1_LAUNDER_L5", LOCAL_PLAYER, 1 }, 
  224. 			{ "RON1_LAUNDER_L6_PHONE", CELLPHONE_CHARACTER, 1 }, 
  225. 		} 
  226.  
  227. 	PLAYER_SYNC	= {[LOCAL_PLAYER] = SYNC_LOCAL, [REMOTE_PLAYER] = SYNC_REMOTE} 
  228.  
  229. 	STATE_PLANT_BOMB =			"crouch plant bomb" 
  230. 	DETONATION_DISTANCE =			15 
  231. 	DETONATOR_ITEM =			"Detonator" 
  232. 	EXPLOSION_NAME =			"Big Bang" 
  233.  
  234. 	BOMB_PLANT_KILLS_REQUIRED			= 15 
  235. 	BOMB_PLANT_KILLS_REQUIRED_COOP	= 20 
  236. 	BOMB_PLANT_MIN_TIME_S				= 60 
  237.  
  238. 	RN01_RONIN_ATTACK_PERSONAS =  
  239. 	{ 
  240. 		["AM_Ron2"]	=	"AMRON2", 
  241.  
  242. 		["AF_Ron1"]	=	"AFRON1", 
  243.  
  244. 		["WM_Ron1"]	=	"WMRON1", 
  245.  
  246. 		["WF_Ron1"]	=	"WFRON1", 
  247. 		["WF_Ron2"]	=	"WFRON2", 
  248. 	} 
  249.  
  250. -- Progress flags 
  251. 	Casino_reached						= false 
  252. 	Bombs_planted						= false 
  253.  
  254. -- Misc 
  255. 	Door_unlocked						= {}  -- List of doors that are unlocked. 
  256. 	Door_opened							= {}	-- Doors have a tendency to close themselves, we need to keep a list of doors 
  257. 													-- that are open. 
  258.  
  259. 	Path_segment_occupied			= {} 
  260. 	Patrol_threads						= {} 
  261.  
  262. 	Gps_waypoint = {[LOCAL_PLAYER] = "", [REMOTE_PLAYER] = ""} 
  263.  
  264. 	-- These two variables are declared in mission_globals.lua so that we have access 
  265. 	-- to the player's location when they restart from a checkpoint: 
  266. 		-- Rn01_local_player_location		-- Location of the local player 
  267. 		-- Rn01_remote_player_location	-- Location of the local player 
  268.  
  269. function rn01_start(rn01_checkpoint, is_restart) 
  270.  
  271. 	mission_start_fade_out() 
  272.  
  273. 	if(rn01_checkpoint == CHECKPOINT_START) then 
  274.  
  275. 		-- Determine the list of groups needed at mission start 
  276. 		local group_list = {GROUP_GAT, GROUP_START_CAR} 
  277. 		if (IN_COOP) then 
  278. 			group_list = {GROUP_GAT, GROUP_START_CAR, GROUP_START_CAR_COOP} 
  279. 		end 
  280.  
  281. 		-- Starting from the mission beginning & not a checkpoint, so play the first cutscene 
  282. 		if (not is_restart) then 
  283. 			cutscene_play("ro01-01", group_list, {NAVPOINT_LOCAL_PLAYER_START, NAVPOINT_REMOTE_PLAYER_START}, false) 
  284.  
  285. 			-- cutscene_play creates hidden groups, make sure that we show them. 
  286. 			for i,group in pairs(group_list) do 
  287. 				group_show(group) 
  288. 			end 
  289. 		else 
  290.  
  291. 			-- Teleport players to start location 
  292. 			teleport_coop(NAVPOINT_LOCAL_PLAYER_START, NAVPOINT_REMOTE_PLAYER_START) 
  293.  
  294. 			-- Create the starting groups 
  295. 			for i,group in pairs(group_list) do 
  296. 				group_create(group, true) 
  297. 			end 
  298. 		end 
  299.  
  300. 	end 
  301.  
  302. 	rn01_initialize(rn01_checkpoint) 
  303.  
  304. 	if(rn01_checkpoint == CHECKPOINT_START) then 
  305. 	 
  306. 		-- Stage 1: Drive to the Casino 
  307. 		rn01_drive_to_casino() 
  308.  
  309. 		mission_set_checkpoint(CHECKPOINT_CASINO, true) 
  310. 		rn01_checkpoint = CHECKPOINT_CASINO 
  311.  
  312. 	end -- ends CHECKPOINT_START 
  313.  
  314. 	if (rn01_checkpoint == CHECKPOINT_CASINO) then 
  315.  
  316. 		-- Stage 2: Gain access to the counting room. 
  317. 				 
  318. 		--make sure doors are unlocked 
  319. 		Door_opened[DOOR_CASINO_AREA_1] = true 
  320. 		Door_opened[DOOR_CASINO_AREA_2] = true 
  321. 		Door_opened[DOOR_CASINO_MAIN_1] = true 
  322. 		Door_opened[DOOR_CASINO_MAIN_2] = true 
  323. 		 
  324. 		rn01_gain_access() 
  325.  
  326. 		mission_set_checkpoint(CHECKPOINT_LOAD_BOXES, true) 
  327. 		rn01_checkpoint = CHECKPOINT_LOAD_BOXES 
  328. 	 
  329. 		-- Fade out for the cutscene 
  330. 		mission_start_fade_out(3.0) 
  331.  
  332. 	end -- ends CHECKPOINT_CASINO 
  333.  
  334. 	if(rn01_checkpoint == CHECKPOINT_LOAD_BOXES) then 
  335.  
  336. 		-- Stage 3: Guard homies while they load boxes into the truck 
  337.  
  338. 		--make sure doors are unlocked 
  339. 		Door_opened[DOOR_CASINO_AREA_1] = true 
  340. 		Door_opened[DOOR_CASINO_AREA_2] = true 
  341. 		Door_opened[DOOR_CASINO_MAIN_1] = true 
  342. 		Door_opened[DOOR_CASINO_MAIN_2] = true 
  343. 		 
  344. 		rn01_guard_box_loaders() 
  345.  
  346. 	end -- ends checkpoint DRIVE_HOME 
  347.  
  348. 	-- Mission ends 
  349. 	player_controls_disable( LOCAL_PLAYER ) 
  350.     vehicle_stop_do( LOCAL_PLAYER ) 
  351. 	 
  352. 	if coop_is_active() then 
  353. 		player_controls_disable( REMOTE_PLAYER ) 
  354. 		vehicle_stop_do( REMOTE_PLAYER ) 
  355. 	end 
  356.  
  357. 	rn01_complete() 
  358.  
  359. end 
  360.  
  361. function rn01_initialize(checkpoint) 
  362.  
  363. 	rn01_initialize_common() 
  364.  
  365. 	rn01_initialize_checkpoint(checkpoint) 
  366.  
  367. 	-- Add failure callbacks which persist throughout the mission 
  368. 	rn01_add_mission_failure_callbacks() 
  369.  
  370. 	if (checkpoint ~= CHECKPOINT_LOAD_BOXES) then 
  371. 		mission_start_fade_in() 
  372. 	end 
  373.  
  374. end 
  375.  
  376. -- Initialization code shared by all checkpoints. 
  377. function rn01_initialize_common() 
  378.  
  379. 	-- Start trigger is hit...the activate button was hit 
  380. 	set_mission_author("Phillip Alexander") 
  381.  
  382. 	if coop_is_active() then 
  383. 		IN_COOP = true 
  384. 	end 
  385.  
  386. 	-- Make sure that casino side and rear doors are unlocked 
  387. 	door_lock(DOOR_CASINO_AREA_1, false) 
  388. 	door_lock(DOOR_CASINO_AREA_2, false) 
  389. 	door_lock(DOOR_CASINO_REAR_1, true) 
  390. 	door_lock(DOOR_CASINO_REAR_2, true) 
  391. 	door_lock(DOOR_CASINO_REAR_3, true) 
  392. 	door_lock(DOOR_CASINO_MAIN_1, false) 
  393. 	door_lock(DOOR_CASINO_MAIN_2, false) 
  394.  
  395. 	-- This thread makes sure that any door that has been marked as open stays open. 
  396. 	thread_new("rn01_keep_doors_open") 
  397. 	Door_opened[DOOR_CASINO_AREA_1] = true 
  398. 	Door_opened[DOOR_CASINO_AREA_2] = true 
  399. 	Door_opened[DOOR_CASINO_MAIN_1] = true 
  400. 	Door_opened[DOOR_CASINO_MAIN_2] = true 
  401.  
  402. 	-- Override Ronin Personas 
  403. 	persona_override_group_start(RN01_RONIN_ATTACK_PERSONAS,POT_SITUATIONS[POT_ATTACK], "RO01_ATTACK") 
  404. 	--[[ 
  405. 	persona_override_group_start(SAINTS_PERSONAS,POT_SITUATIONS[POT_ATTACK], "RO01_ATTACK") 
  406. 	persona_override_group_start(SAINTS_PERSONAS,POT_SITUATIONS[POT_CUSTOM_1], "RO01_FINDMONEY") 
  407. 	persona_override_group_start(SAINTS_PERSONAS,POT_SITUATIONS[POT_CUSTOM_2], "RO01_DROPMONEY") 
  408. 	]] 
  409. 	notoriety_set_max("Ronin", MAX_RONIN_NOTORIETY) 
  410. 	notoriety_set_max("Police", MAX_POLICE_NOTORIETY) 
  411.  
  412. end 
  413.  
  414. -- Initialization code specific to the checkpoint. 
  415. function rn01_initialize_checkpoint(checkpoint) 
  416.  
  417. 	if(checkpoint == CHECKPOINT_START) then 
  418.  
  419. 		-- Put Johnny Gat in the player's party 
  420. 		party_add(CHARACTER_GAT, LOCAL_PLAYER) 
  421.  
  422. 		if ( coop_is_active() == false ) then 
  423. 			-- Find his current index 
  424. 			local gat_follower_index = party_get_follower_index(CHARACTER_GAT) 
  425.  
  426. 			-- If he's not the first follower, swap him and the first one 
  427. 			if ( gat_follower_index > 0 ) then 
  428. 				party_swap_follower_indices( 0, gat_follower_index ) 
  429. 				delay( 1.0 ) 
  430. 			end 
  431. 		end 
  432.  
  433. 		-- Setup the casino guards in a thread so that it is non-blocking 
  434. 		thread_new("rn01_setup_casino_guards") 
  435.  
  436. 	end 
  437.  
  438. 	if(checkpoint == CHECKPOINT_CASINO) then 
  439.  
  440. 		-- Teleport both players to the front of the Casino 
  441. 		teleport_coop(NAVPOINT_CASINO_LOCAL_START, NAVPOINT_CASINO_REMOTE_START, true) 
  442.  
  443. 		-- Setup the guards, block until finished 
  444. 		rn01_setup_casino_guards() 
  445. 		 
  446. 	end 
  447.  
  448. 	-- Override Gat's persona 
  449. 	persona_override_character_start(CHARACTER_GAT, POT_SITUATIONS[POT_ATTACK], "GAT_RON01_ATTACK") 
  450. 	persona_override_character_start(CHARACTER_GAT, POT_SITUATIONS[POT_TAKE_DAMAGE], "GAT_RON01_TAKEDAM") 
  451.  
  452. 	if (checkpoint == CHECKPOINT_START or checkpoint == CHECKPOINT_CASINO) then 
  453.  
  454. 		-- Don't allow ambient cops to spawn 
  455. 		spawning_allow_cop_ambient_spawns(false) 
  456.  
  457. 		-- Lock counting room doors	 
  458. 		door_lock(DOOR_COUNTING_ROOM_1, true) 
  459. 		door_lock(DOOR_COUNTING_ROOM_2, true) 
  460.  
  461. 	end 
  462.  
  463. 	if(checkpoint ~= CHECKPOINT_START) then 
  464.  
  465. 		if(checkpoint ~= CHECKPOINT_CASINO) then 
  466.  
  467. 			-- Make sure that the minimum Ronin notoriety has been set. 
  468. 			if (not IN_COOP) then 
  469. 				notoriety_set_min("Ronin",MIN_RONIN_NOTORIETY) 
  470. 				notoriety_set("Ronin",MIN_RONIN_NOTORIETY) 
  471. 			else 
  472. 				notoriety_set_min("Ronin", COOP_MIN_RONIN_NOTORIETY) 
  473. 				notoriety_set("Ronin", COOP_MIN_RONIN_NOTORIETY) 
  474. 			end 
  475. 		end 
  476.  
  477. 	end 
  478.  
  479. end 
  480.  
  481. function rn01_setup_casino_guards() 
  482. 	-- Setup the guards 
  483. 	group_create(GROUP_CASINO_GUARDS, true) 
  484. 	for i,guard in pairs(MEMBERS_GROUP_CASINO_GUARDS) do 
  485. 		on_take_damage("rn01_casino_guard_damaged",guard) 
  486. 		attack(guard) 
  487. 	end 
  488.  
  489. 	if(IN_COOP) then 
  490. 		group_create(GROUP_COOP_CASINO_GUARDS, true) 
  491. 		for i,guard in pairs(MEMBERS_GROUP_CASINO_GUARDS) do 
  492. 			on_take_damage("rn01_casino_guard_damaged",guard) 
  493. 			attack(guard) 
  494. 		end 
  495. 	end 
  496. end 
  497.  
  498. 	FIXED_VANTAGE_GROUP_MEMBERS =  
  499. 	{ 
  500. 		["rn01_$Gfixed_1"] =	{"rn01_$c018", "rn01_$c019"}, 
  501. 		["rn01_$Gfixed_2"] =	{"rn01_$c020", "rn01_$c021"}, 
  502. 		["rn01_$Gfixed_3"] =	{"rn01_$c022", "rn01_$c023"}, 
  503. 		["rn01_$Gfixed_4"] =	{"rn01_$c024", "rn01_$c053", "rn01_$c054"}, 
  504. 		["rn01_$Gfixed_5"] =	{"rn01_$c055", "rn01_$c056", "rn01_$c057"}, 
  505. 		["rn01_$Gfixed_6"] =	{"rn01_$c058", "rn01_$c059", "rn01_$c060", "rn01_$c061"}, 
  506. 		["rn01_$Gfixed_7"] =	{"rn01_$c062", "rn01_$c063", "rn01_$c064"}, 
  507. 		["rn01_$Gfixed_8"] =	{"rn01_$c065", "rn01_$c066", "rn01_$c067", "rn01_$c068"}, 
  508. 	} 
  509.  
  510. 	FIXED_VANTAGE_ATTACK_UNITS =  
  511. 	{ 
  512. 		{  
  513. 			["groups"] = { "rn01_$Gfixed_1", "rn01_$Gfixed_2", "rn01_$Gfixed_3" }, 
  514. 			["points"] = { "rn01_$n068", "rn01_$n069", "rn01_$n070", "rn01_$n071", "rn01_$n072", "rn01_$n073"}, 
  515. 			["max attackers"] = 2, 
  516. 			["max attackers coop"] = 4, 
  517. 			["attack function"] =  "rn01_fixed_vantage_attack_player", 
  518. 		}, 
  519. 		{  
  520. 			["groups"] = { "rn01_$Gfixed_4", "rn01_$Gfixed_5", "rn01_$Gfixed_6", "rn01_$Gfixed_7", "rn01_$Gfixed_8" }, 
  521. 			["points"] =  
  522. 				{	"rn01_$n056", "rn01_$n057", "rn01_$n058", "rn01_$n059", 
  523. 					"rn01_$n060", "rn01_$n061", "rn01_$n062", "rn01_$n063", 
  524. 					"rn01_$n063", "rn01_$n064", "rn01_$n065", "rn01_$n066", 
  525. 				}, 
  526. 			["max attackers"] = 4, 
  527. 			["max attackers coop"] = 6, 
  528. 			["attack function"] =  "rn01_fixed_vantage_attack_gat", 
  529. 		}, 
  530.  
  531. 	} 
  532.  
  533. Fixed_vantage_attacker_count_per_unit = {}	-- Number of living attackers spawned from a single unit 
  534. Fixed_vantage_attacker_count_per_group = {}	-- Number of living attackers in the same script group 
  535.  
  536. Fixed_vantage_attacker_to_attack_point = {}	-- Maps from attacker to the navpoint from which they're attacking 
  537. Fixed_vantage_attacker_to_unit = {}				-- Maps from attacker to attack unit 
  538. Fixed_vantage_attacker_to_group = {}			-- Maps from attacker to script group 
  539. Attack_point_in_use = {}							-- Attack_point_in_use[point] is true if point is in use 
  540.  
  541. function rn01_fixed_vantage_plant_bombs() 
  542.  
  543. 	-- Ronin attack while gat places bombs. 
  544. 	delay(2.0) 
  545. 	rn01_gat_place_bombs() 
  546. 	--rn01_detonate_bombs(TRIGGER_COUNTING_ROOM_DOOR_1, TRIGGER_COUNTING_ROOM_DOOR_2) 
  547.  
  548. 	Bombs_planted = true 
  549.  
  550. end 
  551.  
  552. Fixed_vantage_kills = 0 
  553. function rn01_fixed_vantage() 
  554.  
  555. 	-- Tell the players to guard Gat while he plants some bombs. 
  556. 	mission_help_table(HELPTEXT_PROMPT_PLANT_BOMBS) 
  557.  
  558. 	-- First we need to make sure that the local player is close to where the bombs will be planted. 
  559. 	-- Otherwise, who knows where Gat is and he may not be able to pathfind to the bomb location. 
  560. 	local max_gat_distance = 35.0 
  561. 	local max_player_distance = 5.0 
  562. 	if (	(get_dist(CHARACTER_GAT, TRIGGER_COUNTING_ROOM_DOOR_1) > max_gat_distance) 
  563. 			and (get_dist(LOCAL_PLAYER, TRIGGER_COUNTING_ROOM_DOOR_1) > max_player_distance) 
  564. 		) then 
  565.  
  566. 		marker_add_navpoint(TRIGGER_COUNTING_ROOM_DOOR_1,MINIMAP_ICON_LOCATION,INGAME_EFFECT_LOCATION, SYNC_LOCAL) 
  567. 		while(get_dist(LOCAL_PLAYER, TRIGGER_COUNTING_ROOM_DOOR_1) > max_player_distance) do 
  568. 			thread_yield() 
  569. 		end 
  570. 		marker_remove_navpoint(TRIGGER_COUNTING_ROOM_DOOR_1, SYNC_LOCAL) 
  571.  
  572. 	end 
  573.  
  574. 	thread_new("rn01_fixed_vantage_plant_bombs") 
  575.  
  576. 	for i, attack_unit in pairs (FIXED_VANTAGE_ATTACK_UNITS) do 
  577. 		Fixed_vantage_attacker_count_per_unit[i] = 0 
  578. 		for j, group in pairs (attack_unit["groups"]) do 
  579. 			Fixed_vantage_attacker_count_per_group[group] = 0 
  580. 		end 
  581. 	end 
  582.  
  583. 	while (not Bombs_planted) do 
  584.  
  585. 		-- Loop over all attack units 
  586. 		for i, attack_unit in pairs (FIXED_VANTAGE_ATTACK_UNITS) do 
  587.  
  588. 			local max_attackers = attack_unit["max attackers"] 
  589. 			if IN_COOP then 
  590. 				max_attackers = attack_unit["max attackers coop"] 
  591. 			end 
  592.  
  593. 			-- Loop over all groups in the attack unit 
  594. 			for j, group in pairs (attack_unit["groups"]) do 
  595.  
  596. 				local group_available = (not group_is_loaded(group)) and (Fixed_vantage_attacker_count_per_group[group] == 0) 
  597. 				local space_available = (Fixed_vantage_attacker_count_per_unit[i] < attack_unit["max attackers"] ) 
  598.  
  599. 				local out_of_sight = true 
  600. 				for i, attacker in pairs(FIXED_VANTAGE_GROUP_MEMBERS[group]) do 
  601. 					out_of_sight = out_of_sight and (not rn01_navpoint_in_fov(attacker)) 
  602. 				end 
  603.  
  604. 				-- If the group isn't loaded ... 
  605. 				if ( group_available and space_available and out_of_sight) then 
  606.  
  607. 					group_create_hidden(group, true) 
  608.  
  609. 					-- Send members of the group to attack 
  610. 					local num_to_send = max_attackers - Fixed_vantage_attacker_count_per_unit[i] 
  611. 					num_to_send = min(num_to_send, sizeof_table(FIXED_VANTAGE_GROUP_MEMBERS[group])) 
  612. 					Fixed_vantage_attacker_count_per_group[group] = num_to_send 
  613. 					Fixed_vantage_attacker_count_per_unit[i] =  Fixed_vantage_attacker_count_per_unit[i] + num_to_send 
  614.  
  615. 					for k=1, num_to_send, 1 do 
  616. 						 
  617. 						-- Show the attacker 
  618. 						local attacker = FIXED_VANTAGE_GROUP_MEMBERS[group][k] 
  619. 						marker_add_npc(attacker, MINIMAP_ICON_KILL, INGAME_EFFECT_KILL, SYNC_ALL) 
  620. 						on_death("rn01_fixed_vantage_attacker_killed", attacker) 
  621.  
  622. 						-- Send to an unused attack point 
  623. 						local num_attack_points = sizeof_table(attack_unit["points"]) 
  624. 						local point_index = rand_int(1,num_attack_points) 
  625. 						for ii=1, num_attack_points,1 do 
  626.  
  627. 							local point = attack_unit["points"][point_index] 
  628. 							 
  629. 							if (not Attack_point_in_use[point]) then 
  630. 								Attack_point_in_use[point] = true 
  631. 								Fixed_vantage_attacker_to_attack_point[attacker] = point 
  632. 								Fixed_vantage_attacker_to_unit[attacker] = i 
  633. 								Fixed_vantage_attacker_to_group[attacker] = group 
  634. 								thread_new(attack_unit["attack function"], attacker,  point) 
  635. 								break; 
  636. 							else 
  637. 								point_index = point_index + 1 
  638. 								if (point_index > num_attack_points) then 
  639. 									point_index = 1 
  640. 								end 
  641. 							end 
  642. 						end 
  643.  
  644. 					end -- End for k=1, ... 
  645.  
  646. 					delay(2.0) 
  647.  
  648. 				end -- End if (not group_is_loaded ...				 
  649. 			end 
  650.  
  651. 		end 
  652. 		thread_yield() 
  653. 	end 
  654.  
  655.  
  656. 	for group, member_list in pairs(FIXED_VANTAGE_GROUP_MEMBERS) do 
  657. 		for j,member in pairs(member_list) do 
  658. 				 
  659. 			if ( character_exists(member) and not character_is_dead(member) ) then 
  660.  
  661. 				on_death("", member) 
  662. 				marker_remove_npc(member) 
  663.  
  664. 			end 
  665.  
  666. 		end 
  667.  
  668. 		-- Destroy the groups in rn01_guard_box_loaders, don't want them popping. 
  669. 		--group_destroy(group) 
  670.  
  671. 	end 
  672.  
  673. end 
  674.  
  675. function rn01_navpoint_in_fov(navpoint, radius) 
  676.  
  677. 	local navpoint_in_local_fov = navpoint_in_player_fov(navpoint, LOCAL_PLAYER, radius) 
  678. 	local navpoint_in_remote_fov = false 
  679. 	if (IN_COOP) then 
  680. 		navpoint_in_remote_fov = navpoint_in_player_fov(navpoint, REMOTE_PLAYER, radius) 
  681. 	end 
  682.  
  683. 	return (navpoint_in_local_fov or navpoint_in_remote_fov) 
  684.  
  685. end 
  686.  
  687. function rn01_fixed_vantage_attack_player(ronin, attack_point) 
  688.  
  689. 	character_show(ronin) 
  690.  
  691. 	-- Move to attack point 
  692. 	move_to(ronin, attack_point, 2, true, true) 
  693. 	npc_leash_to_nav(ronin, attack_point, 1.0) 
  694.  
  695. 	attack(ronin) 
  696.  
  697. end 
  698.  
  699. function rn01_fixed_vantage_attack_gat(ronin, attack_point) 
  700.  
  701. 	character_show(ronin) 
  702.  
  703. 	-- Move to attack point 
  704. 	move_to(ronin, attack_point, 2, true, true) 
  705. 	npc_leash_to_nav(ronin, attack_point, 1.0) 
  706.  
  707. 	if (not character_is_dead(CHARACTER_GAT)) then 
  708. 		attack(ronin, CHARACTER_GAT) 
  709. 	else 
  710. 		attack(ronin) 
  711. 	end 
  712. end 
  713.  
  714. function rn01_fixed_vantage_attacker_killed(attacker) 
  715.  
  716. 	Fixed_vantage_kills = Fixed_vantage_kills + 1 
  717. 	 
  718. 	marker_remove_npc(attacker) 
  719.  
  720. 	local attack_point = Fixed_vantage_attacker_to_attack_point[attacker] 
  721. 	Attack_point_in_use[attack_point] = false 
  722. 	Fixed_vantage_attacker_to_attack_point[attacker] = nil 
  723.  
  724. 	local unit = Fixed_vantage_attacker_to_unit[attacker] 
  725. 	Fixed_vantage_attacker_count_per_unit[unit] = Fixed_vantage_attacker_count_per_unit[unit] - 1 
  726. 	Fixed_vantage_attacker_to_unit[attacker] = nil 
  727.  
  728. 	delay(1.0) 
  729.  
  730. 	-- If there are no more attackers from this group, then release it to the world so that it 
  731. 	-- can be respawned. 
  732. 	local group = Fixed_vantage_attacker_to_group[attacker] 
  733. 	Fixed_vantage_attacker_count_per_group[group] = Fixed_vantage_attacker_count_per_group[group] - 1 
  734. 	if (Fixed_vantage_attacker_count_per_group[group] == 0) then 
  735. 		release_to_world(group) 
  736. 	end 
  737. end 
  738.  
  739. -- Players have to drive to the Casino 
  740. function rn01_drive_to_casino() 
  741.  
  742. 	-- Start a thread to handle Gat's dialogue during the drive. 
  743. 	local gat_dialogue_thread = thread_new("rn01_casino_drive_gat_dialogue") 
  744. 	rn01_send_to_location(	TRIGGER_CASINO_ARRIVAL, INGAME_EFFECT_LOCATION, HELPTEXT_PROMPT_CASINO, true) 
  745. 	thread_kill(gat_dialogue_thread) 
  746.  
  747. end 
  748.  
  749. -- Players have to gain access to the counting room. 
  750. function rn01_gain_access() 
  751. 		 
  752. 	door_lock(DOOR_COUNTING_ROOM_1, true) 
  753. 	door_lock(DOOR_COUNTING_ROOM_2, true) 
  754.  
  755. 	-- Force no notoriety spawns when in the casino 
  756. 	notoriety_force_no_spawn("Ronin", true) 
  757. 	ambient_gang_spawn_enable(false) 
  758.  
  759. 	-- Delay a couple of seconds before telling the player to kill the guards. 
  760. 	delay(2)	 
  761. 	rn01_process_enemy_set(	MEMBERS_GROUP_CASINO_GUARDS, HELPTEXT_PROMPT_GUARDS, HELPTEXT_OBJECTIVE_GUARDS,  
  762. 									DOOR_CASINO_MAIN_1, DOOR_CASINO_MAIN_2) 
  763. 	 
  764. 	rn01_fixed_vantage() 
  765.  
  766. 	-- Warn the player that the bombs are going to detonate 
  767. 	mission_help_table_nag(HELPTEXT_PROMPT_BOMB_WARNING) 
  768.  
  769. 	delay(5.0) 
  770.  
  771. 	explosion_create(EXPLOSION_NAME, TRIGGER_COUNTING_ROOM_DOOR_1, CHARACTER_GAT, false) 
  772. 	explosion_create(EXPLOSION_NAME, TRIGGER_COUNTING_ROOM_DOOR_2, CHARACTER_GAT, false) 
  773.  
  774. 	delay(0.5) 
  775.  
  776. 	mesh_mover_hide(DOOR_COUNTING_ROOM_1) 
  777. 	mesh_mover_hide(DOOR_COUNTING_ROOM_2) 
  778.  
  779. 	delay(2.0) 
  780.  
  781. end 
  782.  
  783. Gat_bomb_progress = 0 
  784. Gat_planting_bomb = false 
  785. function rn01_gat_place_bombs() 
  786.  
  787. 	thread_new("rn01_bomb_progress_bar") 
  788.  
  789. 	local bomb_planting_audio 
  790.  
  791. 	local function rn01_plant_bomb(target, required_progress) 
  792.  
  793. 		while(Gat_bomb_progress < required_progress) do 
  794.  
  795. 			thread_yield() 
  796.  
  797. 			if( not character_is_ready(CHARACTER_GAT) ) then 
  798. 				Gat_planting_bomb = false 
  799. 			-- If Gat is too far, have him move back to the target 
  800. 			elseif( get_dist(CHARACTER_GAT, target) > 2) then 
  801. 				Gat_planting_bomb = false 
  802.             if crouch_is_crouching(CHARACTER_GAT) then 
  803.                crouch_stop(CHARACTER_GAT) 
  804.             end 
  805. 				move_to(CHARACTER_GAT, target, 2, true, false) 
  806. 			elseif (not check_animation_state(CHARACTER_GAT, STATE_PLANT_BOMB)) then 
  807. 				Gat_planting_bomb = false 
  808. 				set_animation_state(CHARACTER_GAT, STATE_PLANT_BOMB)				 
  809. 				bomb_planting_audio = audio_play_for_navpoint("SFX_DON_BOMBPLANTING", target, "foley") 
  810. 			elseif not crouch_is_crouching(CHARACTER_GAT) then 
  811. 				Gat_planting_bomb = false 
  812. 				crouch_start(CHARACTER_GAT) 
  813. 				delay(1) 
  814. 			else 
  815. 				Gat_planting_bomb = true 
  816. 			end 
  817. 		end 
  818.  
  819. 		audio_stop(bomb_planting_audio) 
  820. 		audio_play_for_navpoint("SFX_DON_BOMBPLANTED", target, "foley") 
  821. 		clear_animation_state(CHARACTER_GAT) 
  822. 		if crouch_is_crouching(CHARACTER_GAT) then 
  823. 			crouch_stop(CHARACTER_GAT) 
  824. 		end		 
  825.  
  826. 	end	-- End functions rn01_plant_bomb() 
  827.  
  828. 	follower_make_independent(CHARACTER_GAT, true) 
  829. 	npc_combat_enable(CHARACTER_GAT, false) 
  830. 	character_make_priority_target(CHARACTER_GAT, true, 20) 
  831.  
  832. 	rn01_plant_bomb(TRIGGER_COUNTING_ROOM_DOOR_1, 50) 
  833. 	rn01_plant_bomb(TRIGGER_COUNTING_ROOM_DOOR_2, 100) 
  834.  
  835. 	character_make_priority_target(CHARACTER_GAT, false) 
  836. 	follower_make_independent(CHARACTER_GAT, false) 
  837. 	npc_combat_enable(CHARACTER_GAT, true) 
  838. end 
  839.  
  840. -- Fill the bomb planting progress bar. Max progress limited by # of kills. Progress rate limited 
  841. -- by the min amount of time that it can take for Gat to plant the bombs. 
  842. function rn01_bomb_progress_bar() 
  843.  
  844. 	local max_progress = 0 
  845.  
  846. 	local kills_required = BOMB_PLANT_KILLS_REQUIRED 
  847. 	if ( IN_COOP ) then 
  848. 		kills_required = BOMB_PLANT_KILLS_REQUIRED_COOP 
  849. 	end 
  850.  
  851. 	local progress_per_kill = 100 / kills_required 
  852. 	local progress_per_sec = 100 / BOMB_PLANT_MIN_TIME_S 
  853.  
  854. 	hud_bar_on(0, "Health", HELPTEXT_HUD_GAT_PROGRESS, 1.0 ) 
  855. 	hud_bar_set_range(0, 0, 100, SYNC_ALL) 
  856. 	hud_bar_set_value(0, 0, SYNC_ALL) 
  857.  
  858. 	while (max_progress < 100) do 
  859.  
  860. 		thread_yield() 
  861.  
  862. 		-- Determine the max progress 
  863. 		max_progress = Fixed_vantage_kills * progress_per_kill 
  864. 		if (max_progress > 100) then 
  865. 			max_progress = 100 
  866. 		end 
  867.  
  868. 		-- Increment the progress meter if needed 
  869. 		local increment_size = max_progress - Gat_bomb_progress			-- Amount we can move the progress bar 
  870. 		local increment_time_s = increment_size / progress_per_sec		-- Amount of time it will take 
  871. 		local initial_progress = Gat_bomb_progress 
  872. 		local cumulative_time_s = 0 
  873. 		while (Gat_bomb_progress < max_progress) do 
  874. 			thread_yield() 
  875. 			if (Gat_planting_bomb) then 
  876. 				cumulative_time_s = cumulative_time_s + get_frame_time() 
  877. 				Gat_bomb_progress = initial_progress + increment_size * (cumulative_time_s / increment_time_s) 
  878. 				if (Gat_bomb_progress > max_progress) then 
  879. 					Gat_bomb_progress = max_progress 
  880. 				end 
  881. 				hud_bar_set_value(0, Gat_bomb_progress, SYNC_ALL) 
  882. 			end 
  883. 		end 
  884.  
  885. 	end 
  886.  
  887. 	hud_bar_off(0) 
  888. 	hud_timer_stop(0) 
  889.  
  890. end 
  891.  
  892. -- Guard patrol thread 
  893. -- Currently, if a guard enters combat, then their currently occupied path 
  894. -- is never released. 
  895. function rn01_casino_guard_patrol(guard) 
  896.  
  897. 	turn_to(guard,"rn01_$n030",false) 
  898. 	delay(1.0) 
  899. 	set_animation_state( guard, "Doorman stand") 
  900.  
  901. 	local at_spawn_location = true 
  902. 	local can_patrol = (CASINO_GUARD_INITIAL_PATH_SEGMENTS[guard] ~= nil) 
  903. 	local num_initial_path_segments = 0 
  904. 	if (can_patrol) then 
  905. 		num_initial_path_segments = sizeof_table(CASINO_GUARD_INITIAL_PATH_SEGMENTS[guard]) 
  906. 	end 
  907.  
  908. 	local current_segment_index = 0 
  909. 	local current_direction = DIR_FORWARD 
  910. 	local current_node_index = 0 
  911. 	local current_segment_num_nodes = 0 
  912.  
  913. 	-- If this guard can't patrol, we can let this thrad die 
  914. 	while(can_patrol) do 
  915.  
  916. 		local output = guard .. " seg_ind = " .. current_segment_index 
  917. 		output = output .. " dir = " .. current_direction 
  918. 		output = output .. " node_ind = " .. current_node_index 
  919. 		output = output .. " seg_num_nodes = " .. current_segment_num_nodes 
  920.  
  921. 		-- While we are at the spawn location, maybe decide to go for a little stroll 
  922. 		if (at_spawn_location) then 
  923. 			 
  924. 			local start_patrol_probability = .1 
  925. 			if (current_node_index == 0) then 
  926. 				start_patrol_probability = .5 
  927. 			end 
  928. 			local start_patrol_roll = rand_float(0.0,1.0)			 
  929.  
  930. 			-- If we should try to start a patrol 
  931. 			if (start_patrol_roll < start_patrol_probability) then 
  932.  
  933. 				-- Select a path segment randomly from our list of possible initial paths 
  934. 				local transition_info_index = rand_int(1,num_initial_path_segments) 
  935. 				local transition_info = CASINO_GUARD_INITIAL_PATH_SEGMENTS[guard][transition_info_index] 
  936. 				local path_segment_index = transition_info[1] 
  937.  
  938. 				-- If the path is not occupied, start pathfinding 
  939. 				if ( Path_segment_occupied[path_segment_index] ~= true) then 
  940.  
  941. 					Path_segment_occupied[path_segment_index] = true 
  942.  
  943. 					at_spawn_location = false 
  944.  
  945. 					current_segment_index = path_segment_index 
  946. 					current_direction = transition_info[2] 
  947.  
  948. 					if(current_direction == DIR_EITHER) then 
  949. 						local dir_roll = rand_int(1,2) 
  950. 						if (dir_roll == 1) then 
  951. 							current_direction = DIR_FORWARD 
  952. 						else 
  953. 							current_direction = DIR_REVERSE 
  954. 						end 
  955. 					end 
  956.  
  957. 					current_node_index =  transition_info[3] 
  958. 					current_segment_num_nodes = sizeof_table(CASINO_GUARD_PATH_SEGMENTS[current_segment_index]) 
  959.  
  960. 					move_to(guard, CASINO_GUARD_PATH_SEGMENTS[current_segment_index][current_node_index]) 
  961. 					 
  962. 				end 
  963. 			end 
  964.  
  965. 		-- Otherwise, already on patrol 
  966. 		else 
  967. 			 
  968. 			local end_patrol_probability = .1 
  969. 			local end_patrol_roll = rand_float(0.0,1.0) 
  970.  
  971. 			-- If we are ending the patrol, then return to the spawn location 
  972. 			if(end_patrol_roll < end_patrol_probability) then 
  973.  
  974. 				move_to(guard, guard) 
  975. 				Path_segment_occupied[current_segment_index] = false 
  976. 				at_spawn_location = true 
  977. 				turn_to(guard,"rn01_$n030",false) 
  978. 			-- Otherwise, try to continue patrolling 
  979. 			else 
  980. 				 
  981. 				-- Maybe look for a transition onto another patrol 
  982. 				local transition_probability = 0.5 
  983. 				local transition_roll = rand_float(0.0,1.0) 
  984. 				local transition_found = false 
  985. 				local transition_info = nil 
  986. 				if (transition_roll < transition_probability) then 
  987.  
  988. 					local current_node = CASINO_GUARD_PATH_SEGMENTS[current_segment_index][current_node_index] 
  989.  
  990. 					if (CASINO_GUARD_SEGMENT_TRANSITIONS[current_node] ~= nil) then 
  991.  
  992. 						local num_transitions_in_dir = 0 
  993. 						if (CASINO_GUARD_SEGMENT_TRANSITIONS[current_node][current_direction] ~= nil) then 
  994. 							num_transitions_in_dir = 
  995. 								sizeof_table(CASINO_GUARD_SEGMENT_TRANSITIONS[current_node][current_direction]) 
  996. 						end 
  997.  
  998. 						local num_transitions_in_either = 0 
  999. 						if (CASINO_GUARD_SEGMENT_TRANSITIONS[current_node][DIR_EITHER] ~= nil) then 
  1000. 							num_transitions_in_either = 
  1001. 								sizeof_table(CASINO_GUARD_SEGMENT_TRANSITIONS[current_node][DIR_EITHER]) 
  1002. 						end 
  1003.  
  1004. 						if (num_transitions_in_either + num_transitions_in_dir > 0) then 
  1005.  
  1006. 							local rand_transition = rand_int (1, num_transitions_in_dir + num_transitions_in_either) 
  1007.  
  1008. 							if (rand_transition > num_transitions_in_dir) then 
  1009. 								rand_transition = rand_transition - num_transitions_in_dir 
  1010. 								transition_info = CASINO_GUARD_SEGMENT_TRANSITIONS[current_node][DIR_EITHER][rand_transition] 
  1011. 							else 
  1012. 								transition_info = CASINO_GUARD_SEGMENT_TRANSITIONS[current_node][current_direction][rand_transition] 
  1013. 							end 
  1014. 							 
  1015. 							if (Path_segment_occupied[transition_info[1]] ~= true) then 
  1016. 								transition_found = true 
  1017. 							end 
  1018.  
  1019. 						end 
  1020.  
  1021. 					end 
  1022.  
  1023. 				end 
  1024.  
  1025. 				if (transition_found == true) then 
  1026.  
  1027. 					current_direction = transition_info[2] 
  1028. 					if(current_direction == DIR_EITHER) then 
  1029. 						local dir_roll = rand_int(1,2) 
  1030. 						if (dir_roll == 1) then 
  1031. 							current_direction = DIR_FORWARD 
  1032. 						else 
  1033. 							current_direction = DIR_REVERSE 
  1034. 						end 
  1035. 					end 
  1036. 					current_node_index =  transition_info[3] 
  1037.  
  1038. 					local transition_segment_index = transition_info[1] 
  1039. 					local transition_node_index = transition_info[2] 
  1040. 					move_to(guard, CASINO_GUARD_PATH_SEGMENTS[transition_segment_index][transition_node_index]) 
  1041.  
  1042. 					Path_segment_occupied[current_segment_index] = false 
  1043. 					Path_segment_occupied[transition_segment_index] = true 
  1044. 					current_segment_index = transition_segment_index 
  1045. 					current_segment_num_nodes = sizeof_table(CASINO_GUARD_PATH_SEGMENTS[current_segment_index]) 
  1046.  
  1047. 				else 
  1048. 					 
  1049. 					-- Get the index of the next node to pathfind to 
  1050. 					if(current_direction == DIR_FORWARD) then 
  1051. 						current_node_index = current_node_index + 1 
  1052. 						if (current_node_index > current_segment_num_nodes) then 
  1053. 							current_node_index = 1 
  1054. 						end 
  1055. 					else 
  1056. 						current_node_index = current_node_index - 1 
  1057. 						if (current_node_index == 0) then 
  1058. 							current_node_index = current_segment_num_nodes 
  1059. 						end 
  1060. 					end 
  1061. 				 
  1062. 					move_to(guard, CASINO_GUARD_PATH_SEGMENTS[current_segment_index][current_node_index]) 
  1063.  
  1064. 				end 
  1065. 				 
  1066. 			end 
  1067.  
  1068. 		end 
  1069.  
  1070. 		-- If we're still at the spawn location, then delay a bit before thinking about moving again. 
  1071. 		if (at_spawn_location) then 
  1072. 			delay(2.0,4.0) 
  1073. 		end 
  1074.  
  1075. 		thread_yield() 
  1076.  
  1077. 	end 
  1078.  
  1079. end 
  1080.  
  1081. -- After a guard has been damaged, set players minimum Ronin notoriety 
  1082. function rn01_casino_guard_damaged(guard, attacker, damage_percent) 
  1083. 	if (	attacker == LOCAL_PLAYER or 
  1084. 			attacker == CHARACTER_GAT or 
  1085. 			attacker == REMOTE_PLAYER) then 
  1086.  
  1087. 		-- Turn off action nodes in the Casino at this point. 
  1088. 		action_nodes_enable(false) 
  1089.  
  1090. 		-- Set min Ronin notoriety 
  1091. 		if (not IN_COOP) then 
  1092. 			notoriety_set_min("Ronin",MIN_RONIN_NOTORIETY) 
  1093. 			notoriety_set("Ronin",MIN_RONIN_NOTORIETY) 
  1094. 		else 
  1095. 			notoriety_set_min("Ronin", COOP_MIN_RONIN_NOTORIETY) 
  1096. 			notoriety_set("Ronin", COOP_MIN_RONIN_NOTORIETY) 
  1097. 		end 
  1098. 	end 
  1099.  
  1100. 	for i,guard in pairs(MEMBERS_GROUP_CASINO_GUARDS) do 
  1101. 		if (not character_is_dead(guard)) then 
  1102. 			set_attack_player_flag(guard, true) 
  1103. 		end 
  1104. 	end 
  1105.  
  1106. end 
  1107.  
  1108. -- Plays a series of Gat's dialogue line as the player(s) travel to the Casino. 
  1109. function rn01_casino_drive_gat_dialogue() 
  1110.  
  1111. 	-- Wait until the player is 30& of the way to the casino 
  1112. 	local total_distance = get_dist(LOCAL_PLAYER, TRIGGER_CASINO_ARRIVAL) 
  1113. 	while( get_dist(LOCAL_PLAYER, TRIGGER_CASINO_ARRIVAL) > 0.7 * total_distance ) do 
  1114. 		thread_yield() 
  1115. 	end 
  1116.  
  1117. 	-- Make sure that Gat is near the player 
  1118. 	while( get_dist(LOCAL_PLAYER, CHARACTER_GAT) > 25 ) do 
  1119. 		thread_yield() 
  1120. 	end 
  1121.  
  1122. 	-- Play the conversation 
  1123. 	audio_play_conversation( INTRO_CONVERSATION) 
  1124.  
  1125. end 
  1126.  
  1127. -- Delays a bit and then bumps up police notoriety 
  1128. function rn01_drive_notoriety() 
  1129.  
  1130.  
  1131. 	local total_dist = get_dist(VEHICLE_TRUCK, TRIGGER_AISHAS) 
  1132.  
  1133. 	-- Allow notoriety to be reduced to 0 via Forgive-and-Forgets, but don't let it decay by itself. 
  1134. 	notoriety_set_min("Police", 0) 
  1135. 	notoriety_set_max("Police", 0) 
  1136. 	notoriety_set("Police", 0) 
  1137.  
  1138. 	notoriety_set_min("Ronin", 1) 
  1139. 	notoriety_set("Ronin", 1) 
  1140. 	notoriety_set_max("Ronin",1) 
  1141.  
  1142. 	notoriety_set_can_decay(false) 
  1143.  
  1144. 	delay(8.) 
  1145.  
  1146. 	-- Set min police notoriety 
  1147. 	if (not IN_COOP) then 
  1148. 		notoriety_set_max("Police", MIN_POLICE_NOTORIETY) 
  1149. 		notoriety_set("Police",MIN_POLICE_NOTORIETY) 
  1150. 	else 
  1151. 		notoriety_set_max("Police", COOP_MIN_POLICE_NOTORIETY) 
  1152. 		notoriety_set("Police", COOP_MIN_POLICE_NOTORIETY) 
  1153. 	end 
  1154. 	 
  1155. 	audio_play_for_character("GAT_RON1_ESCAPE_01", CHARACTER_GAT, "voice", false, true) 
  1156.  
  1157. 	delay(10) 
  1158. 	thread_new("rn01_launder_conversation") 
  1159.  
  1160. 	while( get_dist(VEHICLE_TRUCK, TRIGGER_AISHAS) > 0.5 * total_dist ) do 
  1161. 		thread_yield() 
  1162. 	end 
  1163.  
  1164. 	notoriety_set_max("Ronin",2) 
  1165. 	notoriety_set_min("Ronin", 2) 
  1166.  
  1167. end 
  1168.  
  1169. Rn01_call_received = false 
  1170. function rn01_call_received() 
  1171. 	Rn01_call_received = true 
  1172. end 
  1173.  
  1174. function rn01_launder_conversation() 
  1175. 	if (IN_COOP) then 
  1176. 		mid_mission_phonecall("rn01_call_received") 
  1177. 		while( not Rn01_call_received ) do 
  1178. 			thread_yield() 
  1179. 		end 
  1180. 		audio_play_conversation( LAUNDER_CONVERSATION_COOP, INCOMING_CALL) 
  1181. 	else 
  1182. 		audio_play_conversation( LAUNDER_CONVERSATION) 
  1183. 	end 
  1184. end 
  1185.  
  1186. function rn01_cleanup() 
  1187.  
  1188. 	-- Reevaluate IN_COOP, remote player may have dropped. 
  1189. 	IN_COOP = coop_is_active() 
  1190.  
  1191. 	-- Get rid of the any mid-mission phone calls 
  1192. 	mid_mission_phonecall_reset() 
  1193.  
  1194. 	-- Remove the navpoint indicated where the server needs to go before Gat will start planting bombs 
  1195. 	marker_remove_navpoint(TRIGGER_COUNTING_ROOM_DOOR_1, SYNC_LOCAL) 
  1196.  
  1197. 	-- Make sure that trucks are not invulnerable 
  1198. 	if (vehicle_exists(VEHICLE_TRUCK) and (not vehicle_is_destroyed(VEHICLE_TRUCK))) then 
  1199. 		turn_vulnerable(VEHICLE_TRUCK) 
  1200. 		on_vehicle_destroyed("", VEHICLE_TRUCK) 
  1201. 		on_vehicle_enter("", VEHICLE_TRUCK) 
  1202. 		on_vehicle_exit("", VEHICLE_TRUCK) 
  1203. 		vehicle_door_prevent_damage_detach( VEHICLE_TRUCK, "Door_BR", false ) 
  1204. 		vehicle_door_prevent_damage_detach( VEHICLE_TRUCK, "Door_BL", false ) 
  1205. 	end 
  1206.  
  1207. 	-- Remove persona overrides 
  1208. 	persona_override_group_stop(RONIN_PERSONAS,POT_SITUATIONS[POT_ATTACK]) 
  1209. 	persona_override_group_stop(SAINTS_PERSONAS,POT_SITUATIONS[POT_ATTACK]) 
  1210. 	persona_override_group_stop(SAINTS_PERSONAS,POT_SITUATIONS[POT_CUSTOM_1]) 
  1211. 	persona_override_group_stop(SAINTS_PERSONAS,POT_SITUATIONS[POT_CUSTOM_2]) 
  1212.  
  1213. 	-- Get rid of too-far from Casino timer 
  1214. 		hud_timer_stop(1) 
  1215. 		objective_text_clear(1) 
  1216.  
  1217. 	-- Reset global overrides 
  1218.  
  1219. 		-- Reset the spawning 
  1220. 		npc_respawn_dist_reset() 
  1221. 		spawning_vehicles(true) 
  1222. 		spawning_pedestrians(true) 
  1223. 		set_ped_density(1) 
  1224. 		action_nodes_enable(true) 
  1225. 		ambient_gang_spawn_enable(true) 
  1226. 		spawning_allow_cop_ambient_spawns(true) 
  1227.  
  1228. 	-- Clean up the UI 
  1229.  
  1230. 		-- clear mission item pickup text 
  1231. 		on_mission_item_pickup("") 
  1232.  
  1233. 		-- clear objective text 
  1234. 		objective_text_clear(0) 
  1235.  
  1236. 		-- remove any possible waypoint 
  1237. 		rn01_update_waypoint("", LOCAL_PLAYER) 
  1238. 		if( IN_COOP ) then 
  1239. 			rn01_update_waypoint("", REMOTE_PLAYER)	 
  1240. 		end 
  1241.  
  1242. 		-- remove all markers 
  1243. 		for i,enemy in pairs(MEMBERS_GROUP_CASINO_GUARDS) do 
  1244. 			marker_remove_npc(enemy) 
  1245. 		end 
  1246.  
  1247. 		marker_remove_npc(CHARACTER_HELPER) 
  1248. 		marker_remove_npc(CHARACTER_PIERCE) 
  1249.  
  1250. 	-- disable all triggers 
  1251. 	for i, trigger in pairs(TABLE_ALL_TRIGGERS) do 
  1252. 		on_trigger("",trigger) 
  1253. 	end 
  1254.  
  1255. 	-- Remove all callbacks 
  1256.  
  1257. 		-- trigger callbacks 
  1258. 		for i, trigger in pairs(TABLE_ALL_TRIGGERS) do 
  1259. 			on_trigger("",trigger) 
  1260. 			on_trigger_exit("",trigger) 
  1261. 		end 
  1262.  
  1263. 		-- stage 4 ronin waves callbacks 
  1264. 		for i,enemy in pairs(MEMBERS_GROUP_CASINO_GUARDS) do 
  1265. 			on_death("",enemy) 
  1266. 		end 
  1267.  
  1268. 		-- other character callbacks 
  1269. 		on_death("", CHARACTER_GAT) 
  1270. 		on_dismiss("", CHARACTER_GAT) 
  1271.  
  1272. 	-- Remove followers 
  1273. 		party_dismiss_all() 
  1274. end 
  1275.  
  1276. function rn01_success() 
  1277. 	-- Called when the mission has ended with success 
  1278. 	radio_post_event("JANE_NEWS_RON01", true) 
  1279. end 
  1280.  
  1281.  
  1282. -- Player in truck? 
  1283. Truck_markers_displayed = {[LOCAL_PLAYER] = false, [REMOTE_PLAYER] = false} 
  1284. function rn01_prereq_player_in_truck(player) 
  1285.  
  1286. 	if(vehicle_is_destroyed(VEHICLE_TRUCK) or (not vehicle_exists(VEHICLE_TRUCK))) then 
  1287. 		return true 
  1288. 	end 
  1289.  
  1290. 	if (character_is_in_vehicle(player, VEHICLE_TRUCK)) then 
  1291. 		if(Truck_markers_displayed[player]) then 
  1292. 			marker_remove_vehicle(VEHICLE_TRUCK, PLAYER_SYNC[player]) 
  1293. 			Truck_markers_displayed[player] = false 
  1294. 		end 
  1295. 		return true 
  1296. 	else 
  1297. 		if(not Truck_markers_displayed[player]) then 
  1298. 			marker_add_vehicle(VEHICLE_TRUCK,MINIMAP_ICON_PROTECT_ACQUIRE,INGAME_EFFECT_VEHICLE_PROTECT_ACQUIRE,PLAYER_SYNC[player]) 
  1299. 			Truck_markers_displayed[player] = true 
  1300. 			rn01_update_waypoint("", player) 
  1301. 		end 
  1302. 		return false 
  1303. 	end 
  1304. end 
  1305.  
  1306. rn01_location_reached			= false 
  1307. failed_prereq = {[LOCAL_PLAYER] = 0, [REMOTE_PLAYER] = 0} 
  1308. function rn01_send_to_location(trigger, effect, helptext, use_waypoint, prereq_list, time, time_failure_function) 
  1309.  
  1310. 	failed_prereq = {[LOCAL_PLAYER] = 0, [REMOTE_PLAYER] = 0} 
  1311.  
  1312. 	-- Location not yet reached 
  1313. 	rn01_location_reached = false 
  1314.  
  1315. 	-- enable the trigger, add a minimap icon, glow effect, and callback 
  1316. 	trigger_enable(trigger,true) 
  1317. 	marker_add_trigger(trigger,MINIMAP_ICON_LOCATION,effect) 
  1318. 	on_trigger("rn01_toggle_location_reached",trigger) 
  1319. 	trigger_set_delay_between_activations( trigger, 0) 
  1320.  
  1321. 	-- Maybe add waypoint 
  1322. 	if (use_waypoint) then 
  1323. 		rn01_update_waypoint(trigger, LOCAL_PLAYER) 
  1324. 		if(IN_COOP) then 
  1325. 			rn01_update_waypoint(trigger, REMOTE_PLAYER) 
  1326. 		end 
  1327. 	end 
  1328.  
  1329. 	-- Maybe add failure function 
  1330. 	if (time and time_failure_function) then 
  1331. 		hud_timer_set(1, time, time_failure_function) 
  1332. 	end 
  1333.  
  1334. 	-- Tell the player what to do 
  1335. 	if (helptext) then 
  1336. 		mission_help_table(helptext) 
  1337. 	end 
  1338.  
  1339. 	-- wait for player(s) to arrive 
  1340. 	--local initial_pass = true 
  1341.  
  1342. 	-- Maybe check to see if player needs to do something else before heading to location 
  1343. 	local function check_player_prereqs(player) 
  1344.  
  1345. 		-- If we have a list of prereqs 
  1346. 		if(prereq_list ~= nil) then 
  1347.  
  1348. 			-- Loop over all prereqs to see if any have  been failed 
  1349. 			-- Prereqs are listed in order of importance, so we can't use pairs() 
  1350. 			local new_failed_prereq = 0 
  1351. 			for i=1, sizeof_table(prereq_list), 1 do 
  1352.  
  1353. 				local prereq_function = prereq_list[i][1] 
  1354. 				local prereq_helptext = prereq_list[i][2] 
  1355.  
  1356. 				if(not prereq_function(player)) then 
  1357.  
  1358. 					-- If we just began failing the prereq... 
  1359. 					if ( i ~= failed_prereq[player] ) then 
  1360.  
  1361. 						-- Eliminate any leftover waypoints/markers from lower-priority prereqs failing 
  1362. 						rn01_update_waypoint( "", player) 
  1363. 						if(failed_prereq[player] == 0) then 
  1364. 							marker_remove_trigger(trigger, PLAYER_SYNC[player]) 
  1365. 						end 
  1366.  
  1367. 						-- Tell the player what they need to do 
  1368. 						if( prereq_helptext ) then 
  1369. 							mission_help_table_nag(prereq_helptext, "", "", PLAYER_SYNC[player]) 
  1370. 						end 
  1371. 					end 
  1372.  
  1373. 					-- We don't need to check any more prereqs 
  1374. 					new_failed_prereq = i 
  1375. 					break; 
  1376.  
  1377. 				end -- Ends prereq function fulfillment 
  1378. 			end -- Ends loop over prereqs 
  1379.  
  1380. 			-- If the players weren't meeting prereqs and now they are then reenable the destination 
  1381. 			if ( (new_failed_prereq == 0) and (failed_prereq[player] ~= 0) ) then 
  1382. 	 
  1383. 				-- Remove old waypoint that might have been added for failed prereq 
  1384. 				rn01_update_waypoint( "", player) 
  1385. 	 
  1386. 				-- Readd minimap location and waypoint 
  1387. 				marker_add_trigger(trigger,MINIMAP_ICON_LOCATION,effect,SYNC_ALL) 
  1388. 				if (use_waypoint) then 
  1389. 					rn01_update_waypoint( trigger, player) 
  1390. 				end 
  1391.  
  1392. 				-- Remind player what the original goal was 
  1393. 				if (helptext) then 
  1394. 					mission_help_table_nag(helptext, "", "", PLAYER_SYNC[player]) 
  1395. 				end 
  1396.  
  1397. 			-- On the initial pass, if no prereqs were failed then display the helptext 
  1398. 			--elseif( new_failed_prereq == 0 and initial_pass) then 
  1399. 			--	if (helptext) then 
  1400. 			--		mission_help_table(helptext,  "", "", PLAYER_SYNC[player]) 
  1401. 			--	end 
  1402. 			end 
  1403.  
  1404. 			failed_prereq[player] = new_failed_prereq 
  1405.  
  1406. 		end -- Ends prereq list processing	 
  1407.  
  1408. 	end 
  1409.  
  1410. 	while (not rn01_location_reached) do 
  1411.  
  1412. 		check_player_prereqs(LOCAL_PLAYER) 
  1413. 		if(IN_COOP) then 
  1414. 			check_player_prereqs(REMOTE_PLAYER) 
  1415. 		end 
  1416.  
  1417. 		--initial_pass = false 
  1418.  
  1419. 		thread_yield() 
  1420. 	end 
  1421.  
  1422. 	-- Maybe turn off timer 
  1423. 	if (time and time_failure_function) then 
  1424. 			hud_timer_stop(1) 
  1425. 	end 
  1426. end 
  1427.  
  1428. function rn01_toggle_location_reached(triggerer,trigger) 
  1429.  
  1430. 	if(failed_prereq[triggerer] == 0) then 
  1431.  
  1432. 		rn01_location_reached = true		 
  1433. 		trigger_enable(trigger, false) 
  1434. 		marker_remove_trigger(trigger, SYNC_ALL) 
  1435. 		on_trigger("",trigger) 
  1436. 		rn01_update_waypoint("", LOCAL_PLAYER) 
  1437. 		if (IN_COOP) then 
  1438. 			rn01_update_waypoint("", REMOTE_PLAYER) 
  1439. 		end 
  1440.  
  1441. 	end 
  1442. end 
  1443.  
  1444. rn01_enemies_to_kill = 0 
  1445. rn01_enemies_living = 0 
  1446. rn01_enemy_set_objective_helptext = "" 
  1447.  
  1448. -- Wait for the player to kill a group of enemies 
  1449. --  
  1450. -- enemy_table				A table containing the names of the enemies that need to be killed 
  1451. -- mission_helptext		The helptext message that will prompt the player(s) to kill the enemies 
  1452. -- objective_helptext	The objective text displayed in the hud, needs to be in the format %s of %s killed 
  1453. -- ...						A list of doors that will be unlocked to give the player access to the enemies 
  1454. function rn01_process_enemy_set(enemy_table, mission_helptext, objective_helptext, ...) 
  1455.  
  1456. 	-- Assign enemy callbacks, add markers 
  1457. 	for i, enemy in pairs(enemy_table) do 
  1458. 		if (not character_is_dead(enemy)) then 
  1459. 			on_death("rn01_enemy_killed", enemy) 
  1460. 			marker_add_npc(enemy, MINIMAP_ICON_KILL, INGAME_EFFECT_KILL, SYNC_ALL)  
  1461. 			rn01_enemies_to_kill = rn01_enemies_to_kill + 1 
  1462. 		end 
  1463. 	end 
  1464. 	rn01_enemies_living =  rn01_enemies_to_kill 
  1465.  
  1466. 	-- Open doors 
  1467. 	for i, door in ipairs(arg) do 
  1468. 		door_lock(door, false) 
  1469. 	end 
  1470.  
  1471. 	-- Display the objective text 
  1472. 	if(objective_helptext) then 
  1473. 		rn01_enemy_set_objective_helptext = objective_helptext 
  1474. 		objective_text(0, rn01_enemy_set_objective_helptext, rn01_enemies_to_kill - rn01_enemies_living, rn01_enemies_to_kill) 
  1475. 	end 
  1476.  
  1477. 	-- Display the help text 
  1478. 	if(mission_helptext) then 
  1479. 		mission_help_table(mission_helptext) 
  1480. 	end 
  1481.  
  1482. 	 
  1483. 	while (rn01_enemies_living > 0) do 
  1484. 		thread_yield() 
  1485. 	end 
  1486.  
  1487. end 
  1488.  
  1489. function rn01_enemy_killed(enemy) 
  1490. 	marker_remove_npc(enemy) 
  1491. 	on_death("",enemy) 
  1492. 	rn01_enemies_living = rn01_enemies_living - 1 
  1493. 	if (rn01_enemies_living < 1) then 
  1494. 		objective_text_clear(0) 
  1495. 		rn01_enemy_set_objective_helptext = "" 
  1496. 	else 
  1497. 		if (rn01_enemy_set_objective_helptext ~= "") then 
  1498. 			objective_text(0, rn01_enemy_set_objective_helptext, rn01_enemies_to_kill - rn01_enemies_living, rn01_enemies_to_kill) 
  1499. 		end 
  1500.  
  1501. 		if (rn01_enemies_living == 5) then 
  1502. 			for i,guard in pairs(MEMBERS_GROUP_CASINO_GUARDS) do 
  1503. 				if (not character_is_dead(guard)) then 
  1504. 					npc_leash_remove(guard) 
  1505. 					attack(guard) 
  1506. 				end 
  1507. 			end		 
  1508. 		end 
  1509. 	end 
  1510. end 
  1511.  
  1512. function rn01_complete() 
  1513.  
  1514. 	-- Get rid of the any mid-mission phone calls. We don't want them playing during the cutscene. 
  1515. 	mid_mission_phonecall_reset() 
  1516.  
  1517. 	-- End the mission with success 
  1518. 	mission_end_success("rn01", "ro01-02") 
  1519. end 
  1520.  
  1521. -- Doors usually close on chunk load/reload... this keeps them open. 
  1522. function rn01_keep_doors_open() 
  1523. 	while (true) do 
  1524. 		for door,opened in pairs (Door_opened) do 
  1525. 			door_open(door) 
  1526. 		end 
  1527. 		thread_yield() 
  1528. 	end 
  1529. end 
  1530.  
  1531. function rn01_guard_box_loaders() 
  1532.  
  1533.  
  1534. 	for group, member_list in pairs(FIXED_VANTAGE_GROUP_MEMBERS) do 
  1535. 		group_destroy(group) 
  1536. 	end 
  1537.  
  1538. 	-- Make sure these are opened when player can't see them 
  1539. 	Door_opened[DOOR_COUNTING_ROOM_1] = true 
  1540. 	Door_opened[DOOR_COUNTING_ROOM_2] = true 
  1541. 	Door_opened[DOOR_CASINO_AREA_1] = true 
  1542. 	Door_opened[DOOR_CASINO_AREA_2] = true 
  1543. 	Door_opened[DOOR_CASINO_MAIN_1] = true 
  1544. 	Door_opened[DOOR_CASINO_MAIN_2] = true			 
  1545.  
  1546. 	-- Setup the truck and play the cutscene 
  1547. 	rn01_setup_truck() 
  1548.  
  1549. 	-- Don't let the vehicle's doors open 
  1550. 	vehicle_door_prevent_damage_detach( VEHICLE_TRUCK, "Door_BR", true ) 
  1551. 	vehicle_door_prevent_damage_detach( VEHICLE_TRUCK, "Door_BL", true ) 
  1552.  
  1553. 	-- Send player(s) to the casino 
  1554. 	rn01_send_to_hq()	 
  1555. end 
  1556.  
  1557.  
  1558. function rn01_setup_truck() 
  1559.  
  1560. 	-- Kill off vehicle and ped spawning 
  1561. 	spawning_vehicles(false) 
  1562. 	spawning_pedestrians(false, true) 
  1563.  
  1564. 	-- Player(s)/Gat shouldn't be in a vehicle 
  1565. 	character_evacuate_from_all_vehicles(LOCAL_PLAYER) 
  1566. 	if (IN_COOP) then 
  1567. 		character_evacuate_from_all_vehicles(REMOTE_PLAYER) 
  1568. 	end 
  1569. 	if (character_is_in_vehicle(CHARACTER_GAT)) then 
  1570. 		character_evacuate_from_all_vehicles(CHARACTER_GAT) 
  1571. 	end 
  1572.  
  1573. 	-- Play the In Game Cutscene. 
  1574. 	cutscene_play("IG_rn01_scene1", "", "", false) -- don't fade in after 
  1575.  
  1576. 	-- Remove helpers from the truck and destroy them 
  1577. 	vehicle_evacuate(VEHICLE_TRUCK) 
  1578. 	character_destroy(CHARACTER_PIERCE) 
  1579. 	character_destroy(CHARACTER_HELPER) 
  1580.  
  1581. 	-- Add the on-death failure callback to the truck 
  1582. 	on_vehicle_destroyed("rn01_failure_truck_destroyed", VEHICLE_TRUCK) 
  1583.  
  1584. 	-- Place local player and either Gat or the remote player into the vehicle 
  1585. 	if(IN_COOP) then 
  1586. 		npc_stop_following(CHARACTER_GAT) 
  1587. 		character_destroy(CHARACTER_GAT) 
  1588. 		vehicle_enter_teleport(LOCAL_PLAYER, VEHICLE_TRUCK, 0) 
  1589. 		vehicle_enter_teleport(REMOTE_PLAYER, VEHICLE_TRUCK, 1) 
  1590. 	else 
  1591.  
  1592. 		if ( coop_is_active() == false ) then 
  1593. 			-- Find Gat's current index 
  1594. 			local gat_follower_index = party_get_follower_index(CHARACTER_GAT) 
  1595.  
  1596. 			-- If he's not the first follower, swap him and the first one 
  1597. 			if ( gat_follower_index > 0 ) then 
  1598. 				party_swap_follower_indices( 0, gat_follower_index ) 
  1599. 				delay( 1.0 ) 
  1600. 			end 
  1601. 		end 
  1602.  
  1603. 		vehicle_enter_teleport(CHARACTER_GAT, VEHICLE_TRUCK, 1) 
  1604. 		vehicle_enter_teleport(LOCAL_PLAYER, VEHICLE_TRUCK, 0) 
  1605. 		set_perfect_aim(CHARACTER_GAT, false) 
  1606. 		party_add(CHARACTER_GAT, LOCAL_PLAYER) 
  1607. 		npc_combat_enable(CHARACTER_GAT, true) 
  1608. 		set_ignore_ai_flag(CHARACTER_GAT,false) 
  1609. 		set_attack_enemies_flag(CHARACTER_GAT,true) 
  1610. 		npc_weapon_pickup_override(CHARACTER_GAT,true) 
  1611. 	end 
  1612.  
  1613. 	-- Wait for everyone to get in the truck 
  1614. 	rn01_wait_for_vehicle_entry(LOCAL_PLAYER, VEHICLE_TRUCK, 0) 
  1615. 	if(IN_COOP) then 
  1616. 		rn01_wait_for_vehicle_entry(REMOTE_PLAYER, VEHICLE_TRUCK, 1) 
  1617. 		delay(1.0) 
  1618. 	else 
  1619. 		rn01_wait_for_vehicle_entry(CHARACTER_GAT, VEHICLE_TRUCK, 1) 
  1620. 	end 
  1621.  
  1622. 	-- Allow spawning to return to normal 
  1623. 	spawning_vehicles(true) 
  1624. 	spawning_pedestrians(true) 
  1625. 	spawning_allow_cop_ambient_spawns(true)	 
  1626.  
  1627. 	-- Fade back in from the cutscene 
  1628. 	mission_start_fade_in() 
  1629.  
  1630. end 
  1631.  
  1632. -- Wait for a character to enter a vehicle. Blocks  
  1633. function rn01_wait_for_vehicle_entry(character, vehicle, seat_index) 
  1634.  
  1635. 	local delay_length = 0.25 
  1636. 	if (character == REMOTE_PLAYER) then 
  1637. 		delay_length = 0.5 
  1638. 	end 
  1639.  
  1640. 	local teleport_attempts = 1 
  1641. 	while( (not character_is_in_vehicle(character, vehicle)) and (teleport_attempts < 5) ) do 
  1642. 		teleport_attempts = teleport_attempts + 1 
  1643. 		vehicle_enter_teleport(character, vehicle, seat_index) 
  1644. 		delay(delay_length) 
  1645. 	end 
  1646.  
  1647. end 
  1648.  
  1649. function rn01_send_to_hq() 
  1650.  
  1651. 	-- Add the on-death failure callback to the truck 
  1652. 	if (vehicle_exists(VEHICLE_TRUCK) and not vehicle_is_destroyed(VEHICLE_TRUCK)) then 
  1653. 		on_vehicle_destroyed("rn01_failure_truck_destroyed", VEHICLE_TRUCK) 
  1654. 	end 
  1655.  
  1656. 	--Re-allow Ronin notoriety spawns 
  1657. 	notoriety_force_no_spawn("Ronin", false) 
  1658.  
  1659. 	-- Bump up police notoriety a bit after the player(s) enter the truck 
  1660. 	thread_new("rn01_drive_notoriety") 
  1661.  
  1662. 	-- Send the players home, but require them to be in the vehicle and have 0 notoriety. 
  1663. 	rn01_send_to_location(	TRIGGER_AISHAS,  
  1664. 									INGAME_EFFECT_VEHICLE_LOCATION,  
  1665. 									HELPTEXT_PROMPT_HEAD_HOME, 
  1666. 									true,  
  1667. 									{	{rn01_prereq_player_in_truck, HELPTEXT_PROMPT_REENTER_TRUCK}, 
  1668. --										{rn01_prereq_zero_notoriety, HELPTEXT_PROMPT_NOTORIETY_ZERO}, 
  1669. 									} 
  1670. 								) 
  1671.  
  1672. end 
  1673.  
  1674. function rn01_update_waypoint(waypoint, player) 
  1675. 	if(Gps_waypoint[player] ~= waypoint) then 
  1676. 		 
  1677. 		waypoint_remove(PLAYER_SYNC[player]) 
  1678. 		Gps_waypoint[player] = waypoint 
  1679. 		 
  1680. 		if(waypoint ~= "") then 
  1681. 			waypoint_add(waypoint, PLAYER_SYNC[player]) 
  1682. 		end 
  1683. 		 
  1684. 	end 
  1685. end 
  1686.  
  1687. function rn01_prereq_zero_notoriety() 
  1688.  
  1689. 	-- Is notoriety at 0? 
  1690. 	local at_zero_notoriety = (	(notoriety_get_decimal("Ronin") == 0) and  
  1691. 											(notoriety_get_decimal("Police") == 0) 
  1692. 										) 
  1693.  
  1694. 	-- Updates the gps of one player 
  1695. 	local function update_confessional_gps(player) 
  1696.  
  1697. 		if(not at_zero_notoriety) then 
  1698. 			local new_confessional = confessionals_get_nearest_trigger(player) 
  1699. 			rn01_update_waypoint(new_confessional, player) 
  1700. 		end 
  1701.  
  1702. 	end 
  1703.  
  1704. 	-- Update both players' gps 
  1705. 	update_confessional_gps(LOCAL_PLAYER) 
  1706. 	if (IN_COOP) then 
  1707. 		update_confessional_gps(REMOTE_PLAYER) 
  1708. 	end 
  1709.  
  1710. 	-- Return true if the prereq is met, false else 
  1711. 	return at_zero_notoriety 
  1712.  
  1713. end 
  1714.  
  1715. -- MISSION FAILURE FUNCTIONS -------------------------------- 
  1716.  
  1717. -- Add callbacks which need to exist throughout the mission, only adds callbacks 
  1718. -- if the groups are loaded. 
  1719. function rn01_add_mission_failure_callbacks() 
  1720.  
  1721. 	-- Add death/abandoment failures for Johnny Gat 
  1722. 	on_death("rn01_failure_gat_died", CHARACTER_GAT) 
  1723. 	on_dismiss("rn01_failure_gat_abandoned", CHARACTER_GAT) 
  1724. end 
  1725.  
  1726. function rn01_failure_gat_died() 
  1727. 	-- End the mission, Gat died 
  1728. 	mission_end_failure("rn01", HELPTEXT_FAILURE_GAT_DIED) 
  1729. end 
  1730.  
  1731. function rn01_failure_gat_abandoned() 
  1732. 	-- End the mission, Gat abandoned 
  1733. 	mission_end_failure("rn01", HELPTEXT_FAILURE_GAT_ABANDONED) 
  1734. end 
  1735.  
  1736. function rn01_failure_pierce_died() 
  1737. 	-- End the mission, Pierce died 
  1738. 	mission_end_failure("rn01", HELPTEXT_FAILURE_PIERCE_DIED) 
  1739. end 
  1740.  
  1741. function rn01_failure_pierce_abandoned() 
  1742. 	-- End the mission, Pierce abandoned 
  1743. 	mission_end_failure("rn01", HELPTEXT_FAILURE_PIERCE_ABANDONED) 
  1744. end 
  1745.  
  1746. function rn01_failure_truck_destroyed() 
  1747. 	-- End the mission, Gat abandoned 
  1748. 	delay(2.0) 
  1749. 	mission_end_failure("rn01", HELPTEXT_FAILURE_TRUCK_DESTROYED) 
  1750. end 
  1751.