sr2lua/sh_bh_chinatown.lua

  1. --Tables------- 
  2.  
  3. --Storefronts should be triggers. On enter (in_area = true). On exit (in_area = false) 
  4. --storefronts = {"sh_bh_chinatown_$t_store0","sh_bh_chinatown_$t_store1","sh_bh_chinatown_$t_store2","sh_bh_chinatown_$t_store3","sh_bh_chinatown_$t_store4"} --Red markers with radii that test if the player is in the area or not 
  5. storefronts = {"sh_bh_chinatown_$t_store1","sh_bh_chinatown_$t_store2","sh_bh_chinatown_$t_store3","sh_bh_chinatown_$t_store4"} --Red markers with radii that test if the player is in the area or not 
  6. merchants = { "sh_bh_chinatown_$c001", "sh_bh_chinatown_$c002", "sh_bh_chinatown_$c003", "sh_bh_chinatown_$c004" } --on show, green/blue marker 
  7. movers = { "sh_bh_chinatown_mover000","sh_bh_chinatown_mover001","sh_bh_chinatown_mover002", "sh_bh_chinatown_mover003", "sh_bh_chinatown_mover004" } 
  8. brotherhood = { "sh_bh_chinatown_$c005","sh_bh_chinatown_$c006","sh_bh_chinatown_$c007","sh_bh_chinatown_$c008","sh_bh_chinatown_$c009","sh_bh_chinatown_$c010","sh_bh_chinatown_$c011","sh_bh_chinatown_$c012","sh_bh_chinatown_$c013","sh_bh_chinatown_$c014","sh_bh_chinatown_$c015","sh_bh_chinatown_$c016" } 
  9. peds = { "sh_bh_chinatown_$c017","sh_bh_chinatown_$c018","sh_bh_chinatown_$c019","sh_bh_chinatown_$c020","sh_bh_chinatown_$c021","sh_bh_chinatown_$c022" } 
  10. groups = { "sh_bh_chinatown_$Group2", "sh_bh_chinatown_$Group3", "sh_bh_chinatown_$Group4", "sh_bh_chinatown_$Group5"} 
  11. monster_closet =  {"sh_bh_chinatown_Closet1", "sh_bh_chinatown_Closet2", "sh_bh_chinatown_closet3", "sh_bh_chinatown_closet4"} 
  12.  
  13. storefronts_total = sizeof_table(storefronts) 
  14. merchants_total = sizeof_table(merchants) 
  15. merchants_left = 0--sizeof_table(merchants) --Will be decremented through script 
  16. movers_total = sizeof_table(movers) 
  17. brotherhood_total = sizeof_table(brotherhood) 
  18. peds_total = sizeof_table(peds) 
  19.  
  20. --Checks what area the player is in an area 
  21. areas = { false, false, false, false, false } 
  22. --Checks if the player shookdown the merchant yet 
  23. merchants_not_shaked = { true, true, true, true, true } 
  24. --Initializes the amount of damage needed to get a storeowner out of each store 
  25. damages = { 0, 0, 0, 0, 0 } 
  26. damage_per_mover = 10 
  27. merchantHitPoints = 1000 
  28. damage_count = 1 
  29. areatracker = 0 
  30. merch_damage = 0 
  31. total_merchants = 5 
  32. in_area = false 
  33. in_areatwo = false 
  34. last_merchant = "" 
  35. merchant_shown= false 
  36. merchant_shaked = false 
  37. near_thread = "" 
  38. area_entered_once = false 
  39. area_exit_once = false 
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46. function sh_bh_chinatown_start(checkpoint, is_restart) 
  47.  
  48. 	set_mission_author("David Bowring")	 
  49. 	notoriety_set_min("brotherhood", 2) 
  50. 	notoriety_set_max("brotherhood", 2) 
  51. 	notoriety_force_no_spawn("brotherhood", true) 
  52. 	ambient_gang_spawn_enable(false) 
  53. 	on_random_ods_killed("sh_bh_chinatown_mover_death", "sh_bh_chinatown") 
  54.  
  55. 	if (checkpoint == MISSION_START_CHECKPOINT) then		 
  56. 		mission_start_fade_out() 
  57. 		teleport_coop("sh_bh_chinatown_$nstart","sh_bh_chinatown_$nstart (0)") 
  58. 		if (not is_restart) then 
  59. 			cutscene_play("sh_bh_chinatown_ct1") 
  60. 		end 
  61. 		if group_is_loaded("sh_bh_chinatown_$GCTE") then 
  62. 			release_to_world("sh_bh_chinatown_$GCTE") 
  63. 		end 
  64. 		objective_text(0, "sh_bh_chinatown_shopsleft", merchants_left, 4) 
  65. 		mission_help_table("sh_bh_chinatown_setup") 
  66. 		group_create_hidden("sh_bh_chinatown_$Gshopkeepers")		 
  67. 		for i = 1, storefronts_total, 1 do 
  68. 			on_take_damage("sh_bh_chinatown_merch", merchants[i])  
  69. 			on_damage("sh_bh_chinatown_shakedown", merchants[i], 0.7) 
  70. 			on_death("sh_bh_chinatown_merchant_death", merchants[i])				 
  71. 			on_trigger("sh_bh_chinatown_in_area", storefronts[i]) 
  72. 			on_trigger_exit("sh_bh_chinatown_not_area", storefronts[i]) 
  73. 			marker_add_navpoint(storefronts[i],MINIMAP_ICON_LOCATION,"") 
  74. 			set_max_hit_points(merchants[i], merchantHitPoints) 
  75. 			set_max_hit_points("sh_bh_chinatown_$cPagoda", merchantHitPoints)	 
  76. 		end 
  77. 		mission_start_fade_in() 
  78. 		mission_debug("MARK IS WRONG") 
  79. 		near_thread = thread_new("sh_bh_chinatown_nearest")		 
  80. 	else 
  81. 		if group_is_loaded("sh_bh_chinatown_$Gshopkeepers") then 
  82. 			release_to_world("sh_bh_chinatown_$Gshopkeepers") 
  83. 		end	 
  84. 		group_create_hidden("sh_bh_chinatown_$Gshopkeepers")		 
  85. 		 
  86. 		fade_in(1) 
  87. 		sh_bh_chinatown_phase_two()	 
  88. 	end 
  89. end 
  90.  
  91.  
  92. function sh_bh_chinatown_not_area(char, trigger_name) 
  93. 	--hud_remainder = hud_timer_get_remainder(0) 
  94. 	 
  95. 	--on_random_ods_killed("", "sh_bh_chinatown") 
  96. 	on_trigger_exit("", trigger_name) 
  97. 	on_trigger("sh_bh_chinatown_in_area", trigger_name)	 
  98. 	 
  99. 	for i = 1, storefronts_total, 1 do 
  100. 		if ((trigger_name == storefronts[i]))then 
  101. 				mission_debug("Player exits area") 
  102. 				mission_debug("check merchant shown") 
  103. 			if merchant_shown == true then 
  104. 				mission_debug("merchant uber") 
  105. 				--turn_invulnerable(merchants[i], false)  
  106. 			end 
  107. 			areas[i] = false 
  108. 			--sh_bh_chinatown_timer(char) 
  109. 			if merchant_shown==false then 
  110. 				if area_exit_once == false then 
  111. 					mission_help_table("sh_bh_chinatown_setup") 
  112. 				else 
  113. 					mission_help_table_nag("sh_bh_chinatown_setup") 
  114. 				end 
  115. 			area_exit_once = true 
  116. 			end 
  117. 		end 
  118. 	end	 
  119. end 
  120.  
  121.  
  122.  
  123. function sh_bh_chinatown_timer(char) 
  124.  
  125. 	 
  126. 	 
  127. 	in_area = false		 
  128. 		if coop_is_active() then 
  129. 			if char == REMOTE_PLAYER then 
  130. 				in_areatwo = false 
  131. 			end 
  132. 		end 
  133.  
  134. 		local time = 0 
  135. 		local messone = true 
  136. 		local messtwo = true	 
  137. 		mission_debug("LEAVE") 
  138. 		--mission_debug(in_area) 
  139. 	if coop_is_active() then 
  140. 			while(in_area==false and in_areatwo==false) do 
  141. 				 
  142. 				time = time + get_frame_time() 
  143.  
  144. 				if(in_area==true and in_areatwo==false or merchant_shaked) then 
  145. 				return 
  146. 				end 
  147.  
  148. 				if (time > 15) then					 
  149. 					mission_help_table_nag("sh_bh_chinatown_warning_one")		 
  150. 				end 
  151. 				 
  152.  
  153. 				if (time > 10) then				 
  154. 					if (messone == true) then 
  155. 					mission_help_table_nag("sh_bh_chinatown_warning_three") 
  156. 					messone = false 
  157. 					end 
  158. 				end 
  159.  
  160.  
  161. 				if (time > 5) then 
  162. 					-- Second message (10 seconds left) 
  163. 					if (messtwo == true) then 
  164. 						mission_help_table_nag("sh_bh_chinatown_warning_two")						 
  165. 						messtwo = false 
  166. 					end				 
  167. 				end 
  168. 				 
  169. 				if (time == 0) then 
  170. 					-- Fail if timer runs out 
  171. 					if (messtwo == true) then 
  172. 						messtwo = false 
  173. 						sh_bh_chinatown_timeout()						 
  174. 					end				 
  175. 				end 
  176. 				thread_yield()	 
  177. 			end				 
  178.  
  179. 			else 
  180.  
  181. 			while(in_area==false) do 
  182. 				 
  183. 				time = time + get_frame_time() 
  184.  
  185. 				if(in_area==true or merchant_shaked) then 
  186. 				return 
  187. 				end 
  188.  
  189.  
  190. 				if (time > 15) then					 
  191. 					--mission_help_table_nag("sh_bh_chinatown_warning_one") 
  192. 					mission_end_failure("sh_bh_chinatown", "msn_sh_bh_chinatown_warning_fail") 
  193. 				end				 
  194.  
  195. 				if (time > 10) then				 
  196. 					if (messone == true) then 
  197. 						mission_help_table_nag("sh_bh_chinatown_warning_three") 
  198. 						messone = false 
  199. 					end 
  200. 				end 
  201.  
  202.  
  203. 				if (time > 5) then 
  204. 					-- Second message (10 seconds left) 
  205. 					if (messtwo == true) then 
  206. 						mission_help_table_nag("sh_bh_chinatown_warning_two") 
  207. 						messtwo = false 
  208. 					end 
  209. 				end 
  210.  
  211. 				if (time == 0) then 
  212. 					-- Fail if timer runs out 
  213. 					if (messtwo == true) then 
  214. 						sh_bh_chinatown_timeout()				 
  215. 						messtwo = false 
  216. 					end				 
  217. 				end 
  218. 				thread_yield() 
  219. 		end				 
  220. 	end				 
  221. end 
  222.  
  223.  
  224. --When the player enters a shop area, turn on the damage HUD and help text 
  225.  
  226.  
  227.  
  228. function sh_bh_chinatown_in_area( triggerer_name, trigger_name )	 
  229. 	mission_debug("IN area called") 
  230. 	 
  231. 	if merchant_shown==false then 
  232. 	merchant_shaked = false 
  233.  
  234. 	if area_entered_once==false then 
  235. 		objective_text_clear(0) --Clear out the "Shop Owners Left:" line 
  236. 		mission_help_table("sh_bh_chinatown_damage") 
  237. 	else 
  238. 	--objective_text_clear(0) --Clear out the "Shop Owners Left:" line 
  239. 	mission_help_table_nag("sh_bh_chinatown_damage") 
  240. 	end 
  241. 	--mission_help_table("sh_bh_chinatown_instruct_one") --Destroy the storefronts to get the shopkeepers to come out 
  242. 	on_random_ods_killed("sh_bh_chinatown_mover_death", "sh_bh_chinatown")		--Set HUD range	 
  243. 	hud_bar_on(0, "Damage", "MSN_SH_BH_CHINATOWN_DESTRUCTION_BAR", 100) --Turn on the damage meter 
  244. 	hud_bar_set_range(0, 0, 100, SYNC_ALL)	 
  245. 	end 
  246.  
  247. 	area_entered_once = true 
  248. 	in_area = true 
  249. 	mission_debug("In area True") 
  250. 	if coop_is_active() then 
  251. 		if triggerer_name == REMOTE_PLAYER then 
  252. 			in_areatwo = true 
  253. 		end 
  254. 	end 
  255. 	thread_kill(near_thread) 
  256. 	mission_waypoint_remove(SYNC_ALL)  
  257. 	mission_debug("waypoint removed") 
  258. 	 
  259. 	for i = 1, storefronts_total, 1 do			 
  260. 		marker_remove_navpoint(storefronts[i])	--remove area markers		 
  261. 	end 
  262. 	 
  263. 		for i = 1, storefronts_total, 1 do 
  264. 		 
  265. 			if merchant_shown then 
  266. 			turn_invulnerable(merchants[i], true)  
  267. 			end 
  268.  
  269. 			if (storefronts[i] == trigger_name) then 
  270. 				areatracker = i 
  271. 				areas[i] = true 
  272. 				damage_count = i 
  273. 				in_area = true 
  274.  
  275. 			 
  276.  
  277. 				if coop_is_active() then 
  278. 					if triggerer_name == REMOTE_PLAYER then 
  279. 						hud_timer_stop(0) 
  280. 						in_areatwo = true 
  281. 					else 
  282. 						hud_timer_stop(0) 
  283. 					end 
  284. 				end 
  285. 				--minimap_icon_add_navpoint_radius(storefronts[i], MINIMAP_ICON_LOCATION, 45, true, nil, SYNC_ALL ) 
  286. 				render_script_trigger_on_minimap_add(storefronts[i], {250, 81, 81}, false,SYNC_ALL) 
  287. 				--minimap_icon_add_navpoint_radius(storefronts[i],MINIMAP_ICON_LOCATION, 45, nil, SYNC_ALL ) -- add radius marker			 
  288. 				on_trigger("", trigger_name) 
  289. 				on_trigger_exit("sh_bh_chinatown_not_area", trigger_name) 
  290. 				mission_debug("Player enters area") 
  291. 				if merchant_shown== false then 
  292. 				hud_bar_set_value(0, damages[damage_count], SYNC_ALL)			 
  293. 				--mission_help_table("sh_bh_chinatown_damage") 
  294. 				end 
  295.  
  296. 			if(not group_is_loaded(groups[i])) then	 
  297. 				group_create(groups[i], true) 
  298. 			end 
  299.  
  300. 			if (damages[damage_count] >= 100) and merchant_shown == false then			 
  301. 				sh_bh_chinatown_show_merchant(merchants[areatracker])				 
  302. 			end 
  303. 		end 
  304. 	end 
  305.  
  306. 	for i = 1, storefronts_total, 1 do 
  307. 		if (trigger_name ~= storefronts[i] ) then 
  308. 			--marker_add_navpoint(storefronts[i],MINIMAP_ICON_LOCATION, INGAME_EFFECT_LOCATION) --add marker to remaining stores 
  309. 			thread_new("sh_bh_chinatown_trigger", storefronts[i], false) 
  310. 			on_trigger("", storefronts[i]) 
  311. 		end 
  312. 	end 
  313. end 
  314.  
  315.  
  316.  
  317. function sh_bh_chinatown_trigger(name, switch) 
  318. trigger_enable(name, switch) 
  319. end 
  320.  
  321. --After something is destroyed at a storefront, it adds to the total damage 
  322. function sh_bh_chinatown_mover_death(attacker, mover_type, X, Y, Z)	 
  323. 	 
  324. 	if (damages[damage_count] >= 100) then		 
  325. 			return	 
  326. 	else 
  327. 		for i = 1, storefronts_total, 1 do			 
  328. 			if position_is_in_trigger(storefronts[i], X, Y, Z) then 
  329. 				damages[i] = (damages[i]) + damage_per_mover --add damage to that area's total damage			 
  330. 				if damage_count == i then 
  331. 				--mission_debug("mover destroyed"..damages[i]..storefronts[i], 5) 
  332. 				hud_bar_set_value(0, damages[i], SYNC_ALL) 
  333. 					if (damages[damage_count] == 100) then 
  334. 						--on_random_ods_killed("", "sh_bh_chinatown") 
  335. 						--mission_debug("ods removed") 
  336. 						delay(5) 
  337. 						sh_bh_chinatown_show_merchant(merchants[areatracker]) 
  338. 					end 
  339. 				end 
  340. 			end 
  341. 		end 
  342. 	end	 
  343. end 
  344.  
  345.  
  346.  
  347.  
  348.  
  349.  
  350.  
  351.  
  352.   
  353.  
  354.  
  355.  
  356.  
  357. --Once the player damages enough goods, the merchant shows up 
  358. function sh_bh_chinatown_show_merchant(merchant_name) 
  359. 	 
  360. 	if merchant_shown then 
  361. 		return 
  362. 	end 
  363. 		 
  364. 	for i = 1, merchants_total, 1 do --For each area value 
  365. 		if (merchants[i] == merchant_name) then 
  366. 			if group_is_loaded(groups[i]) then 
  367. 			release_to_world(groups[i]) 
  368. 			mission_debug("Group released = ".. groups[i]) 
  369. 			end 
  370. 			--set_max_hit_points(merchants[i], merchantHitPoints) 
  371. 			--trigger_enable(storefronts[i], false) 
  372. 			mission_debug("Merchant appears="..merch_damage) 
  373. 			--marker_remove_navpoint(storefronts[i]) --take away markers for area  
  374. 			objective_text_clear(0) 
  375. 			--objective_text("sh_bh_chinatown_shopsleft", merchants_left)			 
  376. 			set_unrecruitable_flag(merchants[i], true) 
  377. 			character_show(merchants[i]) 
  378. 			--door_open(monster_closet[i])			 
  379. 			mission_debug("closet opened =  "..monster_closet[i],15) 
  380. 			turn_invulnerable(merchant_name, true) 
  381. 			mission_debug("Merchant Marked"..merchant_name,10) 
  382. 			marker_add_npc(merchants[i], MINIMAP_ICON_KILL,  INGAME_EFFECT_KILL)--add marker to merchant			 
  383. 			set_always_sees_player_flag(merchants[i], true) 
  384. 			set_attack_player_flag(merchants[i], true) 
  385. 			set_cant_flee_flag(merchants[i], true) 
  386. 			attack(merchants[i], LOCAL_PLAYER) 
  387. 			mesh_mover_play_action(monster_closet[i], "start2") 
  388. 			LAST_DOOR_OPENED = monster_closet[i] 
  389. 			mission_help_table("sh_bh_chinatown_help") --"Shakedown the storeowners but dont kill them" 
  390. 			hud_bar_off(0) 
  391. 			merch_damage = merchantHitPoints			 
  392. 			if merch_damage > 1000 then 
  393. 				merch_damage = 1000 
  394. 			elseif merch_damage < 0 then 
  395. 				merch_damage = 0 
  396. 			end 
  397. 			--mission_debug("Merchant appears="..merch_damage) 
  398. 			--hud_bar_on(0,"Health", "MSN_SH_BH_CHINATOWN_SHOP_OWNER_BAR", 1000)--Turn on the damage meter	 
  399. 			--hud_bar_set_range(0,0, 1000, SYNC_ALL)			 
  400. 			--hud_bar_set_value(0,merch_damage, SYNC_ALL) 
  401. 			damage_indicator_on(0, merchants[i], 0, "MSN_SH_BH_CHINATOWN_SHOP_OWNER_BAR") 
  402. 			on_take_damage("sh_bh_chinatown_merch", merchants[i])  
  403. 			on_damage("sh_bh_chinatown_shakedown", merchants[i], 0.7) 
  404. 			on_death("sh_bh_chinatown_merchant_death", merchants[i])	 
  405. 		end 
  406. 	end 
  407. merchant_shown= true 
  408. end 
  409.  
  410. function sh_bh_chinatown_merchant_death() 
  411. 	mission_end_failure("sh_bh_chinatown", "sh_bh_chinatown_failure")  
  412. end 
  413.  
  414.  
  415.  
  416. function sh_bh_chinatown_merch(npc_name, attacker)	 
  417. 	 
  418. 	if merchant_shaked then 
  419. 		return 
  420. 	end 
  421. 	 
  422. 	if merch_damage > 1000 then 
  423. 		merch_damage = 1000 
  424. 	elseif merch_damage < 0 then 
  425. 		merch_damage = 0 
  426. 	end 
  427. 	merch_damage = get_current_hit_points(npc_name) 
  428. 	mission_debug("Merchant is damaged=  "..merch_damage) 
  429. 	--hud_bar_set_value(0,merch_damage, SYNC_ALL)  
  430. end 
  431.  
  432.  
  433. function sh_bh_chinatown_shakedown(npc_name, attacker) --When a merchant reaches 20% health, do this 
  434. 	mission_debug("Shakedown success!") 
  435. 	local count = true 
  436. 	merchant_shown= true 
  437. 	merchant_shaked = true 
  438. 	area_entered_once = false 
  439. 	area_exit_once = false 
  440. 	 
  441. 	for i = 1, merchants_total, 1 do		 
  442. 		if (get_current_hit_points(merchants[i]) < get_max_hit_points(merchants[i])) then  
  443. 			if (not character_is_dead(merchants[i])) then --CRASH 
  444. 				if (merchants_not_shaked[i]) then 
  445. 					trigger_enable(storefronts[i], false) 
  446. 					audio_play_for_character("AMELD_BR_STRONG_CHINA", merchants[i], "voice", false, false) 
  447. 					on_take_damage("", merchants[i])  
  448. 					mission_debug("not_shaked == true") 
  449. 					merchants_not_shaked[i] = false 
  450. 					areas[i] = true 
  451. 					marker_remove_navpoint(storefronts[i]) --take away markers for area 
  452. 					marker_remove_npc(merchants[i]) 
  453. 					render_script_trigger_on_minimap_remove() 
  454. 					mission_debug("marker Removed from=  "..merchants[i], 5) 
  455. 					set_team (merchants[i], "playas") 
  456. 					set_unrecruitable_flag(merchants[i], true)					 
  457. 					merchants_left = merchants_left + 1 
  458. 					if merchants_left < 4 then 
  459. 					mission_help_table("sh_bh_chinatown_instruct_three") 
  460. 					end 
  461. 					damage_indicator_off(0) 
  462. 					--hud_bar_off(0)	 
  463. 					near_thread = thread_new("sh_bh_chinatown_nearest") 
  464. 					if (merchants_left ~= 4) then 
  465. 						objective_text(0, "sh_bh_chinatown_shopsleft", merchants_left, 4) 
  466. 					end 
  467. 					thread_new("sh_bh_chinatown_merchant_timer", merchants[i])			 
  468. 					--on_damage("", merchants[i], 0.7) 
  469. 					--release_to_world(merchants[i]) 
  470. 				end 
  471. 			end			 
  472.  
  473. 			if (merchants_left == 1) then 
  474. 				notoriety_set_min("brotherhood", 2) 
  475. 				notoriety_set_max("brotherhood", 2) 
  476. 			end 
  477.  
  478. 			if (merchants_left == 4 and count == true) then 
  479. 				count=false 
  480. 				mission_set_checkpoint("phase two") 
  481. 				mission_waypoint_remove() 
  482. 				sh_bh_chinatown_phase_two() 
  483. 			end 
  484. 		end 
  485. 	end 
  486.  
  487. 	 
  488. 	for i = 1, storefronts_total, 1 do 
  489. 		if (merchants_not_shaked[i] == true) then 
  490. 			marker_add_navpoint(storefronts[i],MINIMAP_ICON_LOCATION, INGAME_EFFECT_LOCATION) --add marker to remaining stores 
  491. 			trigger_enable( storefronts[i], true) 
  492. 			on_trigger("sh_bh_chinatown_in_area", storefronts[i]) 
  493. 			--on_trigger_exit("sh_bh_chinatown_not_area", storefronts[i]) 
  494. 		end		 
  495. 	end 
  496. 	in_area= false 
  497. 	near_thread = thread_new("sh_bh_chinatown_nearest")	 
  498. end 
  499.  
  500.  
  501.  
  502. --Turn the merchants invulnerable after 5 seconds 
  503. function sh_bh_chinatown_merchant_timer(merchant_name) 
  504. 	 
  505. 	set_team (merchant_name, "playas") 	 
  506. 	while (get_current_hit_points(merchant_name) > 0) do 
  507. 		set_attack_player_flag (merchant_name, false) 
  508. 		set_cant_flee_flag(merchant_name, false) 
  509. 		set_cower_flee_mode(merchant_name, "always flee when attacked") 
  510. 		delay(5) 
  511. 		thread_yield() 
  512. 	end 
  513. 	near_thread = thread_new("sh_bh_chinatown_nearest")	 
  514. end 
  515.  
  516.  
  517.  
  518.  
  519. function sh_bh_chinatown_phase_two()	 
  520. 	delay(2) 
  521. 	cutscene_play("sh_bh_chinatown_ct2")	   
  522. 	merchant_shaked = false 
  523. 	mission_help_table("sh_bh_chinatown_instruct_four")	 
  524. 	marker_add_trigger("sh_bh_chinatown_$t_Pagoda", MINIMAP_ICON_LOCATION, INGAME_EFFECT_LOCATION) 
  525. 	on_trigger("sh_bh_chinatown_show_pagoda_merchant", "sh_bh_chinatown_$t_Pagoda") 
  526. 	trigger_enable("sh_bh_chinatown_$t_Pagoda", true)	 
  527. 	--Create the guards and reinforcments around the pagoda 
  528. 	notoriety_set_max("brotherhood", 3) 
  529. 	notoriety_set_min("brotherhood", 3) 
  530. 	notoriety_force_no_spawn("brotherhood", false) 
  531. 	group_create("sh_bh_chinatown_$GBrotherhood") 
  532. 	--Create the peds in the padoda and make them wander 
  533. 	--group_create("sh_bh_chinatown_$Gpeds") 
  534. 	--[[ 
  535. 	for i = 1, peds_total, 1 do 
  536. 		wander_start(peds[i], peds[i], 15) 
  537. 	end 
  538. 	--]] 
  539. 	mission_waypoint_add("sh_bh_chinatown_$t_Pagoda")	 
  540. 	mesh_mover_play_action(LAST_DOOR_OPENED, "start2")  
  541. end 
  542.  
  543.  
  544. function sh_bh_chinatown_show_pagoda_merchant() 
  545. 	delay(2) 
  546. 	mission_debug("FINAL MERCHANT") 
  547. 	 
  548. 	trigger_enable("sh_bh_chinatown_$t_Pagoda", false) 
  549. 	mission_help_table("sh_bh_chinatown_instruct_two") --Shake down the owner of the pagoda hotel 
  550. 	--mission_help_table("sh_bh_chinatown_instruct_two") 
  551. 	character_show("sh_bh_chinatown_$cPagoda") 
  552. 	marker_add_npc("sh_bh_chinatown_$cPagoda", MINIMAP_ICON_KILL,  INGAME_EFFECT_KILL) 
  553. 	--set_max_hit_points("sh_bh_chinatown_$cPagoda", merchantHitPoints)	 
  554. 	on_take_damage("sh_bh_chinatown_merch", "sh_bh_chinatown_$cPagoda")  
  555. 	on_damage("sh_bh_chinatown_end", "sh_bh_chinatown_$cPagoda", 0.5) 
  556. 	on_death("sh_bh_chinatown_merchant_death", "sh_bh_chinatown_$cPagoda") 
  557. 	attack("sh_bh_chinatown_$cPagoda") 
  558. 	merch_damage = merchantHitPoints 
  559. 	--Set Range 
  560. 	if merch_damage > 1000 then 
  561. 		merch_damage = 1000 
  562. 	elseif merch_damage < 0 then 
  563. 		merch_damage = 0 
  564. 	end 
  565. 	set_team ("sh_bh_chinatown_$cPagoda", "brotherhood")  
  566. 	damage_indicator_on(0,"sh_bh_chinatown_$cPagoda", 0, "MSN_SH_BH_CHINATOWN_HOTEL_OWNER_BAR") 
  567. 	--hud_bar_on(0,"Health", "MSN_SH_BH_CHINATOWN_HOTEL_OWNER_BAR", 1000)--Turn on the damage meter 
  568. 	--hud_bar_set_range(0,0, 1000, SYNC_ALL) 
  569. 	--hud_bar_set_value(0,merch_damage, SYNC_ALL)	 
  570. end 
  571.  
  572. function sh_bh_chinatown_end() 
  573. 	set_attack_player_flag ("sh_bh_chinatown_$cPagoda", false) 
  574. 	set_cant_flee_flag("sh_bh_chinatown_$cPagoda", false) 
  575. 	set_cower_flee_mode("sh_bh_chinatown_$cPagoda", "cower flee normal") 
  576. 	mission_end_success("sh_bh_chinatown") 
  577. end 
  578.  
  579. function sh_bh_chinatown_cleanup() 
  580.  
  581. --Checks what area the player is in an area 
  582. areas = { false, false, false, false, false } 
  583. --Checks if the player shookdown the merchant yet 
  584. merchants_not_shaked = { true, true, true, true, true } 
  585. --Initializes the amount of damage needed to get a storeowner out of each store 
  586. damages = { 0, 0, 0, 0, 0 } 
  587. damage_per_mover = 5 
  588. merchantHitPoints = 1000 
  589. damage_count = 0 
  590. storefronts_total = sizeof_table(storefronts) 
  591. ambient_gang_spawn_enable(true) 
  592. notoriety_set_max("brotherhood", 5) 
  593. notoriety_set_min("brotherhood", 0) 
  594. notoriety_set("brotherhood", 0) 
  595. notoriety_force_no_spawn("brotherhood", false) 
  596. --for i = 1, storefronts_total, 1 do			 
  597. --	marker_remove_navpoint(storefronts[i])	--remove area markers		 
  598. --end 
  599. 	marker_remove_trigger("sh_bh_chinatown_$t_Pagoda")  
  600. 	on_random_ods_killed("", "sh_bh_chinatown") 
  601. damage_indicator_off(0)	 
  602. render_script_trigger_on_minimap_remove() 
  603. if group_is_loaded("sh_bh_chinatown_$Gshopkeepers") then 
  604. 	for i = 1, merchants_total, 1 do 
  605. 		if (character_is_dead(merchants[i])==false) then 
  606. 			trigger_enable(storefronts[i], false) 
  607. 			on_take_damage("", merchants[i])  
  608. 			marker_remove_npc(merchants[i]) 
  609. 			set_unrecruitable_flag(merchants[i], false) 
  610. 		 
  611. 		end		 
  612. 	end 
  613. end 
  614.  
  615.  
  616. for i = 1, merchants_total, 1 do 
  617. 	trigger_enable(storefronts[i], false) 
  618. 	on_trigger("",storefronts[i]) 
  619. 	marker_remove_navpoint(storefronts[i]) 
  620. end 
  621.  
  622.  
  623. group_destroy("sh_bh_chinatown_$Gshopkeepers") 
  624.  
  625. end 
  626.  
  627. function sh_bh_chinatown_success() 
  628.  
  629. end 
  630.  
  631.  
  632. function sh_bh_chinatown_timeout() 
  633.  
  634. mission_end_failure("sh_bh_chinatown", "sh_bh_chinatown_warning_fail") 
  635.  
  636. end 
  637.  
  638.  
  639. function  sh_bh_chinatown_nearest()	 
  640.  
  641. 		mission_debug("nearest Called") 
  642. 		merchant_shown=false 
  643. 		if last_merchant ~= "" then 
  644. 			release_to_world(last_merchant) 
  645. 		end 
  646. 	 
  647.  
  648. 		while (in_area == false) do 
  649. 		--mission_debug("near loop") 
  650. 		delay(.5) 
  651. 		sh_bh_chinatown_get_closest_nav_to_char( storefronts, LOCAL_PLAYER ) 
  652. 		end 
  653. end 
  654.  
  655. function  sh_bh_chinatown_get_closest_nav_to_char( navpoint_names, character_name ) 
  656.    local closest_nav_name = navpoint_names[1] 
  657.    local closest_dist = 2000 --get_dist_char_to_nav( character_name, navpoint_names[1] ) 
  658.    local closest_index = 0 
  659. 	local cur_dist = 0 
  660.  
  661. 	for nav_index, nav_name in pairs( navpoint_names ) do 
  662. 		  
  663. 			if merchants_not_shaked[nav_index] == true then 
  664. 			cur_dist = get_dist_char_to_nav( character_name, nav_name ) 
  665. 			 
  666.  
  667. 			--mission_debug( "nav_name = "..nav_name..", cur_dist = "..cur_dist, 15 ) 
  668. 			 
  669. 				if ( cur_dist < closest_dist ) then 
  670. 					closest_nav_name = nav_name 
  671. 					closest_dist = cur_dist 
  672. 					closest_index = nav_index 
  673. 				end 
  674. 			 
  675. 			end 
  676. 	end 
  677.  
  678. 	if closest_index == 0 then 
  679. 		return 
  680. 	end 
  681. 	--mission_debug( "nav_name = "..closest_nav_name..", cur_dist = "..cur_dist, 15 )	 
  682. 	mission_waypoint_add(closest_nav_name, SYNC_ALL)	  
  683.    --return closest_nav_name, closest_index, closest_dist 
  684. end