sr2lua/ug_lib.lua

  1.  
  2. -------------------- 
  3. -- Script Globals -- 
  4. -------------------- 
  5.  
  6. MINIMAP_ICON_KILL								= "map_act_kill" 
  7. MINIMAP_ICON_PROTECT_ACQUIRE				= "map_act_protectacquire" 
  8. MINIMAP_ICON_LOCATION						= "map_act_location" 
  9.  
  10. INGAME_EFFECT_KILL							= "icon_red" 
  11. INGAME_EFFECT_NPC_INTERACT					= "icon_blue" 
  12. INGAME_EFFECT_PROTECT_ACQUIRE				= "icon_green" 
  13. INGAME_EFFECT_LOCATION						= "mission_complete" 
  14. INGAME_EFFECT_CUTSCENE						= "mission_purchase" 
  15. INGAME_EFFECT_MP_TUTORIAL					= "mission_complete_mp" 
  16.  
  17. INGAME_EFFECT_VEHICLE_INTERACT			= "Icon_lg_b" 
  18. INGAME_EFFECT_VEHICLE_PROTECT_ACQUIRE	= "Icon_lg_c" 
  19. INGAME_EFFECT_VEHICLE_KILL					= "Icon_lg_d" 
  20.  
  21. INGAME_EFFECT_VEHICLE_LOCATION			= "Mission_car_a" 
  22. INGAME_EFFECT_VEHICLE_CUTSCENE			= "Mission_car_b" 
  23.  
  24. SYNC_LOCAL	= 1 
  25. SYNC_REMOTE = 2 
  26. SYNC_ALL		= 3 
  27.  
  28. MAX_NOTORIETY_LEVEL		= 5 
  29. INVALID_THREAD_HANDLE	= -1 
  30.  
  31. MISSION_START_CHECKPOINT = "mission start" 
  32.  
  33. LOCAL_PLAYER	= "#PLAYER1#" 
  34. REMOTE_PLAYER	= "#PLAYER2#" 
  35. CLOSEST_PLAYER = "#CLOSEST_PLAYER#" 
  36. CLOSEST_TEAM1	= "#CLOSEST_TEAM1#" 
  37. CLOSEST_TEAM2	= "#CLOSEST_TEAM2#" 
  38.  
  39. PLAYER_TAG_LIST = { 
  40. 	"#PLAYER1#", 
  41. 	"#PLAYER2#", 
  42. 	"#PLAYER3#", 
  43. 	"#PLAYER4#", 
  44. 	"#PLAYER5#", 
  45. 	"#PLAYER6#", 
  46. 	"#PLAYER7#", 
  47. 	"#PLAYER8#" 
  48. } 
  49.  
  50. WEAPON_SLOT_NONE		= -1 
  51. WEAPON_SLOT_UNARMED	= 0 
  52. WEAPON_SLOT_MELEE		= 1 
  53. WEAPON_SLOT_PISTOL	= 2 
  54. WEAPON_SLOT_SMG		= 3 
  55. WEAPON_SLOT_SHOTGUN	= 4 
  56. WEAPON_SLOT_RIFLE		= 5 
  57. WEAPON_SLOT_LAUNCHER = 6 
  58. WEAPON_SLOT_THROWN	= 7 
  59.  
  60. Mission_waypoint		= -1 
  61.  
  62. VT_AUTOMOBILE	= 0 
  63. VT_MOTORCYCLE	= 1 
  64. VT_AIRPLANE		= 2 
  65. VT_HELICOPTER	= 3 
  66. VT_WATERCRAFT	= 4 
  67. VT_TRAIN			= 5 
  68. -- This means the player isn't in a vehicle. 
  69. VT_NONE			= 6 
  70.  
  71. IS_MOVER		= 1 
  72. IS_ITEM			= 2 
  73. INDETERMINATE	= 3 
  74.  
  75. VST_AMBULANCE = 0 
  76. VST_BUS = 1 
  77. VST_FBI = 2 
  78. VST_FIRETRUCK = 3 
  79. VST_INDUSTRIAL = 4 
  80. VST_METER_MAID = 5 
  81. VST_NEWS_VAN = 6 
  82. VST_POLICE = 7 
  83. VST_SWAT_VAN = 8 
  84. VST_TAXI = 9 
  85. VST_TOW_TRUCK = 10 
  86. VST_LIMO = 11 
  87. VST_ATV = 12 
  88. -- This player's vehicle isn't special or 
  89. -- this player isn't in a vehicle. 
  90. VST_NONE = 13 
  91.  
  92. -- Gender types 
  93. GT_NONE = 0 
  94. GT_MALE = 1 
  95. GT_FEMALE = 2 
  96.  
  97. -- Trigger event state tracker globals 
  98. UPDATE_DEACTIVATED = 1 
  99. ALL_PLAYERS_DEACTIVATED = 2 
  100. ANY_PLAYER_DEACTIVATED = 3 
  101. UPDATE_ACTIVATED = 4 
  102. ALL_PLAYERS_ACTIVATED = 5 
  103. ALL_PLAYERS_ACTIVATED_RESET = 6 
  104. TRIGGER_MULTIPLE_TIMES = 7 
  105. TRIGGER_ONCE_FIRST_TRIGGERER = 8 
  106. TRIGGER_ONCE_PER_PLAYER = 9 
  107.  
  108. -- Parameters for use with npc_set_boss_ai 
  109. AI_BOSS_JYUNICHI = "Jyunichi" 
  110. AI_BOSS_AKUJI = "Akuji" 
  111.  
  112. START_FADE_OUT_TIME = 1.0 
  113. START_FADE_IN_TIME = 2.0 
  114. DEFAULT_END_DELAY_TIME = 2.0 
  115. DEFAULT_END_FADE_OUT_TIME = 3.0 
  116.  
  117. -- Persona override types 
  118. POT_ATTACK				= 1 
  119. POT_TAKE_DAMAGE		= 2 
  120. -- POT_TAUNT_NEGATIVE	= 3 (PA 7-14-08. There is no longer code-side support for this override type.) 
  121. POT_CUSTOM_1			= 4 
  122. POT_CUSTOM_2			= 5 
  123. POT_PRAISED_BY_PC		= 6 
  124. POT_TAUNTED_BY_PC		= 7 
  125. POT_BARTER				= 8 
  126. POT_GRATS_PC			= 9 
  127. POT_GRATS_SELF			= 10 
  128. POT_HIT_CAR				= 11 
  129. POT_HIT_OBJ				= 12 
  130. POT_HIT_PED				= 13 
  131.  
  132. -- Build types 
  133. BUILD_TYPE_NORMAL			= 1 
  134. BUILD_TYPE_AUSTRALIAN	= 2 
  135. BUILD_TYPE_GERMAN			= 3 
  136. BUILD_TYPE_JAPANESE_360	= 4 
  137. BUILD_TYPE_JAPANESE_PS3	= 5 
  138.  
  139. -- Persona situations associated w/ each override type 
  140. POT_SITUATIONS = { 
  141. 	[POT_ATTACK]			=	{"threat - alert (group attack)", 
  142. 									 "threat - alert (solo attack)"}, 
  143. 	[POT_TAKE_DAMAGE]		=	{"take damage",  
  144. 									 "threat - damage received (firearm)", 
  145. 									 "threat - damage received (melee)", 
  146. 									 "threat - damage received (vehicle)"}, 
  147. 	[POT_CUSTOM_1]			=	{"custom line 1"}, 
  148. 	[POT_CUSTOM_2]			=	{"custom line 2"}, 
  149. 	[POT_PRAISED_BY_PC]	=	{"observe - praised by pc"}, 
  150. 	[POT_TAUNTED_BY_PC]	=	{"misc - respond to player taunt w/taunt"}, 
  151. 	[POT_BARTER]			=	{"hostage - barters"}, 
  152. 	[POT_GRATS_PC]			=	{"combat - congratulate player"}, 
  153. 	[POT_GRATS_SELF]		=	{"combat - congratulate self"}, 
  154. 	[POT_HIT_CAR]			=	{"observe - passenger when driver hits cars"}, 
  155. 	[POT_HIT_OBJ]			=	{"observe - passenger when driver hits object"}, 
  156. 	[POT_HIT_PED]			=	{"observe - passenger when driver hits peds"} 
  157. } 
  158.  
  159. -- Constants use by the audio_play_conversation function. 
  160. -- These indices are the indices of each segment of a dialog stream 
  161. -- in the dialog stream table. 
  162. DIALOG_STREAM_AUDIO_NAME_INDEX = 1 
  163. DIALOG_STREAM_CHAR_NAME_INDEX = 2 
  164. DIALOG_STREAM_DELAY_SECONDS_INDEX = 3 
  165. DIALOG_STREAM_ANIM_ACTION_INDEX = 4 
  166.  
  167. -- Types of conversations 
  168. NOT_CALL = 1 
  169. OUTGOING_CALL = 2 
  170. INCOMING_CALL = 3 
  171.  
  172. -- Used in a dialog stream to denote that this is a character speaking through the cellphone 
  173. CELLPHONE_CHARACTER  = "cellphone character" 
  174.  
  175. -- Ring sounds 
  176. CELLPHONE_INCOMING = "SYS_CELL_RING_1" 
  177. CELLPHONE_OUTGOING = "SYS_CELL_RING_OTHER" 
  178.  
  179. -- Gang persona tables 
  180. -- 
  181. --	The key of each entry is the persona, and the value is the tag prfix of its situation triggers. 
  182. -- 
  183. -- These tables are used in conjunction with persona_override_group_start and persona_override_group_stop. 
  184.  
  185. BROTHERHOOD_PERSONAS = { 
  186. 	["HM_Bro1"]	=	"HMBRO1", 
  187. 	["HM_Bro2"]	=	"HMBRO2", 
  188. 	["HM_Bro3"]	=	"HMBRO3", 
  189.  
  190. 	["HF_Bro1"]	=	"HFBRO1", 
  191. 	["HF_Bro2"]	=	"HFBRO2", 
  192.  
  193. 	["WM_Bro1"]	=	"WMBRO1", 
  194. 	["WM_Bro2"]	=	"WMBRO2", 
  195. 	["WM_Bro3"]	=	"WMBRO3", 
  196.  
  197. 	["WF_Bro1"]	=	"WFBRO1", 
  198. 	["WF_Bro2"]	=	"WFBRO2", 
  199. } 
  200.  
  201. RONIN_PERSONAS	= { 
  202. 	["AM_Ron1"]	=	"AMRON1", 
  203. 	["AM_Ron2"]	=	"AMRON2", 
  204. 	["AM_Ron3"]	=	"AMRON3", 
  205.  
  206. 	["AF_Ron1"]	=	"AFRON1", 
  207. 	["AF_Ron2"]	=	"AFRON2", 
  208. 	["AF_Ron3"]	=	"AFRON3", 
  209.  
  210. 	["WM_Ron1"]	=	"WMRON1", 
  211. 	["WM_Ron2"]	=	"WMRON2", 
  212.  
  213. 	["WF_Ron1"]	=	"WFRON1", 
  214. 	["WF_Ron2"]	=	"WFRON2", 
  215. } 
  216.  
  217. SAINTS_PERSONAS = { 
  218. 	["AM_TSS1"]	=	"AMTSS1", 
  219. 	["AM_TSS2"]	=	"AMTSS2", 
  220. 	["AM_TSS3"]	=	"AMTSS3", 
  221.  
  222. 	["AF_TSS1"]	=	"AFTSS1", 
  223. 	["AF_TSS2"]	=	"AFTSS2", 
  224. 	["AF_TSS3"]	=	"AFTSS3", 
  225.  
  226. 	["BM_TSS1"]	=	"BMTSS1", 
  227. 	["BM_TSS2"]	=	"BMTSS2", 
  228. 	["BM_TSS3"]	=	"BMTSS3", 
  229.  
  230. 	["BF_TSS1"]	=	"BFTSS1", 
  231. 	["BF_TSS2"]	=	"BFTSS2", 
  232. 	["BF_TSS3"]	=	"BFTSS3", 
  233.  
  234. 	["HM_TSS1"]	=	"HMTSS1", 
  235. 	["HM_TSS2"]	=	"HMTSS2", 
  236. 	["HM_TSS3"]	=	"HMTSS3", 
  237.  
  238. 	["HF_TSS1"]	=	"HFTSS1", 
  239. 	["HF_TSS2"]	=	"HFTSS2", 
  240. 	["HF_TSS3"]	=	"HFTSS3", 
  241.  
  242. 	["WM_TSS1"]	=	"WMTSS1", 
  243. 	["WM_TSS2"]	=	"WMTSS2", 
  244. 	["WM_TSS3"]	=	"WMTSS3", 
  245.  
  246. 	["WF_TSS1"]	=	"WFTSS1", 
  247. 	["WF_TSS2"]	=	"WFTSS2", 
  248. 	["WF_TSS3"]	=	"WFTSS3", 
  249. } 
  250.  
  251. SAMEDI_PERSONAS = { 
  252. 	["BM_SoS2"]	=	"BMSOS2", 
  253.  
  254. 	["BF_SoS1"]	=	"BFSOS1", 
  255. 	["BF_SoS2"]	=	"BFSOS2", 
  256. 	["BF_SoS3"]	=	"BFSOS3", 
  257.  
  258. 	["WM_SoS2"]	=	"WMSOS2", 
  259.  
  260. 	["WF_SoS1"]	=	"WFSOS1", 
  261. } 
  262.  
  263. COP_PERSONAS = { 
  264. --	["AM_Cop"]	=	"AMCOP",		Currently has no mission specific lines 
  265. 	["AF_Cop"]	=	"AFCOP", 
  266. 	 
  267. 	["BM_Cop"]	=	"BMCOP", 
  268. 	["BF_Cop"]	=	"BFCOP", 
  269. 	 
  270. 	["HM_Cop"]	=	"HMCOP", 
  271. 	["HF_Cop"]	=	"HFCOP", 
  272. 	 
  273. 	["WM_Cop"]	=	"WMCOP", 
  274. 	["WF_Cop"]	=	"WFCOP", 
  275. } 
  276.  
  277. BUM_PERSONAS = { 
  278. 	["BM_Hobo"]		=	"BMHOBO1", 
  279. 	["BF_Hobo"]		=	"BFHOBO1", 
  280. 	 
  281. 	["HM_Hobo"]		=	"HMHOBO1", 
  282. 	["HF_Hobo"]		=	"HFHOBO1", 
  283. 	 
  284. 	["WM_Hobo1"]	=	"WMHOBO1", 
  285. 	["WM_Hobo2"]	=	"WMHOBO2", 
  286. 	 
  287. 	["WF_Hobo1"]	=	"WFHOBO1", 
  288. 	["WF_Hobo2"]	=	"WFHOBO2", 
  289. } 
  290.  
  291. -- Human teams ( gangs ) 
  292. HUMAN_TEAM_BROTHERHOOD		= 1 
  293. HUMAN_TEAM_RONIN				= 2 
  294. HUMAN_TEAM_SAMEDI				= 3 
  295.  
  296. -- Global Variables -- 
  297. Player_controls_disabled_by_mission_start_fadeout = false 
  298.  
  299. -------------------- 
  300. -- Script Actions -- 
  301. -------------------- 
  302.  
  303. function action_or_state_play( npc, name ) 
  304. 	if (animation_is_state( name )) then 
  305. 		set_animation_state( npc, name ) 
  306. 		 
  307. 		while (not(action_play_is_finished(npc, 1))) do 
  308. 			thread_yield() 
  309. 		end 
  310. 	else 
  311. 		action_play( npc, name ) 
  312. 	end 
  313. end 
  314.  
  315. -- Make a human play an animation, blocking until the animation is done 
  316. -- 
  317. -- name:			name of human 
  318. -- anim_name:		name of animation to play 
  319. -- morph_name:		(optional) name of morph to use 
  320. -- force_play:		(optional) if true, force play 
  321. -- percentage:		percentage done to check for (defaults to .8) 
  322. -- stand_still:	(optional) if true, human's movement mode set to none before playing 
  323. function action_play(name, anim_name, morph_name, force_play, percentage, stand_still) 
  324.  
  325. 	action_play_non_blocking(name, anim_name, morph_name, force_play, stand_still) 
  326. 	repeat 
  327. 		thread_yield() 
  328. 	until action_play_is_finished(name, percentage) 
  329. end 
  330.  
  331. -- Make a human play a custom animation, blocking until the animation is done 
  332. -- 
  333. -- name:			name of human 
  334. -- anim_name:	filename of animation to play 
  335. -- 
  336. function action_play_custom(name, anim_name, percentage) 
  337.  
  338. 	while not action_play_custom_do(name, anim_name) do 
  339. 		thread_yield() 
  340. 	end 
  341.  
  342. 	repeat 
  343. 		thread_yield() 
  344. 	until action_play_is_finished(name, percentage) 
  345. end 
  346.  
  347. -- Make a human play an animation without blocking 
  348. -- This function will still block until the animation STARTS playing 
  349. -- 
  350. -- name:			name of human 
  351. -- anim_name:		name of animation to play 
  352. -- morph_name:		(optional) name of morph to use 
  353. -- force_play:		(optional) if true, force play 
  354. -- stand_still:	(optional) if true, human's movement mode set to none before playing 
  355. function action_play_non_blocking(name, anim_name, morph_name, force_play, stand_still) 
  356. 	while not action_play_do(name, anim_name, morph_name, force_play, stand_still) do 
  357. 		thread_yield() 
  358. 	end 
  359. end 
  360.  
  361. function action_sequence_play( name, ... ) 
  362. 	action_sequence_table_play( name, arg ) 
  363. end 
  364.  
  365. function action_sequence_table_play( name, table ) 
  366.  
  367. 	local size = table.n 
  368. 	 
  369. 	if (size == nil) then 
  370. 		size = sizeof_table( table ) 
  371. 	end 
  372. 	 
  373. 	for x=1, size, 1 do 
  374. 		local data = table[x] 
  375. 		local typename = type(data) 
  376. 		 
  377. 		if (typename == "number") then 
  378. 			delay( data ) 
  379. 		elseif (typename == "table") then 
  380. 			action_sequence_table_play( data ) 
  381. 		else 
  382. 			action_or_state_play( name, data ) 
  383. 		end 
  384. 	end 
  385.  
  386. end 
  387.  
  388. function action_sequence_play_thread( name, ... ) 
  389. 	thread_new( "action_sequence_table_play", name, arg ) 
  390. end 
  391.  
  392. -- Make a helicopter go to a series of navpoints (could just be 1) 
  393. --  
  394. -- name:		name of the helicopter 
  395. -- dest:		name of destination navpoint(s) 
  396. -- 
  397. function airplane_fly_to(name, speed, ...) 
  398. 	local num_args, use_navmesh, force_path 
  399.  
  400. 	-- Wait until the resource is loaded. 
  401. 	-- character_wait_for_loaded_resource(name) 
  402. 			 
  403. 	num_args = arg.n 
  404.  
  405. 	local arg_type = type(arg[1]) 
  406. 	 
  407. 	if (arg_type == "table") then 
  408. 		num_args = sizeof_table(arg[1]) 
  409. 		if (airplane_fly_to_do(name, speed, num_args, arg[1])) then 
  410. 			local check_done = vehicle_pathfind_check_done(name) 
  411. 			 
  412. 			while ( check_done == 0) do 
  413. 				thread_yield() 
  414. 				check_done = vehicle_pathfind_check_done(name) 
  415. 			end 
  416. 			 
  417. 			return check_done == 1 
  418. 		else 
  419. 			return false 
  420. 		end 
  421. 	elseif (arg_type == "string") then 
  422. 		if (airplane_fly_to_do(name, speed, num_args, arg)) then 
  423. 			local check_done = vehicle_pathfind_check_done(name) 
  424. 			 
  425. 			while ( check_done == 0) do 
  426. 				thread_yield() 
  427. 				check_done = vehicle_pathfind_check_done(name) 
  428. 			end 
  429. 			 
  430. 			return check_done == 1 
  431. 		else 
  432. 			return false 
  433. 		end 
  434. 	end 
  435. end 
  436.  
  437. -- make an airplane land on a runway specified by 2 navpoints 
  438. -- Plane should already be heading in approximately the correct direction 
  439. -- Name:			name of the airplane 
  440. -- runway_start:	navpoint for the start of the runway, the plane will land after this position 
  441. --					should be oriented in the direction of the runway 
  442. function airplane_land(name, runway_start) 
  443. 	if (not airplane_land_do( name, runway_start )) then 
  444. 		return 
  445. 	end 
  446. 	 
  447. 	while( vehicle_pathfind_check_done(name) == 0) do 
  448. 		thread_yield() 
  449. 	end 
  450.  
  451. end 
  452.  
  453. -- Make an airplane takeoff straight infront of them 
  454. -- name:		name of the airplane 
  455. -- 
  456. function airplane_takeoff(name) 
  457. 	if (not airplane_takeoff_do( name )) then 
  458. 		return 
  459. 	end 
  460. 	 
  461. 	while( vehicle_pathfind_check_done(name) == 0) do 
  462. 		thread_yield() 
  463. 	end 
  464.  
  465. end 
  466.  
  467. -- Cause a character to attack another character 
  468. -- 
  469. -- attacker:	name of attacker 
  470. -- target:		(optional) name of target (if not specified, player is the target) 
  471. -- yield:		(optional) set to true to yield until attack is finished 
  472. -- 
  473. function attack(attacker, target, yield) 
  474. 	attack_do(attacker, target) 
  475. end 
  476.  
  477. -- Checks whether the npc or target is dead before attacking 
  478. -- 
  479. function attack_safe( npc_name, target, yield ) 
  480. 	if target == nil then 
  481. 		target = CLOSEST_PLAYER 
  482. 	end 
  483.  
  484. 	if ( ( not character_is_dead( npc_name ) ) and ( ( not character_is_dead( target ) ) ) ) then 
  485. 		attack( npc_name, target, yield )  
  486. 	end 
  487. end 
  488.  
  489. function attack_closest_player( npc_name, yield ) 
  490.    local distance, closest_player = get_dist_closest_player_to_object( npc_name ) 
  491.    attack_safe( npc_name, closest_player, yield ) 
  492. end 
  493.  
  494. function character_is_ready_to_speak( speaking_character ) 
  495.    -- Check for a character that does not exist first 
  496.    if (not character_exists(speaking_character)) then 
  497. 		return false 
  498. 	end 
  499.  
  500. 	if (character_is_dead(speaking_character)) then 
  501. 		return false 
  502. 	end 
  503.  
  504. 	if (character_is_ragdolled(speaking_character)) then 
  505. 		return false 
  506. 	end 
  507. 	 
  508. 	if (character_is_on_fire(speaking_character)) then 
  509.       return false 
  510.    end 
  511.  
  512. 	-- The character can speak 
  513.    return true 
  514. end 
  515.  
  516. -- Plays a conversation, which consists of a series 
  517. -- of lines played by characters. 
  518. -- 
  519. -- dialog_stream: A table containing dialog stream segments. 
  520. --                Each segment has a speaking character name, 
  521. --                the name of the audio to play, and a delay in 
  522. --                seconds after the audio is played for the 
  523. --                next one to be played. 
  524. --                For cellphone calls, the character name isn't 
  525. --                necessary. 
  526. -- 
  527. -- cellphone_call: (optional, default NOT_CALL) If this is a 
  528. --                 cellphone call, pass in the type of call here: 
  529. --                   NOT_CALL 
  530. --                   OUTGOING_CALL 
  531. --                   INCOMING_CALL 
  532. -- 
  533. function audio_play_conversation( dialog_stream, cellphone_call ) 
  534.    if ( cellphone_call == nil ) then 
  535.       cellphone_call = NOT_CALL 
  536.    end 
  537.  
  538.    -- Open with the cellphone, if this is a cellphone 
  539.    -- conversation 
  540.    if ( cellphone_call == INCOMING_CALL ) then 
  541.       cellphone_animate_start_do() 
  542.       delay(0.5) 
  543.    elseif ( cellphone_call == OUTGOING_CALL ) then 
  544.       cellphone_animate_start_do() 
  545.       audio_play( CELLPHONE_OUTGOING, "foley", true ) 
  546.       delay(0.5) 
  547.    end 
  548.  
  549. 	-- Build a list of characters that will be tested for readyness before any line in the 
  550. 	-- conversation is played. We only use this list for NOT_CALL conversations. 
  551. 	local character_list = {} 
  552. 	if (cellphone_call == NOT_CALL) then 
  553. 		for segment_index, dialog_segment in pairs( dialog_stream ) do 
  554. 			local speaking_character = dialog_segment[DIALOG_STREAM_CHAR_NAME_INDEX] 
  555. 			character_list[speaking_character] = speaking_character 
  556. 		end 
  557. 	end 
  558.  
  559. 	local function dialog_characters_ready() 
  560. 		for i,character in pairs(character_list) do 
  561. 			if (not character_is_ready_to_speak(character)) then 
  562. 				return false 
  563. 			end 
  564. 		end 
  565. 		return true 
  566. 	end 
  567.  
  568.    for segment_index, dialog_segment in pairs( dialog_stream ) do 
  569.       local audio_name = dialog_segment[DIALOG_STREAM_AUDIO_NAME_INDEX] 
  570.       local speaking_character = dialog_segment[DIALOG_STREAM_CHAR_NAME_INDEX] 
  571.       local delay_seconds = dialog_segment[DIALOG_STREAM_DELAY_SECONDS_INDEX] 
  572. 		local anim_action = dialog_segment[DIALOG_STREAM_ANIM_ACTION_INDEX] 
  573.  
  574.       -- Play the dialog stream for each character 
  575.       if ( cellphone_call == NOT_CALL ) then 
  576.          repeat 
  577.             thread_yield() 
  578.          until ( dialog_characters_ready() ) 
  579.  
  580. 			local playing_action = (	(anim_action ~= nil) 
  581. 												and (not character_is_in_vehicle(speaking_character))  
  582. 												and (not character_is_combat_ready(speaking_character)) 
  583. 												and (not mesh_mover_wielding(speaking_character)) 
  584. 												and (vehicle_exit_check_done(speaking_character)) 
  585. 												and (vehicle_enter_check_done(speaking_character)) 
  586. 											) 
  587.  
  588. 			if (playing_action ) then	 
  589. 				inv_item_equip(nil,speaking_character) 
  590. 				action_play(speaking_character, anim_action, anim_action, true, 0.0, true) 
  591. 			end 
  592.          audio_play_for_character( audio_name, speaking_character, "voice", false, true) 
  593.          delay( delay_seconds ) 
  594.       -- Cellphone calls are different - just play the audio, don't use the character function unless 
  595.       -- it's the player. 
  596.       else 
  597.          -- For players, use audio_play_for_character so that the tag can be correctly translated 
  598.          if (	speaking_character ~= nil and character_is_player( speaking_character ) ) then 
  599.             -- Don't play lines unless and until the player is alive and in a state to deliver them 
  600.             repeat 
  601.                thread_yield() 
  602.             until ( character_is_ready_to_speak( speaking_character ) ) 
  603.             audio_play_for_character( audio_name, speaking_character, "voice", false, true) 
  604.          elseif ( speaking_character == CELLPHONE_CHARACTER or speaking_character == nil ) then 
  605.             -- for_cutscene = false, blocking = true, variant = nil, voice_distance = nil, cellphone_line = true 
  606.             audio_play_for_character( audio_name, LOCAL_PLAYER, "voice", false, true, nil, nil, true ) 
  607.          else 
  608.             script_assert( false, "You must specify CELLPHONE_CHARACTER as the speaking character ( or leave it at nil ) for the other side of a cellphone conversation." ) 
  609.          	audio_play( audio_name, "voice", true ) 
  610.          end 
  611.          delay( delay_seconds ) 
  612.       end 
  613.    end 
  614.  
  615.    -- Close the cellphone, if this was a cellphone 
  616.    -- conversation 
  617.    if ( cellphone_call ~= NOT_CALL ) then 
  618.       cellphone_animate_stop_do() 
  619.    end 
  620. end 
  621.  
  622. -- Plays a conversation, which consists of a series of lines played by characters. 
  623. -- 
  624. -- dialog_stream: A table containing dialog stream segments. Each segment has a speaking character name, 
  625. --                the name of the audio to play, and a delay in seconds after the audio is played for the 
  626. --                next one to be played. Conversation will not exectute unless the speaker is in a vehicle. 
  627. -- 
  628. function audio_play_conversation_in_vehicle(dialog_stream) 
  629. 	-- Loop through the table conversation... 
  630.    for segment_index, dialog_segment in pairs( dialog_stream ) do 
  631.       local audio_name = dialog_segment[DIALOG_STREAM_AUDIO_NAME_INDEX] 
  632.       local speaking_character = dialog_segment[DIALOG_STREAM_CHAR_NAME_INDEX] 
  633.       local delay_seconds = dialog_segment[DIALOG_STREAM_DELAY_SECONDS_INDEX] 
  634.  
  635. 		-- Conversation requires them to be in a vehicle 
  636. 		while (not character_is_in_vehicle(speaking_character)) do 
  637. 			thread_yield() 
  638. 		end 
  639.  
  640.       -- Play the dialog stream for each character 
  641. 		audio_play_for_character(audio_name, speaking_character, "voice", false, true) 
  642. 		delay(delay_seconds) 
  643.    end 
  644. end 
  645.  
  646. -- Play 2D audio 
  647. -- 
  648. -- audio_name:		name of audio to play 
  649. -- type_name:		(optional) name of audio type 
  650. --										foley 
  651. --										voice 
  652. --										music 
  653. --										ambient 
  654. -- blocking:		(optional) true or false 
  655. -- 
  656. -- returns:			audio instance handle 
  657. -- 
  658. function audio_play(audio_name, type_name, blocking, ignore_fade) 
  659. 	local handle = audio_play_do(audio_name, type_name, ignore_fade) 
  660. 	 
  661. 	if (not blocking) then 
  662. 		return handle; 
  663. 	end 
  664. 	 
  665. 	while (audio_is_playing(handle)) do 
  666. 		thread_yield() 
  667. 	end 
  668. 	 
  669. 	return -1; 
  670. end 
  671.  
  672. -- Play a cellphone ring... and conversation 
  673. --		doesn't put put a "press Y to..." message 
  674. --    rings 2* and then plays conversation. 
  675. --    Also animates the player 
  676. -- ring_name:		name of ring tone from foley.xtbl 
  677. -- conv_name:		name of the conversation from the voice.xtbl 
  678. -- 
  679. function audio_play_for_cellphone_force(ring_name, conv_name ) 
  680.  
  681. 	audio_play(ring_name, "foley", false, true) 
  682. 	delay(0.5) 
  683. 	audio_play(ring_name, "foley", false, true) 
  684. 	delay(0.5) 
  685. 	cellphone_animate_start_do() 
  686.  
  687. 	-- RCS: I think these should probably play in 2D...so audio_play would be more appropriate... 
  688. 	audio_play_for_character(conv_name, LOCAL_PLAYER, "voice", false, true) 
  689. 	cellphone_animate_stop_do() 
  690.  
  691. end 
  692.  
  693. -- Play a riff of 3D audio on a character 
  694. -- 
  695. -- audio_name:		name of audio to play 
  696. -- human_name:		name of character to play audio on 
  697. -- type_name:		(optional) name of audio type 
  698. --										foley 
  699. --										voice 
  700. --										music 
  701. --										ambient 
  702. -- for_cutscene:	play for a cutscene 
  703. -- blocking: function blocks until line is played 
  704. -- variant: ??? 
  705. -- voice_distance: ??? 
  706. -- cellphone_line: (optional, default false) 
  707. --                 if this is a line coming from a cellphone 
  708. -- ignore_fade: (optional, default false) 
  709. --						 if true, the audio will ignore the screen fade's volume multiplier 
  710. -- 
  711. -- returns:			audio instance handle 
  712. -- 
  713. function audio_play_for_character(audio_name, human_name, type_name, for_cutscene, blocking, variant, voice_distance, cellphone_line, ignore_fade)	 
  714. 	if (character_is_dead(human_name)) then 
  715. 		return -1, 0 
  716. 	end 
  717.    if ( cellphone_line == nil ) then 
  718.       cellphone_line = false 
  719.    end 
  720.  
  721. 	-- If we're playing a voice line, update the audio name to reflect the player's persona. 
  722. 	local new_audio_name = audio_name 
  723. 	if ( (type_name == "voice") and (character_is_player(human_name)) and cellphone_line == false ) then 
  724. 		new_audio_name = persona_trigger_get_player_prefix(human_name) .. audio_name 
  725. 	end 
  726.  
  727. 	local handle, play_time = audio_play_for_character_do(new_audio_name, human_name, type_name, blocking, variant, voice_distance, cellphone_line, ignore_fade) 
  728.  
  729. 	if (not(blocking)) then 
  730. 		return handle, play_time; 
  731. 	end 
  732.  
  733. 	-- While playing blocking audio, prevent random persona lines from playing 
  734. 	if (character_is_player(human_name)) then 
  735. 		audio_suppress_ambient_player_lines(true) 
  736. 	else 
  737. 		npc_suppress_persona(human_name, true) 
  738. 	end 
  739. 	 
  740. 	if (handle > 0) then 
  741. 		while (audio_is_playing(handle)) do 
  742. 			thread_yield() 
  743. 		end 
  744. 	else 
  745. 		delay( play_time ) 
  746. 	end 
  747.  
  748. 	-- Allow random persona lines to play again 
  749. 	if (character_is_player(human_name)) then 
  750. 		audio_suppress_ambient_player_lines(false) 
  751. 	else 
  752. 		npc_suppress_persona(human_name, true) 
  753. 	end	 
  754.  
  755. 	return -1, 0 
  756. end 
  757.  
  758. function audio_play_for_character_weapon( audio_name, character, type_name, blocking)	 
  759. 	local handle = audio_play_for_character_weapon_do( audio_name, character, type_name) 
  760. 	 
  761. 	if not blocking then 
  762. 		return handle 
  763. 	end 
  764. 	 
  765. 	if handle >= 0 then 
  766. 		repeat  
  767. 			thread_yield() 
  768. 		until not audio_is_playing(handle) 
  769. 		return 0 
  770. 	end 
  771.  
  772. 	return -1 
  773. end 
  774.  
  775. function audio_play_for_mover( audio_name, script_mover, type_name, blocking ) 
  776.  
  777. 	local handle = audio_play_for_mover_do( audio_name, script_mover, type_name ) 
  778. 	 
  779. 	if (not blocking) then 
  780. 		return handle 
  781. 	end 
  782. 	 
  783. 	if (handle > 0) then 
  784. 		while (audio_is_playing(handle)) do 
  785. 			thread_yield() 
  786. 		end 
  787. 	end 
  788. 	 
  789. 	return -1 
  790. end 
  791.  
  792. -- Play 2D audio 
  793. -- 
  794. -- audio_id:		id of audio to play 
  795. -- type:				type of audio id 
  796. -- blocking:		(optional) 
  797. -- 
  798. -- returns:			audio instance handle 
  799. -- 
  800. function audio_play_id(audio_id, type, blocking) 
  801. 	local handle = audio_play_id_do(audio_id, type) 
  802. 	 
  803. 	if (not blocking) then 
  804. 		return handle; 
  805. 	end 
  806. 	 
  807. 	while (audio_is_playing(handle)) do 
  808. 		thread_yield() 
  809. 	end 
  810. 	 
  811. 	return -1; 
  812. end 
  813.  
  814. -- Play a riff of 3D audio on a character 
  815. -- 
  816. -- human_name:		name of character to play audio on 
  817. -- audio_id:		the id of the audio to play 
  818. -- type:				the type id of the audio_id to play 
  819. -- blocking:		(optional) wait for the audio to finish playing...if this is a voice, then it will play even if it is out of range 
  820. -- variant:			(optional) the variant to play 
  821. -- distance:		(optional) the distance override 
  822. -- 
  823. -- returns:			audio instance handle 
  824. -- 
  825. function audio_play_id_for_character(human_name, audio_id, type, blocking, variant, voice_distance) 
  826. 	if (character_is_dead(human_name)) then 
  827. 		return -1 
  828. 	end 
  829. 	 
  830. 	local	handle = audio_play_id_for_character_do(human_name, audio_id, type, blocking, variant, voice_distance) 
  831.  
  832. 	if (not blocking) then 
  833. 		return handle 
  834. 	end 
  835. 	 
  836. 	while (audio_is_playing(handle)) do 
  837. 		thread_yield() 
  838. 	end 
  839. 	 
  840. 	return -1 
  841. end 
  842.  
  843. -- Play 3D audio at a navpoint 
  844. -- 
  845. -- navpoint_name:	name of navpoint to play sound at 
  846. -- audio_id:		id of audio to play 
  847. -- type:				type of audio id 
  848. -- blocking:		(optional) 
  849. -- 
  850. -- returns:			audio instance handle 
  851. -- 
  852. -- 
  853. function audio_play_id_for_navpoint(navpoint_name, audio_id, type, blocking) 
  854. 	local handle = audio_play_id_for_navpoint_do(navpoint_name, audio_id, type) 
  855.  
  856. 	if (not blocking) then 
  857. 		return handle 
  858. 	end 
  859.  
  860. 	while (audio_is_playing(handle)) do 
  861. 		thread_yield() 
  862. 	end 
  863.  
  864. 	return -1 
  865. end 
  866.  
  867. -- Return when the bink movie is done playing 
  868. -- 
  869. function bink_play_movie(filename) 
  870. 	if (coop_is_active()) then 
  871. 		return 
  872. 	end 
  873.  
  874. 	-- Play the movie 
  875. 	bink_play_movie_do(filename) 
  876.  
  877. 	-- Block until it is finished 
  878. 	while (not bink_movie_done()) do 
  879. 		thread_yield() 
  880. 	end 
  881. end 
  882.  
  883. -- Return camera movement to default behavior 
  884. -- 
  885. -- snap:	(optional) set to true to jump directly to default position, else set to false 
  886. -- 
  887. function camera_begin_script(script_name, ...) 
  888. 	local yield 
  889.  
  890. 	if (arg.n > 0) then 
  891. 		yield = arg[1] 
  892. 	else 
  893. 		yield = false 
  894. 	end 
  895.  
  896. 	camera_begin_script_do(script_name) 
  897.  
  898. 	if (yield) then	 
  899. 		while (not(camera_script_is_finished())) do 
  900. 			thread_yield() 
  901. 		end 
  902. 	end 
  903. end 
  904.  
  905. -- Smoothly move the camera to look through the specified navpoint 
  906. -- 
  907. -- navp:			navpoint to look through 
  908. -- duration:	duration of movement 
  909. -- 
  910. function camera_look_through(navp, duration, yield) 
  911. 	camera_look_through_do(navp, duration) 
  912.  
  913. 	if (yield) then	 
  914. 		while (not(camera_script_is_finished())) do 
  915. 			thread_yield() 
  916. 		end 
  917. 	end 
  918. end 
  919.  
  920. function character_take_human_shield( character, victim ) 
  921.    character_take_human_shield_do( character, victim ) 
  922.  
  923.    -- loop as long as grabber and grabee are alive until we've succeeded 
  924.    while ( character_is_dead( character ) == false and 
  925.            character_is_dead( victim ) == false and 
  926. 	   character_take_human_shield_check_done( character, victim) == false) do 
  927.       thread_yield(); 
  928.    end 
  929. end 
  930.  
  931. function character_voice_block(char) 
  932. 	while (character_void_is_playing(char)) do 
  933. 		thread_yield() 
  934. 	end 
  935. end 
  936.  
  937. -- Wait for the human's resources to be loaded. 
  938. -- 
  939. -- name:	Name of the human. 
  940. -- 
  941. function character_wait_for_loaded_resource(name) 
  942. 	while (not(character_check_resource_loaded(name))) do 
  943. 		thread_yield() 
  944. 	end 
  945. end 
  946.  
  947. function console_wrapper( function_name ) 
  948. 	_UGGlobals[function_name]() 
  949. end 
  950.  
  951. -- Intro for a cutscene 
  952. -- 
  953. function cutscene_in() 
  954.  
  955. 	if ( character_is_dead(LOCAL_PLAYER) ) then 
  956. 		return 
  957. 	end 
  958.  
  959. 	fade_out(1.0) 
  960. 	fade_out_block() 
  961. end 
  962.  
  963. -- Play a cutscene 
  964. -- 
  965. -- name:				name of cutscene to play 
  966. -- group_name:		group for the cutscene to load before returning. 
  967. -- teleport_name:	name of script_navpoint cutscene will position player at. 
  968. -- 
  969. function cutscene_play(name, group_name, teleport_name, fade_in_after) 
  970. 	cutscene_in() -- ScottP wants all cutscenes to fade in. 
  971. 	 
  972. 	local function convert_to_table( var ) 
  973. 		if (var == "" or var == nil) then 
  974. 			return nil 
  975. 		elseif (type(var) == "table") then		 
  976. 			return var 
  977. 		else 
  978. 			return { var, n = 1 } 
  979. 		end 
  980. 	end 
  981. 	 
  982. 	local converted_group = convert_to_table( group_name ) 
  983. 	local converted_teleports = convert_to_table( teleport_name ) 
  984. 	 
  985. 	cutscene_play_do(name, converted_group, converted_teleports, fade_in_after) 
  986.  
  987. 	while (not(cutscene_play_check_done())) do 
  988. 		thread_yield() 
  989. 	end 
  990. end 
  991.  
  992. -- Outtro from a cutscene 
  993. -- 
  994. function cutscene_out() 
  995. 	fade_in(0.5) 
  996. 	fade_in_block() 
  997. end 
  998.  
  999. function cutscene_tester( cutscene_name ) 
  1000. 	cutscene_in( cutscene_name ) 
  1001. 	cutscene_play( cutscene_name ) 
  1002. end 
  1003.  
  1004. -- Returns an event state tracker for use by the trigger_event_state_tracker 
  1005. -- function using all legal player tags.  If nothing is sent in, then the  
  1006. -- states default to false. 
  1007. -- 
  1008. -- starting_state: Initial state for all players, true or false.  For example,  
  1009. -- if the event state is "players in car," then set this to false if the players 
  1010. --  start outside the car. 
  1011. -- 
  1012. function event_state_tracker_create(starting_state) 
  1013. 	if starting_state == nil then 
  1014. 		starting_state = false 
  1015. 	end 
  1016. 	 
  1017. 	local tracker = {} 
  1018. 	for i, p in pairs(PLAYER_TAG_LIST) do 
  1019. 		tracker[p] = starting_state 
  1020. 	end 
  1021. 	 
  1022. 	return tracker 
  1023. end 
  1024.  
  1025. -- Gets the value of the state for a particular player, given 
  1026. -- that player and the event state tracker. 
  1027. -- 
  1028. function event_state_tracker_get_state( event_state_tracker, player ) 
  1029. 	return event_state_tracker[player] 
  1030. end 
  1031.  
  1032. function fade_in_block() 
  1033. 	while( fade_get_percent() > 0.0 ) do 
  1034. 		thread_yield() 
  1035. 	end 
  1036. 	 
  1037. 	thread_yield() 
  1038. end 
  1039.  
  1040. function fade_out_block() 
  1041. 	while( fade_get_percent() < 1.0 ) do 
  1042. 		thread_yield() 
  1043. 	end 
  1044. 	 
  1045. 	thread_yield() 
  1046. end 
  1047.  
  1048. -- Make a NPC fire at a navpoint 
  1049. -- 
  1050. -- name:					NPC that is firing 
  1051. -- fire_at_navpoint:	navpoint to fire at 
  1052. -- fire_once:			(optional) set to true to only fire once at the navpoint 
  1053. -- 
  1054. function force_fire(name, fire_at_navpoint, fire_once) 
  1055. 	if (force_fire_do(name, fire_at_navpoint, fire_once)) then 
  1056. 		while (not(force_ai_mode_check_done(name))) do 
  1057. 			thread_yield() 
  1058. 		end 
  1059. 	end 
  1060. end 
  1061.  
  1062. -- Make a NPC fire at an object's position 
  1063. -- 
  1064. -- name:					NPC that is firing 
  1065. -- fire_at_object:	object to fire at 
  1066. -- fire_once:			(optional) set to true to only fire once at the object 
  1067. -- 
  1068. function force_fire_object_position( name, fire_at_object, fire_once ) 
  1069.    if ( force_fire_object_position_do( name, fire_at_object, fire_once ) ) then 
  1070.       while ( not ( force_ai_mode_check_done( name ) ) ) do 
  1071.          thread_yield() 
  1072.       end 
  1073.    end 
  1074. end 
  1075.  
  1076. -- Make a NPC fire at a target 
  1077. -- 
  1078. -- name:					NPC that is firing 
  1079. -- fire_at_target:	target to fire at 
  1080. -- fire_once:			(optional) set to true to only fire once at the target 
  1081. -- 
  1082. function force_fire_target(name, fire_at_target, fire_once) 
  1083. 	if (force_fire_target_do(name, fire_at_target, fire_once)) then 
  1084. 		while (not(force_ai_mode_check_done(name))) do 
  1085. 			thread_yield() 
  1086. 		end 
  1087. 	end 
  1088. end 
  1089.  
  1090. -- Make a NPC throw a grenade at a navpoint 
  1091. -- 
  1092. -- name:					NPC that is throwing 
  1093. -- target_navp:		navpoint to throw at 
  1094. -- throw_pitch:		(optional) pitch to throw at 
  1095. -- throw_speed:		(optional) speed to throw at 
  1096. -- 
  1097. function force_throw(name, target_navp, throw_pitch, throw_speed) 
  1098. 	if (force_throw_do(name, target_navp, throw_pitch, throw_speed)) then 
  1099. 		while (not(force_ai_mode_check_done(name))) do 
  1100. 			thread_yield() 
  1101. 		end 
  1102. 	end 
  1103. end 
  1104.  
  1105. -- Make an NPC throw a grenade at a character 
  1106. -- 
  1107. -- name:				NPC that is throwing 
  1108. -- target:			Target NPC or Player 
  1109. function force_throw_char(name, target) 
  1110. 	if (force_throw_char_do(name, target)) then 
  1111. 		while (not(force_ai_mode_check_done(name))) do 
  1112. 			thread_yield() 
  1113. 		end 
  1114. 	end 
  1115. end 
  1116.  
  1117. function get_dist_char_to_char(obj1, obj2) 
  1118. 	return get_dist(obj1, obj2) 
  1119. end 
  1120.  
  1121. function get_dist_char_to_nav(obj1, obj2) 
  1122. 	return get_dist(obj1, obj2) 
  1123. end 
  1124.  
  1125. function get_dist_char_to_vehicle(obj1, obj2) 
  1126. 	return get_dist(obj1, obj2) 
  1127. end 
  1128.  
  1129. -- Gets the distance of the closest player to the given object, and returns that 
  1130. -- distance along with whichever player is closest 
  1131. -- 
  1132. -- object: object to find distance from 
  1133. -- player_list: (optional) list of players to test, defaults to all players 
  1134. -- 
  1135. -- NOTE: This function is returning two values! 
  1136. function get_dist_closest_player_to_object(object, player_list) 
  1137. 	if player_list == nil then 
  1138. 		player_list = player_names_get_all() 
  1139. 	end 
  1140. 	 
  1141. 	if sizeof_table( player_list ) == 0 then 
  1142. 		return 
  1143. 	end 
  1144. 	 
  1145. 	local closest_dist = get_dist(player_list[1], object) 
  1146. 	local closest_player = player_list[1] 
  1147. 	 
  1148. 	-- Spin through the available players 
  1149. 	for i, p in pairs(player_list) do 
  1150. 		local current_dist = get_dist(p, object) 
  1151. 		if current_dist < closest_dist then 
  1152. 			closest_dist = current_dist 
  1153. 			closest_player = p 
  1154. 		end 
  1155. 	end 
  1156. 	 
  1157. 	return closest_dist, closest_player 
  1158. end 
  1159.  
  1160. function get_dist_mover_to_nav(obj1, obj2) 
  1161. 	return get_dist(obj1, obj2) 
  1162. end 
  1163.  
  1164. function get_dist_vehicle_to_nav(obj1, obj2) 
  1165. 	return get_dist(obj1, obj2) 
  1166. end 
  1167.  
  1168. function get_dist_vehicle_to_mover(obj1, obj2) 
  1169. 	return get_dist(obj1, obj2) 
  1170. end 
  1171.  
  1172. function get_other_sync_type( sync_type ) 
  1173.    if ( sync_type == SYNC_LOCAL ) then 
  1174.       return SYNC_REMOTE 
  1175.    elseif ( sync_type == SYNC_REMOTE ) then 
  1176.       return SYNC_LOCAL 
  1177.    end 
  1178.  
  1179.    return SYNC_ALL 
  1180. end 
  1181.  
  1182. function get_other_coop_player(player_name) 
  1183.    if ( player_name == LOCAL_PLAYER ) then 
  1184.       return REMOTE_PLAYER 
  1185.    elseif ( player_name == REMOTE_PLAYER ) then 
  1186.       return LOCAL_PLAYER 
  1187.    end 
  1188.  
  1189.    return REMOTE_PLAYER 
  1190. end 
  1191.  
  1192. -- Spawn a group 
  1193. -- 
  1194. -- name: Name of the group to spawn 
  1195. -- block (optional, default false): Don't continue this thread until they're all streamed in.  Yield to other threads. 
  1196. -- 
  1197. function group_create(name, block) 
  1198. 	if (block == nil) then 
  1199. 		block = false 
  1200. 	end 
  1201. 	 
  1202. 	group_create_do(name) 
  1203.  
  1204. 	local handle = thread_new("group_create_check_done_loop",name) 
  1205.  
  1206. 	while(block and not thread_check_done(handle)) do 
  1207. 		thread_yield() 
  1208. 	end 
  1209. end 
  1210.  
  1211. function group_create_check_done_loop(name) 
  1212. 	while (not(group_create_check_done(name))) do 
  1213. 		thread_yield() 
  1214. 	end 
  1215. end 
  1216.  
  1217. -- Spawn a group as hidden 
  1218. -- 
  1219. -- name: Name of the group to spawn 
  1220. -- 
  1221. function group_create_hidden(name, block) 
  1222. 	group_create_hidden_do(name) 
  1223.  
  1224. 	local handle = thread_new("group_create_check_done_loop", name) 
  1225.  
  1226. 	if (block) then 
  1227. 		while (not thread_check_done(handle)) do 
  1228. 			thread_yield() 
  1229. 		end 
  1230. 	end 
  1231. end 
  1232.  
  1233. -- Internal use: generalized helicopter_fly_to function 
  1234. -- 
  1235. -- name:		name of the helicopter 
  1236. -- dest:		name of destination navpoint(s) 
  1237. -- direct:		if true, move directly, ignoring heightmap 
  1238. -- follow:		if non-empty, target vehicle to follow 
  1239. -- continue_at_goal:	if true, continue forward at goal 
  1240. -- path:		list of navpoints to use for path 
  1241. -- 
  1242. function helicopter_fly_to_internal(name, speed, direct, follow, continue_at_goal, path) 
  1243. 	local num_args 
  1244. 	num_args = path.n 
  1245.  
  1246. 	local arg_type = type(path[1]) 
  1247. 	 
  1248. 	if (arg_type == "table") then 
  1249. 		num_args = sizeof_table(path[1]) 
  1250. 		if (helicopter_fly_to_do(name, speed, direct, follow, continue_at_goal, num_args, path[1])) then 
  1251. 			local check_done = vehicle_pathfind_check_done(name) 
  1252. 			 
  1253. 			while ( check_done == 0) do 
  1254. 				thread_yield() 
  1255. 				check_done = vehicle_pathfind_check_done(name) 
  1256. 			end 
  1257. 			 
  1258. 			return check_done == 1 
  1259. 		else 
  1260. 			return false 
  1261. 		end 
  1262. 	elseif (arg_type == "string") then 
  1263. 		if (helicopter_fly_to_do(name, speed, direct, follow, continue_at_goal, num_args, path)) then 
  1264. 			local check_done = vehicle_pathfind_check_done(name) 
  1265. 			 
  1266. 			while ( check_done == 0) do 
  1267. 				thread_yield() 
  1268. 				check_done = vehicle_pathfind_check_done(name) 
  1269. 			end 
  1270. 			 
  1271. 			return check_done == 1 
  1272. 		else 
  1273. 			return false 
  1274. 		end 
  1275. 	end 
  1276. end 
  1277.  
  1278. -- Make a helicopter go to a series of navpoints (could just be 1) 
  1279. --  
  1280. -- name:		name of the helicopter 
  1281. -- dest:		name of destination navpoint(s) 
  1282. -- 
  1283. function helicopter_fly_to(name, speed, ...) 
  1284. 	return helicopter_fly_to_internal(name, speed, false, "", false, arg); 
  1285. end 
  1286.  
  1287. -- Make a helicopter go to a series of navpoints (could just be 1) 
  1288. -- ignores heightmap and uses points directly as control points for the path 
  1289. -- WARNING BE CAREFUL USING THIS!!!! HELICOPTER WILL NOT AVOID ANYTHING!!! 
  1290. --  
  1291. -- name:		name of the helicopter 
  1292. -- dest:		name of destination navpoint(s) 
  1293. -- 
  1294. function helicopter_fly_to_direct(name, speed, ...) 
  1295. 	return helicopter_fly_to_internal(name, speed, true, "", false, arg) 
  1296. end 
  1297.  
  1298. -- Make a helicopter go to a series of navpoints (could just be 1) while following a target 
  1299. -- ignores heightmap and uses points directly as control points for the path 
  1300. -- WARNING BE CAREFUL USING THIS!!!! HELICOPTER WILL NOT AVOID ANYTHING!!! 
  1301. --  
  1302. -- name:		name of the helicopter 
  1303. -- dest:		name of destination navpoint(s) 
  1304. -- target:		name of target to follow 
  1305. -- 
  1306. function helicopter_fly_to_direct_follow(name, speed, target, ...) 
  1307. 	return helicopter_fly_to_internal(name, speed, true, target, false, arg) 
  1308. end 
  1309.  
  1310. -- Make a helicopter go to a series of navpoints (could just be 1) while following a target 
  1311. --  
  1312. -- name:		name of the helicopter 
  1313. -- dest:		name of destination navpoint(s) 
  1314. -- target:		name of target to follow 
  1315. -- 
  1316. function helicopter_fly_to_follow(name, speed, target, ...) 
  1317. 	return helicopter_fly_to_internal(name, speed, false, target, false, arg) 
  1318. end 
  1319.  
  1320. -- Make a helicopter go to a series of navpoints (could just be 1) without stopping 
  1321. --  
  1322. -- name:		name of the helicopter 
  1323. -- dest:		name of destination navpoint(s) 
  1324. -- 
  1325. function helicopter_fly_to_dont_stop(name, speed, ...) 
  1326. 	return helicopter_fly_to_internal(name, speed, false, "", true, arg); 
  1327. end 
  1328.  
  1329. -- Make a helicopter go to a series of navpoints (could just be 1) without stopping 
  1330. -- ignores heightmap and uses points directly as control points for the path 
  1331. -- WARNING BE CAREFUL USING THIS!!!! HELICOPTER WILL NOT AVOID ANYTHING!!! 
  1332. --  
  1333. -- name:		name of the helicopter 
  1334. -- dest:		name of destination navpoint(s) 
  1335. -- 
  1336. function helicopter_fly_to_direct_dont_stop(name, speed, ...) 
  1337. 	return helicopter_fly_to_internal(name, speed, true, "", true, arg) 
  1338. end 
  1339.  
  1340. -- Make a helicopter go to a series of navpoints (could just be 1) while following a target without stopping 
  1341. -- ignores heightmap and uses points directly as control points for the path 
  1342. -- WARNING BE CAREFUL USING THIS!!!! HELICOPTER WILL NOT AVOID ANYTHING!!! 
  1343. --  
  1344. -- name:		name of the helicopter 
  1345. -- dest:		name of destination navpoint(s) 
  1346. -- target:		name of target to follow 
  1347. -- 
  1348. function helicopter_fly_to_direct_follow_dont_stop(name, speed, target, ...) 
  1349. 	return helicopter_fly_to_internal(name, speed, true, target, true, arg) 
  1350. end 
  1351.  
  1352. -- Make a helicopter go to a series of navpoints (could just be 1) while following a target without stopping 
  1353. --  
  1354. -- name:		name of the helicopter 
  1355. -- dest:		name of destination navpoint(s) 
  1356. -- target:		name of target to follow 
  1357. -- 
  1358. function helicopter_fly_to_follow_dont_stop(name, speed, target, ...) 
  1359. 	return helicopter_fly_to_internal(name, speed, false, target, true, arg) 
  1360. end 
  1361.  
  1362. -- Add an item to the player's inventory 
  1363. -- 
  1364. -- item_name:	name of item to give 
  1365. -- count:		(optional) number of the item to give (default = 1) 
  1366. -- player:		(optional) player to add item to (default = LOCAL_PLAYER) 
  1367. -- equip_now:	(optional) forces item to become the currently equipped one (default = false) 
  1368. -- 
  1369. function inv_item_add(item_name, count, player, equip_now)	 
  1370. 	if (type(item_name) == "table" ) then 
  1371. 		local size = sizeof_table(item_name) 
  1372. 		 
  1373. 		for x=1, size, 1 do 
  1374. 			inv_item_add_do(item_name[x], count[x], player, equip_now) 
  1375. 		end	 
  1376. 	else 
  1377. 		inv_item_add_do(item_name, count, player, equip_now) 
  1378. 	end 
  1379. end 
  1380.  
  1381. function inv_item_get_all(char_name) 
  1382. 	return inv_item_get_all_do(char_name), inv_item_get_all_ammo_do(char_name) 
  1383. end 
  1384.  
  1385. function is_hood_owner( hood_name, ... ) 
  1386.  
  1387. 	if( arg.n > 0 ) then 
  1388. 		return is_hood_owner_do( hood_name, arg[1] ) 
  1389. 	end 
  1390. 		 
  1391. 	return is_hood_owner_do( hood_name, "Playas" ) 
  1392. end 
  1393.  
  1394. function is_player_tag(tag) 
  1395. 	-- Search the "closest" tags 
  1396. 	if tag == CLOSEST_PLAYER or tag == CLOSEST_TEAM1 or tag == CLOSEST_TEAM2 then 
  1397. 		return true 
  1398. 	end 
  1399. 	 
  1400. 	-- Loop through the player tags 
  1401. 	for i, player in pairs(PLAYER_TAG_LIST) do 
  1402. 		if tag == player then 
  1403. 			return true 
  1404. 		end 
  1405. 	end 
  1406. 	 
  1407. 	return false 
  1408. end 
  1409.  
  1410. -- Check line of sight between two human-types 
  1411. -- 
  1412. -- name_one, name_two:  Names of the people to check los between 
  1413. -- 
  1414. function los_check(name_one, name_two) 
  1415. 	local retval = false 
  1416. 	local current_los_result = -1 
  1417. 	local num_retries = 0 
  1418. 	-- It's possible for the los check to continually get deleted intead of processed 
  1419. 	-- For example, if one of the humans is hidden.  So only try re-issuing 100 times. 
  1420. 	while (current_los_result == -1 and num_retries < 100) do 
  1421. 		current_los_result = los_check_do(name_one, name_two) 
  1422. 		thread_yield() 
  1423. 		num_retries = num_retries + 1 
  1424. 	end 
  1425. 	if (current_los_result == 0) then 
  1426. 		return false 
  1427. 	end 
  1428. 	if (current_los_result == 1) then 
  1429. 		return true 
  1430. 	end 
  1431. 	return false 
  1432. end 
  1433.  
  1434. -- Object marking functions ---------------------------------------------------------- 
  1435.  
  1436. function marker_add_group(group_name, minimap_icon_name, ingame_effect_name, sync_type) 
  1437. 	if (sync_type == nil) then 
  1438. 		sync_type = SYNC_ALL 
  1439. 	end 
  1440.  
  1441. 	minimap_icon_add_group( group_name, minimap_icon_name, "", sync_type ) 
  1442. 	ingame_effect_add_group( group_name, ingame_effect_name, sync_type ) 
  1443. end 
  1444.  
  1445. function marker_add_item( item_name, minimap_icon_name, ingame_icon_name, sync_type ) 
  1446. 	if (sync_type == nil) then 
  1447. 		sync_type = SYNC_ALL 
  1448. 	end 
  1449.  
  1450. 	minimap_icon_add_item( item_name, minimap_icon_name, "", sync_type ) 
  1451. 	ingame_effect_add_item( item_name, ingame_icon_name, sync_type ) 
  1452. end 
  1453.  
  1454. function marker_add_mover( mover_name, minimap_icon_name, ingame_icon_name, sync_type ) 
  1455. 	if (sync_type == nil) then 
  1456. 		sync_type = SYNC_ALL 
  1457. 	end 
  1458.  
  1459. 	minimap_icon_add_mover( mover_name, minimap_icon_name, "", sync_type ) 
  1460. 	ingame_effect_add_mover( mover_name, ingame_icon_name, sync_type ) 
  1461. end 
  1462.  
  1463. function marker_add_navpoint(nav_name, minimap_icon_name, ingame_icon_name, sync_type) 
  1464. 	if (sync_type == nil) then 
  1465. 		sync_type = SYNC_ALL 
  1466. 	end 
  1467.  
  1468. 	minimap_icon_add_navpoint(nav_name, minimap_icon_name, "", sync_type) 
  1469. 	ingame_effect_add_navpoint(nav_name, ingame_icon_name, sync_type) 
  1470. end 
  1471.  
  1472. function marker_add_npc(char_name, minimap_icon_name, ingame_icon_name, sync_type) 
  1473. 	if (not character_is_dead(char_name)) then 
  1474.  
  1475. 		if (sync_type == nil) then 
  1476. 			sync_type = SYNC_ALL 
  1477. 		end 
  1478. 	 
  1479. 		minimap_icon_add_npc(char_name, minimap_icon_name, "", sync_type) 
  1480. 		ingame_effect_add_npc(char_name, ingame_icon_name, sync_type) 
  1481. 	end 
  1482. end 
  1483.  
  1484. function marker_add_player( player_name, minimap_icon_name, ingame_icon_name, sync_type ) 
  1485. 	if not character_is_dead( player_name ) then 
  1486.  
  1487. 		if sync_type == nil then 
  1488. 			sync_type = SYNC_ALL 
  1489. 		end 
  1490. 	 
  1491. 		minimap_icon_add_player( player_name, minimap_icon_name, "", sync_type ) 
  1492. 		ingame_effect_add_player( player_name, ingame_icon_name, sync_type ) 
  1493. 	end 
  1494. end 
  1495.  
  1496. function marker_add_trigger(trigger_name, minimap_icon_name, ingame_effect_name, sync_type) 
  1497. 	if (sync_type == nil) then 
  1498. 		sync_type = SYNC_ALL 
  1499. 	end 
  1500.  
  1501. 	minimap_icon_add_trigger(trigger_name, minimap_icon_name, "", sync_type) 
  1502. 	ingame_effect_add_trigger(trigger_name, ingame_effect_name, sync_type) 
  1503. end 
  1504.  
  1505. function marker_add_vehicle(vehicle_name, minimap_icon_name, ingame_icon_name, sync_type) 
  1506. 	if (not vehicle_is_destroyed(vehicle_name)) then 
  1507.  
  1508. 	if (sync_type == nil) then 
  1509. 		sync_type = SYNC_ALL 
  1510. 	end 
  1511.  
  1512. 		minimap_icon_add_vehicle(vehicle_name, minimap_icon_name, "", sync_type) 
  1513. 		ingame_effect_add_vehicle(vehicle_name, ingame_icon_name, sync_type) 
  1514. 	end 
  1515. end 
  1516.  
  1517. function marker_remove_group( group_name, sync_type ) 
  1518. 	if (sync_type == nil) then 
  1519. 		sync_type = SYNC_ALL 
  1520. 	end 
  1521. 	 
  1522. 	minimap_icon_remove_group( group_name, sync_type ) 
  1523. 	ingame_effect_remove_group( group_name, sync_type ) 
  1524. end 
  1525.  
  1526. function marker_remove_item( item_name, sync_type ) 
  1527. 	if (sync_type == nil) then 
  1528. 		sync_type = SYNC_ALL 
  1529. 	end 
  1530. 	 
  1531. 	minimap_icon_remove_item( item_name, sync_type ) 
  1532. 	ingame_effect_remove_item( item_name, sync_type ) 
  1533. end 
  1534.  
  1535. function marker_remove_mover( mover_name, sync_type ) 
  1536. 	if (sync_type == nil) then 
  1537. 		sync_type = SYNC_ALL 
  1538. 	end 
  1539. 	 
  1540. 	minimap_icon_remove_mover( mover_name, sync_type ) 
  1541. 	ingame_effect_remove_mover( mover_name, sync_type ) 
  1542. end 
  1543.  
  1544. function marker_remove_navpoint(nav_name, sync_type) 
  1545. 	if (sync_type == nil) then 
  1546. 		sync_type = SYNC_ALL 
  1547. 	end 
  1548. 	 
  1549. 	minimap_icon_remove_navpoint(nav_name, sync_type) 
  1550. 	ingame_effect_remove_navpoint(nav_name, sync_type) 
  1551. end 
  1552.  
  1553. function marker_remove_npc(char_name, sync_type) 
  1554. 	if (sync_type == nil) then 
  1555. 		sync_type = SYNC_ALL 
  1556. 	end 
  1557.  
  1558. 	minimap_icon_remove_npc(char_name, sync_type) 
  1559. 	ingame_effect_remove_npc(char_name, sync_type) 
  1560. end 
  1561.  
  1562. function marker_remove_player( player_name, sync_type ) 
  1563. 	if (sync_type == nil) then 
  1564. 		sync_type = SYNC_ALL 
  1565. 	end 
  1566.  
  1567. 	minimap_icon_remove_player( player_name, sync_type ) 
  1568. 	ingame_effect_remove_player( player_name, sync_type ) 
  1569. end 
  1570.  
  1571. function marker_remove_trigger(trigger_name, sync_type) 
  1572. 	if (sync_type == nil) then 
  1573. 		sync_type = SYNC_ALL 
  1574. 	end 
  1575. 	 
  1576. 	minimap_icon_remove_trigger(trigger_name, sync_type) 
  1577. 	ingame_effect_remove_trigger(trigger_name, sync_type) 
  1578. end 
  1579.  
  1580. function marker_remove_vehicle(vehicle_name, sync_type) 
  1581. 	if (sync_type == nil) then 
  1582. 		sync_type = SYNC_ALL 
  1583. 	end 
  1584. 	 
  1585. 	minimap_icon_remove_vehicle(vehicle_name, sync_type) 
  1586. 	ingame_effect_remove_vehicle(vehicle_name, sync_type) 
  1587. end 
  1588.  
  1589. -- Adds a minimap icon to all members of a group 
  1590. -- 
  1591. -- name: name of group 
  1592. -- bitmap_name: name of minimap icon file 
  1593. -- bitmap_glow_name: (optional) name of minimap icon glow file 
  1594. -- sync_type: (optional) sync type 
  1595. -- 
  1596. function minimap_icon_add_group(name, bitmap_name, bitmap_glow_name, sync_type) 
  1597. 	minimap_icon_add_group_do(name, bitmap_name, bitmap_glow_name, nil, sync_type) 
  1598. end  
  1599.  
  1600. -- Adds a minimap icon to an item 
  1601. -- 
  1602. -- name: name of item 
  1603. -- bitmap_name: name of minimap icon file 
  1604. -- bitmap_glow_name: (optional) name of minimap icon glow file 
  1605. -- sync_type: (optional) sync type 
  1606. -- 
  1607. function minimap_icon_add_item(name, bitmap_name, bitmap_glow_name, sync_type) 
  1608. 	minimap_icon_add_item_do(name, bitmap_name, bitmap_glow_name, nil, sync_type) 
  1609. end  
  1610.  
  1611. -- Adds a minimap icon to a mover 
  1612. -- 
  1613. -- name: name of vehicle 
  1614. -- bitmap_name: name of minimap icon file 
  1615. -- bitmap_glow_name: (optional) name of minimap icon glow file 
  1616. -- sync_type: (optional) sync type 
  1617. -- 
  1618. function minimap_icon_add_mover(name, bitmap_name, bitmap_glow_name, sync_type) 
  1619. 	minimap_icon_add_mover_do(name, bitmap_name, bitmap_glow_name, nil, sync_type) 
  1620. end 
  1621.  
  1622. -- Adds a minimap icon to a navpoint 
  1623. -- 
  1624. -- name: name of navpoint 
  1625. -- bitmap_name: name of minimap icon file 
  1626. -- bitmap_glow_name: (optional) name of minimap icon glow file 
  1627. -- sync_type: (optional) sync type 
  1628. -- 
  1629. function minimap_icon_add_navpoint(name, bitmap_name, bitmap_glow_name, sync_type) 
  1630. 	minimap_icon_add_navpoint_do(name, bitmap_name, bitmap_glow_name, nil, sync_type) 
  1631. end  
  1632.  
  1633. -- Adds a minimap icon to an NPC 
  1634. -- 
  1635. -- name: name of NPC 
  1636. -- bitmap_name: name of minimap icon file 
  1637. -- bitmap_glow_name: (optional) name of minimap icon glow file 
  1638. -- sync_type: (optional) sync type 
  1639. -- 
  1640. function minimap_icon_add_npc(name, bitmap_name, bitmap_glow_name, sync_type) 
  1641. 	minimap_icon_add_npc_do(name, bitmap_name, bitmap_glow_name, nil, sync_type) 
  1642. end  
  1643.  
  1644. -- Adds a minimap icon to a player 
  1645. -- 
  1646. -- name: name of player 
  1647. -- bitmap_name: name of minimap icon file 
  1648. -- bitmap_glow_name: (optional) name of minimap icon glow file 
  1649. -- sync_type: (optional) sync type 
  1650. -- 
  1651. function minimap_icon_add_player( name, bitmap_name, bitmap_glow_name, sync_type ) 
  1652. 	minimap_icon_add_player_do( name, bitmap_name, bitmap_glow_name, nil, sync_type ) 
  1653. end  
  1654.  
  1655. -- Adds a minimap icon to a trigger 
  1656. -- 
  1657. -- name: name of trigger 
  1658. -- bitmap_name: name of minimap icon file 
  1659. -- bitmap_glow_name: (optional) name of minimap icon glow file 
  1660. -- sync_type: (optional) sync type 
  1661. -- 
  1662. function minimap_icon_add_trigger(name, bitmap_name, bitmap_glow_name, sync_type) 
  1663. 	minimap_icon_add_trigger_do(name, bitmap_name, bitmap_glow_name, nil, sync_type) 
  1664. end  
  1665.  
  1666. -- Adds a minimap icon to a vehicle 
  1667. -- 
  1668. -- name: name of vehicle 
  1669. -- bitmap_name: name of minimap icon file 
  1670. -- bitmap_glow_name: (optional) name of minimap icon glow file 
  1671. -- sync_type: (optional) sync type 
  1672. -- 
  1673. function minimap_icon_add_vehicle(name, bitmap_name, bitmap_glow_name, sync_type) 
  1674. 	minimap_icon_add_vehicle_do(name, bitmap_name, bitmap_glow_name, nil, sync_type) 
  1675. end  
  1676.  
  1677. ------------------------------------ 
  1678. -- The below are the same as the above, only with a radius 
  1679. ------------------------------------ 
  1680.  
  1681. -- Adds a minimap icon to all members of a group 
  1682. -- 
  1683. -- name: name of group 
  1684. -- bitmap_name: name of minimap icon file 
  1685. -- radius: radius of the minimap icon 
  1686. -- bitmap_glow_name: (optional) name of minimap icon glow file 
  1687. -- sync_type: (optional) sync type 
  1688. -- 
  1689. function minimap_icon_add_group_radius(name, bitmap_name, radius, bitmap_glow_name, sync_type) 
  1690. 	minimap_icon_add_group_do(name, bitmap_name, bitmap_glow_name, radius, sync_type) 
  1691. end  
  1692.  
  1693. -- Adds a minimap icon to an item 
  1694. -- 
  1695. -- name: name of item 
  1696. -- bitmap_name: name of minimap icon file 
  1697. -- radius: radius of the minimap icon 
  1698. -- bitmap_glow_name: (optional) name of minimap icon glow file 
  1699. -- sync_type: (optional) sync type 
  1700. -- 
  1701. function minimap_icon_add_item_radius(name, bitmap_name, radius, bitmap_glow_name, sync_type) 
  1702. 	minimap_icon_add_item_do(name, bitmap_name, bitmap_glow_name, radius, sync_type) 
  1703. end  
  1704.  
  1705. -- Adds a minimap icon to a navpoint 
  1706. -- 
  1707. -- name: name of navpoint 
  1708. -- bitmap_name: name of minimap icon file 
  1709. -- radius: radius of the minimap icon 
  1710. -- bitmap_glow_name: (optional) name of minimap icon glow file 
  1711. -- sync_type: (optional) sync type 
  1712. -- 
  1713. function minimap_icon_add_navpoint_radius(name, bitmap_name, radius, bitmap_glow_name, sync_type) 
  1714. 	minimap_icon_add_navpoint_do(name, bitmap_name, bitmap_glow_name, radius, sync_type) 
  1715. end  
  1716.  
  1717. -- Adds a minimap icon to an NPC 
  1718. -- 
  1719. -- name: name of NPC 
  1720. -- bitmap_name: name of minimap icon file 
  1721. -- radius: radius of the minimap icon 
  1722. -- bitmap_glow_name: (optional) name of minimap icon glow file 
  1723. -- sync_type: (optional) sync type 
  1724. -- 
  1725. function minimap_icon_add_npc_radius(name, bitmap_name, radius, bitmap_glow_name, sync_type) 
  1726. 	minimap_icon_add_npc_do(name, bitmap_name, bitmap_glow_name, radius, sync_type) 
  1727. end  
  1728.  
  1729. -- Adds a minimap icon to a player 
  1730. -- 
  1731. -- name: name of player 
  1732. -- bitmap_name: name of minimap icon file 
  1733. -- radius: radius of the minimap icon 
  1734. -- bitmap_glow_name: (optional) name of minimap icon glow file 
  1735. -- sync_type: (optional) sync type 
  1736. -- 
  1737. function minimap_icon_add_player_radius( name, bitmap_name, radius, bitmap_glow_name, sync_type ) 
  1738. 	minimap_icon_add_player_do( name, bitmap_name, bitmap_glow_name, radius, sync_type ) 
  1739. end  
  1740.  
  1741. -- Adds a minimap icon to a trigger 
  1742. -- 
  1743. -- name: name of trigger 
  1744. -- bitmap_name: name of minimap icon file 
  1745. -- radius: radius of the minimap icon 
  1746. -- bitmap_glow_name: (optional) name of minimap icon glow file 
  1747. -- sync_type: (optional) sync type 
  1748. -- 
  1749. function minimap_icon_add_trigger_radius(name, bitmap_name, radius, bitmap_glow_name, sync_type) 
  1750. 	minimap_icon_add_trigger_do(name, bitmap_name, bitmap_glow_name, radius, sync_type) 
  1751. end  
  1752.  
  1753. -- Adds a minimap icon to a vehicle 
  1754. -- 
  1755. -- name: name of vehicle 
  1756. -- bitmap_name: name of minimap icon file 
  1757. -- radius: radius of the minimap icon 
  1758. -- bitmap_glow_name: (optional) name of minimap icon glow file 
  1759. -- sync_type: (optional) sync type 
  1760. -- 
  1761. function minimap_icon_add_vehicle_radius(name, bitmap_name, radius, bitmap_glow_name, sync_type) 
  1762. 	minimap_icon_add_vehicle_do(name, bitmap_name, bitmap_glow_name, radius, sync_type) 
  1763. end  
  1764.  
  1765. -- Adds a minimap icon to a mover 
  1766. -- 
  1767. -- name: name of vehicle 
  1768. -- bitmap_name: name of minimap icon file 
  1769. -- radius: radius of the minimap icon 
  1770. -- bitmap_glow_name: (optional) name of minimap icon glow file 
  1771. -- sync_type: (optional) sync type 
  1772. -- 
  1773. function minimap_icon_add_mover_radius(name, bitmap_name, radius, bitmap_glow_name, sync_type) 
  1774. 	minimap_icon_add_mover_do(name, bitmap_name, bitmap_glow_name, radius, sync_type) 
  1775. end 
  1776.  
  1777. -- Generates a mission help message from string table 
  1778. -- Also updates Objectives screen 
  1779. -- 
  1780. function mission_help_table(tag, string1, string2, sync) 
  1781. 	mission_help_table_do(tag, true, false, string1, string2, sync, 0) 
  1782. end 
  1783.  
  1784. -- Generates a mission help nag message from string table 
  1785. -- Doesn't update Objectives screen 
  1786. -- 
  1787. function mission_help_table_nag(tag, string1, string2, sync) 
  1788. 	mission_help_table_do(tag, false, false, string1, string2, sync, 0) 
  1789. end 
  1790.  
  1791. -- Generates a mission help nag message from string table 
  1792. -- Doesn't update Objectives screen 
  1793. -- 
  1794. function mission_help_table_repeating(tag, string1, string2, sync, repeat_delay)	 
  1795. 	mission_help_table_do(tag, true, true, string1, string2, sync, repeat_delay) 
  1796. end 
  1797.  
  1798. -- Companion to mission_start_fade_in. This function disables player 
  1799. -- controls and instantly fades out the screen. 
  1800. -- 
  1801. -- Intended to be used when the mission is loading groups at start - 
  1802. -- prevents the player from moving or seeing anything happening. 
  1803. -- 
  1804. function mission_start_fade_out() 
  1805.    chunk_enable_ambient_streaming( false ) 
  1806.  
  1807.    fade_out( START_FADE_OUT_TIME ) 
  1808.    player_controls_disable( LOCAL_PLAYER ) 
  1809.    if ( coop_is_active() ) then 
  1810.       player_controls_disable( REMOTE_PLAYER ) 
  1811.    end 
  1812.    Player_controls_disabled_by_mission_start_fadeout = true 
  1813. 	fade_out_block() 
  1814. end 
  1815.  
  1816. -- Companion to mission_start_fade_out. This function enables player 
  1817. -- controls and fades in the screen. 
  1818. -- 
  1819. -- Intended to be used when the mission is loading groups at start - 
  1820. -- prevents the player from moving or seeing anything happening. 
  1821. -- 
  1822. function mission_start_fade_in( fade_in_time_seconds ) 
  1823.    chunk_enable_ambient_streaming( true ) 
  1824.  
  1825.    fade_in( START_FADE_IN_TIME ) 
  1826. 	fade_in_block() 
  1827.    player_controls_enable( LOCAL_PLAYER ) 
  1828.    if ( coop_is_active() ) then 
  1829.       player_controls_enable( REMOTE_PLAYER ) 
  1830.    end 
  1831.    Player_controls_disabled_by_mission_start_fadeout = false 
  1832. end 
  1833.  
  1834. -- Companion to mission_start_fade_out/in: This function potentially 
  1835. -- reenables player controls if they've been disabled by the start fade in 
  1836. -- function. Should be called in mission cleanup by all missions that use 
  1837. -- these two functions. 
  1838. -- 
  1839. function mission_cleanup_maybe_reenable_player_controls() 
  1840.    if ( Player_controls_disabled_by_mission_start_fadeout ) then 
  1841.       player_controls_enable( LOCAL_PLAYER ) 
  1842.       if ( coop_is_active() ) then 
  1843.          player_controls_enable( REMOTE_PLAYER ) 
  1844.       end 
  1845.       Player_controls_disabled_by_mission_start_fadeout = false 
  1846.    end 
  1847. end 
  1848.  
  1849. function mission_waypoint_add(navpoint, sync_type) 
  1850. 	mission_waypoint_remove(sync_type) 
  1851. 	Mission_waypoint = waypoint_add(navpoint, sync_type) 
  1852. end 
  1853.  
  1854. function mission_waypoint_remove(sync_type) 
  1855. 	if (Mission_waypoint ~= -1) then	 
  1856. 		waypoint_remove(sync_type) 
  1857. 		Mission_waypoint = -1 
  1858. 	end 
  1859. end 
  1860.  
  1861. -- Make a human move to a destination 
  1862. --  
  1863. -- name:					name of the human 
  1864. -- dest:					name of destination navpoint(s) 
  1865. -- speed:				(optional) movement speed (1 = walk, 2 = run, 3 = sprint; default = 1) 
  1866. -- retry_on_failure:	(optional) set to true to keep retrying if path calculation fails (default = false) 
  1867. -- move_and_fire:		(optional) set to true to allow the NPC to fire on the move (default = false) 
  1868. -- 
  1869. function move_to(name, ...) 
  1870. 	local num_args, speed, retry_on_failure, move_and_fire, path_index 
  1871.  
  1872. 	-- Wait until the resource is loaded. 
  1873. 	character_wait_for_loaded_resource(name) 
  1874. 			 
  1875. 	num_args = arg.n 
  1876.  
  1877. 	-- get move and fire 
  1878. 	if ( (num_args > 3) and (type(arg[num_args]) == "boolean") ) then 
  1879. 		move_and_fire = arg[num_args] 
  1880. 		num_args = num_args - 1 
  1881. 	else 
  1882. 		move_and_fire = false 
  1883. 	end 
  1884.  
  1885. 	-- get retry 
  1886. 	if ( (num_args > 2) and (type(arg[num_args]) == "boolean") ) then 
  1887. 		retry_on_failure = arg[num_args] 
  1888. 		num_args = num_args - 1 
  1889. 	else 
  1890. 		retry_on_failure = false 
  1891. 	end 
  1892. 	 
  1893. 	-- get speed 
  1894. 	if ( (num_args > 1) and (type(arg[num_args]) == "number") ) then 
  1895. 		speed = arg[num_args] 
  1896. 		num_args = num_args - 1 
  1897. 	else 
  1898. 		speed = 1 
  1899. 	end 
  1900. 	 
  1901. 	while( not character_is_ready( name ) ) do 
  1902. 		thread_yield() 
  1903. 	end 
  1904. 	 
  1905. 	-- for each argument (not including the optional speed argument) 
  1906. 	for i = 1, num_args, 1 do 
  1907. 		local arg_val, arg_type 
  1908. 		 
  1909. 		arg_val = arg[i] 
  1910. 		arg_type = type(arg_val) 
  1911. 		if (arg_type == "table") then 
  1912. 			local j 
  1913. 			 
  1914. 			j = 1 
  1915. 			while (arg_val[j] ~= nil) do 
  1916. 				path_index = move_to_do(name, arg_val[j], speed, retry_on_failure, move_and_fire, false, 0) 
  1917. 				if (not (path_index == 0)) then 
  1918.                 -- Keep checking for done until the character dies or reaches the destination 
  1919.  					while ( character_is_dead( name ) == false and 
  1920. 			 not( move_to_check_done(path_index,  name, arg_val[j], speed, retry_on_failure, move_and_fire, false, 0 ) ) ) do 
  1921.                         thread_yield() 
  1922.                     end 
  1923.  
  1924. 					j = j + 1 
  1925. 				else 
  1926. 					return false 
  1927. 				end 
  1928. 			end					 
  1929. 		elseif (arg_type == "string") then 
  1930. 			-- Is it a path list of navpoints are a single navpoint? 
  1931. 			if ( path_name_is_path(arg_val)) then 
  1932. 				local	idx 
  1933.  
  1934. 				idx = 0 
  1935. 				while (1) do 
  1936. 					path_index = move_to_do(name, arg_val, speed, retry_on_failure, move_and_fire, true, idx) 
  1937. 					if (not (path_index == 0)) then 
  1938. 						-- Keep checking for done until the character dies or reaches the destination 
  1939. 						while ( character_is_dead( name ) == false and 
  1940. 							not( move_to_check_done(path_index,  name, arg_val, speed, retry_on_failure, move_and_fire, true, idx ) ) ) do 
  1941. 							thread_yield() 
  1942. 						end 
  1943.  
  1944. 						idx = idx + 1 
  1945. 					else 
  1946. 						return false 
  1947. 					end 
  1948. 				end 
  1949. 			else 
  1950. 				path_index = move_to_do(name, arg_val, speed, retry_on_failure, move_and_fire, false, 0) 
  1951. 				if (not (path_index == 0)) then 
  1952. 				-- Keep checking for done until the character dies or reaches the destination 
  1953. 					while ( character_is_dead( name ) == false and 
  1954. 						not( move_to_check_done(path_index,  name, arg_val, speed, retry_on_failure, move_and_fire, false, 0 ) ) ) do 
  1955. 						thread_yield() 
  1956. 					end 
  1957. 				else 
  1958. 					return false 
  1959. 				end 
  1960. 			end 
  1961. 		end 
  1962. 	end 
  1963. 	 
  1964. 	return (not character_is_dead( name )) 
  1965. end 
  1966.  
  1967. -- Make a human move to a destination...if the human no longer exists during execution, it will safely exit 
  1968. --  
  1969. -- name:					name of the human 
  1970. -- dest:					name of destination navpoint(s) 
  1971. -- speed:				(optional) movement speed (1 = walk, 2 = run, 3 = sprint; default = 1) 
  1972. -- retry_on_failure:	(optional) set to true to keep retrying if path calculation fails (default = false) 
  1973. -- move_and_fire:		(optional) set to true to allow the NPC to fire on the move (default = false) 
  1974. -- 
  1975. function move_to_safe(name, ...) 
  1976.  
  1977.    -- If the character is dead, then forget about pathfinding 
  1978.    if ( character_is_dead( name ) == true ) then 
  1979.       return false 
  1980.    end 
  1981.  
  1982. 	local num_args, speed, retry_on_failure, move_and_fire, path_index 
  1983.  
  1984. 	-- Wait until the resource is loaded. 
  1985. 	character_wait_for_loaded_resource(name) 
  1986. 			 
  1987. 	num_args = arg.n 
  1988.  
  1989. 	-- get move and fire 
  1990. 	if ( (num_args > 3) and (type(arg[num_args]) == "boolean") ) then 
  1991. 		move_and_fire = arg[num_args] 
  1992. 		num_args = num_args - 1 
  1993. 	else 
  1994. 		move_and_fire = false 
  1995. 	end 
  1996.  
  1997. 	-- get retry 
  1998. 	if ( (num_args > 2) and (type(arg[num_args]) == "boolean") ) then 
  1999. 		retry_on_failure = arg[num_args] 
  2000. 		num_args = num_args - 1 
  2001. 	else 
  2002. 		retry_on_failure = false 
  2003. 	end 
  2004. 	 
  2005. 	-- get speed 
  2006. 	if ( (num_args > 1) and (type(arg[num_args]) == "number") ) then 
  2007. 		speed = arg[num_args] 
  2008. 		num_args = num_args - 1 
  2009. 	else 
  2010. 		speed = 1 
  2011. 	end 
  2012. 	 
  2013. 	while( not character_is_ready( name )) do 
  2014. 		thread_yield() 
  2015.  
  2016. 		-- Don't pathfind if character is dead or entered a vehicle 
  2017. 		if (character_is_dead(name) or character_is_in_vehicle( name )) then 
  2018. 			return false 
  2019. 		end 
  2020. 	end 
  2021.  
  2022. 	-- Character may have entered a vehicle in the same frame that it became ready. 
  2023. 		if (character_is_in_vehicle( name )) then 
  2024. 			return false 
  2025. 		end 
  2026.  
  2027. 	-- for each argument (not including the optional speed argument) 
  2028. 	for i = 1, num_args, 1 do 
  2029. 		local arg_val, arg_type 
  2030. 		 
  2031. 		arg_val = arg[i] 
  2032. 		arg_type = type(arg_val) 
  2033. 		if (arg_type == "table") then 
  2034. 			local j 
  2035. 			 
  2036. 			j = 1 
  2037. 			while (arg_val[j] ~= nil) do 
  2038. 				path_index = move_to_do(name, arg_val[j], speed, retry_on_failure, move_and_fire, false, 0) 
  2039. 				if (not (path_index == 0)) then 
  2040. 					while(not(move_to_check_done(path_index, name, arg_val[j], speed, retry_on_failure, move_and_fire, false, 0))) do 
  2041. 						thread_yield() 
  2042.  
  2043. 						-- Don't pathfind if character is dead or entered a vehicle 
  2044. 						if (character_is_dead(name) or character_is_in_vehicle( name )) then 
  2045. 							return false 
  2046. 						end 
  2047. 					end 
  2048. 					 
  2049. 					j = j + 1 
  2050. 				else 
  2051. 					return false 
  2052. 				end 
  2053. 			end					 
  2054. 		elseif (arg_type == "string") then 
  2055. 			-- Is it a path list of navpoints are a single navpoint? 
  2056. 			if (path_name_is_path(arg_val)) then 
  2057. 				local	idx 
  2058.  
  2059. 				idx = 0 
  2060. 				while (1) do 
  2061. 					path_index = move_to_do(name, arg_val, speed, retry_on_failure, move_and_fire, true, idx) 
  2062. 					if (not (path_index == 0)) then 
  2063. 						while(not(move_to_check_done(path_index, name, arg_val, speed, retry_on_failure, move_and_fire, true, idx))) do 
  2064. 							thread_yield() 
  2065.  
  2066. 							-- Don't pathfind if character is dead or entered a vehicle 
  2067. 							if (character_is_dead(name) or character_is_in_vehicle( name )) then 
  2068. 								return false 
  2069. 							end 
  2070. 						end 
  2071.  
  2072. 						idx = idx + 1 
  2073. 					else 
  2074. 						return false 
  2075. 					end 
  2076. 				end 
  2077. 			else 
  2078. 				path_index = move_to_do(name, arg_val, speed, retry_on_failure, move_and_fire, false, 0) 
  2079. 				if (not (path_index == 0)) then 
  2080. 					while(not(move_to_check_done(path_index, name, arg_val, speed, retry_on_failure, move_and_fire, false, 0))) do 
  2081. 						thread_yield() 
  2082.  
  2083. 						-- Don't pathfind if character is dead or entered a vehicle 
  2084. 						if (character_is_dead(name) or character_is_in_vehicle( name )) then 
  2085. 							return false 
  2086. 						end 
  2087. 					end 
  2088. 				else 
  2089. 					return false 
  2090. 				end 
  2091. 			end 
  2092. 		end 
  2093. 	end 
  2094. 	 
  2095. 	return true 
  2096. end 
  2097.  
  2098. -- Make a human move to a vehicle entry point without getting into the vehicle 
  2099. --  
  2100. -- name:				name of the human 
  2101. -- vehicle:				name of destination vehicle 
  2102. -- entry_point:			(optional) car door entry point to use (default = 0; driver side) 
  2103. -- speed:				(optional) movement speed (1 = walk, 2 = run, 3 = sprint; default = 1) 
  2104. -- retry_on_failure:	(optional) set to true to keep retrying if path calculation fails (default = false) 
  2105. -- move_and_fire:		(optional) set to true to allow the NPC to fire on the move (default = false) 
  2106. -- 
  2107. function move_to_vehicle_entry_point(name, vehicle, entry_point, speed, retry_on_failure, move_and_fire) 
  2108. 	-- Wait until the resource is loaded. 
  2109. 	character_wait_for_loaded_resource(name) 
  2110. 	 
  2111. 	while( not character_is_ready( name ) ) do 
  2112. 		thread_yield() 
  2113. 	end 
  2114. 	 
  2115. 	if move_to_vehicle_entry_point_do(name, vehicle, entry_point, speed, retry_on_failure, move_and_fire) then 
  2116. 		repeat 
  2117. 			thread_yield() 
  2118. 		until move_to_vehicle_entry_point_check_done(name, vehicle, entry_point, speed, retry_on_failure, move_and_fire) 
  2119. 	end 
  2120. 	 
  2121. 	return true 
  2122. end 
  2123.  
  2124. function notoriety_reset_vehicle_count( gang_name ) 
  2125. 	notoriety_set_desired_vehicle_count( gang_name, -1 ) 
  2126. end 
  2127.  
  2128. function on_random_human_killed( function_name, mission_name ) 
  2129. 	on_random_obj_killed( function_name, mission_name, 1 ) 
  2130. end 
  2131.  
  2132. function on_random_mover_killed( function_name, mission_name ) 
  2133. 	on_random_obj_killed( function_name, mission_name, 2 ) 
  2134. end 
  2135.  
  2136. function on_random_vehicle_killed( function_name, mission_name ) 
  2137. 	on_random_obj_killed( function_name, mission_name, 3 ) 
  2138. end 
  2139.  
  2140. -- Callback for when an object in the object destroyed script is killed 
  2141. -- 
  2142. -- This is a file that is generated by Art...it contains the chunk number (all three digits, even leading zeros) 
  2143. --	and the object name. The file is named exactly the same as the mission, stronghold, and activity and has the 
  2144. -- file extension "ods". 
  2145. function on_random_ods_killed( function_name, mission_name ) 
  2146. 	on_random_obj_killed( function_name, mission_name, 4 ) 
  2147. end 
  2148.  
  2149. function open_vint_dialog(title_tag, body_tag, tag1, tag2) 
  2150. 	open_vint_dialog_do(title_tag, body_tag, tag1, tag2) 
  2151.  
  2152. 	local		check_value = open_vint_dialog_check_done() 
  2153.  
  2154. 	while (check_value == -1) do 
  2155. 		thread_yield() 
  2156. 		check_value = open_vint_dialog_check_done() 
  2157. 	end 
  2158.  
  2159. 	return check_value 
  2160. end 
  2161.  
  2162. -- Add members to the player's party 
  2163. -- 
  2164. -- name:	name of NPC to add to player's party 
  2165. -- 
  2166. function party_add(...) 
  2167. 	local player = CLOSEST_PLAYER 
  2168. 	 
  2169. 	if is_player_tag(arg[arg.n]) then 
  2170. 		player = arg[arg.n] 
  2171. 		arg.n = arg.n - 1 
  2172. 	end 
  2173. 		 
  2174. 	party_add_do(player, arg, false) 
  2175. end 
  2176.  
  2177. function party_add_optional(...) 
  2178. 	local player = CLOSEST_PLAYER 
  2179. 	 
  2180. 	if is_player_tag(arg[arg.n]) then 
  2181. 		player = arg[arg.n] 
  2182. 		arg.n = arg.n - 1 
  2183. 	end 
  2184. 		 
  2185. 	party_add_do(player, arg, true) 
  2186. end 
  2187.  
  2188. -- Dismiss members from the player party 
  2189. -- 
  2190. -- name:	name of NPC to dismiss from player party 
  2191. -- 
  2192. function party_dismiss(...) 
  2193. 	party_dismiss_do(arg) 
  2194. end 
  2195.  
  2196. -- Get the prefix that should be prepended to the character's persona triggers. 
  2197. -- 
  2198. -- name:	player's name 
  2199. -- 
  2200. --	returns: string to append to the trigger 
  2201. --  
  2202. function persona_trigger_get_player_prefix(name) 
  2203.  
  2204. 	local voice_prefixes = {[0] = "WM", [1] = "BM", [2] = "HM", [3] = "WF", [4] = "BF", [5] = "HF"} 
  2205. 	local trigger_prefix = "" 
  2206.  
  2207. 	if(character_is_player(name)) then 
  2208. 		local player_voice_prefix = voice_prefixes[player_get_custom_voice(name)] 
  2209. 		if(player_voice_prefix ~= nil) then 
  2210. 			trigger_prefix = player_voice_prefix 
  2211. 		end 
  2212. 	end 
  2213.  
  2214. 	return trigger_prefix 
  2215.  
  2216. end 
  2217.  
  2218. function persona_override_character_start(character, situation, trigger, count) 
  2219.  
  2220. 	if type(situation) == "table" then 
  2221. 		for i, persona_situation in pairs(situation) do 
  2222. 			local trigger_prefix = persona_trigger_get_player_prefix(character) 
  2223. 			persona_override_character_start_do(character, persona_situation, trigger_prefix .. trigger, count) 
  2224. 		end 
  2225. 	else 
  2226. 		local trigger_prefix = persona_trigger_get_player_prefix(character) 
  2227. 		persona_override_character_start_do(character, situation, trigger_prefix .. trigger, count) 
  2228. 	end 
  2229.  
  2230. end 
  2231.  
  2232. function persona_override_character_stop(character, situation) 
  2233.  
  2234. 	if type(situation) == "table" then 
  2235. 		for i, persona_situation in pairs(situation) do 
  2236. 			persona_override_character_stop_do(character, persona_situation) 
  2237. 		end 
  2238. 	else 
  2239. 		persona_override_character_stop_do(character, situation) 
  2240. 	end 
  2241.  
  2242. end 
  2243.  
  2244. -- Override a group of personas  
  2245. -- 
  2246. --	The following 3 lines: 
  2247. -- 
  2248. --		EX_PERSONAS	=	{	["AM_Gang1"]	=	"AMGNG1"; 
  2249. --								["AM_Gang2"]	=	"AMGNG2"; 
  2250. --							} 
  2251. --		persona_override_group(EX_PERSONAS, POT_SITUATIONS[POT_ATTACK], "EX01_ATTACK") 
  2252. -- 
  2253. --	Are equivalent to: 
  2254. -- 
  2255. --		persona_override_persona_start(“AM_Gang1”, "threat - alert (group attack)",	"AMGNG1_EX01_ATTACK") 
  2256. --		persona_override_persona_start(“AM_Gang1”, "threat - alert (solo attack)",		"AFGNG1_EX01_ATTACK") 
  2257. --		persona_override_persona_start(“AM_Gang2", "threat - alert (group attack)",	"AMGNG2_EX01_ATTACK") 
  2258. --		persona_override_persona_start(“AM_Gang2”, "threat - alert (solo attack)",		"AFGNG2_EX01_ATTACK") 
  2259. -- 
  2260. -- Generally this function will be used with one of 4 predefined gang persona tables: 
  2261. --		BROTHERHOOD_PERSONAS 
  2262. --		RONIN_PERSONAS 
  2263. --		SAINTS_PERSONAS 
  2264. --		SAMEDI_PERSONAS 
  2265. -- 
  2266. -- persona_list: Table w/ persona names as keys to the corresponding tag_prefix value. 
  2267. --		see BROTHERHOOD_PERSONAS defined in this file for an example. 
  2268. -- situation: Persona situation(s) to override - may be a scalar or a table value. 
  2269. --	tag_suffix: The common trigger suffix. 
  2270. -- 
  2271. function persona_override_group_start(persona_list, situation, tag_suffix) 
  2272. 	for persona, tag_prefix in pairs(persona_list) do 
  2273. 		persona_override_persona_start(persona, situation, tag_prefix .. "_" .. tag_suffix) 
  2274. 	end 
  2275. end 
  2276.  
  2277. -- Stop the overrides for a group of personas  
  2278. -- 
  2279. --	See persona_override_group_start() for a more detailed description of the parameters 
  2280. -- 
  2281. -- persona_list: Table w/ persona names as keys to the corresponding tag_prefix value. 
  2282. --		see BROTHERHOOD_PERSONAS defined in this file for an example. 
  2283. -- situation: Persona situation(s) to stop overriding - may be a scalar or a table value. 
  2284. -- 
  2285. function persona_override_group_stop(persona_list, situation) 
  2286. 	for persona, tag_prefix in pairs(persona_list) do 
  2287. 		persona_override_persona_stop(persona, situation) 
  2288. 	end 
  2289. end 
  2290.  
  2291. function persona_override_persona_start(persona, situation, trigger, count) 
  2292.  
  2293. 	if type(situation) == "table" then 
  2294. 		for i, persona_situation in pairs(situation) do 
  2295. 			persona_override_persona_start_do(persona, persona_situation, trigger, count) 
  2296. 		end 
  2297. 	else 
  2298. 		persona_override_persona_start_do(persona, situation) 
  2299. 	end 
  2300.  
  2301. end 
  2302.  
  2303. function persona_override_persona_stop(persona, situation) 
  2304.  
  2305. 	if type(situation) == "table" then 
  2306. 		for i, persona_situation in pairs(situation) do 
  2307. 			persona_override_persona_stop_do(persona, persona_situation) 
  2308. 		end 
  2309. 	else 
  2310. 		persona_override_persona_stop_do(persona, situation) 
  2311. 	end 
  2312.  
  2313. end 
  2314.  
  2315. function player_is_targeting( char, player ) 
  2316. 	if player == nil then 
  2317. 		for i, p in pairs(player_names_get_all()) do 
  2318. 			if player_is_targeting_do(char, p) then 
  2319. 				return true 
  2320. 			end 
  2321. 		end 
  2322. 	 
  2323. 		return false 
  2324. 	end 
  2325. 	 
  2326. 	return player_is_targeting_do(char, player)	 
  2327. end 
  2328.  
  2329. function player_creation_open() 
  2330. 	player_creation_open_do() 
  2331. 	 
  2332. 	while (player_creation_is_open_do()) do 
  2333. 		thread_yield() 
  2334. 	end 
  2335. end 
  2336.  
  2337. -- Takes a table and returns a random key and value 
  2338. -- NOTE: Use this for tables that have non-numerical or non-sequential keys.   
  2339. -- Otherwise, it's faster just to rand_int() the key directly. 
  2340. -- 
  2341. -- input_table: table to choose a random entry from 
  2342. -- 
  2343. -- returns: chosen key, value from input_table 
  2344. -- 
  2345. function rand_table_key_value( input_table ) 
  2346. 	local size = sizeof_table( input_table ) 
  2347. 	if size == 0 then 
  2348. 		return 
  2349. 	end 
  2350. 	 
  2351. 	-- Choose the random entry 
  2352. 	local rand_idx = rand_int( 1, size ) 
  2353. 	 
  2354. 	local idx = 1 
  2355. 	for k, v in pairs( input_table ) do 
  2356. 		if idx == rand_idx then 
  2357. 			return k, v 
  2358. 		end 
  2359. 		 
  2360. 		idx = idx + 1 
  2361. 	end 
  2362. end 
  2363.  
  2364. -- Take a screenshot (file is stored on the kit) 
  2365. -- 
  2366. -- filename:	(optional) filename to use for screenshot (do not include extension) 
  2367. -- 
  2368. function screenshot(...) 
  2369. 	if (arg.n > 0) then 
  2370. 		screenshot_do(arg[1]) 
  2371. 	else 
  2372. 		screenshot_do("") 
  2373. 	end 
  2374.  
  2375. 	while (not(screenshot_check_done())) do 
  2376. 		thread_yield() 
  2377. 	end 
  2378. end 
  2379.  
  2380. function scripted_cutscene_play( cutscene_func, abort_func ) 
  2381. 	scripted_cutscene_playing( true ) 
  2382.  
  2383. 	thread_new_block( cutscene_func ) 
  2384. 	 
  2385. 	thread_new_block( abort_func ) 
  2386. 	 
  2387. 	scripted_cutscene_playing( false ) 
  2388. end 
  2389.  
  2390. function subgroup_create( group_name, count, ... ) 
  2391.  
  2392. 	subgroup_create_do( group_name, count ) 
  2393. 	 
  2394. 	local handle = thread_new("create_group_check_done_loop",group_name) 
  2395.  
  2396. 	while((arg.n>0 and arg[1]) and not thread_check_done(handle)) do 
  2397. 		thread_yield() 
  2398. 	end 
  2399. end 
  2400.  
  2401. -- Make a human turn a certain amount 
  2402. -- 
  2403. -- name:		name of character that is turning 
  2404. -- angle:	relative angle to turn, in degrees 
  2405. -- 
  2406. function turn_angle(name, angle) 
  2407.  
  2408. 	while (not(character_is_ready(name))) do 
  2409. 		thread_yield() 
  2410. 	end 
  2411.  
  2412. 	turn_angle_do(name, angle) 
  2413.  
  2414. 	while (not(turn_to_check_done(name))) do 
  2415. 		thread_yield() 
  2416. 	end 
  2417.  
  2418. end 
  2419.  
  2420. function sync_from_player(player_name) 
  2421. 	if player_name == REMOTE_PLAYER then 
  2422. 		return SYNC_REMOTE 
  2423. 	end 
  2424. 	if player_name == LOCAL_PLAYER then 
  2425. 		return SYNC_LOCAL 
  2426. 	end 
  2427. 	 
  2428. 	return SYNC_ALL 
  2429. end 
  2430.  
  2431. function teleport_coop( local_player_nav, remote_player_nav, exit_vehicles ) 
  2432.  
  2433. 	if (coop_is_active()) then 
  2434. 		teleport( REMOTE_PLAYER, remote_player_nav, exit_vehicles ) 
  2435. 	end 
  2436.  
  2437. 	teleport( LOCAL_PLAYER, local_player_nav, exit_vehicles ) 
  2438.  
  2439. 	if (coop_is_active()) then 
  2440. 		waiting_for_player_dialog( true ) 
  2441.  
  2442. 		while( not teleport_check_done(REMOTE_PLAYER)) do 
  2443. 			thread_yield() 
  2444. 		end 
  2445. 		waiting_for_player_dialog( false ) 
  2446. 	end		 
  2447. end 
  2448.  
  2449. -- Trigger Event State Tracker 
  2450. -- Function to deal with trigger events for multiple players 
  2451. -- 
  2452. -- player_name: The name of the human that triggered the 
  2453. --	event. Nothing happens if it's not a player. 
  2454. -- event_state_tracker: A global variable that should 
  2455. --	only be changed by this function. 
  2456. --	Assign the return value of the function 
  2457. --	event_state_tracker_create to setup this value. 
  2458. -- 
  2459. -- trigger_option: Changes the behavior of the function. 
  2460. --	Defaults to UPDATE_ACTIVATED. 
  2461.  
  2462. -- Trigger Option Values: 
  2463. -- UPDATE_ACTIVATED: Doesn't do anything but update the 
  2464. --	event_state_tracker, and assumes that the 
  2465. --	passed-in player name is the player that just 
  2466. --	activated the state. 
  2467. -- 
  2468. -- UPDATE_DEACTIVATED: Same as UPDATE_ACTIVATED, but 
  2469. --	assumes that the player deactivated the state. 
  2470. -- 
  2471. -- ALL_PLAYERS_DEACTIVATED: Assumes the passed-in 
  2472. --	player just deactivated the state, and returns 
  2473. --	true if all players have done so. 
  2474. -- 
  2475. -- ANY_PLAYER_DEACTIVATED: Assumes the passed-in 
  2476. --	player just deactivated the state, and returns 
  2477. --	true if indeed player_name is a player. 
  2478. -- 
  2479. -- ALL_PLAYERS_ACTIVATED: Assumes the passed-in player 
  2480. --	just activated the state. Returns true if all 
  2481. --	players have triggered the state, false otherwise. 
  2482. --	Will continue to trigger if either player 
  2483. --	activates the trigger a second time. 
  2484. -- 
  2485. -- ALL_PLAYERS_ACTIVATED_RESET: Just like 
  2486. --	ALL_PLAYERS_ACTIVATED, only it sets the trackers 
  2487. --	to false after both are triggered before 
  2488. --	returning true. 
  2489. -- 
  2490. -- TRIGGER_MULTIPLE_TIMES: Returns true if either of 
  2491. --	the players triggered. 
  2492. -- 
  2493. -- TRIGGER_ONCE_FIRST_ACTIVATION: Returns true for the 
  2494. --	first player to trigger the trigger, false 
  2495. --	afterward and otherwise. 
  2496. -- 
  2497. -- TRIGGER_ONCE_PER_PLAYER: Returns true one for each 
  2498. --	player's first triggering of the trigger. 
  2499. -- 
  2500. function trigger_event_state_tracker( player_name, event_state_tracker, track_option ) 
  2501.  
  2502. 	-- First check whether the player_name is valid 
  2503. 	local current_players = player_names_get_all() 
  2504. 	local player_found = false 
  2505. 	for i, player in pairs(current_players) do 
  2506. 		if player_name == player then 
  2507. 			player_found = true 
  2508. 			break 
  2509. 		end 
  2510. 	end 
  2511. 	 
  2512. 	if not player_found then 
  2513. 		return false 
  2514. 	end 
  2515.  
  2516. 	-- Use default track option 
  2517. 	if track_option == nil then 
  2518. 		track_option = UPDATE_ACTIVATED 
  2519. 	end 
  2520. 	 
  2521. 	-- UPDATE_DEACTIVATED, ALL_PLAYERS_DEACTIVATED, and ANY_PLAYER_DEACTIVATED 
  2522. 	if track_option >= UPDATE_DEACTIVATED and track_option <= ANY_PLAYER_DEACTIVATED then 
  2523. 		event_state_tracker[player_name] = false 
  2524. 		 
  2525. 		if track_option == ALL_PLAYERS_DEACTIVATED then 
  2526. 			-- Spin through all the current players looking for an active trigger 
  2527. 			for i, player in pairs(current_players) do 
  2528. 				if event_state_tracker[player] == true then 
  2529. 					return false 
  2530. 				end 
  2531. 			end 
  2532. 			 
  2533. 			-- Trigger when all players have deactivated 
  2534. 			return true 
  2535. 		 
  2536. 		elseif track_option == ANY_PLAYER_DEACTIVATED then 
  2537. 			-- Return true if any deactivated the state 
  2538. 			return true 
  2539. 		end 
  2540. 	 
  2541. 	-- UPDATE_ACTIVATED, ALL_PLAYERS_ACTIVATED, ALL_PLAYERS_ACTIVATED_RESET, and TRIGGER_MULTIPLE_TIMES 
  2542. 	elseif track_option >= UPDATE_ACTIVATED and track_option <= TRIGGER_MULTIPLE_TIMES then 
  2543. 		event_state_tracker[player_name] = true 
  2544. 		 
  2545. 		if track_option == ALL_PLAYERS_ACTIVATED or track_option == ALL_PLAYERS_ACTIVATED_RESET then 
  2546. 			-- Spin through all the current players looking for an inactive trigger 
  2547. 			for i, player in pairs(current_players) do 
  2548. 				if event_state_tracker[player] == false then 
  2549. 					return false 
  2550. 				end 
  2551. 			end 
  2552. 			 
  2553. 			if track_option == ALL_PLAYERS_ACTIVATED_RESET then 
  2554. 				-- Reset everyone, including inactive players, just in case 
  2555. 				for i, player in pairs(PLAYER_TAG_LIST) do 
  2556. 					event_state_tracker[player] = false 
  2557. 				end 
  2558. 			end 
  2559. 			 
  2560. 			-- Trigger when all players have activated the event 
  2561. 			return true 
  2562. 			 
  2563. 		elseif track_option == TRIGGER_MULTIPLE_TIMES then 
  2564. 			-- Trigger when any player hits the trigger 
  2565. 			return true 
  2566. 		end 
  2567. 		 
  2568. 	elseif track_option == TRIGGER_ONCE_FIRST_TRIGGERER then 
  2569. 		-- If any of the state triggers are set, this event has already been triggered 
  2570. 		for i, player in pairs(current_players) do 
  2571. 			if event_state_tracker[player] == true then 
  2572. 				return false 
  2573. 			end 
  2574. 		end 
  2575. 		 
  2576. 		-- Trigger once for the first person that activates the event 
  2577. 		event_state_tracker[player_name] = true 
  2578. 		return true 
  2579. 		 
  2580. 	elseif track_option == TRIGGER_ONCE_PER_PLAYER then 
  2581. 		-- Check if this player's already fired the event 
  2582. 		if event_state_tracker[player] == true then 
  2583. 			return false 
  2584. 		end 
  2585. 		 
  2586. 		-- Trigger once for each player 
  2587. 		event_state_tracker[player_name] = true 
  2588. 		return true 
  2589. 	end 
  2590. 	 
  2591. 	-- Unrecognized track_option? 
  2592. 	return false 
  2593. end 
  2594.  
  2595. -- Make a human turn to face an arbitrary object or navpoint 
  2596. -- 
  2597. -- name:		name of character that is turning 
  2598. -- target:		name of target object 
  2599. -- orient:		if true, turn to same direction as target's orient instead (default: false) 
  2600. -- 
  2601. function turn_to(name, target, orient) 
  2602. 	while (not(character_is_ready(name))) do 
  2603. 		thread_yield() 
  2604. 	end 
  2605.  
  2606. 	turn_to_do(name, target, orient) 
  2607.  
  2608. 	while (not(turn_to_check_done(name))) do 
  2609. 		thread_yield() 
  2610. 	end 
  2611. end 
  2612.  
  2613. -- Make a human turn to face a character 
  2614. -- 
  2615. -- name:		name of character that is turning 
  2616. -- target:		name of target character 
  2617. -- 
  2618. function turn_to_char(name, target) 
  2619. 	turn_to(name, target) 
  2620. end 
  2621.  
  2622. -- Make a human turn to face a navpoint 
  2623. -- 
  2624. -- name:			name of character that is turning 
  2625. -- nav_name:		name of target navpoint 
  2626. -- 
  2627. function turn_to_nav(name, nav_name) 
  2628. 	turn_to(name, nav_name) 
  2629. end 
  2630.  
  2631. -- Make a human turn to face in the same direction as an arbitrary object 
  2632. -- 
  2633. -- name:			name of character that is turning 
  2634. -- target:			name of target to get orientation from 
  2635. -- 
  2636. function turn_to_orient(name, target) 
  2637. 	turn_to(name, target, true) 
  2638. end 
  2639.  
  2640. -- Make a npc enter a vehicle 
  2641. -- 
  2642. -- name:			name of character that is entering the vehicle 
  2643. -- vehicle_name:	name of vehicle to enter 
  2644. -- seat:			specific seat to enter (default: 0) 
  2645. -- block:			if true, block until done (default: true) 
  2646. -- force_hijack_success: if true, forces any hijack attempts resulting from this 
  2647. --                       call to succeed. 
  2648. -- 
  2649. function vehicle_enter(name, vehicle_name, seat, block, force_hijack_success) 
  2650.    if ( force_hijack_success == nil ) then 
  2651.       force_hijack_success = false 
  2652.    end 
  2653. 	local s = vehicle_enter_do(name, vehicle_name, false, seat, force_hijack_success) 
  2654. 	local r 
  2655. 	 
  2656. 	if (block or (block == nil)) then 
  2657. 		repeat 
  2658. 			thread_yield() 
  2659. 			r = vehicle_enter_check_done(name) 
  2660. 		until r ~= 0 
  2661. 	else 
  2662. 		return s 
  2663. 	end 
  2664. 	 
  2665. 	if r == 2 then 
  2666. 		return false 
  2667. 	else 
  2668. 		return true 
  2669. 	end 
  2670. end 
  2671.  
  2672. -- Make a npc teleport into a vehicle 
  2673. -- 
  2674. -- name:			name of character that is entering the vehicle 
  2675. -- vehicle_name:	name of vehicle to enter 
  2676. -- seat:			specific seat to enter (default: 0) 
  2677. -- block:			if true, block until done (default: true) 
  2678. -- 
  2679. function vehicle_enter_teleport(name, vehicle_name, seat, block) 
  2680. 	local s = vehicle_enter_do(name, vehicle_name, true, seat) 
  2681. 	local r 
  2682. 	 
  2683. 	if (block or (block == nil)) then 
  2684. 		repeat 
  2685. 			thread_yield() 
  2686. 			r = vehicle_enter_check_done(name) 
  2687. 		until r ~= 0 
  2688. 	else 
  2689. 		return s 
  2690. 	end 
  2691. 	 
  2692. 	if r == 2 then 
  2693. 		return false 
  2694. 	else 
  2695. 		return true 
  2696. 	end 
  2697. end 
  2698.  
  2699. -- Make a group of NPCs enter a vehicle 
  2700. -- 
  2701. -- names:			names of characters entering the vehicle 
  2702. -- vehicle_name:	name of vehicle to enter 
  2703. --  
  2704. function vehicle_enter_group(...) 
  2705. 	local npcs = {} 
  2706. 	local vehicle_name 
  2707.  
  2708. 	if type(arg[1]) == "table" then 
  2709. 		npcs = arg[1] 
  2710. 		npcs[ "n" ] = sizeof_table( npcs ) 
  2711. 		 
  2712. 		vehicle_name = arg[2] 
  2713. 	else		 
  2714. 		vehicle_name = arg[ arg.n ] 
  2715. 		 
  2716. 		npcs = arg; 
  2717. 		npcs.n = npcs.n - 1 
  2718. 	end 
  2719.  
  2720. 	if (vehicle_enter_group_do(vehicle_name, false, npcs)) then 
  2721. 		while (not(vehicle_enter_group_check_done(vehicle_name, false, npcs))) do 
  2722. 			thread_yield() 
  2723. 		end 
  2724. 	end 
  2725.  
  2726. 	-- remove the appended entry from the table 
  2727. 	npcs.n = nil 
  2728. end 
  2729.  
  2730. -- Make a group of NPCs teleport into a vehicle 
  2731. -- 
  2732. -- names:			names of characters entering the vehicle 
  2733. -- vehicle_name:	name of vehicle to enter 
  2734. --  
  2735. function vehicle_enter_group_teleport(...) 
  2736. 	local npcs = {} 
  2737. 	local vehicle_name 
  2738.  
  2739. 	if type(arg[1]) == "table" then 
  2740. 		npcs = arg[1] 
  2741. 		npcs[ "n" ] = sizeof_table( npcs ) 
  2742. 		 
  2743. 		vehicle_name = arg[2] 
  2744. 	else		 
  2745. 		vehicle_name = arg[ arg.n ] 
  2746. 		 
  2747. 		npcs = arg; 
  2748. 		npcs.n = npcs.n - 1 
  2749. 	end 
  2750. 	 
  2751. 	if (vehicle_enter_group_do(vehicle_name, true, npcs)) then 
  2752. 		while (not(vehicle_enter_group_check_done(vehicle_name, true, npcs))) do 
  2753. 			thread_yield() 
  2754. 		end 
  2755. 	end 
  2756.  
  2757. 	--remove the appended entry from the table 
  2758. 	npcs.n = nil 
  2759. end 
  2760.  
  2761. -- Make a npc exit a vehicle 
  2762. -- 
  2763. -- name:	name of character to exit a vehicle 
  2764. -- 
  2765. function vehicle_exit(name, not_enterable) 
  2766. 	if (vehicle_exit_do(name, false, not_enterable, false)) then 
  2767. 		while (not(vehicle_exit_check_done(name))) do 
  2768. 			thread_yield() 
  2769. 		end 
  2770. 	end 
  2771. end 
  2772.  
  2773. -- Make a npc exit a vehicle by diving 
  2774. -- 
  2775. -- name:	name of character to exit a vehicle 
  2776. -- 
  2777. function vehicle_exit_dive(name, not_enterable) 
  2778. 	if (vehicle_exit_do(name, true, not_enterable, true)) then 
  2779. 		while (not(vehicle_exit_check_done(name))) do 
  2780. 			thread_yield() 
  2781. 		end 
  2782. 	end 
  2783. end 
  2784.  
  2785.  
  2786. -- Make a npc exit a vehicle by teleporting 
  2787. -- 
  2788. -- name:	name of character to exit a vehicle 
  2789. -- 
  2790. function vehicle_exit_teleport(name, not_enterable) 
  2791. 	if (vehicle_exit_do(name, true, not_enterable, false)) then 
  2792. 		while (not(vehicle_exit_check_done(name))) do 
  2793. 			thread_yield() 
  2794. 		end 
  2795. 	end 
  2796. end 
  2797.  
  2798. -- Make a vehicle navmesh pathfind to a series of navpoints, starting from a specific point along the path 
  2799. --  
  2800. -- name: name of the vehicle 
  2801. -- start_index: index into the path to start from 
  2802. -- path: either a script path or a list of script navpoints 
  2803. -- stop_at_goal:	(optional) whether vehicle should stop at end of goal (default true) 
  2804. -- force_path:		(optional) whether to ignore current position to support looping (defualt false) 
  2805. -- suppress_errors: (optional, default false) 
  2806. -- 
  2807. function vehicle_navmesh_pathfind_to_starting_from(name, start_index, ...) 
  2808. 	local num_args, stop_at_goal, force_path, suppress_errors 
  2809.  
  2810. 	stop_at_goal = true 
  2811. 	force_path = false 
  2812. 	suppress_errors = false 
  2813.  
  2814. 	num_args = arg.n 
  2815. 	 
  2816. 	local bool_count = 0; 
  2817. 	local index = num_args; 
  2818. 	 
  2819. 	while (type(arg[num_args]) == "boolean") do 
  2820. 		bool_count = bool_count + 1 
  2821. 		num_args = num_args - 1 
  2822. 	end 
  2823.  
  2824. 	if (bool_count >= 3) then 
  2825. 		suppress_errors = arg[num_args + 3] 
  2826. 	end 
  2827.  
  2828. 	if (bool_count >= 2) then 
  2829. 		force_path = arg[num_args + 2] 
  2830. 	end 
  2831.  
  2832. 	if (bool_count >= 1) then 
  2833. 		stop_at_goal = arg[num_args + 1] 
  2834. 	end 
  2835.  
  2836. 	local arg_type = type(arg[1]) 
  2837.  
  2838. 	if (arg_type == "table") then 
  2839. 		num_args = sizeof_table(arg[1]) 
  2840. 		if (vehicle_pathfind_navmesh_do(name, force_path, stop_at_goal, suppress_errors, start_index, num_args, arg[1])) then 
  2841. 			local check_done = vehicle_pathfind_check_done(name) 
  2842. 			 
  2843. 			while ( check_done == 0) do 
  2844. 				thread_yield() 
  2845. 				check_done = vehicle_pathfind_check_done(name) 
  2846. 			end 
  2847. 			 
  2848. 			return check_done == 1 
  2849. 		else 
  2850. 			return false 
  2851. 		end 
  2852. 	elseif (arg_type == "string") then 
  2853. 		if (vehicle_pathfind_navmesh_do(name, force_path, stop_at_goal, suppress_errors, start_index, num_args, arg)) then 
  2854. 			local check_done = vehicle_pathfind_check_done(name) 
  2855. 			 
  2856. 			while ( check_done == 0) do 
  2857. 				thread_yield() 
  2858. 				check_done = vehicle_pathfind_check_done(name) 
  2859. 			end 
  2860. 			 
  2861. 			return check_done == 1 
  2862. 		else 
  2863. 			return false 
  2864. 		end 
  2865. 	end 
  2866.  
  2867. end 
  2868.  
  2869. -- Make a vehicle go to a series of navpoints (could just be 1) 
  2870. --  
  2871. -- name: name of the vehicle 
  2872. -- path: either a script path or a list of script navpoints 
  2873. -- use_navmesh:	if the car should use navmesh or traffic splines(default normal) 
  2874. -- stop_at_goal:	(optional) whether vehicle should stop at end of goal (default true) 
  2875. -- force_path:		(optional) whether to ignore current position to support looping (defualt false) 
  2876. -- suppress_errors: (optional, default false) 
  2877. -- 
  2878. function vehicle_pathfind_to(name, ...) 
  2879. 	local num_args, use_navmesh, stop_at_goal, force_path, suppress_errors 
  2880. 	 
  2881. 	stop_at_goal = true 
  2882. 	force_path = false 
  2883. 	suppress_errors = false; 
  2884. 	use_navmesh = false; 
  2885.  
  2886. 	-- Wait until the resource is loaded. 
  2887. 	-- character_wait_for_loaded_resource(name) 
  2888. 			 
  2889. 	num_args = arg.n 
  2890. 	 
  2891. 	local bool_count = 0; 
  2892. 	local index = num_args; 
  2893. 	 
  2894. 	while (type(arg[num_args]) == "boolean") do 
  2895. 		bool_count = bool_count + 1 
  2896. 		num_args = num_args - 1 
  2897. 	end 
  2898.  
  2899. 	if (bool_count >= 4) then 
  2900. 		suppress_errors = arg[num_args + 4] 
  2901. 	end 
  2902.  
  2903. 	if (bool_count >= 3) then 
  2904. 		force_path = arg[num_args + 3] 
  2905. 	end 
  2906.  
  2907. 	if (bool_count >= 2) then 
  2908. 		stop_at_goal = arg[num_args + 2] 
  2909. 	end 
  2910.  
  2911. 	if (bool_count >= 1) then 
  2912. 		use_navmesh = arg[num_args + 1] 
  2913. 	end 
  2914.  
  2915. 	local arg_type = type(arg[1]) 
  2916. 	if (use_navmesh) then 
  2917.  
  2918. 		if (arg_type == "table") then 
  2919. 			num_args = sizeof_table(arg[1]) 
  2920. 			if (vehicle_pathfind_navmesh_do(name, force_path, stop_at_goal, suppress_errors, 0, num_args, arg[1])) then 
  2921. 				local check_done = vehicle_pathfind_check_done(name) 
  2922. 				 
  2923. 				while ( check_done == 0) do 
  2924. 					thread_yield() 
  2925. 					check_done = vehicle_pathfind_check_done(name) 
  2926. 				end 
  2927. 				 
  2928. 				return check_done == 1 
  2929. 			else 
  2930. 				return false 
  2931. 			end 
  2932. 		elseif (arg_type == "string") then 
  2933. 			if (vehicle_pathfind_navmesh_do(name, force_path, stop_at_goal, suppress_errors, 0, num_args, arg)) then 
  2934. 				local check_done = vehicle_pathfind_check_done(name) 
  2935. 				 
  2936. 				while ( check_done == 0) do 
  2937. 					thread_yield() 
  2938. 					check_done = vehicle_pathfind_check_done(name) 
  2939. 				end 
  2940. 				 
  2941. 				return check_done == 1 
  2942. 			else 
  2943. 				return false 
  2944. 			end 
  2945. 		end 
  2946. 	else 
  2947. 		if (arg_type == "table") then 
  2948. 			local table_size = sizeof_table(arg[1]) 
  2949. 			if (vehicle_pathfind_to_do(name, stop_at_goal, suppress_errors, table_size, arg[1])) then 
  2950. 				local check_done = vehicle_pathfind_check_done(name) 
  2951. 				 
  2952. 				while ( check_done == 0) do 
  2953. 					thread_yield() 
  2954. 					check_done = vehicle_pathfind_check_done(name) 
  2955. 				end 
  2956. 				 
  2957. 				return check_done == 1 
  2958. 			else 
  2959. 				return false 
  2960. 			end 
  2961. 		elseif (arg_type == "string") then 
  2962. 			if (vehicle_pathfind_to_do(name, stop_at_goal, suppress_errors, num_args, arg)) then 
  2963. 				local check_done = vehicle_pathfind_check_done(name) 
  2964. 				 
  2965. 				while ( check_done == 0) do 
  2966. 					thread_yield() 
  2967. 					check_done = vehicle_pathfind_check_done(name) 
  2968. 				end 
  2969. 				 
  2970. 				return check_done == 1 
  2971. 			else 
  2972. 				return false 
  2973. 			end 
  2974. 		end 
  2975. 	end 
  2976. end 
  2977.  
  2978. -- Make a vehicle use turret mode to move througha series of navpoints (could just be 1) 
  2979. --  
  2980. -- name:		name of the vehicle 
  2981. -- dest:		name of destination navpoint(s) 
  2982. -- stop_at_goal:	(optional) whether vehicle should stop at end of goal (default true) 
  2983. -- 
  2984. function vehicle_turret_base_to(name, ...) 
  2985. 	local num_args, stop_at_goal 
  2986. 	 
  2987. 	-- Wait until the resource is loaded. 
  2988. 	-- character_wait_for_loaded_resource(name) 
  2989. 			 
  2990. 	num_args = arg.n 
  2991. 	 
  2992. 	-- get whether to stop_at_goal is passed in... 
  2993. 	local last_arg_bool = type(arg[num_args]) == "boolean" 
  2994. 	 
  2995. 	if (last_arg_bool == true) then 
  2996. 		stop_at_goal = arg[num_args] 
  2997. 		num_args = num_args - 1 
  2998. 	else 
  2999. 		stop_at_goal = true 
  3000. 		num_args = num_args 
  3001. 	end 
  3002. 	 
  3003. 	local arg_type = type(arg[1]) 
  3004.  
  3005. 	if (arg_type == "table") then 
  3006. 		num_args = sizeof_table(arg[1]) 
  3007. 		if (vehicle_turret_base_to_do(name, stop_at_goal, num_args, arg[1])) then 
  3008. 			local check_done = vehicle_pathfind_check_done(name) 
  3009. 			 
  3010. 			while ( check_done == 0) do 
  3011. 				thread_yield() 
  3012. 				check_done = vehicle_pathfind_check_done(name) 
  3013. 			end 
  3014. 			 
  3015. 			return check_done == 1 
  3016. 		else 
  3017. 			return false 
  3018. 		end 
  3019. 	elseif (arg_type == "string") then 
  3020. 		if (vehicle_turret_base_to_do(name, stop_at_goal, num_args, arg)) then 
  3021. 			local check_done = vehicle_pathfind_check_done(name) 
  3022. 			 
  3023. 			while ( check_done == 0) do 
  3024. 				thread_yield() 
  3025. 				check_done = vehicle_pathfind_check_done(name) 
  3026. 			end 
  3027. 			 
  3028. 			return check_done == 1 
  3029. 		else 
  3030. 			return false 
  3031. 		end 
  3032. 	end 
  3033. end 
  3034.  
  3035. function vehicle_stop( name, dont_block ) 
  3036.  
  3037. 	if( (name == nil) or (not vehicle_exists(name)) or  (vehicle_is_destroyed(name)) ) then 
  3038. 		return 
  3039. 	end 
  3040.  
  3041. 	vehicle_stop_do( name ) 
  3042. 	 
  3043. 	while( (not dont_block) and get_vehicle_speed(name) > 0 ) do 
  3044. 		thread_yield() 
  3045. 	end 
  3046. end 
  3047.  
  3048.  
  3049.  -- Between projects these 4 function can be removed and scripting can instead use the general character functions 
  3050. function item_throw( human_name, nav_name ) 
  3051. 	character_throw_havok_weapon( human_name, nav_name ) 
  3052. end 
  3053.  
  3054. function mesh_mover_throw( human_name ) 
  3055. 	character_throw_havok_weapon( human_name, nil ) 
  3056. end 
  3057.  
  3058. function mesh_mover_wield( mover_name, human_name, instant ) 
  3059. 	return character_wield_havok_weapon( human_name, mover_name, instant, IS_MOVER ) 
  3060. end 
  3061.  
  3062. function item_wield( item_name, human_name, instant ) 
  3063. 	return character_wield_havok_weapon( human_name, item_name, instant, IS_ITEM ) 
  3064. end