sr2lua/bh11.lua

  1. -- bh11.lua 
  2. -- SR2 mission script 
  3. -- 3/28/07 
  4.  
  5.  
  6. 	CURRENT_MISSION =			"bh11" 
  7. 	ENEMY_GANG =				"Brotherhood" 
  8.  
  9. 	-- Navpoints -- 
  10. 	NAV_PLAYER_START =		"bh11_$player_start" 
  11. 	NAV_REMOTE_START =		"bh11_$remote_start" 
  12. 	NAV_MISSION_END_RESTORE_POS = "bh11_$Mission_End_Restore_Pos" 
  13. 	NAV_MISSION_END_REMOTE_RESTORE_POS = "bh11_$Mission_End_Remote_Restore_Pos" 
  14.  
  15. 	-- Tables -- 
  16. 	Bh11_maero_patrol =		"bh11_$Maero_Path" 
  17. 	Bh11_tribal_vehicles =  {"bh11_$v000", "bh11_$v001", "bh11_$v002", "bh11_$v003", "bh11_$v004", "bh11_$v005", "bh11_$v006", "bh11_$v007"} 
  18. 	Bh11_tribal_vehicles_coop = {"bh11_$v008", "bh11_$v009", "bh11_$v010", "bh11_$v011"} 
  19. 	Bh11_all_vehicles =		{"bh11_$v000", "bh11_$v001", "bh11_$v002", "bh11_$v003", "bh11_$v004", "bh11_$v005", "bh11_$v006", "bh11_$v007", "bh11_$v008", "bh11_$v009", "bh11_$v010", "bh11_$v011"} 
  20.  
  21. 	Bh11_tribal_chars =     {	{"bh11_$c000", "bh11_$c001"}, 
  22. 										{"bh11_$c004", "bh11_$c005"}, 
  23. 										{"bh11_$c008", "bh11_$c009"}, 
  24. 										{"bh11_$c012", "bh11_$c013"}, 
  25. 										{"bh11_$c016", "bh11_$c017"}, 
  26. 										{"bh11_$c020", "bh11_$c021"}, 
  27. 										{"bh11_$c024", "bh11_$c025"}, 
  28. 										{"bh11_$c028", "bh11_$c029"} 
  29. 									} 
  30.  
  31. 	Bh11_tribal_chars_coop = {	{"bh11_$c032", "bh11_$c033"}, 
  32. 										{"bh11_$c036", "bh11_$c037"}, 
  33. 										{"bh11_$c040", "bh11_$c041"}, 
  34. 										{"bh11_$c044", "bh11_$c045"} 
  35. 									 } 
  36. 	--Bh11_tribal_navs =		{"bh11_$n008", "bh11_$n009", "bh11_$n010", "bh11_$n011", "bh11_$n012", "bh11_$n013", "bh11_$n014", "bh11_$n015"} 
  37. 	Bh11_tribal_navs =		{"bh11_$n008", "bh11_$v001",  
  38. 									 "bh11_$n009", "bh11_$v002", 
  39. 									 "bh11_$n010", "bh11_$v003", 
  40. 									 "bh11_$n011", "bh11_$v004", 
  41. 									 "bh11_$n012", "bh11_$v005", 
  42. 									 "bh11_$n013", "bh11_$v006", 
  43. 									 "bh11_$n014", "bh11_$v007", 
  44. 									 "bh11_$n015", "bh11_$v000"} 
  45. 	Bh11_tribal_navs_coop =	{"bh11_$n008", "bh11_$n010", "bh11_$n012", "bh11_$n014"} 
  46.  
  47. 	-- Characters -- 
  48. 	CHAR_MAERO =				"bh11_$maero" 
  49.  
  50. 	-- Vehicles -- 
  51. 	MONSTER_TRUCK =			"bh11_$monster_truck" 
  52.  
  53. 	-- Groups -- 
  54. 	GROUP_MAERO =				"bh11_$maero" 
  55. 	GROUP_TRIBAL =				"bh11_$tribal" 
  56. 	GROUP_TRIBAL_COOP =		"bh11_$tribal_coop" 
  57. 	GROUP_WEAPONS =			"bh11_$weapons" 
  58.  
  59. 	-- Cutscenes -- 
  60. 	CUTSCENE_IN =						"br11-01" 
  61. 	CUTSCENE_OUT =						"br11-02" 
  62.  
  63. 	-- Voice -- 
  64. 	VOICE_MAERO_TAKE_DAMAGE =		"MAERO_BR11_TAKEDAM" 
  65.  
  66.    BH11_BROTHERHOOD_PERSONAS = { 
  67.                                  ["HM_Bro1"]	=	"HMBRO1", 
  68.                                  ["HM_Bro2"]	=	"HMBRO2", 
  69.                                  ["HM_Bro3"]	=	"HMBRO3", 
  70.  
  71.                                  ["HF_Bro2"]	=	"HFBRO2", 
  72.  
  73.                                  ["WM_Bro3"]	=	"WMBRO3", 
  74.  
  75.                                  ["WF_Bro1"]	=	"WFBRO1", 
  76.                                  ["WF_Bro2"]	=	"WFBRO2", 
  77.                                } 
  78.  
  79. 	-- Threads -- 
  80. 	Patrol_threads =			{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1} 
  81. 	Thread_maero_patrol =			-1 
  82. 	Thread_car_on_fire_watch =		{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1} 
  83. 	Thread_drivebys =					-1 
  84. 	Thread_remote_drivebys =		-1 
  85. 	Thread_secondary_drivebys =	-1 
  86. 	Thread_secondary_remote_drivebys =		-1 
  87. 	Thread_chase =						-1 
  88. 	Thread_remote_chase =			-1 
  89. 	Thread_secondary_chase =		-1 
  90. 	Thread_secondary_remote_chase = -1 
  91. 	TABLE_ALL_THREADS = {Patrol_threads[1],  
  92. 								Patrol_threads[2],  
  93. 								Patrol_threads[3],  
  94. 								Patrol_threads[4],  
  95. 								Patrol_threads[5],  
  96. 								Patrol_threads[6],  
  97. 								Patrol_threads[7],  
  98. 								Patrol_threads[8],  
  99. 								Patrol_threads[9],  
  100. 								Patrol_threads[10],  
  101. 								Patrol_threads[11],  
  102. 								Patrol_threads[12],  
  103. 								Thread_maero_patrol,  
  104. 								Thread_car_on_fire_watch[1],  
  105. 								Thread_car_on_fire_watch[2],  
  106. 								Thread_car_on_fire_watch[3],  
  107. 								Thread_car_on_fire_watch[4],  
  108. 								Thread_car_on_fire_watch[5],  
  109. 								Thread_car_on_fire_watch[6],  
  110. 								Thread_car_on_fire_watch[7],  
  111. 								Thread_car_on_fire_watch[8],  
  112. 								Thread_car_on_fire_watch[9],  
  113. 								Thread_car_on_fire_watch[10],  
  114. 								Thread_car_on_fire_watch[11],  
  115. 								Thread_car_on_fire_watch[12],  
  116. 								Thread_drivebys,  
  117. 								Thread_remote_drivebys,  
  118. 								Thread_secondary_drivebys, 
  119. 								Thread_secondary_remote_drivebys, 
  120. 								Thread_chase,  
  121. 								Thread_remote_chase, 
  122. 								Thread_secondary_chase,  
  123. 								Thread_secondary_remote_chase} 
  124.  
  125. 	-- Others -- 
  126. 	Num_tribal_vehicles =				sizeof_table(Bh11_tribal_vehicles) 
  127. 	Num_tribal_vehicles_coop =			sizeof_table(Bh11_tribal_vehicles_coop) 
  128. 	Num_tribal_vehicles_total =		0 
  129. 	Chaser_vehicle_id =					-1 
  130. 	Remote_chaser_vehicle_id =			-1 
  131. 	Secondary_chaser_vehicle_id =		-1 
  132. 	Secondary_remote_chaser_vehicle_id =		-1 
  133. 	Maero_truck_health_multiplier =	1.9 
  134.    Maero_truck_health_multiplier_coop = 3 
  135.  
  136.    Tribal_vehicle_health_multiplier = 0.7 
  137.  
  138. 	IN_COOP =								false 
  139. 	bh11_mission_cancelled =			true 
  140. 	first_chase =							true 
  141. 	TABLE_PATROL_DELAYS =				{6, 4, 2, 0, 0, 2, 4, 6} 
  142. 	Maero_truck_health_decrease =		2000 
  143. 	Maero_next_damage_level_voice_callback =		0.9 
  144.  
  145.    Sony_PEG_Demo = false 
  146.    Sony_PEG_Damage_Multiplier = 0.5 
  147.  
  148.    SONY_PEG_REGEN_RESUME_TIME_SECONDS = 3.0 
  149.  
  150. function bh11_sony_peg_damage_reduction( attacked_object_name, attacker_name, percent_hp_remaining_after_attack ) 
  151.    -- Find out the health status before being attacked 
  152.    local pre_attack_hit_points = get_current_hit_points( attacked_object_name ) 
  153.    local max_hit_points = get_max_hit_points( attacked_object_name ) 
  154.    local percent_hp_before_attack = pre_attack_hit_points / max_hit_points 
  155.  
  156.    -- Now, find out how much percent damage was done 
  157.    local percent_damage_done = percent_hp_before_attack - percent_hp_remaining_after_attack 
  158.  
  159.    -- Reduce the damage done percent by the multiplier 
  160.    local reduced_percent_damage_done = percent_damage_done * Sony_PEG_Damage_Multiplier 
  161.    local reduced_points_damage_done = reduced_percent_damage_done * max_hit_points 
  162.  
  163. 	if ( reduced_points_damage_done < 1) then 
  164. 		reduced_points_damage_done = 1 
  165. 	end 
  166.  
  167.    character_damage( attacked_object_name, reduced_points_damage_done ) 
  168.  
  169.    local points_damage_done = percent_damage_done * max_hit_points 
  170.    mission_debug( "Original damage: "..points_damage_done..", new damage: "..reduced_points_damage_done ) 
  171. end 
  172.  
  173. function bh11_start(bh11_checkpoint, is_restart) 
  174. 	-- Start trigger is hit...the activate button was hit 
  175. 	set_mission_author("Aaron Hanson") 
  176.  
  177.    if ( Sony_PEG_Demo ) then 
  178.       turn_invulnerable( LOCAL_PLAYER ) 
  179.       on_take_damage( "bh11_sony_peg_damage_reduction", LOCAL_PLAYER ) 
  180.  
  181.       if ( coop_is_active() ) then 
  182.          turn_invulnerable( REMOTE_PLAYER ) 
  183.          on_take_damage( "bh11_sony_peg_damage_reduction", REMOTE_PLAYER ) 
  184.       end 
  185.    end 
  186.  
  187.    action_nodes_restrict_spawning( true ) 
  188.  
  189.    mission_start_fade_out() 
  190.    if (not is_restart) then 
  191. 		cutscene_play( CUTSCENE_IN, "", { NAV_PLAYER_START, NAV_REMOTE_START }, false ) 
  192.    else 
  193. 		teleport_coop( NAV_PLAYER_START, NAV_REMOTE_START ) 
  194. 	end 
  195.  
  196. 	if coop_is_active() then 
  197. 		IN_COOP = true 
  198. 	end 
  199. 	-- Create groups -- 
  200. 	group_create(GROUP_MAERO, true) 
  201. 	group_create(GROUP_WEAPONS, true) 
  202. 	group_create(GROUP_TRIBAL, true) 
  203. 	Num_tribal_vehicles_total = Num_tribal_vehicles 
  204. 	if IN_COOP then 
  205. 		group_create(GROUP_TRIBAL_COOP, true) 
  206. 	end 
  207.  
  208. 	bh11_start_persona_overrides() 
  209.  
  210. 	-- On Maero's vehicle destroyed, mission success -- 
  211. 	on_vehicle_destroyed("bh11_success_maero_vehicle_destroyed", MONSTER_TRUCK) 
  212.  
  213.    mission_start_fade_in() 
  214.  
  215. 	delay(2) 
  216. 	mission_help_table("bh11_kill_maero") 
  217.  
  218. 	-- Lock Brotherhood notoriety at 1 -- 
  219. 	notoriety_set("Brotherhood", 1)  
  220. 	notoriety_set_min("Brotherhood",1) 
  221. 	notoriety_set_max("Brotherhood",1) 
  222.  
  223. 	-- Start gang patrol threads, and threads to allow npc's to exit their vehicle only if it's on fire -- 
  224. 	for i = 1, Num_tribal_vehicles, 1 do 
  225. 		Thread_car_on_fire_watch[i] = thread_new("bh11_tribal_car_on_fire_watch", Bh11_tribal_vehicles[i]) 
  226. 		Patrol_threads[i] = thread_new("bh11_tribal_patrol", Bh11_tribal_chars[i], Bh11_tribal_vehicles[i], Bh11_tribal_navs, i) 
  227. 		on_vehicle_destroyed("bh11_tribal_car_destroyed", Bh11_tribal_vehicles[i]) 
  228. 	end 
  229.  
  230. 	if IN_COOP then 
  231. 		for i = 1, Num_tribal_vehicles_coop, 1 do 
  232. 			Thread_car_on_fire_watch[Num_tribal_vehicles+i] = thread_new("bh11_tribal_car_on_fire_watch", Bh11_tribal_vehicles_coop[i]) 
  233. 			Patrol_threads[Num_tribal_vehicles+i] = thread_new("bh11_tribal_patrol", Bh11_tribal_chars_coop[i], Bh11_tribal_vehicles_coop[i], Bh11_tribal_navs_coop, 8+i) 
  234. 			on_vehicle_destroyed("bh11_tribal_car_destroyed", Bh11_tribal_vehicles_coop[i]) 
  235. 		end 
  236. 	end 
  237.  
  238. 	-- Begin Maero's circling of the arena 
  239. 	Thread_maero_patrol = thread_new("bh11_maero_patrol") 
  240.  
  241. 	delay(6) 
  242.  
  243. 	-- Start thread to always have one Brotherhood car chasing the player -- 
  244. 	Thread_drivebys = thread_new("bh11_tribal_drivebys") 
  245. 	Thread_secondary_drivebys = thread_new("bh11_tribal_drivebys_for_local_player_in_vehicle") 
  246.  
  247. 	-- if in coop, start thread to always have one Brotherhood car chasing the remote player -- 
  248. 	if IN_COOP then 
  249. 		Thread_remote_drivebys = thread_new("bh11_tribal_drivebys_remote") 
  250. 		Thread_secondary_remote_drivebys = thread_new("bh11_tribal_drivebys_for_remote_player_in_vehicle") 
  251. 	end 
  252. end 
  253.  
  254. function bh11_start_persona_overrides() 
  255. 	persona_override_character_start(CHAR_MAERO, POT_SITUATIONS[POT_ATTACK], "MAERO_BR11_ATTACK") 
  256. 	persona_override_group_start(BH11_BROTHERHOOD_PERSONAS, POT_SITUATIONS[POT_ATTACK], "BR11_ATTACK") 
  257. end 
  258.  
  259. function bh11_stop_persona_overrides() 
  260. 	persona_override_group_stop(BH11_BROTHERHOOD_PERSONAS, POT_SITUATIONS[POT_ATTACK]) 
  261. end 
  262.  
  263. function bh11_maero_damage_voice() 
  264. 	audio_play_for_character(VOICE_MAERO_TAKE_DAMAGE, CHAR_MAERO, "voice") 
  265. 	Maero_next_damage_level_voice_callback = Maero_next_damage_level_voice_callback - 0.1 
  266. 	if Maero_next_damage_level_voice_callback <= 0 then 
  267. 		on_damage("", MONSTER_TRUCK, Maero_next_damage_level_voice_callback) 
  268. 	else 
  269. 		on_damage("bh11_maero_damage_voice", MONSTER_TRUCK, Maero_next_damage_level_voice_callback) 
  270. 	end 
  271. end 
  272.  
  273. function bh11_tribal_car_destroyed() 
  274.    bh11_reduce_maero_hp() 
  275. end 
  276.  
  277. function bh11_reduce_maero_hp() 
  278.    if ( vehicle_is_destroyed( MONSTER_TRUCK ) == false ) then 
  279.       -- Reduce the max hit points by the constant value, and keep the percentage damage the same 
  280.       local cur_hp = get_current_hit_points(MONSTER_TRUCK) 
  281.       local max_hp = get_max_hit_points(MONSTER_TRUCK) 
  282.       local cur_percent = cur_hp / max_hp 
  283.  
  284.       -- Calculate the new max from the old max minus the decrease, and the current from the old 
  285.       -- percent and the new max. 
  286.       local new_max_hp = max_hp - Maero_truck_health_decrease 
  287.       local new_cur_hp = cur_percent * new_max_hp 
  288.  
  289.       set_max_hit_points(MONSTER_TRUCK, new_max_hp) 
  290.       set_current_hit_points(MONSTER_TRUCK, new_cur_hp) 
  291.       damage_indicator_on( 0, MONSTER_TRUCK, 0, "bh11_maeros_health" ) 
  292.  
  293.       mission_debug( "Reducing Maero hp, old value was"..max_hp..", new value is "..new_max_hp, 12 ) 
  294.    end 
  295. end 
  296.  
  297. function bh11_tribal_car_on_fire_watch(vehicle) 
  298. 	-- Check for vehicles on fire, and allow npc's to exit the vehicle if on fire -- 
  299. 	while(not vehicle_is_destroyed(vehicle)) do 
  300. 		local Vehicle_smoke, Vehicle_fire = vehicle_get_smoke_and_fire_state(vehicle) 
  301. 		if Vehicle_fire then 
  302. 			vehicle_suppress_npc_exit(vehicle, false) 
  303. 		end 
  304. 		thread_yield() 
  305. 	end 
  306. end 
  307.  
  308.  
  309. function bh11_tribal_patrol(chars, vehicle, navs, vehicle_id) 
  310. 	vehicle_suppress_npc_exit(vehicle,true) 
  311.  
  312. 	-- setup npc weapons -- 
  313. 	for i = 1, sizeof_table(chars), 1 do 
  314. 		npc_combat_enable(chars[i],true) 
  315. 		npc_unholster_best_weapon(chars[i]) 
  316. 	end 
  317.  
  318.    local new_hp = get_max_hit_points( vehicle ) * Tribal_vehicle_health_multiplier 
  319.    set_max_hit_points( vehicle, new_hp ) 
  320.    set_current_hit_points( vehicle, new_hp ) 
  321.  
  322. 	vehicle_enter_group_teleport(chars, vehicle) 
  323. 	-- This prevents this vehicle from transitioning to ambient and then teleporting out 
  324. 	-- of the arena. 
  325. 	vehicle_prevent_transition_to_ambient( vehicle, true ) 
  326.  
  327. 	delay(TABLE_PATROL_DELAYS[vehicle_id]) 
  328.  
  329. 	-- while this vehicle is not selected as a "chaser", patrol the navpoint path -- 
  330. 	while (not bh11_vehicle_destroyed_or_unoccupied(vehicle))  
  331. 			and (Chaser_vehicle_id ~= vehicle_id)  
  332. 			and (Remote_chaser_vehicle_id ~= vehicle_id) 
  333. 			and (Secondary_chaser_vehicle_id ~= vehicle_id)  
  334. 			and (Secondary_remote_chaser_vehicle_id ~= vehicle_id) do 
  335. 		for i = 1, 16, 1 do 
  336. 			local navoffset = (vehicle_id - 1) * 2 
  337. 			local navid = i + navoffset 
  338. 			if navid > 16 then 
  339. 				navid = navid - 16 
  340. 			end 
  341. 			if ( bh11_vehicle_destroyed_or_unoccupied(vehicle) == false and 
  342.               Chaser_vehicle_id ~= vehicle_id and 
  343.               Remote_chaser_vehicle_id ~= vehicle_id and 
  344. 				  Secondary_chaser_vehicle_id ~= vehicle_id and 
  345. 				  Secondary_remote_chaser_vehicle_id ~= vehicle_id ) then 
  346. 				vehicle_pathfind_to(vehicle, navs[navid], true, true) 
  347. 			end 
  348. 			thread_yield() 
  349. 		end 
  350. 	end 
  351.  
  352.    bh11_cleanup_vehicle_on_destroyed_or_abandoned( vehicle, chars ) 
  353. end 
  354.  
  355. function bh11_cleanup_vehicle_on_destroyed_or_abandoned( vehicle, passengers ) 
  356.    bh11_abandon_vehicle( vehicle, passengers ) 
  357.  
  358.    if ( vehicle_exists( vehicle ) and vehicle_is_destroyed( vehicle ) == false ) then 
  359.       on_vehicle_destroyed( "", vehicle ) 
  360.       bh11_reduce_maero_hp() 
  361.    end 
  362. end 
  363.  
  364. function bh11_abandon_vehicle( vehicle, passengers ) 
  365. 	vehicle_suppress_npc_exit(vehicle, false) 
  366.    for index, passenger_name in pairs( passengers ) do 
  367.       if ( character_exists( passenger_name ) and character_is_dead( passenger_name ) == false ) then 
  368.          thread_new( "bh11_tribal_abandon_car", passenger_name ) 
  369.       end 
  370.    end 
  371. end 
  372.  
  373. function bh11_tribal_abandon_car( name ) 
  374.    vehicle_exit( name ) 
  375.    attack_closest_player( name ) 
  376. end 
  377.  
  378. function bh11_tribal_drivebys() 
  379. 	local temp_chaser_id 
  380. 	temp_chaser_id = rand_int(1,Num_tribal_vehicles_total) 
  381.  
  382. 	while(1) do 
  383. 		-- find vehicle that is not destroyed and not chasing remote player -- 
  384. 		if first_chase then 
  385. 			temp_chaser_id = 8 
  386. 			first_chase = false 
  387. 		else 
  388. 			while bh11_vehicle_destroyed_or_unoccupied(Bh11_all_vehicles[temp_chaser_id])  
  389. 					or temp_chaser_id == Remote_chaser_vehicle_id  
  390. 					or temp_chaser_id == Secondary_chaser_vehicle_id 
  391. 					or temp_chaser_id == Secondary_remote_chaser_vehicle_id do 
  392. 				temp_chaser_id = rand_int(1,Num_tribal_vehicles_total) 
  393. 				thread_yield() 
  394. 			end 
  395. 		end 
  396.  
  397. 		-- kill the selected vehicle's patrol thread -- 
  398. 		Chaser_vehicle_id = temp_chaser_id 
  399. 		thread_kill(Patrol_threads[Chaser_vehicle_id]) 
  400. 		delay(2) 
  401.  
  402. 		-- start thread to make vehicle chase the player -- 
  403. 		Thread_chase = thread_new("bh11_driveby", Bh11_all_vehicles[Chaser_vehicle_id], LOCAL_PLAYER, false, true, true) 
  404.  
  405. 		-- continue chase until vehicle is destroyed -- 
  406. 		while not bh11_vehicle_destroyed_or_unoccupied(Bh11_all_vehicles[Chaser_vehicle_id]) do 
  407. 			thread_yield() 
  408. 		end 
  409.  
  410.       bh11_cleanup_vehicle_on_destroyed_or_abandoned( Bh11_all_vehicles[Chaser_vehicle_id], Bh11_tribal_chars[Chaser_vehicle_id] ) 
  411.  
  412. 		-- kill the chasing vehicle thread 
  413. 		thread_kill(Thread_chase) 
  414.  
  415. 		thread_yield() 
  416. 	end 
  417. end 
  418.  
  419. function bh11_driveby(veh, target, b1, b2, b3) 
  420. 	vehicle_chase(veh, target, b1, b2, b3) 
  421. end 
  422.  
  423. function bh11_tribal_drivebys_remote() 
  424. 	local temp_remote_chaser_id 
  425. 	temp_remote_chaser_id = rand_int(1,Num_tribal_vehicles_total) 
  426.  
  427. 	while(1) do 
  428. 		-- find vehicle that is not destroyed and not chasing local player -- 
  429. 		while bh11_vehicle_destroyed_or_unoccupied(Bh11_all_vehicles[temp_remote_chaser_id])  
  430. 				or temp_remote_chaser_id == Chaser_vehicle_id  
  431. 				or temp_remote_chaser_id == Secondary_chaser_vehicle_id 
  432. 				or temp_remote_chaser_id == Secondary_remote_chaser_vehicle_id do 
  433. 			temp_remote_chaser_id = rand_int(1,Num_tribal_vehicles_total) 
  434. 			thread_yield() 
  435. 		end 
  436.  
  437. 		-- kill the selected vehicle's patrol thread -- 
  438. 		Remote_chaser_vehicle_id = temp_remote_chaser_id 
  439. 		thread_kill(Patrol_threads[Remote_chaser_vehicle_id]) 
  440. 		delay(2) 
  441.  
  442. 		-- start thread to make vehicle chase the player -- 
  443. 		Thread_remote_chase = thread_new("bh11_driveby", Bh11_all_vehicles[Remote_chaser_vehicle_id], REMOTE_PLAYER, false, true, true) 
  444.  
  445. 		-- continue chase until vehicle is destroyed -- 
  446. 		while not bh11_vehicle_destroyed_or_unoccupied(Bh11_all_vehicles[Remote_chaser_vehicle_id]) do 
  447. 			thread_yield() 
  448. 		end 
  449.       bh11_cleanup_vehicle_on_destroyed_or_abandoned( Bh11_all_vehicles[Remote_chaser_vehicle_id], Bh11_tribal_chars[Remote_chaser_vehicle_id] ) 
  450.  
  451. 		-- kill the chasing vehicle thread 
  452. 		thread_kill(Thread_remote_chase) 
  453.  
  454. 		thread_yield() 
  455. 	end 
  456. end 
  457.  
  458. function bh11_tribal_drivebys_for_local_player_in_vehicle() 
  459. 	local temp_chaser_id 
  460. 	temp_chaser_id = rand_int(1,Num_tribal_vehicles_total) 
  461.  
  462. 	while(1) do 
  463. 		while (not character_is_in_vehicle(LOCAL_PLAYER)) do 
  464. 			thread_yield() 
  465. 		end 
  466.  
  467. 		-- find vehicle that is not destroyed and not chasing remote player and isnt the other chaser of the local_player -- 
  468. 		while bh11_vehicle_destroyed_or_unoccupied(Bh11_all_vehicles[temp_chaser_id])  
  469. 				or temp_chaser_id == Chaser_vehicle_id  
  470. 				or temp_chaser_id == Remote_chaser_vehicle_id 
  471. 				or temp_chaser_id == Secondary_remote_chaser_vehicle_id do 
  472. 			temp_chaser_id = rand_int(1,Num_tribal_vehicles_total) 
  473. 			thread_yield() 
  474. 		end 
  475.  
  476. 		-- kill the selected vehicle's patrol thread -- 
  477. 		Secondary_chaser_vehicle_id = temp_chaser_id 
  478. 		thread_kill(Patrol_threads[Secondary_chaser_vehicle_id]) 
  479. 		delay(2) 
  480.  
  481. 		-- start thread to make vehicle chase the player -- 
  482. 		Thread_secondary_chase = thread_new("bh11_driveby", Bh11_all_vehicles[Secondary_chaser_vehicle_id], LOCAL_PLAYER, false, true, true) 
  483.  
  484. 		-- continue chase until vehicle is destroyed -- 
  485. 		while (not bh11_vehicle_destroyed_or_unoccupied(Bh11_all_vehicles[Secondary_chaser_vehicle_id])) 
  486. 				and (character_is_in_vehicle(LOCAL_PLAYER)) do 
  487. 			thread_yield() 
  488. 		end 
  489.  
  490.       bh11_cleanup_vehicle_on_destroyed_or_abandoned( Bh11_all_vehicles[Secondary_chaser_vehicle_id], Bh11_tribal_chars[Secondary_chaser_vehicle_id] ) 
  491.  
  492. 		-- kill the chasing vehicle thread 
  493. 		thread_kill(Thread_secondary_chase) 
  494. 		Secondary_chaser_vehicle_id = -1 
  495.  
  496. 		thread_yield() 
  497. 	end 
  498. end 
  499.  
  500. function bh11_tribal_drivebys_for_remote_player_in_vehicle() 
  501. 	local temp_chaser_id 
  502. 	temp_chaser_id = rand_int(1,Num_tribal_vehicles_total) 
  503.  
  504. 	while(1) do 
  505. 		while (not character_is_in_vehicle(REMOTE_PLAYER)) do 
  506. 			thread_yield() 
  507. 		end 
  508.  
  509. 		-- find vehicle that is not destroyed and not chasing remote player and isnt the other chaser of the local_player -- 
  510. 		while bh11_vehicle_destroyed_or_unoccupied(Bh11_all_vehicles[temp_chaser_id])  
  511. 				or temp_chaser_id == Chaser_vehicle_id  
  512. 				or temp_chaser_id == Remote_chaser_vehicle_id  
  513. 				or temp_chaser_id == Secondary_chaser_vehicle_id do 
  514. 			temp_chaser_id = rand_int(1,Num_tribal_vehicles_total) 
  515. 			thread_yield() 
  516. 		end 
  517.  
  518. 		-- kill the selected vehicle's patrol thread -- 
  519. 		Secondary_remote_chaser_vehicle_id = temp_chaser_id 
  520. 		thread_kill(Patrol_threads[Secondary_remote_chaser_vehicle_id]) 
  521. 		delay(2) 
  522.  
  523. 		-- start thread to make vehicle chase the player -- 
  524. 		Thread_secondary_remote_chase = thread_new("bh11_driveby", Bh11_all_vehicles[Secondary_remote_chaser_vehicle_id], REMOTE_PLAYER, false, true, true) 
  525.  
  526. 		-- continue chase until vehicle is destroyed -- 
  527. 		while (not bh11_vehicle_destroyed_or_unoccupied(Bh11_all_vehicles[Secondary_remote_chaser_vehicle_id])) 
  528. 				and (character_is_in_vehicle(REMOTE_PLAYER)) do 
  529. 			thread_yield() 
  530. 		end 
  531.  
  532. 		-- kill the chasing vehicle thread 
  533. 		thread_kill(Thread_secondary_remote_chase) 
  534. 		Secondary_remote_chaser_vehicle_id = -1 
  535.  
  536. 		thread_yield() 
  537. 	end 
  538. end 
  539.  
  540. function bh11_vehicle_destroyed_or_unoccupied(vehicle) 
  541. 	if ( vehicle_is_destroyed(vehicle) ) then 
  542.       return true 
  543.    end 
  544.  
  545.    local character_driving = get_char_in_vehicle(vehicle, 0) 
  546.  
  547.    if ( character_driving == nil ) then 
  548.       return true 
  549.    elseif ( character_is_player( character_driving ) ) then 
  550.       return true 
  551.    end 
  552.  
  553.    return false 
  554. end 
  555.  
  556. function bh11_maero_shot( attacker_name, attacked_name, percent_hp_remaining_after_attack ) 
  557.    if ( coop_is_active() == false ) then 
  558.       local percent_damage_done = 1.0 - percent_hp_remaining_after_attack 
  559.  
  560.       local hit_points_damage_done = percent_damage_done * get_max_hit_points( CHAR_MAERO ) 
  561.  
  562.       local new_truck_hp = get_current_hit_points( MONSTER_TRUCK ) - hit_points_damage_done 
  563.       set_current_hit_points( MONSTER_TRUCK, new_truck_hp ) 
  564.    end 
  565. end 
  566.  
  567. function bh11_maero_patrol() 
  568. 	marker_add_vehicle(MONSTER_TRUCK, MINIMAP_ICON_KILL, INGAME_EFFECT_VEHICLE_KILL, SYNC_ALL) 
  569.  
  570. 	-- increase Maero's truck's hit points 
  571. 	local standard_hit_points = get_max_hit_points(MONSTER_TRUCK) 
  572.    local starting_hp = Maero_truck_health_multiplier * standard_hit_points 
  573.    if ( coop_is_active() ) then 
  574.       starting_hp = Maero_truck_health_multiplier_coop * standard_hit_points 
  575.    end 
  576.  
  577. 	set_max_hit_points( MONSTER_TRUCK, starting_hp ) 
  578. 	set_current_hit_points( MONSTER_TRUCK, starting_hp ) 
  579.    damage_indicator_on( 0, MONSTER_TRUCK, 0, "bh11_maeros_health" ) 
  580.  
  581. 	vehicle_max_speed(MONSTER_TRUCK, 35) 
  582. 	vehicle_enter_teleport(CHAR_MAERO, MONSTER_TRUCK) 
  583. 	set_unjackable_flag(MONSTER_TRUCK, true) 
  584. 	-- This prevents the monster truck from transitioning to ambient and then teleporting out 
  585. 	-- of the arena. 
  586. 	vehicle_prevent_transition_to_ambient( MONSTER_TRUCK, true ) 
  587. 	vehicle_set_allow_ram_ped(MONSTER_TRUCK, true) 
  588.  
  589. 	-- setup Maero's behaviour 
  590.    turn_invulnerable( CHAR_MAERO ) 
  591.    on_take_damage( "bh11_maero_shot", CHAR_MAERO ) 
  592. 	set_seatbelt_flag(CHAR_MAERO, true) 
  593. 	vehicle_suppress_npc_exit(MONSTER_TRUCK,true) 
  594.  
  595. 	on_damage("bh11_maero_damage_voice", MONSTER_TRUCK, Maero_next_damage_level_voice_callback) 
  596.  
  597. 	-- make Maero circle the arena while more than three Brotherhood vehicles exist -- 
  598. 	while(bh11_num_tribal_drivers_driving() > 3 and not player_is_in_vehicle("#PLAYER1#")) do 
  599. 		vehicle_pathfind_to(MONSTER_TRUCK, Bh11_maero_patrol, true, false) 
  600. 		thread_yield() 
  601. 	end 
  602.  
  603. 	-- when three or less Brotherhood vehicles exist, have Maero chase the player -- 
  604.    vehicle_disable_flee( MONSTER_TRUCK, true ) 
  605.  
  606. 	--  
  607. 	while ( true ) do 
  608. 		-- Find the closest living player to chase 
  609. 		local distance, target_player = get_dist_closest_player_to_object( MONSTER_TRUCK ) 
  610. 		if ( character_is_dead( target_player ) ) then 
  611. 			-- If we're in coop, there's potentially another target 
  612. 			if ( coop_is_active() ) then 
  613. 				if ( target_player == LOCAL_PLAYER ) then 
  614. 					target_player = REMOTE_PLAYER 
  615. 				else 
  616. 					target_player = LOCAL_PLAYER 
  617. 				end 
  618.  
  619. 				-- If the other potential target is dead, the mission is over 
  620. 				if ( character_is_dead( target_player ) ) then 
  621. 					return 
  622. 				end 
  623. 			else -- local player is dead and coop is inactive - the mission is over 
  624. 				return 
  625. 			end 
  626. 		end 
  627.  
  628. 		-- Chase the player until he is dead 
  629. 		vehicle_chase(MONSTER_TRUCK, target_player, false, true, true) 
  630. 		mission_debug( "Maero chasing "..target_player ) 
  631. 		repeat 
  632. 			thread_yield() 
  633. 		until ( character_is_dead( target_player ) ) 
  634.  
  635. 		-- Path back to the arena's center in case we're stuck on a wall 
  636. 		mission_debug( "Maero pathing to center" ) 
  637. 		vehicle_pathfind_to( MONSTER_TRUCK, "bh11_$n011", true, false ) 
  638. 		mission_debug( "Maero done pathing to center" ) 
  639. 	end 
  640. end 
  641.  
  642. function bh11_num_tribal_drivers_driving() 
  643. 	local count = 0 
  644. 	for i, vehicle in pairs(Bh11_all_vehicles) do 
  645. 		if not bh11_vehicle_destroyed_or_unoccupied(vehicle) then 
  646. 			count = count + 1 
  647. 		end 
  648. 	end 
  649. 	return count 
  650. end 
  651.  
  652. function bh11_success_maero_vehicle_destroyed() 
  653. 	-- kill Maero -- 
  654.    on_take_damage( "", CHAR_MAERO ) 
  655.    turn_vulnerable( CHAR_MAERO ) 
  656. 	character_kill(CHAR_MAERO) 
  657.    damage_indicator_off( 0 ) 
  658.  
  659. 	mission_end_success("bh11", CUTSCENE_OUT, { NAV_MISSION_END_RESTORE_POS, NAV_MISSION_END_REMOTE_RESTORE_POS } ) 
  660. end														   
  661.  
  662. function bh11_cleanup() 
  663. 	-- Cleanup mission here 
  664.  
  665. 	marker_remove_vehicle(MONSTER_TRUCK, SYNC_ALL) 
  666.  
  667. 	on_death("", LOCAL_PLAYER) 
  668. 	on_vehicle_destroyed("", MONSTER_TRUCK) 
  669. 	for i = 1, 8, 1 do 
  670. 		on_vehicle_destroyed("", Bh11_tribal_vehicles[i]) 
  671. 	end 
  672.  
  673. 	for i, thread in pairs(TABLE_ALL_THREADS) do 
  674. 		if thread ~= -1 then 
  675. 			thread_kill(thread) 
  676. 		end 
  677. 	end 
  678.    if ( coop_is_active() ) then 
  679.       if ( character_is_dead( REMOTE_PLAYER ) == false ) then 
  680. 			teleport(REMOTE_PLAYER, NAV_MISSION_END_REMOTE_RESTORE_POS ) 
  681.       end 
  682.    end 
  683. 	if ( character_is_dead(LOCAL_PLAYER) == false ) then 
  684. 		teleport(LOCAL_PLAYER, NAV_MISSION_END_RESTORE_POS) 
  685. 	end 
  686.  
  687. 	bh11_stop_persona_overrides() 
  688.  
  689. 	group_destroy(GROUP_TRIBAL) 
  690. 	group_destroy(GROUP_TRIBAL_COOP) 
  691. 	group_destroy(GROUP_MAERO) 
  692. 	group_destroy(GROUP_WEAPONS) 
  693. 	release_to_world(GROUP_TRIBAL) 
  694. 	release_to_world(GROUP_TRIBAL_COOP) 
  695. 	release_to_world(GROUP_MAERO) 
  696. 	release_to_world(GROUP_WEAPONS) 
  697.    action_nodes_restrict_spawning( false ) 
  698.  
  699.    if ( Sony_PEG_Demo ) then 
  700.       turn_vulnerable( LOCAL_PLAYER ) 
  701.       on_take_damage( "", LOCAL_PLAYER ) 
  702.       if ( coop_is_active() ) then 
  703.          turn_vulnerable( REMOTE_PLAYER ) 
  704.          on_take_damage( "", REMOTE_PLAYER ) 
  705.       end 
  706.    end 
  707. end 
  708.  
  709. function bh11_success() 
  710. 	-- Called when the mission has ended with success 
  711. 	-- Unlock story arc complete rewards 
  712. end 
  713.