./game_lib.lua

  1. -- Exclude the following functions from automatic documentation generation 
  2. --[[DocGenExclude: 
  3. character_is_ready_to_speak 
  4. group_create_check_done_loop 
  5. helicopter_fly_to_internal 
  6. ]] 
  7.  
  8. -------------------- 
  9. -- Script Globals -- 
  10. -------------------- 
  11.  
  12. -- floating_values_types in autil_hud.h 
  13. FLOATING_VALUE_CASH				= 0 
  14. FLOATING_VALUE_POINTS			= 1 
  15. FLOATING_VALUE_TIME				= 2 
  16. FLOATING_VALUE_BONUS_TIME		= 3 
  17. FLOATING_VALUE_CUSTOM_TEXT		= 4 
  18.  
  19.  
  20. MINIMAP_ICON_KILL								= "icon_class_kill" 
  21. MINIMAP_ICON_PROTECT_ACQUIRE				= "icon_class_protectacquire" 
  22. MINIMAP_ICON_LOCATION						= "icon_class_location" 
  23. MINIMAP_ICON_USE								= "icon_class_use" 
  24. MINIMAP_ICON_SAINTS							= "icon_class_saints" 
  25. MINIMAP_ICON_SYNDICATE						= "icon_class_syndicate" 
  26. MINIMAP_ICON_STOMP							= "icon_class_stomp" 
  27. MINIMAP_ICON_BLAST							= "icon_class_blast" 
  28. MINIMAP_ICON_BUFF								= "icon_class_buff" 
  29. MINIMAP_ICON_TELE								= "icon_class_tele" 
  30. MINIMAP_ICON_SUMMON								= MINIMAP_ICON_TELE -- Since we replaced tk, we'll just assign it the same value, in case there are any other scripts referencing this. 
  31. MINIMAP_ICON_DLC_XMAS_GIFT						= "icon_class_xmas_gift" 
  32. MINIMAP_ICON_DLC_XMAS_NAUGHTY					= "icon_class_xmas_naughty" 
  33.  
  34. INGAME_EFFECT_LOCATION						= "vfx_missioncheckPointicon" 
  35. INGAME_EFFECT_CUTSCENE						= "mission_purchase" 
  36. INGAME_EFFECT_MP_TUTORIAL					= "mission_complete_mp" 
  37.  
  38. INGAME_EFFECT_VEHICLE_INTERACT			= "Icon_lg_b" 
  39. INGAME_EFFECT_VEHICLE_PROTECT_ACQUIRE	= "Icon_lg_c" 
  40. INGAME_EFFECT_VEHICLE_KILL					= "Icon_lg_d" 
  41.  
  42. INGAME_EFFECT_VEHICLE_LOCATION			= "vfx_missioncheckPointCar" 
  43. INGAME_EFFECT_VEHICLE_CUTSCENE			= "vfx_missioncheckPointCar" 
  44.  
  45. INGAME_EFFECT_CHECKPOINT					= "vfx_missioncheckPointicon" 
  46.  
  47. -- Object Indicator Assets 
  48. OI_ASSET_INVALID	  = -1 
  49. OI_ASSET_KILL		  = 0 
  50. OI_ASSET_DEFEND	  = 1 
  51. OI_ASSET_USE		  = 2 
  52. OI_ASSET_REVIVE	  = 3 
  53. OI_ASSET_LOCATION	  = 4 
  54. OI_ASSET_COOP		  = 5 
  55. OI_ASSET_KILL_FULL  = 6 
  56. OI_ASSET_FINSHER    = 7 -- Not used in lua, just here so we stay in sync with C. 
  57. OI_ASSET_KILL_TIRES = 8 
  58. OI_ASSET_HITMAN     = 9 
  59. OI_ASSET_CHOP_SHOP  = 10 
  60. OI_ASSET_ALL        = 11 -- Not used in lua, just here so we stay in sync with C. 
  61. OI_ASSET_SYNDICATE  = 12 
  62. OI_ASSET_GRENADE 		= 13 
  63. OI_ASSET_FINISHER_WARDEN 	= 14 -- Not used in lua, just here so we stay in sync with C. 
  64. OI_ASSET_GT_HUMAN 	= 15 -- Not used in lua, just here so we stay in sync with C. 
  65. OI_ASSET_GT_MOVER 	= 16 -- Not used in lua, just here so we stay in sync with C. 
  66. OI_ASSET_GT_VEHICLE 	= 17 -- Not used in lua, just here so we stay in sync with C. 
  67. OI_ASSET_POWER_TELE	= 18 
  68. OI_ASSET_POWER_SUMMON = OI_ASSET_POWER_TELE -- Since we replaced tk, we'll just assign it the same value, in case there are any other scripts referencing this. 
  69. OI_ASSET_CID = 19 
  70. OI_ASSET_POWER_STOMP = 20 
  71. OI_ASSET_POWER_FREEZE = 21 
  72. OI_ASSET_POWER_BLAST	= 22 
  73. OI_ASSET_POWER_BUFF	= 23 
  74. OI_ASSET_DLC_XMAS_GIFT    = 24 
  75. OI_ASSET_DLC_XMAS_NAUGHTY = 25 
  76.  
  77. -- This must match the flags defined in object_indicators.h 
  78. OI_FLAG_NONE					= 0x00 
  79. OI_FLAG_STICKY					= 0x01 
  80. OI_FLAG_DISPLAY_DISTANCE	= 0x02 
  81. OI_FLAG_PULSE					= 0x04 
  82. OI_FLAG_FADE					= 0x08 
  83. OI_FLAG_PARTIAL_HIDE			= 0x10 
  84. OI_FLAGS_DEFAULT				= OI_FLAG_STICKY + OI_FLAG_DISPLAY_DISTANCE + OI_FLAG_PARTIAL_HIDE 
  85. OI_FLAGS_LOCATION				= OI_FLAG_STICKY + OI_FLAG_DISPLAY_DISTANCE + OI_FLAG_PULSE 
  86. OI_FLAGS_FULL					= OI_FLAG_STICKY + OI_FLAG_DISPLAY_DISTANCE 
  87.  
  88. SYNC_LOCAL	= 1 
  89. SYNC_REMOTE = 2 
  90. SYNC_ALL		= 3 
  91.  
  92. VAULT_SEQUENCE = 0 
  93. BALL_SEQUENCE = 1 
  94.  
  95. MAX_NOTORIETY_LEVEL	= 6 
  96. MAX_NOTORIETY_NO_WARDENS = 5 
  97. INVALID_THREAD_HANDLE = -1 
  98. INVALID_CONVERSATION_HANDLE = -1 
  99. INVALID_PERSONA_HANDLE = 0 
  100. INVALID_MESSAGE_HANDLE = -1  
  101. INVALID_HUD_DISPLAY_STATE = -1 
  102. INVALID_EFFECT_HANDLE = -1 
  103.  
  104. MISSION_START_CHECKPOINT = "mission start" 
  105.  
  106. LOCAL_PLAYER	= "#PLAYER1#" 
  107. REMOTE_PLAYER	= "#PLAYER2#" 
  108. CLOSEST_PLAYER = "#CLOSEST_PLAYER#" 
  109. CLOSEST_TEAM1	= "#CLOSEST_TEAM1#" 
  110. CLOSEST_TEAM2	= "#CLOSEST_TEAM2#" 
  111. FOLLOWER1		= "#FOLLOWER1#" 
  112. FOLLOWER2		= "#FOLLOWER2#" 
  113. FOLLOWER3		= "#FOLLOWER3#" 
  114.  
  115. PLAYER_TAG_LIST = { 
  116. 	"#PLAYER1#", 
  117. 	"#PLAYER2#", 
  118. 	"#PLAYER3#", 
  119. 	"#PLAYER4#", 
  120. 	"#PLAYER5#", 
  121. 	"#PLAYER6#", 
  122. 	"#PLAYER7#", 
  123. 	"#PLAYER8#" 
  124. } 
  125.  
  126. WEAPON_SLOT_NONE			= -1 
  127. WEAPON_SLOT_UNARMED		= 0 
  128. WEAPON_SLOT_MELEE			= 1 
  129. WEAPON_SLOT_PISTOL		= 2 
  130. WEAPON_SLOT_SMG			= 3 
  131. WEAPON_SLOT_SHOTGUN		= 4 
  132. WEAPON_SLOT_RIFLE			= 5 
  133. WEAPON_SLOT_EXPLOSIVE	= 6 
  134. WEAPON_SLOT_SPECIAL		= 7 
  135.  
  136. Mission_waypoint		= -1 
  137.  
  138. VT_AUTOMOBILE	= 0 
  139. VT_MOTORCYCLE	= 1 
  140. VT_AIRPLANE		= 2 
  141. VT_HELICOPTER	= 3 
  142. VT_VTOL			= 4 
  143. VT_WATERCRAFT	= 5 
  144. -- This means the player isn't in a vehicle. 
  145. VT_NONE			= 6 
  146.  
  147. IS_MOVER		= 1 
  148. IS_ITEM			= 2 
  149. INDETERMINATE	= 3 
  150.  
  151. VST_AMBULANCE = 0 
  152. VST_BUS = 1 
  153. VST_FBI = 2 
  154. VST_FIRETRUCK = 3 
  155. VST_INDUSTRIAL = 4 
  156. VST_METER_MAID = 5 
  157. VST_NEWS_VAN = 6 
  158. VST_POLICE = 7 
  159. VST_SWAT_VAN = 8 
  160. VST_TAXI = 9 
  161. VST_TOW_TRUCK = 10 
  162. VST_LIMO = 11 
  163. VST_ATV = 12 
  164. VST_TANK = 14 
  165. -- This player's vehicle isn't special or 
  166. -- this player isn't in a vehicle. 
  167. VST_NONE = 13 
  168.  
  169. -- Gender types 
  170. GT_NONE = 0 
  171. GT_MALE = 1 
  172. GT_FEMALE = 2 
  173.  
  174. -- Enable/Disable 
  175. ENABLE = true 
  176. DISABLE = false 
  177.  
  178. -- Trigger event state tracker globals 
  179. UPDATE_DEACTIVATED = 1 
  180. ALL_PLAYERS_DEACTIVATED = 2 
  181. ANY_PLAYER_DEACTIVATED = 3 
  182. UPDATE_ACTIVATED = 4 
  183. ALL_PLAYERS_ACTIVATED = 5 
  184. ALL_PLAYERS_ACTIVATED_RESET = 6 
  185. TRIGGER_MULTIPLE_TIMES = 7 
  186. TRIGGER_ONCE_FIRST_TRIGGERER = 8 
  187. TRIGGER_ONCE_PER_PLAYER = 9 
  188.  
  189. -- Parameters for use with npc_set_boss_ai 
  190. AI_BOSS_JYUNICHI = "Jyunichi" 
  191. AI_BOSS_AKUJI = "Akuji" 
  192.  
  193. START_FADE_OUT_TIME = 1.0 
  194. START_FADE_IN_TIME = 2.0 
  195. DEFAULT_END_DELAY_TIME = 2.0 
  196. DEFAULT_END_FADE_OUT_TIME = 3.0 
  197.  
  198. -- Persona override types 
  199. POT_ATTACK				= 1 
  200. POT_TAKE_DAMAGE		= 2 
  201. -- POT_TAUNT_NEGATIVE	= 3 (PA 7-14-08. There is no longer code-side support for this override type.) 
  202. POT_CUSTOM_1			= 4 
  203. POT_CUSTOM_2			= 5 
  204. POT_PRAISED_BY_PC		= 6 
  205. POT_TAUNTED_BY_PC		= 7 
  206. POT_BARTER				= 8 
  207. POT_GRATS_PC			= 9 
  208. POT_GRATS_SELF			= 10 
  209. POT_HIT_CAR				= 11 
  210. POT_HIT_OBJ				= 12 
  211. POT_HIT_PED				= 13 
  212.  
  213. -- Build types 
  214. BUILD_TYPE_NORMAL			= 1 
  215. BUILD_TYPE_AUSTRALIAN	= 2 
  216. BUILD_TYPE_GERMAN			= 3 
  217. BUILD_TYPE_JAPANESE_360	= 4 
  218. BUILD_TYPE_JAPANESE_PS3	= 5 
  219.  
  220. -- Persona situations associated w/ each override type 
  221. POT_SITUATIONS = { 
  222. 	[POT_ATTACK]			=	{"threat - alert (group attack)", 
  223. 									 "threat - alert (solo attack)"}, 
  224. 	[POT_TAKE_DAMAGE]		=	{"take damage",  
  225. 									 "threat - damage received (firearm)", 
  226. 									 "threat - damage received (melee)", 
  227. 									 "threat - damage received (vehicle)"}, 
  228. 	[POT_CUSTOM_1]			=	{"custom line 1"}, 
  229. 	[POT_CUSTOM_2]			=	{"custom line 2"}, 
  230. 	[POT_PRAISED_BY_PC]	=	{"observe - praised by pc"}, 
  231. 	[POT_TAUNTED_BY_PC]	=	{"misc - respond to player taunt w/taunt"}, 
  232. 	[POT_BARTER]			=	{"hostage - barters"}, 
  233. 	[POT_GRATS_PC]			=	{"combat - congratulate player"}, 
  234. 	[POT_GRATS_SELF]		=	{"combat - congratulate self"}, 
  235. 	[POT_HIT_CAR]			=	{"observe - passenger when driver hits cars"}, 
  236. 	[POT_HIT_OBJ]			=	{"observe - passenger when driver hits object"}, 
  237. 	[POT_HIT_PED]			=	{"observe - passenger when driver hits peds"} 
  238. } 
  239.  
  240. -- Persona situation overrides, correlates to enum persona_situation_override 
  241. PS_OVERRIDE_MISSION01 = 1 
  242. PS_OVERRIDE_MISSION07 = 2 
  243. PS_OVERRIDE_MISSION17 = 3 
  244. PS_OVERRIDE_HELI_ACTIVITY = 4 
  245. PS_OVERRIDE_MISSION03 = 5 
  246. PS_OVERRIDE_SH02 = 6 
  247. PS_OVERRIDE_ESCORT = 7 
  248. PS_OVERRIDE_SH02_BRUTE = 8 
  249.  
  250. -- Constants use by the audio_play_conversation function. 
  251. -- These indices are the indices of each segment of a dialog stream 
  252. -- in the dialog stream table. 
  253. DIALOG_STREAM_AUDIO_NAME_INDEX = 1 
  254. DIALOG_STREAM_CHAR_NAME_INDEX = 2 
  255. DIALOG_STREAM_DELAY_SECONDS_INDEX = 3 
  256. DIALOG_STREAM_ANIM_ACTION_INDEX = 4 
  257.  
  258. -- Types of conversations 
  259. NOT_CALL = 1 
  260. OUTGOING_CALL = 2 
  261. INCOMING_CALL = 3 
  262.  
  263. -- Used in a dialog stream to denote that this is a character speaking through the cellphone 
  264. CELLPHONE_CHARACTER  = "cellphone character" 
  265.  
  266. -- Ring sounds 
  267. CELLPHONE_INCOMING = "SYS_CELL_RING_1" 
  268. CELLPHONE_OUTGOING = "SYS_CELL_RING_OTHER" 
  269.  
  270. -- Screen fade styles 
  271. SFX_FADE_LEFT_TO_RIGHT = 0 
  272. SFX_FADE_ALPHA_FADE = 1 
  273.  
  274. -- Screen fade types 
  275. SFX_FADE_TYPE_DEFAULT = 0 
  276. SFX_FADE_TYPE_CRIB = 1 
  277. SFX_FADE_TYPE_WORLD = 2 
  278. SFX_FADE_TYPE_NIGHTMARE = 3 
  279.  
  280. -- Damaged by types (from damaged_by_types enum) 
  281. DBT_NONE			= -1 
  282. DBT_CAR				= 0		-- collision with vehicle 
  283. DBT_EXPLOSION		= 1		-- explosion-type weapon 
  284. DBT_BULLET			= 2		-- bullet-type weapon 
  285. DBT_LEVEL_OBJECT	= 3		-- collision with mover 
  286. DBT_MELEE			= 4		-- melee-type weapon 
  287. DBT_WORLD			= 5		-- collision with world 
  288. DBT_HUMAN			= 6		-- collision with human 
  289. DBT_FIRE			= 7		-- fire or flame-type weapon 
  290. DBT_WIND			= 8		-- helicopter downdraft 
  291. DBT_SONIC			= 9		-- sonic-type weapon 
  292. DBT_LASER			= 10	-- laser-type weapon 
  293. DBT_KNEECAPPER		= 11	-- vehicle kneecapper 
  294. DBT_FORCED			= 12	-- hard-coded or scripted damage 
  295. DBT_DFA				= 13	-- death from above 
  296. DBT_STOMP			= 14	-- super stomp 
  297. DBT_ENERGY_BLAST	= 15	-- energy blast 
  298.  
  299. -- Gang persona tables 
  300. -- 
  301. --	The key of each entry is the persona, and the value is the tag prfix of its situation triggers. 
  302. -- 
  303. -- These tables are used in conjunction with persona_override_group_start and persona_override_group_stop. 
  304.  
  305. BROTHERHOOD_PERSONAS = { 
  306. 	["HM_Bro1"]	=	"HMBRO1", 
  307. 	["HM_Bro2"]	=	"HMBRO2", 
  308. 	["HM_Bro3"]	=	"HMBRO3", 
  309.  
  310. 	["HF_Bro1"]	=	"HFBRO1", 
  311. 	["HF_Bro2"]	=	"HFBRO2", 
  312.  
  313. 	["WM_Bro1"]	=	"WMBRO1", 
  314. 	["WM_Bro2"]	=	"WMBRO2", 
  315. 	["WM_Bro3"]	=	"WMBRO3", 
  316.  
  317. 	["WF_Bro1"]	=	"WFBRO1", 
  318. 	["WF_Bro2"]	=	"WFBRO2", 
  319. } 
  320.  
  321. RONIN_PERSONAS	= { 
  322. 	["AM_Ron1"]	=	"AMRON1", 
  323. 	["AM_Ron2"]	=	"AMRON2", 
  324. 	["AM_Ron3"]	=	"AMRON3", 
  325.  
  326. 	["AF_Ron1"]	=	"AFRON1", 
  327. 	["AF_Ron2"]	=	"AFRON2", 
  328. 	["AF_Ron3"]	=	"AFRON3", 
  329.  
  330. 	["WM_Ron1"]	=	"WMRON1", 
  331. 	["WM_Ron2"]	=	"WMRON2", 
  332.  
  333. 	["WF_Ron1"]	=	"WFRON1", 
  334. 	["WF_Ron2"]	=	"WFRON2", 
  335. } 
  336.  
  337. SAINTS_PERSONAS = { 
  338. 	["AM_TSS1"]	=	"AMTSS1", 
  339. 	["AM_TSS2"]	=	"AMTSS2", 
  340. 	["AM_TSS3"]	=	"AMTSS3", 
  341.  
  342. 	["AF_TSS1"]	=	"AFTSS1", 
  343. 	["AF_TSS2"]	=	"AFTSS2", 
  344. 	["AF_TSS3"]	=	"AFTSS3", 
  345.  
  346. 	["BM_TSS1"]	=	"BMTSS1", 
  347. 	["BM_TSS2"]	=	"BMTSS2", 
  348. 	["BM_TSS3"]	=	"BMTSS3", 
  349.  
  350. 	["BF_TSS1"]	=	"BFTSS1", 
  351. 	["BF_TSS2"]	=	"BFTSS2", 
  352. 	["BF_TSS3"]	=	"BFTSS3", 
  353.  
  354. 	["HM_TSS1"]	=	"HMTSS1", 
  355. 	["HM_TSS2"]	=	"HMTSS2", 
  356. 	["HM_TSS3"]	=	"HMTSS3", 
  357.  
  358. 	["HF_TSS1"]	=	"HFTSS1", 
  359. 	["HF_TSS2"]	=	"HFTSS2", 
  360. 	["HF_TSS3"]	=	"HFTSS3", 
  361.  
  362. 	["WM_TSS1"]	=	"WMTSS1", 
  363. 	["WM_TSS2"]	=	"WMTSS2", 
  364. 	["WM_TSS3"]	=	"WMTSS3", 
  365.  
  366. 	["WF_TSS1"]	=	"WFTSS1", 
  367. 	["WF_TSS2"]	=	"WFTSS2", 
  368. 	["WF_TSS3"]	=	"WFTSS3", 
  369. } 
  370.  
  371. SAMEDI_PERSONAS = { 
  372. 	["BM_SoS2"]	=	"BMSOS2", 
  373.  
  374. 	["BF_SoS1"]	=	"BFSOS1", 
  375. 	["BF_SoS2"]	=	"BFSOS2", 
  376. 	["BF_SoS3"]	=	"BFSOS3", 
  377.  
  378. 	["WM_SoS2"]	=	"WMSOS2", 
  379.  
  380. 	["WF_SoS1"]	=	"WFSOS1", 
  381. } 
  382.  
  383. COP_PERSONAS = { 
  384. --	["AM_Cop"]	=	"AMCOP",		Currently has no mission specific lines 
  385. 	["AF_Cop"]	=	"AFCOP", 
  386. 	 
  387. 	["BM_Cop"]	=	"BMCOP", 
  388. 	["BF_Cop"]	=	"BFCOP", 
  389. 	 
  390. 	["HM_Cop"]	=	"HMCOP", 
  391. 	["HF_Cop"]	=	"HFCOP", 
  392. 	 
  393. 	["WM_Cop"]	=	"WMCOP", 
  394. 	["WF_Cop"]	=	"WFCOP", 
  395. } 
  396.  
  397. BUM_PERSONAS = { 
  398. 	["BM_Hobo"]		=	"BMHOBO1", 
  399. 	["BF_Hobo"]		=	"BFHOBO1", 
  400. 	 
  401. 	["HM_Hobo"]		=	"HMHOBO1", 
  402. 	["HF_Hobo"]		=	"HFHOBO1", 
  403. 	 
  404. 	["WM_Hobo1"]	=	"WMHOBO1", 
  405. 	["WM_Hobo2"]	=	"WMHOBO2", 
  406. 	 
  407. 	["WF_Hobo1"]	=	"WFHOBO1", 
  408. 	["WF_Hobo2"]	=	"WFHOBO2", 
  409. } 
  410.  
  411. -- Human teams ( gangs ) 
  412. HUMAN_TEAM_BROTHERHOOD		= 1 
  413. HUMAN_TEAM_RONIN				= 2 
  414. HUMAN_TEAM_SAMEDI				= 3 
  415.  
  416. -- AI Atttack modes 
  417. ATTACK_ON_SIGHT = 0 
  418. ATTACK_NOW = 1 
  419. ATTACK_NOW_NEVER_LOSE = 2 
  420.  
  421. -- Level light toggle styles 
  422. LEVEL_LIGHT_TOGGLE_STYLE_POP = 0 
  423. LEVEL_LIGHT_TOGGLE_STYLE_FADE = 1 
  424. LEVEL_LIGHT_TOGGLE_STYLE_FLICKER = 2 
  425.  
  426. -- Spawn Region Filters 
  427. SRF_DEFAULT = 1 
  428. SRF_1 = 2 
  429. SRF_2 = 4 
  430. SRF_3 = 8 
  431. SRF_4 = 16 
  432. SRF_5 = 32 
  433. SRF_6 = 64 
  434. SRF_7 = 128 
  435. SRF_ALL = 255 
  436.  
  437. -- Global Variables -- 
  438. Player_controls_disabled_by_mission_start_fadeout = false 
  439.  
  440. -- HUD Elements -- 
  441. HUD_ELEM_GSI 					= 0 
  442. HUD_ELEM_MINIMAP 				= 1 
  443. HUD_ELEM_RETICLE 				= 2 
  444. HUD_ELEM_HIT_INDICATORS 		= 3 
  445. HUD_ELEM_WEAPONS 				= 4 
  446. HUD_ELEM_CASH_RESPECT_HOMEY 	= 5 
  447. HUD_ELEM_WEAPON_SWAP_MESSAGE 	= 6 
  448. HUD_ELEM_RADIO_STATION 			= 7 
  449. HUD_ELEM_VEHICLE_NAME 			= 8 
  450. HUD_ELEM_DIVERSIONS 			= 9 
  451. HUD_ELEM_MESSAGES 				= 10 
  452. HUD_ELEM_TUTORIAL_HELP 			= 11 
  453. HUD_ELEM_AMMO_PICKUP			= 12 
  454. HUD_ELEM_COLLECTION				= 13 
  455. HUD_ELEM_SUPER_REWARD			= 14 
  456. HUD_ELEM_MECH					= 15 
  457.  
  458. -- Must be explicitly hidden 
  459. HUD_ELEM_SCREEN_FX 				= 16 
  460. HUD_ELEM_SUBTITLES 				= 17 
  461. HUD_ELEM_OI 					= 18 
  462. HUD_ELEM_RADIAL					= 19 
  463.  
  464. HUD_ALL_ELEM 					= 20 
  465.  
  466.  
  467. -- HUD Fade Levels -- 
  468. HUD_FADE_HIDDEN = 0 
  469. HUD_FADE_TRANSPARENT = 1 
  470. HUD_FADE_VISIBLE = 2 
  471. HUD_FADE_NO_CHANGE = 3 
  472.  
  473. -- Helicopter pathfinding orientations 
  474. HELI_PF_FACE_ALONG_PATH = 0 
  475. HELI_PF_FACE_TARGET = 1 
  476. HELI_PF_LEFT_SIDE_FACE_TARGET = 2 
  477. HELI_PF_RIGHT_SIDE_FACE_TARGT = 3 
  478. HELI_PF_FACE_DOWN_AT_TARGET = 4 
  479. HELI_PF_PATH_PITCH = 5 
  480. HELI_PF_LEFT_WING_UP = 6 
  481.  
  482. -- Upgraded weapon levels 
  483. WEAPON_LEVEL1 = 0x0		-- no upgrades 
  484. WEAPON_LEVEL2 = 0x1		-- first upgrade 
  485. WEAPON_LEVEL3 = 0x3		-- first and second upgrades 
  486. WEAPON_LEVEL4 = 0x7		-- first second and third upgrades 
  487.  
  488. -- Character Gender Types 
  489. GENDER_TYPE_MALE = 0 
  490. GENDER_TYPE_FEMALE = 1 
  491.  
  492. -- Hit Locations 
  493. HIT_NONE 			= 0 
  494. HIT_GENERAL 		= 1 
  495. HIT_TORSO 			= 2 
  496. HIT_PELVIS 			= 3 
  497. HIT_LEFT_ARM 		= 4 
  498. HIT_RIGHT_ARM 		= 5 
  499. HIT_HEAD 			= 6 
  500. HIT_LEFT_LEG 		= 7 
  501. HIT_RIGHT_LEG 		= 8 
  502. HIT_RIOT_SHIELD 	= 9 
  503. HIT_ARMOR 			= 10 
  504. HIT_LOWER_BODY		= 11 
  505. HIT_EXPLOSIVE		= 12 
  506.  
  507. -- Shop types 
  508. SHOP_TYPE_CLOTHING 			= 0 
  509. SHOP_TYPE_WEAPON 			= 1 
  510. SHOP_TYPE_PLASTIC_SURGEON 	= 2 
  511. SHOP_TYPE_JEWELRY 			= 3 
  512. SHOP_TYPE_TATTOO 			= 4 
  513. SHOP_TYPE_MECHANIC 			= 5 
  514. SHOP_TYPE_VEHICLE_DEALER 	= 6 
  515. SHOP_TYPE_MISC_PROPERTY 	= 7 
  516.  
  517. -- player superpowers 
  518. SUPERPOWER_SUMMON = 0 
  519. SUPERPOWER_STOMP = 1 
  520. SUPERPOWER_BUFF = 2 
  521. SUPERPOWER_BLAST = 3 
  522.  
  523. -- elements 
  524. PLAYER_SUPERPOWER_ELEMENT_NONE = -1 
  525.  
  526. PLAYER_SUPERPOWER_SUMMON_IMP = 0 
  527. PLAYER_SUPERPOWER_SUMMON_TOWER = 1 
  528. PLAYER_SUPERPOWER_SUMMON_TITAN = 2 
  529.  
  530. PLAYER_SUPERPOWER_STOMP_FORCE = 3 
  531. PLAYER_SUPERPOWER_STOMP_VACUUM = 4 
  532. PLAYER_SUPERPOWER_STOMP_FLASH = 5 
  533.  
  534. PLAYER_SUPERPOWER_BLAST_STONE = 6 
  535. PLAYER_SUPERPOWER_BLAST_SOUL = 7 
  536. PLAYER_SUPERPOWER_BLAST_SHADOW = 8 
  537.  
  538. PLAYER_SUPERPOWER_AURA_COLDFIRE = 9 
  539. PLAYER_SUPERPOWER_AURA_VAMP = 10 
  540. PLAYER_SUPERPOWER_AURA_WORSHIP = 11 
  541.  
  542. --PLAYER_SUPERPOWER_TK_FORCE = 12 
  543. --PLAYER_SUPERPOWER_TK_LIGHTNING = 13 
  544. --PLAYER_SUPERPOWER_TK_LIFE_STEAL = 14 
  545.  
  546. PLAYER_SUPERPOWER_TK_EXPLODE 		= 12 
  547. PLAYER_SUPERPOWER_STOMP_EXPLODE 	= 13 
  548. PLAYER_SUPERPOWER_BLAST_EXPLODE 	= 14 
  549. PLAYER_SUPERPOWER_BUFF_EXPLODE 		= 15 
  550.  
  551. PLAYER_SUPERPOWER_TK_BLING 			= 16 
  552. PLAYER_SUPERPOWER_STOMP_BLING 		= 17 
  553. PLAYER_SUPERPOWER_BLAST_BLING 		= 18 
  554. PLAYER_SUPERPOWER_BUFF_BLING 		= 19 
  555.  
  556.  
  557.  
  558. -- Rail table  
  559. Rail_data = { } 
  560.  
  561. -- 
  562. Generator_data = { } 
  563. Generator_objective = "" 
  564.  
  565. ------------------------ 
  566. -- Internal functions -- 
  567. ------------------------ 
  568.  
  569. function character_is_ready_to_speak( speaking_character ) 
  570.    -- Check for a character that does not exist first 
  571.    if (not character_exists(speaking_character)) then 
  572. 		return false 
  573. 	end 
  574.  
  575. 	if (character_is_dead(speaking_character)) then 
  576. 		return false 
  577. 	end 
  578.  
  579. 	if (character_is_ragdolled(speaking_character)) then 
  580. 		return false 
  581. 	end 
  582. 	 
  583. 	if (character_is_on_fire(speaking_character)) then 
  584.       return false 
  585.    end 
  586.  
  587. 	-- The character can speak 
  588.    return true 
  589. end 
  590.  
  591. function group_create_check_done_loop(group) 
  592. 	local group_name = group 
  593.  
  594. 	if (type(group) == "table" and type(group.name) == "string") then 
  595. 		group_name = group.name 
  596. 	end 
  597.  
  598. 	while (not(group_create_check_done(group_name))) do 
  599. 		thread_yield() 
  600. 	end 
  601. end 
  602.  
  603. function group_create_unsynced_check_done_loop(group) 
  604. 	local group_name = group 
  605.  
  606. 	if (type(group) == "table" and type(group.name) == "string") then 
  607. 		group_name = group.name 
  608. 	end 
  609.  
  610. 	while (not(group_create_unsynced_check_done(group_name))) do 
  611. 		thread_yield() 
  612. 	end 
  613. 	 
  614. 	group_unsynced_do(group_name) 
  615. end 
  616.  
  617. -- Internal use: generalized helicopter_fly_to function 
  618. -- 
  619. -- name:				name of the helicopter 
  620. -- speed:				speed at which the helicopter will fly 
  621. -- direct:				if true, move directly, ignoring heightmap 
  622. -- follow:				if non-empty, target vehicle to follow 
  623. -- continue_at_goal:	if true, continue forward at goal 
  624. -- path:				name of scripted_path or single navpoint 
  625. -- follow_dist:			distance at which to follow 
  626. -- directly_above:		whether the helicopter should be directly above the target vehicle 
  627. -- loop_path:			If true, the path should loop back on itself 
  628. -- start_full_speed:	if true, the helicopter will start the path at the full speed specified 
  629. -- reverse_sp:			fly in the reverse direction of the spline 
  630. -- 
  631. function helicopter_fly_to_internal(name, speed, direct, follow, continue_at_goal, path, follow_dist, directly_above, loop_path, start_full_speed, reverse_sp) 
  632. 	local override_player_control = false -- very specific use case for path while player is in control - DO NOT USE 
  633. 	if (helicopter_fly_to_do(name, speed, direct, follow, continue_at_goal, path, follow_dist, directly_above, loop_path, start_full_speed, reverse_sp, override_player_control)) then 
  634. 		local check_done = vehicle_pathfind_check_done(name) 
  635. 		 
  636. 		while ( check_done == 0) do 
  637. 			thread_yield() 
  638. 			check_done = vehicle_pathfind_check_done(name) 
  639. 		end 
  640. 		 
  641. 		return check_done == 1 
  642. 	else 
  643. 		return false 
  644. 	end 
  645. end 
  646.  
  647. -------------------- 
  648. -- Script Actions -- 
  649. -------------------- 
  650.  
  651. -- Make a human play an animation and optional morph, blocking until the animation is done. 
  652. -- 
  653. -- name:			(string) name of character 
  654. -- anim_name:		(string) name of animation to play (valid action names can be found in anim_actions.xtbl, in data/tables) 
  655. -- morph_name:		(string, optional) name of morph to use (defaults to the animation name) 
  656. -- force_play:		(boolean, optional) if true, forces the animation to play on the character, even if dead (defaults to false) 
  657. -- percentage:		(float, optional) percentage done to check for (defaults to 0.8) 
  658. -- stand_still:		(boolean, optional) if true, the character is reset to a standing state before the animation is played (defaults to false) 
  659. -- zero_movement:	(boolean, optional) if ture, the charaters movement speed it set to zero (defaults to false) 
  660. -- navpoint:		(string, optional) slide into navpoint if provided 
  661. -- dest_nav:		(string, optional) destination navpoint to slide into if provided 
  662. -- layered:			(boolean, optional) TRUE if the action should be layered ontop of other scripted actions, FALSE otherwise [layered anims cannot be querried with action_play_is_finished()] (defaults to false) 
  663. -- hold_last_frame:	(boolean, optional) TRUE if the action should be hold its last frame. (defaults to false) 
  664. -- no_script_control:	(boolean, optional) TRUE if we should skip the script control mode for the player. 
  665. -- navpoint_orient_only:(boolean, optional) TRUE if we only want to  
  666. -- 
  667. function action_play(name, anim_name, morph_name, force_play, percentage, stand_still, zero_movement, navpoint, dest_nav, hold_last_frame, no_script_control, navpoint_orient_only) 
  668. 	action_play_non_blocking(name, anim_name, morph_name, force_play, stand_still, zero_movement, navpoint, dest_nav, nil, hold_last_frame, no_script_control, navpoint_orient_only) 
  669. 	repeat 
  670. 		thread_yield() 
  671. 	until action_play_is_finished(name, percentage) 
  672. end 
  673.  
  674. -- Make a human play a custom animation, blocking until the animation is done. 
  675. -- 
  676. -- name:				(string) name of character 
  677. -- anim_name:		(string) name of animation to play (valid action names can be found in anim_actions.xtbl, in data/tables) 
  678. -- percentage:		(float, optional) percentage done to check for (defaults to 0.8) 
  679. -- 
  680. -- If possible, the action_play script action should be used instead where possible. 
  681. -- 
  682. function action_play_custom(name, anim_name, percentage) 
  683. 	while not action_play_custom_do(name, anim_name) do 
  684. 		thread_yield() 
  685. 	end 
  686.  
  687. 	repeat 
  688. 		thread_yield() 
  689. 	until action_play_is_finished(name, percentage) 
  690. end 
  691.  
  692. -- Make a human play a direction stumble, blocking until the animation is done 
  693. -- 
  694. -- name:			(string) name of character 
  695. -- nav_name:		(string) name of navpoint indicating the direction to stumble 
  696. -- percentage:		(float, optional) percentage done to check for (defaults to 0.8) 
  697. -- do_flinch:		(boolean, optional) true if a flinch should be in place of the stumble animations 
  698. -- 
  699. -- If possible, the action_play script action should be used instead where possible. 
  700. -- 
  701. function action_play_directional_stumble(name, nav_name, percentage, do_flinch) 
  702. 	while not action_play_directional_stumble_do(name, nav_name, do_flinch) do 
  703. 		thread_yield() 
  704. 	end 
  705. 	 
  706. 	repeat 
  707. 		thread_yield() 
  708. 	until action_play_is_finished(name, percentage) 
  709. end 
  710.  
  711. -- Make a human play an animation without blocking. 
  712. -- 
  713. -- name:			(string) name of character 
  714. -- anim_name:		(string) name of animation to play (valid action names can be found in anim_actions.xtbl, in data/tables) 
  715. -- morph_name:		(string, optional) name of morph to use (defaults to the animation name) 
  716. -- force_play:		(boolean, optional) if true, forces the animation to play on the character, even if dead (defaults to false) 
  717. -- stand_still:		(boolean, optional) if true, the character is reset to a standing state before the animation is played (defaults to false) 
  718. -- zero_movement:	(boolean, optional) if ture, the charaters movement speed it set to zero (defaults to false)	 
  719. -- navpoint:		(string, optional) slide into navpoint if provided 
  720. -- dest_nav:		(string, optional) slide into destination navpoint if provided 
  721. -- layered:			(boolean, optional) TRUE if the action should be layered ontop of other scripted actions, FALSE otherwise [layered anims cannot be querried with action_play_is_finished()] (defaults to false) 
  722. -- hold_last_frame:	(boolean, optional) TRUE if the action should be hold its last frame. (defaults to false) 
  723. -- 
  724. -- NB: This function will still block until the animation actually starts playing. 
  725. -- 
  726. function action_play_non_blocking(name, anim_name, morph_name, force_play, stand_still, zero_movement, navpoint, dest_nav, layered, hold_last_frame, no_script_control, navpoint_orient_only) 
  727. 	while not action_play_do(name, anim_name, morph_name, force_play, stand_still, zero_movement, navpoint, dest_nav, layered, hold_last_frame, no_script_control, navpoint_orient_only) do 
  728. 		thread_yield() 
  729. 	end 
  730. end 
  731.  
  732. -- Make a pair of humans play an animation.  This function blocks 
  733. -- 
  734. -- attacker:			(string) name of attacker 
  735. -- victim: 				(string) name of victim 
  736. -- anim_name:			(string) name of synced animation 
  737. -- start_nav_name:      (string, optional) name of the nav point with which to orient the synced animation 
  738. -- warp_to_nav:			(boolean, optional) Set to true to warp the attacker and victim to the start nav point (Generally should be false, navpoint must be in loaded zone) (defaults to false) 
  739. -- sync_type:			(integer, optional) synchronization type (SYNC_LOCAL = affects local player, SYNC_REMOTE = affects remote player, or SYNC_ALL = affects both players; defaults to SYNC_ALL) 
  740. -- percentage:			(float, optional) Percentage of animation playback before returning (defaults to 1.0) 
  741. -- 
  742. function action_play_synced(attacker, victim, anim_name, start_nav, warp_to_nav, sync_type, percentage) 
  743. 	while not action_play_synced_do(attacker, victim, anim_name, start_nav, warp_to_nav, sync_type) do 
  744. 		thread_yield() 
  745. 	end 
  746. 	 
  747. 	repeat 
  748. 		thread_yield() 
  749. 	until action_play_synced_is_finished(attacker, victim, percentage) 
  750. end 
  751.  
  752. -- Make a pair of humans play an animation.  This function blocks 
  753. -- 
  754. -- attacker:			(string) name of attacker 
  755. -- victim: 				(string) name of victim 
  756. -- anim_name:			(string) name of synced animation 
  757. -- start_nav_name:      (string, optional) name of the nav point with which to orient the synced animation 
  758. -- sync_type:			(integer, optional) synchronization type (SYNC_LOCAL = affects local player, SYNC_REMOTE = affects remote player, or SYNC_ALL = affects both players; defaults to SYNC_ALL) 
  759. -- 
  760. -- NB: This function will still block until the animation actually starts playing. 
  761. -- 
  762. function action_play_synced_non_blocking(attacker, victim, anim_name, start_nav, sync_type) 
  763. 	while not action_play_synced_do(attacker, victim, anim_name, start_nav, nil, sync_type) do 
  764. 		thread_yield() 
  765. 	end 
  766. end 
  767.  
  768. -- Make an airplane fly through a series of navpoints 
  769. --  
  770. -- name:		(string) name of the airplane 
  771. -- speed:		(float) speed in m/s 
  772. -- path:		(string) name of a scripted_path, or single navpoint  
  773. -- 
  774. function airplane_fly_to(name, speed, path) 
  775. 	-- Wait until the resource is loaded. 
  776. 	-- character_wait_for_loaded_resource(name) 
  777. 			 
  778. 	if (airplane_fly_to_do(name, speed, path)) then 
  779. 		local check_done = vehicle_pathfind_check_done(name) 
  780. 		 
  781. 		while ( check_done == 0) do 
  782. 			thread_yield() 
  783. 			check_done = vehicle_pathfind_check_done(name) 
  784. 		end 
  785. 		 
  786. 		return check_done == 1 
  787. 	else 
  788. 		return false 
  789. 	end 
  790. end 
  791.  
  792.  
  793. -- Make an airplane land on a runway. 
  794. -- 
  795. -- name:				(string) name of the airplane 
  796. -- runway_start:	(string) name of the navpoint for the start of the runway (must be oriented in the direction of the runway) 
  797. -- 
  798. -- Note that the plane must already be heading in approximately the correct direction of the runway. 
  799. -- The plane will land after the runway_start position. 
  800. -- 
  801. function airplane_land(name, runway_start) 
  802. 	if (not airplane_land_do( name, runway_start )) then 
  803. 		return 
  804. 	end 
  805. 	 
  806. 	while( vehicle_pathfind_check_done(name) == 0) do 
  807. 		thread_yield() 
  808. 	end 
  809.  
  810. end 
  811.  
  812. -- Make an airplane take off straight in the direction they are currently facing. 
  813. -- 
  814. -- name:	(string) name of the airplane 
  815. -- 
  816. function airplane_takeoff(name) 
  817. 	if (not airplane_takeoff_do( name )) then 
  818. 		return 
  819. 	end 
  820. 	 
  821. 	while( vehicle_pathfind_check_done(name) == 0) do 
  822. 		thread_yield() 
  823. 	end 
  824.  
  825. end 
  826.  
  827. -- Make an NPC attack the closest player. 
  828. -- 
  829. -- name:		(string) name of the NPC 
  830. -- 
  831. -- This script action will silently fail if the NPC is dead. 
  832. -- 
  833. function attack_closest_player( npc_name ) 
  834.    local distance, closest_player = get_dist_closest_player_to_object( npc_name ) 
  835.    attack_safe( npc_name, closest_player ) 
  836. end 
  837.  
  838. -- Make a character attack another character, but checks to see if either character is dead first. 
  839. -- 
  840. -- attacker:	(string) name of the attacker 
  841. -- target:		(string, optional) name of the target (defaults to the player) 
  842. -- 
  843. -- If either the attacker of target is dead, the attack command is ignored. 
  844. -- 
  845. function attack_safe( npc_name, target ) 
  846. 	if target == nil then 
  847. 		target = CLOSEST_PLAYER 
  848. 	end 
  849.  
  850. 	if ( ( not character_is_dead( npc_name ) ) and ( ( not character_is_dead( target ) ) ) ) then 
  851. 		attack( npc_name, target )  
  852. 	end 
  853. end 
  854.  
  855. -- Play a 2D sound (by name). 
  856. -- 
  857. -- audio_name:		(string) name of sound to play 
  858. -- type_name:		(string, optional) name of audio source (can be "foley", "voice", "music", or "ambient"; defaults to "foley") 
  859. -- blocking:		(boolean, optional) set to true to block until the sound starts playing, else set to false to return immediately (defaults to false) 
  860. -- ignore_fade:	(boolean, optional) set to true to ignore the volume throttling that occurs with screen fades (defaults to false) 
  861. -- 
  862. -- returns:			(integer) audio instance handle, or -1 on error 
  863. -- 
  864. -- Example: 
  865. -- 
  866. --		audio_play("Some Foley Sound", "foley") 
  867. -- 
  868. -- Plays the foley sound, "Some Foley Sound", in 2D. 
  869. -- 
  870. function audio_play(audio_name, type_name, blocking, ignore_fade) 
  871. 	local handle = audio_play_do(audio_name, type_name, ignore_fade) 
  872. 	 
  873. 	if (not blocking) then 
  874. 		return handle; 
  875. 	end 
  876. 	 
  877. 	while (audio_is_playing(handle)) do 
  878. 		thread_yield() 
  879. 	end 
  880. 	 
  881. 	return -1; 
  882. end 
  883.  
  884. function audio_conversation_wait_for_end(handle) 
  885. 	while audio_conversation_playing(handle) do 
  886. 		thread_yield() 
  887. 	end 
  888. 	audio_conversation_end(handle) 
  889. end 
  890.  
  891. -- Play a conversation, which consists of a series of lines played by characters. 
  892. -- 
  893. -- dialog_stream:		(table) dialog stream segments that consist of a speaking character name, the name of the audio to play, and a delay in seconds between each dialog segment (character name is not necessary for cellphone calls) 
  894. -- cellphone_call:	(enumeration, optional) type of cellphone call (can be NOT_CALL, OUTGOING_CALL, or INCOMING_CALL; defaults to NOT_CALL) 
  895. -- 
  896. -- For cellphone calls, this function also takes care of cellphone animations. 
  897. -- 
  898. -- Example: 
  899. -- 
  900. --		FLEEING_LIEUTENANTS_DIALOG_STREAM = { 
  901. --			{ "SOS3_FLEE_L1", TOBIAS_NAME, 0 }, 
  902. --			{ "SOS3_FLEE_L2", LOCAL_PLAYER, 0 } 
  903. --		} 
  904. --		audio_play_conversation( FLEEING_LIEUTENANTS_DIALOG_STREAM, NOT_CALL ) 
  905. -- 
  906. -- Plays "SOS3_FLEE_L1" from Tobias and then "SOS3_FLEE_L2" from the local player. 
  907. -- 
  908. function audio_play_conversation( dialog_stream, cellphone_call ) 
  909.    if ( cellphone_call == nil ) then 
  910.       cellphone_call = NOT_CALL 
  911.    end 
  912.  
  913.    -- Open with the cellphone, if this is a cellphone 
  914.    -- conversation 
  915.    if ( cellphone_call == INCOMING_CALL ) then 
  916.       cellphone_animate_start_do() 
  917.       delay(0.5) 
  918.    elseif ( cellphone_call == OUTGOING_CALL ) then 
  919.       cellphone_animate_start_do() 
  920.       audio_play( CELLPHONE_OUTGOING, "foley", true ) 
  921.       delay(0.5) 
  922.    end 
  923.  
  924. 	-- Build a list of characters that will be tested for readyness before any line in the 
  925. 	-- conversation is played. We only use this list for NOT_CALL conversations. 
  926. 	local character_list = {} 
  927. 	if (cellphone_call == NOT_CALL) then 
  928. 		for segment_index, dialog_segment in pairs( dialog_stream ) do 
  929. 			local speaking_character = dialog_segment[DIALOG_STREAM_CHAR_NAME_INDEX] 
  930. 			character_list[speaking_character] = speaking_character 
  931. 		end 
  932. 	end 
  933.  
  934. 	local function dialog_characters_ready() 
  935. 		for i,character in pairs(character_list) do 
  936. 			if (not character_is_ready_to_speak(character)) then 
  937. 				return false 
  938. 			end 
  939. 		end 
  940. 		return true 
  941. 	end 
  942.  
  943.    for segment_index, dialog_segment in pairs( dialog_stream ) do 
  944.       local audio_name = dialog_segment[DIALOG_STREAM_AUDIO_NAME_INDEX] 
  945.       local speaking_character = dialog_segment[DIALOG_STREAM_CHAR_NAME_INDEX] 
  946.       local delay_seconds = dialog_segment[DIALOG_STREAM_DELAY_SECONDS_INDEX] 
  947. 		local anim_action = dialog_segment[DIALOG_STREAM_ANIM_ACTION_INDEX] 
  948.  
  949.       -- Play the dialog stream for each character 
  950.       if ( cellphone_call == NOT_CALL ) then 
  951.          repeat 
  952.             thread_yield() 
  953.          until ( dialog_characters_ready() ) 
  954.  
  955. 			local playing_action = (	(anim_action ~= nil) 
  956. 												and (not character_is_in_vehicle(speaking_character))  
  957. 												and (not character_is_combat_ready(speaking_character)) 
  958. 												and (not mesh_mover_wielding(speaking_character)) 
  959. 												and (vehicle_exit_check_done(speaking_character)) 
  960. 												and (vehicle_enter_check_done(speaking_character)) 
  961. 											) 
  962.  
  963. 			if (playing_action ) then	 
  964. 				inv_item_equip(nil,speaking_character) 
  965. 				action_play(speaking_character, anim_action, anim_action, true, 0.0, true) 
  966. 			end 
  967.          audio_play_for_character( audio_name, speaking_character, "voice", false, true) 
  968.          delay( delay_seconds ) 
  969.       -- Cellphone calls are different - just play the audio, don't use the character function unless 
  970.       -- it's the player. 
  971.       else 
  972.          -- For players, use audio_play_for_character so that the tag can be correctly translated 
  973.          if (	speaking_character ~= nil and character_is_player( speaking_character ) ) then 
  974.             -- Don't play lines unless and until the player is alive and in a state to deliver them 
  975.             repeat 
  976.                thread_yield() 
  977.             until ( character_is_ready_to_speak( speaking_character ) ) 
  978.             audio_play_for_character( audio_name, speaking_character, "voice", false, true) 
  979.          elseif ( speaking_character == CELLPHONE_CHARACTER or speaking_character == nil ) then 
  980.             -- for_cutscene = false, blocking = true, variant = nil, voice_distance = nil, cellphone_line = true 
  981.             audio_play_for_character( audio_name, LOCAL_PLAYER, "voice", false, true, nil, nil, true ) 
  982.          else 
  983.             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." ) 
  984.          	audio_play( audio_name, "voice", true ) 
  985.          end 
  986.          delay( delay_seconds ) 
  987.       end 
  988.    end 
  989.  
  990.    -- Close the cellphone, if this was a cellphone 
  991.    -- conversation 
  992.    if ( cellphone_call ~= NOT_CALL ) then 
  993.       cellphone_animate_stop_do() 
  994.    end 
  995. end 
  996.  
  997. -- Play a conversation while the speaker is in a vehicle. 
  998. -- 
  999. -- dialog_stream:		(table) dialog stream segments that consist of a speaking character name, the name of the audio to play, and a delay in seconds between each dialog segment (character name is not necessary for cellphone calls) 
  1000. -- 
  1001. -- Behaves in much the same way as audio_play_conversation, but blocks while the speaking character is not in a vehicle. 
  1002. -- 
  1003. function audio_play_conversation_in_vehicle(dialog_stream) 
  1004. 	-- Loop through the table conversation... 
  1005.    for segment_index, dialog_segment in pairs( dialog_stream ) do 
  1006.       local audio_name = dialog_segment[DIALOG_STREAM_AUDIO_NAME_INDEX] 
  1007.       local speaking_character = dialog_segment[DIALOG_STREAM_CHAR_NAME_INDEX] 
  1008.       local delay_seconds = dialog_segment[DIALOG_STREAM_DELAY_SECONDS_INDEX] 
  1009.  
  1010. 		-- Conversation requires them to be in a vehicle 
  1011. 		while (not character_is_in_vehicle(speaking_character)) do 
  1012. 			thread_yield() 
  1013. 		end 
  1014.  
  1015.       -- Play the dialog stream for each character 
  1016. 		audio_play_for_character(audio_name, speaking_character, "voice", false, true) 
  1017. 		delay(delay_seconds) 
  1018.    end 
  1019. end 
  1020.  
  1021. -- Play a cellphone ring and then a conversation. 
  1022. -- 
  1023. -- ring_name:	(string) name of the ring sound (from foley.xtbl) 
  1024. -- conv_name:	(string) name of the conversation (from voice.xtbl) 
  1025. -- 
  1026. -- The ring sound plays twice before the conversation occurs. This function also player cellphone animations. 
  1027. -- 
  1028. -- Note: this function does not display a "Press Y to ..." message on the screen. 
  1029. -- 
  1030. function audio_play_for_cellphone_force(ring_name, conv_name ) 
  1031.  
  1032. 	audio_play(ring_name, "foley", false, true) 
  1033. 	delay(0.5) 
  1034. 	audio_play(ring_name, "foley", false, true) 
  1035. 	delay(0.5) 
  1036. 	cellphone_animate_start_do() 
  1037.  
  1038. 	-- RCS: I think these should probably play in 2D...so audio_play would be more appropriate... 
  1039. 	audio_play_for_character(conv_name, LOCAL_PLAYER, "voice", false, true) 
  1040. 	cellphone_animate_stop_do() 
  1041.  
  1042. end 
  1043.  
  1044. -- Play a 3D sound (by name) on a character. 
  1045. -- 
  1046. -- audio_name:			(string) name of sound 
  1047. -- human_name:			(string) name of character 
  1048. -- type_name:			(string, optional) name of audio source (can be "foley", "voice", "music", or "ambient"; defaults to "foley") 
  1049. -- for_cutscene:		(boolean, optional) no longer used (NIQ 4/2/09: this parameter needs to be removed) 
  1050. -- blocking:			(boolean, optional) set to true if the function should block until the sound has finished playing (defaults to false) 
  1051. -- variant:				(integer, optional) index of the specific variant of the voice line to play (or -1 for a random selection; defaults to -1) 
  1052. -- voice_distance:	(integer, optional) distance that the foley can be heard from; only used for voices (0 = short, 1 = normal, 2 = long, 3 = extreme; defaults to -1, which is normal distance for peds, and extreme distance for passengers in cars) 
  1053. -- cellphone_line:	(boolean, optional) set to true if the audio is for a cellphone line (defaults to false) 
  1054. -- ignore_fade:		(boolean, optional) set to true to ignore the volume throttling that occurs with screen fades (defaults to false) 
  1055. -- 
  1056. -- returns:				(integer) audio instance handle, or -1 on error 
  1057. -- 
  1058. -- Example: 
  1059. -- 
  1060. --		audio_play_for_character("Woot", "#PLAYER1#", "foley") 
  1061. -- 
  1062. -- Plays the sound "Woot" on the local player. 
  1063. --  
  1064. function audio_play_for_character(audio_name, human_name, type_name, for_cutscene, blocking, variant, voice_distance, cellphone_line, ignore_fade)	 
  1065. 	if (character_is_dead(human_name)) then 
  1066. 		return -1, 0 
  1067. 	end 
  1068.    if ( cellphone_line == nil ) then 
  1069.       cellphone_line = false 
  1070.    end 
  1071.  
  1072. 	-- If we're playing a voice line, update the audio name to reflect the player's persona. 
  1073. 	local new_audio_name = audio_name 
  1074. 	if ( (type_name == "voice") and (character_is_player(human_name)) and cellphone_line == false ) then 
  1075. 		new_audio_name = persona_trigger_get_player_prefix(human_name) .. audio_name 
  1076. 	end 
  1077.  
  1078. 	local handle, play_time = audio_play_for_character_do(new_audio_name, human_name, type_name, blocking, variant, voice_distance, cellphone_line, ignore_fade) 
  1079.  
  1080. 	if (not(blocking)) then 
  1081. 		return handle, play_time; 
  1082. 	end 
  1083.  
  1084. 	-- While playing blocking audio, prevent random persona lines from playing 
  1085. 	if (character_is_player(human_name)) then 
  1086. 		audio_suppress_ambient_player_lines(true) 
  1087. 	else 
  1088. 		npc_suppress_persona(human_name, true) 
  1089. 	end 
  1090. 	 
  1091. 	if (handle > 0) then 
  1092. 		while (audio_is_playing(handle)) do 
  1093. 			thread_yield() 
  1094. 		end 
  1095. 	else 
  1096. 		delay( play_time ) 
  1097. 	end 
  1098.  
  1099. 	-- Allow random persona lines to play again 
  1100. 	if (character_is_player(human_name)) then 
  1101. 		audio_suppress_ambient_player_lines(false) 
  1102. 	else 
  1103. 		npc_suppress_persona(human_name, true) 
  1104. 	end	 
  1105.  
  1106. 	return -1, 0 
  1107. end 
  1108.  
  1109. -- Play a 3D sound (by name) on a character's weapon. 
  1110. -- 
  1111. -- audio_name:	(string) name of sound 
  1112. -- human_name:	(string) name of character 
  1113. -- type_name:	(string, optional) name of audio source (can be "foley", "voice", "music", or "ambient"; defaults to "foley") 
  1114. -- blocking:	(boolean, optional) set to true if the function should block until the sound has finished playing (defaults to false) 
  1115. -- 
  1116. -- returns:		(integer) audio instance handle, or -1 on error 
  1117. -- 
  1118. function audio_play_for_character_weapon( audio_name, character, type_name, blocking)	 
  1119. 	local handle = audio_play_for_character_weapon_do( audio_name, character, type_name) 
  1120. 	 
  1121. 	if not blocking then 
  1122. 		return handle 
  1123. 	end 
  1124. 	 
  1125. 	if handle >= 0 then 
  1126. 		repeat  
  1127. 			thread_yield() 
  1128. 		until not audio_is_playing(handle) 
  1129. 		return 0 
  1130. 	end 
  1131.  
  1132. 	return -1 
  1133. end 
  1134.  
  1135. -- Play a 3D sound (by name) on a mover. 
  1136. -- 
  1137. -- audio_name:		(string) name of sound 
  1138. -- script_mover:	(string) name of mover 
  1139. -- type_name:		(string, optional) name of audio source (can be "foley", "voice", "music", or "ambient"; defaults to "foley") 
  1140. -- blocking:		(boolean, optional) set to true if the function should block until the sound has finished playing (defaults to false) 
  1141. -- 
  1142. -- returns:			(integer) audio instance handle, or -1 on error 
  1143. -- 
  1144. function audio_play_for_mover( audio_name, script_mover, type_name, blocking ) 
  1145.  
  1146. 	local handle = audio_play_for_mover_do( audio_name, script_mover, type_name ) 
  1147. 	 
  1148. 	if (not blocking) then 
  1149. 		return handle 
  1150. 	end 
  1151. 	 
  1152. 	if (handle > 0) then 
  1153. 		while (audio_is_playing(handle)) do 
  1154. 			thread_yield() 
  1155. 		end 
  1156. 	end 
  1157. 	 
  1158. 	return -1 
  1159. end 
  1160.  
  1161. -- Play a 2D sound (by ID). 
  1162. -- 
  1163. -- audio_id:	(integer) ID of sound to play 
  1164. -- type_name:	(string, optional) name of audio source (can be "foley", "voice", "music", or "ambient"; defaults to "foley") 
  1165. -- blocking:	(boolean, optional) set to true if the function should block until the sound has finished playing (defaults to false) 
  1166. -- 
  1167. -- returns:		(integer) audio instance handle, or -1 on error 
  1168. -- 
  1169. function audio_play_id(audio_id, type, blocking) 
  1170. 	local handle = audio_play_id_do(audio_id, type) 
  1171. 	 
  1172. 	if (not blocking) then 
  1173. 		return handle; 
  1174. 	end 
  1175. 	 
  1176. 	while (audio_is_playing(handle)) do 
  1177. 		thread_yield() 
  1178. 	end 
  1179. 	 
  1180. 	return -1; 
  1181. end 
  1182.  
  1183. -- Play a 3D sound (by ID) on a character. 
  1184. -- 
  1185. -- human_name:			(string) name of character 
  1186. -- audio_id:			(integer) ID of sound to play 
  1187. -- type_name:			(string, optional) name of audio source (can be "foley", "voice", "music", or "ambient"; defaults to "foley") 
  1188. -- blocking:			(boolean, optional) set to true if the function should block until the sound has finished playing (defaults to false) 
  1189. -- variant:				(integer, optional) index of the specific variant of the voice line to play (or -1 for a random selection; defaults to -1) 
  1190. -- voice_distance:	(integer, optional) distance that the foley can be heard from; only used for voices (0 = short, 1 = normal, 2 = long, 3 = extreme; defaults to -1, which is normal distance for peds, and extreme distance for passengers in cars) 
  1191. -- 
  1192. -- returns:				(integer) audio instance handle, or -1 on error 
  1193. -- 
  1194. function audio_play_id_for_character(human_name, audio_id, type, blocking, variant, voice_distance) 
  1195. 	if (character_is_dead(human_name)) then 
  1196. 		return -1 
  1197. 	end 
  1198. 	 
  1199. 	local	handle = audio_play_id_for_character_do(human_name, audio_id, type, blocking, variant, voice_distance) 
  1200.  
  1201. 	if (not blocking) then 
  1202. 		return handle 
  1203. 	end 
  1204. 	 
  1205. 	while (audio_is_playing(handle)) do 
  1206. 		thread_yield() 
  1207. 	end 
  1208. 	 
  1209. 	return -1 
  1210. end 
  1211.  
  1212. -- Play a 3D sound (by ID) on a navpoint. 
  1213. -- 
  1214. -- navpoint_name:		(string) name of the navpoint 
  1215. -- audio_id:			(integer) ID of sound to play 
  1216. -- type_name:			(string, optional) name of audio source (can be "foley", "voice", "music", or "ambient"; defaults to "foley") 
  1217. -- blocking:			(boolean, optional) set to true if the function should block until the sound has finished playing (defaults to false) 
  1218. -- 
  1219. -- returns:				(integer) audio instance handle, or -1 on error 
  1220. --  
  1221. function audio_play_id_for_navpoint(navpoint_name, audio_id, type, blocking) 
  1222. 	local handle = audio_play_id_for_navpoint_do(navpoint_name, audio_id, type) 
  1223.  
  1224. 	if (not blocking) then 
  1225. 		return handle 
  1226. 	end 
  1227.  
  1228. 	while (audio_is_playing(handle)) do 
  1229. 		thread_yield() 
  1230. 	end 
  1231.  
  1232. 	return -1 
  1233. end 
  1234.  
  1235. -- Call the given function on each member of the given table 
  1236. -- 
  1237. -- function_ref:	(function reference - NOT a string) the function to call for each member of the table 
  1238. -- table:			(table) the table whose members the function should be called on 
  1239. -- ...:				(list) list of arguments to send to the function 
  1240. -- 
  1241. function call_function_on_each_member(function_ref, table, ...) 
  1242. 	if (type(function_ref) ~= "function") then 
  1243. 		return 
  1244. 	end 
  1245.  
  1246. 	if (type(table) ~= "table") then 
  1247. 		function_ref(table, unpack(arg)) 
  1248. 	else 
  1249. 		for i,member in pairs(table) do 
  1250. 			call_function_on_each_member(function_ref, member, unpack(arg)) 
  1251. 		end 
  1252. 	end 
  1253. end 
  1254.  
  1255. -- Moves the camera from its current position and orientation to the specified navpoint's position and orientation. 
  1256. -- 
  1257. -- navpoint_name:		(string) navpoint to look through 
  1258. -- duration:			(float, optional) duration of movement, in seconds; if set to 0, camera will instantly jump to the end position and orientation (defaults to 0) 
  1259. -- yield:				(boolean, optional) set to true to block until the camera movement is complete (defaults to false) 
  1260. -- hide_hud:			(boolean, option) set to false to not disable the hud when using this camera (defaults to true) 
  1261. -- sync_flag:			(enum, optional) SYNC_LOCAL, SYNC_REMOTE, SYNC_ALL (defaults to SYNC_ALL) 
  1262. -- 
  1263. -- NB: the camera will not return to its default behavior unless a camera_end_script() action is issued. If the camera script finishes execution before the 
  1264. -- camera_end_script() action is issued, the camera will hold the last position of the camera script. 
  1265. -- 
  1266. -- Example: 
  1267. -- 
  1268. --		camera_look_through("$npc000", 5.0, true) 
  1269. --		camera_end_script() 
  1270. -- 
  1271. -- Move the camera over a period of five seconds so that it is looking through navpoint "$npc000".  
  1272. -- 
  1273. function camera_look_through(navp, duration, yield, hide_hud, sync_flag) 
  1274. 	camera_look_through_do(navp, duration, hide_hud, sync_flag) 
  1275.  
  1276. 	if (yield) then	 
  1277. 		while (not(camera_script_is_finished())) do 
  1278. 			thread_yield() 
  1279. 		end 
  1280. 	end 
  1281. end 
  1282.  
  1283. -- Make a character take another character as a human shield. 
  1284. -- 
  1285. -- attacker:	(string) name of attacker 
  1286. -- victim:		(string) name of target 
  1287. -- bypass_ai:	(bool, optional) bypass AI and take shield immediately 
  1288. -- 
  1289. function character_take_human_shield( character, victim, ... ) 
  1290. 	local bypass_ai = false 
  1291. 	if (arg.n > 0) then 
  1292. 		bypass_ai = arg[1] 
  1293. 	end 
  1294. 	 
  1295.    character_take_human_shield_do( character, victim, bypass_ai ) 
  1296.  
  1297.    -- loop as long as grabber and grabee are alive until we've succeeded 
  1298.    while ( character_is_dead( character ) == false and 
  1299.            character_is_dead( victim ) == false and 
  1300. 	   character_take_human_shield_check_done( character, victim) == false) do 
  1301.       thread_yield(); 
  1302.    end 
  1303. end 
  1304.  
  1305. -- Blocks until the specified character's resources have loaded. 
  1306. -- 
  1307. -- name:	(string) name of the character to wait on 
  1308. -- 
  1309. function character_wait_for_loaded_resource(name) 
  1310. 	while (not(character_check_resource_loaded(name))) do 
  1311. 		thread_yield() 
  1312. 	end 
  1313. end 
  1314.  
  1315. -- Recursively cleanup all the callbacks for an object or table of objects. 
  1316. -- 
  1317. -- objects:	(string or table) object, table of objects, table of tables of objects, etc. 
  1318. -- 
  1319. function cleanup_callbacks(objects) 
  1320. 	if (type(objects) == "string") then 
  1321. 		clear_callbacks_for_obj(objects) 
  1322. 	elseif (type(objects) == "table") then 
  1323. 		for i,obj in pairs(objects) do 
  1324. 			cleanup_callbacks(obj) 
  1325. 		end 
  1326. 	end 
  1327. end 
  1328.  
  1329. -- Recursively cleanup all the audio conversations that may still be playing 
  1330. -- 
  1331. -- convos:	(table) conversation, table of conversations, table of tables of conversations, etc. 
  1332. -- 
  1333. function cleanup_conversations(convos) 
  1334. 	local ret_val = convos 
  1335.  
  1336. 	-- An audio conversation is a table, so if we've come to something that's not a table, there is no conversation here 
  1337. 	if (type(convos) ~= "table") then 
  1338. 		return ret_val 
  1339. 	end 
  1340.  
  1341. 	-- Conversations must have a name and a handle to the conversation as it plays, so having both should be a good sign that this is a conversation 
  1342. 	if (convos.name ~= nil and convos.handle ~= nil) then 
  1343. 		if (convos.handle ~= INVALID_CONVERSATION_HANDLE) then 
  1344. 			audio_conversation_end(convos.handle) 
  1345. 			ret_val.handle = INVALID_CONVERSATION_HANDLE 
  1346. 		end 
  1347. 	else 
  1348. 		-- The table didn't have a member called "handle", so this table isn't a conversation (though could be a table of conversations) 
  1349. 		for i,convo in pairs(convos) do 
  1350. 			ret_val[i] = cleanup_conversations(convo) 
  1351. 		end 
  1352. 	end 
  1353.  
  1354. 	-- Return a copy with the ended conversation handles set to INVALID_CONVERSATION_HANDLE 
  1355. 	return ret_val 
  1356. end 
  1357.  
  1358. -- Recursively clean up a script group or table of script groups. 
  1359. -- 
  1360. -- group:	(string or table) a group, table of groups, table of tables of groups, etc. 
  1361. -- 
  1362. function cleanup_groups(group) 
  1363. 	if (type(group) == "string") then 
  1364. 		if (group_is_loaded(group)) then 
  1365. 			group_destroy_do(group) 
  1366. 		end 
  1367. 	elseif (type(group) == "table") then 
  1368. 		if (type(group.name) == "string") then 
  1369. 			if (group_is_loaded(group.name)) then 
  1370. 				group_destroy_do(group.name) 
  1371. 			end 
  1372. 		else 
  1373. 			for i,group_member in pairs(group) do 
  1374. 				cleanup_groups(group_member) 
  1375. 			end 
  1376. 		end 
  1377. 	end 
  1378. end 
  1379.  
  1380. -- Recursively cleanup all the spawn groups (i.e. stop their spawning) 
  1381. -- 
  1382. -- group:	(string or table) a spawn group, table of spawn groups, table of tables of spawn groups, etc. 
  1383. -- 
  1384. function cleanup_spawn_groups(group) 
  1385. 	if (type(group) == "string") then 
  1386. 		continuous_spawn_stop(group, true) 
  1387. 	elseif (type(group) == "table") then 
  1388. 		-- See if the spawn group is within the regular group table 
  1389. 		if (type(group.name) == "string") then 
  1390. 			continuous_spawn_stop(group.name, true) 
  1391. 		else 
  1392. 			for i, member in pairs(group) do 
  1393. 				cleanup_spawn_groups(member) 
  1394. 			end 
  1395. 		end 
  1396. 	end 
  1397. end 
  1398.  
  1399. -- Recursively disable all spawn regions in a table 
  1400. -- 
  1401. -- regions:	(string or table) spawn region, table of spawn regions, table of tables of spawn regions, etc. 
  1402. -- 
  1403. function cleanup_spawn_regions(regions) 
  1404. 	continuous_spawn_regions_enable(regions, false) 
  1405. end 
  1406.  
  1407. -- Recursively remove temporary weapons from player inventory 
  1408. -- 
  1409. -- weapons:		(string or table) weapon, table of weapons, table of tables of weapons, etc. 
  1410. -- sync_type:	(enum, optional) SYNC_LOCAL, SYNC_REMOTE, SYNC_ALL (defaults to SYNC_ALL) 
  1411. -- 
  1412. function cleanup_temporary_weapons(weapons, sync_type) 
  1413. 	if (sync_type == nil) then 
  1414. 		sync_type = SYNC_ALL 
  1415. 	end 
  1416.  
  1417. 	if (type(weapons) == "string") then 
  1418. 		if (SYNC_LOCAL or SYNC_ALL) then 
  1419. 			inv_weapon_remove_temporary(LOCAL_PLAYER, weapons) 
  1420. 		end 
  1421. 		if (coop_is_active()) then 
  1422. 			if (SYNC_REMOTE or SYNC_ALL) then 
  1423. 				inv_weapon_remove_temporary(REMOTE_PLAYER, weapons) 
  1424. 			end 
  1425. 		end 
  1426. 	elseif (type(weapons) == "table") then 
  1427. 		for i,weapon in pairs(weapons) do 
  1428. 			cleanup_temporary_weapons(weapon, sync_type) 
  1429. 		end 
  1430. 	end 
  1431. end 
  1432.  
  1433. -- Iterates recursively through a table of threads, cleaning up any thread it finds. 
  1434. -- 
  1435. -- threads:	(string or table) a single thread, table of threads, table of tables of threads, etc. 
  1436. -- 
  1437. function cleanup_threads(threads) 
  1438. 	local ret_val = threads 
  1439.  
  1440. 	if (type(threads) == "number") then 
  1441. 		if (threads ~= INVALID_THREAD_HANDLE) then 
  1442. 			thread_kill(threads) 
  1443. 			ret_val = INVALID_THREAD_HANDLE 
  1444. 		end 
  1445. 	elseif (type(threads) == "table") then 
  1446. 		for i,thread in pairs(threads) do 
  1447. 			ret_val[i] = cleanup_threads(thread) 
  1448. 		end 
  1449. 	end 
  1450.  
  1451. 	-- Returns a copy with killed threads set to INVALID_THREAD_HANDLE 
  1452. 	return ret_val 
  1453. end 
  1454.  
  1455. -- Debug function for making a Lua function executable through the console. 
  1456. -- 
  1457. -- function_name:	(string) name of function 
  1458. -- 
  1459. function console_wrapper( function_name ) 
  1460. 	_UGGlobals[function_name]() 
  1461. end 
  1462.  
  1463. -- Recursively dig down into a spawn region table and enable/disable each region found 
  1464. -- 
  1465. -- regions:	(table or string) spawn region, table of spawn regions, table of tables of spawn regions, etc. 
  1466. -- enable:	(bool) whether to enable or disable these regions 
  1467. -- 
  1468. function continuous_spawn_regions_enable(regions, enable) 
  1469. 	if (type(regions) == "string") then 
  1470. 		spawn_region_enable(regions, enable) 
  1471. 	elseif (type(regions) == "table") then 
  1472. 		for i,region in pairs(regions) do 
  1473. 			continuous_spawn_regions_enable(region, enable) 
  1474. 		end 
  1475. 	end 
  1476. end 
  1477.  
  1478. -- Play a cutscene. 
  1479. -- 
  1480. -- name:				(string) name of cutscene to play 
  1481. -- group_name:		(string, or table of strings; optional) group(s) for the cutscene to load before returning (defaults to nil) 
  1482. -- teleport_name:	(table of strings, optional) names of navpoints to teleport the local and remote players to after the cutscene (defaults to nil) 
  1483. -- fade_in_after:	(boolean, optional) set to true to automatically fade in after the cutscene is finished (defaults to true) 
  1484. -- wait_for_spawning:   (boolean, optional) set to false to have the cutscene drop immediately into the world without waiting for spawning to finish up (defaults to true) 
  1485. -- 
  1486. -- This function blocks until the cutscene has finished playing. 
  1487. -- 
  1488. function cutscene_play(name, group_name, teleport_name, fade_in_after, wait_for_spawning, restore_players_vehicle) 
  1489. 	while (not zscene_is_loaded(name)) do 
  1490. 		thread_yield() 
  1491. 	end 
  1492. 	 
  1493. 	local function convert_to_table( var ) 
  1494. 		if (var == "" or var == nil) then 
  1495. 			return nil 
  1496. 		elseif (type(var) == "table") then		 
  1497. 			return var 
  1498. 		else 
  1499. 			return { var, n = 1 } 
  1500. 		end 
  1501. 	end 
  1502. 	 
  1503. 	local converted_group = convert_to_table( group_name ) 
  1504. 	local converted_teleports = convert_to_table( teleport_name ) 
  1505. 	 
  1506. 	cutscene_play_do(name, converted_group, converted_teleports, fade_in_after, wait_for_spawning, restore_players_vehicle) 
  1507.  
  1508. 	while (not(cutscene_play_check_done())) do 
  1509. 		thread_yield() 
  1510. 	end 
  1511. end 
  1512.  
  1513. -- Play a fake conversation by displaying consecutive lines of text on the screen 
  1514. -- 
  1515. -- conversation:	(table) character name, audio tag, delay between lines  
  1516. -- 
  1517. -- NOTE: conversation should be formatted the way it is for audio_play_conversation { "text", "name", duration } 
  1518. -- 
  1519. -- convo = { 
  1520. --		{ "This is the first line of the convo", "Speaker's Name", 3 }, 
  1521. --		{ "This is the second line of the convo", "Other Speaker's Name", 2 }, 
  1522. -- } 
  1523. -- 
  1524. -- This will display on the screen for 3 seconds: "Speaker's Name: This is the first line of the convo" 
  1525. -- This will display on the screen for 2 seconds: "Other Speaker's Name: This is the second line of the convo" 
  1526. -- 
  1527. function debug_conversation(conversation) 
  1528. 	if (conversation == nil) then 
  1529. 		return 
  1530. 	end 
  1531.  
  1532. 	for i,line in pairs(conversation) do 
  1533. 		local current_handle = message(line[DIALOG_STREAM_CHAR_NAME_INDEX] .. ": " .. line[DIALOG_STREAM_AUDIO_NAME_INDEX], line[DIALOG_STREAM_DELAY_SECONDS_INDEX]) 
  1534. 		delay(line[DIALOG_STREAM_DELAY_SECONDS_INDEX]) 
  1535. 		message_remove(current_handle) 
  1536. 		current_handle = INVALID_MESSAGE_HANDLE 
  1537. 	end 
  1538. end 
  1539.  
  1540. -- Block until the screen is completely faded in. 
  1541. -- sync_type:	(enum, optional) SYNC_LOCAL, SYNC_REMOTE, SYNC_ALL (defaults to SYNC_ALL) 
  1542. -- 
  1543. function fade_in_block(sync_type) 
  1544. 	if (sync_type == nil) then 
  1545. 		sync_type = SYNC_ALL 
  1546. 	end 
  1547. 	 
  1548. 	while( not fade_is_fully_faded_in(sync_type) ) do 
  1549. 		thread_yield() 
  1550. 	end 
  1551. 	 
  1552. 	thread_yield() 
  1553. end 
  1554.  
  1555. -- Block until the screen is completely faded out. 
  1556. -- sync_type:	(enum, optional) SYNC_LOCAL, SYNC_REMOTE, SYNC_ALL (defaults to SYNC_ALL) 
  1557. -- 
  1558. function fade_out_block(sync_type) 
  1559. 	if (sync_type == nil) then 
  1560. 		sync_type = SYNC_ALL 
  1561. 	end 
  1562. 	 
  1563. 	while( not fade_is_fully_faded_out(sync_type) ) do 
  1564. 		thread_yield() 
  1565. 	end 
  1566. 	 
  1567. 	thread_yield() 
  1568. end 
  1569.  
  1570. -- Force an NPC to fire at a navpoint. 
  1571. -- 
  1572. -- name:					(string) name of the NPC 
  1573. -- fire_at_navpoint:	(string) name of navpoitn to fire at 
  1574. -- fire_once:			(boolean, optional) set to true to only fire once, or false to fire continuously (defaults to false) 
  1575. -- 
  1576. function force_fire(name, fire_at_navpoint, fire_once) 
  1577. 	if (force_fire_do(name, fire_at_navpoint, fire_once)) then 
  1578. 		while (not(force_ai_mode_check_done(name))) do 
  1579. 			thread_yield() 
  1580. 		end 
  1581. 	end 
  1582. end 
  1583.  
  1584. -- Force an NPC to fire at a character. 
  1585. -- 
  1586. -- name:					(string) name of the NPC 
  1587. -- fire_at_target:	(string) name of the target character 
  1588. -- fire_once:			(boolean, optional) set to true to only fire once, or false to fire continuously (defaults to false) 
  1589. -- 
  1590. function force_fire_target(name, fire_at_target, fire_once) 
  1591. 	if (force_fire_target_do(name, fire_at_target, fire_once)) then 
  1592. 		while (not(force_ai_mode_check_done(name))) do 
  1593. 			thread_yield() 
  1594. 		end 
  1595. 	end 
  1596. end 
  1597.  
  1598. -- Force an NPC to toss a thrown weapon at a navpoint. 
  1599. -- 
  1600. -- name:				(string) name of the NPC 
  1601. -- target_navp:	(string) name of the target navpoint 
  1602. -- throw_pitch:	(float, optional) angle of elevation to throw at, in degrees (defaults to 45 degrees) 
  1603. -- throw_speed:	(float, optional) speed to throw at, in m/s (defaults to -1, which means use the default throw speed of the weapon) 
  1604. -- 
  1605. function force_throw(name, target_navp, throw_pitch, throw_speed) 
  1606. 	if (force_throw_do(name, target_navp, throw_pitch, throw_speed)) then 
  1607. 		while (not(force_ai_mode_check_done(name))) do 
  1608. 			thread_yield() 
  1609. 		end 
  1610. 	end 
  1611. end 
  1612.  
  1613. -- Force an NPC to toss a thrown weapon at a character. 
  1614. -- 
  1615. -- name:		(string) name of the NPC 
  1616. -- target:	(string) name of the target character 
  1617. -- 
  1618. function force_throw_char(name, target) 
  1619. 	if (force_throw_char_do(name, target)) then 
  1620. 		while (not(force_ai_mode_check_done(name))) do 
  1621. 			thread_yield() 
  1622. 		end 
  1623. 	end 
  1624. end 
  1625.  
  1626. -- Get the distance from an object to the closest player, and also returns the closest player. 
  1627. -- 
  1628. -- object:			(string) name of the object 
  1629. -- player_list:	(table of strings, optional) list of players to test against, or nil to test against all players (defaults to nil) 
  1630. -- 
  1631. -- returns:			(float) distance from the object to the closest player 
  1632. -- returns:			(string) name of closest player 
  1633. -- 
  1634. function get_dist_closest_player_to_object(object, player_list) 
  1635. 	if player_list == nil then 
  1636. 		player_list = player_names_get_all() 
  1637. 	end 
  1638. 	 
  1639. 	if sizeof_table( player_list ) == 0 then 
  1640. 		return 
  1641. 	end 
  1642. 	 
  1643. 	local closest_dist = get_dist(player_list[1], object) 
  1644. 	local closest_player = player_list[1] 
  1645. 	 
  1646. 	-- Spin through the available players 
  1647. 	for i, p in pairs(player_list) do 
  1648. 		local current_dist = get_dist(p, object) 
  1649. 		if current_dist < closest_dist then 
  1650. 			closest_dist = current_dist 
  1651. 			closest_player = p 
  1652. 		end 
  1653. 	end 
  1654. 	 
  1655. 	return closest_dist, closest_player 
  1656. end 
  1657.  
  1658. -- Get a random entry from a lua table. 
  1659. -- 
  1660. -- returns:		(any type) a random entry from the table passed in (can be any type) 
  1661. -- returns:		(nil) if the table passed in is not a table or has no entries, returns nil 
  1662. -- 
  1663. function get_random_table_entry(input_table) 
  1664. 	if (type(input_table) ~= "table") then 
  1665. 		return nil 
  1666. 	end 
  1667.  
  1668. 	if (sizeof_table(input_table) == 0) then 
  1669. 		return nil 
  1670. 	end 
  1671.  
  1672. 	return input_table[rand_int(1, sizeof_table(input_table))] 
  1673. end 
  1674.  
  1675. -- Gets a random player. If the game's not in coop, always returns the local player. 
  1676. -- Created this to select a random player for the AI to target. 
  1677. -- 
  1678. -- returns: LOCAL_PLAYER or REMOTE_PLAYER. In non-coop games, returns LOCAL_PLAYER. 
  1679. -- 
  1680. function get_random_target_player() 
  1681. 	if ( coop_is_active() == false ) then 
  1682. 		return LOCAL_PLAYER 
  1683. 	end 
  1684.  
  1685. 	local players_table = { LOCAL_PLAYER, REMOTE_PLAYER } 
  1686.  
  1687. 	return get_random_table_entry( players_table ) 
  1688. end 
  1689.  
  1690. -- Get a child table from a parent table by its "name" variable. 
  1691. -- 
  1692. -- parent_table:	(table) Table that contains child tables with a "name" variable. 
  1693. -- child_name:		(string) Name of the table that we want from the parent table. 
  1694. -- 
  1695. function get_table_by_name(parent_table, child_name) 
  1696. 	local found_table = nil 
  1697. 	for i, child_table in pairs(parent_table) do 
  1698. 		if child_table.name == child_name then 
  1699. 			found_table = child_table 
  1700. 			break 
  1701. 		end 
  1702. 	end 
  1703. 	return found_table 
  1704. end 
  1705.  
  1706. -- Creates all script objects belonging to the specified script group. 
  1707. -- 
  1708. -- group:	(string or table) name of the script group, or a group table (should have a "name" field that contains the name of the group) 
  1709. -- block:	(boolean, optional) set to true to block until everything in the group has finished streaming in (defaults to false) 
  1710. -- 
  1711. -- If the script object is already created, it will reset the script object to initial position and state. The objects will be unhidden by default. 
  1712. -- 
  1713. -- Example: 
  1714. -- 
  1715. --		group_create("mission 1 characters", true) 
  1716. -- 
  1717. -- Creates all objects in the "mission 1 characters" group and waits for them to stream in. 
  1718. -- 
  1719. -- Notes: 
  1720. --  - before group_create() is called, script objects in the group don�t exist, so they don�t need to be hidden 
  1721. --  - also, this means that any script commands using those script objects must come AFTER the group_create() call; otherwise those commands will do nothing 
  1722. --  - group_create() call should probably go in mission_start() rather than mission_setup(), as in the final game, the player might have several missions open at once 
  1723. -- 
  1724. function group_create(group, block) 
  1725. 	local group_name = group 
  1726.  
  1727. 	-- With the new setup of groups in mission scripts, each group should have a "name" field that contains the name of the group 
  1728. 	if (type(group) == "table" and type(group.name) == "string") then 
  1729. 		group_name = group.name 
  1730. 	end 
  1731.  
  1732. 	-- pause npc spawning. we are starting in an area where we can't see peds and cars. so don't bother waiting for them 
  1733. 	-- object_spawn_pause(true, "group_create") 
  1734. 	 
  1735. 	group_create_do(group_name) 
  1736.  
  1737. 	local handle = thread_new("group_create_check_done_loop", group_name) 
  1738.  
  1739. 	if (block == true) then 
  1740. 		while (not thread_check_done(handle)) do 
  1741. 			thread_yield() 
  1742. 		end 
  1743. 		thread_yield() 
  1744. 	end 
  1745.  
  1746. 	-- pause npc spawning. we are starting in an area where we can't see peds and cars. so don't bother waiting for them 
  1747. 	-- object_spawn_pause(false, "group_create") 
  1748. end 
  1749.  
  1750. -- Creates all script objects belonging to the specified script group, and makes them all hidden. 
  1751. -- 
  1752. -- group:	(string or table) name of the script group, or a group table (should have a "name" field that contains the name of the group) 
  1753. -- block:	(boolean, optional) set to true to block until everything in the group has finished streaming in (defaults to false) 
  1754. -- 
  1755. -- If the script object is already created, it will reset the script object to initial position and state. 
  1756. -- 
  1757. -- This function behaves the same as the group_create script action, except that all members of the group remain hidden until manually made visible. 
  1758. -- 
  1759. function group_create_hidden(group, block) 
  1760. 	local group_name = group 
  1761.  
  1762. 	-- With the new setup of groups in mission scripts, each group should have a "name" field that contains the name of the group 
  1763. 	if (type(group) == "table" and type(group.name) == "string") then 
  1764. 		group_name = group.name 
  1765. 	end 
  1766. 	 
  1767. 	group_create_hidden_do(group_name) 
  1768.  
  1769. 	local handle = thread_new("group_create_check_done_loop", group_name) 
  1770.  
  1771. 	if (block == true) then 
  1772. 		while (not thread_check_done(handle)) do 
  1773. 			thread_yield() 
  1774. 		end 
  1775. 		thread_yield() 
  1776. 	end 
  1777. end 
  1778.  
  1779. -- Creates all script objects belonging to the specified script group, and makes them unsynced 
  1780. -- 
  1781. -- group:	(string or table) name of the script group, or a group table (should have a "name" field that contains the name of the group) 
  1782. -- block:	(boolean, optional) set to true to block until everything in the group has finished streaming in (defaults to false) 
  1783. -- 
  1784. -- WARNING: Only use with groups that contain only script_items 
  1785. -- 
  1786. function group_create_unsynced(group, block) 
  1787. 	local group_name = group 
  1788. 		-- With the new setup of groups in mission scripts, each group should have a "name" field that contains the name of the group 
  1789. 	if (type(group) == "table" and type(group.name) == "string") then 
  1790. 		group_name = group.name 
  1791. 	end 
  1792. 	 
  1793. 	group_create_do(group_name) 
  1794.  
  1795. 	local handle = thread_new("group_create_unsynced_check_done_loop", group_name) 
  1796.  
  1797. 	if (block == true) then 
  1798. 		while (not thread_check_done(handle)) do 
  1799. 			thread_yield() 
  1800. 		end 
  1801. 		thread_yield() 
  1802. 	end 
  1803. end 
  1804.  
  1805. -- Spawn a list of groups 
  1806. -- 
  1807. -- groups_table:		(table) list of groups to spawn 
  1808. -- block_override:		(optional, boolean) If set, the value will override the invidual .block variables for each group 
  1809. -- 
  1810. function group_create_list(groups_table, block_override) 
  1811. 	for i, group in pairs(groups_table) do 
  1812. 		local blocking = true 
  1813. 		if (block_override ~= nil) then 
  1814. 			blocking = block_override 
  1815. 		else 
  1816. 			if group.block == false then 
  1817. 				blocking = false 
  1818. 			end 
  1819. 		end 
  1820. 		 
  1821. 		if group.hidden == true then 
  1822. 			group_create_hidden(group.name, blocking) 
  1823. 		else 
  1824. 			group_create(group.name, blocking) 
  1825. 		end 
  1826. 	end 
  1827. end 
  1828.  
  1829. -- Destroys all objects belonging to the specified script group 
  1830. -- 
  1831. -- group:	(string or table) name of a script group, or a script group table with a "name" field 
  1832. -- 
  1833. function group_destroy(group) 
  1834. 	if (type(group) == "table" and type(group.name) == "string") then 
  1835. 		group_destroy_do(group.name) 
  1836. 	else 
  1837. 		group_destroy_do(group) 
  1838. 	end 
  1839. end 
  1840.  
  1841. -- Destroys all objects belonging to the specified unsynced script group 
  1842. -- 
  1843. -- group:	(string or table) name of a script group, or a script group table with a "name" field 
  1844. -- 
  1845. function group_destroy_unsynced(group) 
  1846. 	if (type(group) == "table" and type(group.name) == "string") then 
  1847. 		group_destroy_unsynced_do(group.name) 
  1848. 	else 
  1849. 		group_destroy_unsynced_do(group) 
  1850. 	end 
  1851. end 
  1852. -- Hide a group of script objects 
  1853. -- 
  1854. -- group:	(string or table) name of a script group, or a script group table with a "name" field 
  1855. -- 
  1856. function group_hide(group) 
  1857. 	if (type(group) == "table" and type(group.name) == "string") then 
  1858. 		group_hide_do(group.name) 
  1859. 	else 
  1860. 		group_hide_do(group) 
  1861. 	end 
  1862. end 
  1863.  
  1864. -- Check if a group is loaded 
  1865. -- 
  1866. -- group:	(string or table) name of a script group, or a script group table with a "name" field 
  1867. -- 
  1868. -- returns:	(boolean) true if the group is loaded, false otherwise 
  1869. -- 
  1870. function group_is_loaded(group) 
  1871. 	if (type(group) == "table" and type(group.name) == "string") then 
  1872. 		return group_is_loaded_internal(group.name) 
  1873. 	else 
  1874. 		return group_is_loaded_internal(group) 
  1875. 	end 
  1876. end 
  1877.  
  1878. -- run a function on each NPC in a provided group. 
  1879. -- 
  1880. -- group: (string or table) the name of the script group or a script group table with a "name" field. 
  1881. -- fn: (function reference) the funciton you wish to execute on each NPC.  Should be protoyped like so - my_func(npc_name) 
  1882. -- 
  1883. function group_foreach_npc(group, fn) 
  1884. 	if (type(group) == "table" and type(group.name) == "string") then 
  1885. 		group = group.name 
  1886. 	end 
  1887. 	 
  1888. 	-- If it's not a function, that's no good. 
  1889. 	if (type(fn) == "function") then 
  1890. 		local np = group_get_first_npc(group) 
  1891. 		while (np) do 
  1892. 			fn(np) 
  1893. 			np = group_get_next_npc(group, np) 
  1894. 		end 
  1895. 	end 
  1896. end 
  1897.  
  1898. -- Unhide a group of script objects 
  1899. -- 
  1900. -- group:	(string or table) name of a script group, or a script group table with a "name" field 
  1901. -- 
  1902. function group_show(group) 
  1903. 	if (type(group) == "table" and type(group.name) == "string") then 
  1904. 		group_show_do(group.name) 
  1905. 	else 
  1906. 		group_show_do(group) 
  1907. 	end 
  1908. end 
  1909.  
  1910. -- Make a helicopter fly through one or more navpoints. 
  1911. -- 
  1912. -- name:		(string) name of the helicopter 
  1913. -- speed:		(float) spead to fly at, in m/s (-1 to use default movement speed) 
  1914. -- path:		(string) name of a scripted_path, or single navpoint  
  1915. -- 
  1916. -- The helicopter will pathfind through the specified path or to the specified point, 
  1917. -- avoiding buildings and other obstacles along the way. 
  1918. -- 
  1919. function helicopter_fly_to(name, speed, path, reverse_sp) 
  1920. 	local direct = false 
  1921. 	local follow = "" 
  1922. 	local continue_at_goal = false 
  1923. 	local follow_dist = 0.0 
  1924. 	local directly_above = false 
  1925. 	local loop_path = false 
  1926. 	local start_full_speed = false 
  1927. 	return helicopter_fly_to_internal(name, speed, direct, follow, continue_at_goal, path, follow_dist, directly_above, loop_path, start_full_speed, reverse_sp) 
  1928. end 
  1929.  
  1930. -- Make a helicopter fly through one or more navpoints, ignoring any obstacles along the way. 
  1931. -- 
  1932. -- name:		(string) name of the helicopter 
  1933. -- speed:		(float) spead to fly at, in m/s (-1 to use default movement speed) 
  1934. -- path:		(string) name of a scripted_path, or single navpoint  
  1935. -- 
  1936. -- Use the function only when you are absolutely sure there are no obstacles between waypoints. The helicopter will not move around them when using this function. 
  1937. -- 
  1938. function helicopter_fly_to_direct(name, speed, path,reverse_sp) 
  1939. 	local direct = true 
  1940. 	local follow = "" 
  1941. 	local continue_at_goal = false 
  1942. 	local follow_dist = 0.0 
  1943. 	local directly_above = false 
  1944. 	local loop_path = false 
  1945. 	local start_full_speed = false 
  1946. 	return helicopter_fly_to_internal(name, speed, direct, follow, continue_at_goal, path, follow_dist, directly_above, loop_path, start_full_speed, reverse_sp) 
  1947. end 
  1948.  
  1949. -- Make a helicopter fly through one or more navpoints, ignoring any obstacles along the way. 
  1950. -- 
  1951. -- name:		(string) name of the helicopter 
  1952. -- speed:		(float) spead to fly at, in m/s (-1 to use default movement speed) 
  1953. -- path:		(string) name of a scripted_path NOTE:  SHOULD BE A PATH!!! 
  1954. -- 
  1955. -- Use the function only when you are absolutely sure there are no obstacles between waypoints. 
  1956. --	The helicopter will not move around them when using this function. 
  1957. --	WARNING:  This function will return immediately unlike other similar functions. (when do you end running in a loop?) 
  1958. -- 
  1959. function helicopter_fly_to_direct_loop(name, speed, path) 
  1960. 	local direct = true 
  1961. 	local follow = "" 
  1962. 	local continue_at_goal = false 
  1963. 	local follow_dist = 0.0 
  1964. 	local directly_above = false 
  1965. 	local loop_path = true 
  1966.  
  1967. 	-- direct call to helicopter_fly_to_do because we don't want to wait for completion 
  1968. 	if (helicopter_fly_to_do(name, speed, direct, follow, continue_at_goal, path, follow_dist, directly_above, loop_path)) then 
  1969. 		-- immediate return 
  1970. 		return true 
  1971. 	else 
  1972. 		return false 
  1973. 	end 
  1974. end 
  1975.  
  1976. -- Make a helicopter fly through one or more navpoints, ignoring any obstacles along the way and without stopping. 
  1977. -- 
  1978. -- name:			(string) name of the helicopter 
  1979. -- speed:		(float) spead to fly at, in m/s (-1 to use default movement speed) 
  1980. -- path:		(string) name of a scripted_path, or single navpoint  
  1981. -- 
  1982. -- Use the function only when you are absolutely sure there are no obstacles between waypoints. The helicopter will not move around them when using this function. 
  1983. -- 
  1984. function helicopter_fly_to_direct_dont_stop(name, speed, path) 
  1985. 	local direct = true 
  1986. 	local follow = "" 
  1987. 	local continue_at_goal = true 
  1988. 	local follow_dist = 0.0 
  1989. 	local directly_above = false 
  1990. 	local loop_path = false 
  1991. 	local start_full_speed = false 
  1992. 	local reverse_sp = false 
  1993. 	return helicopter_fly_to_internal(name, speed, direct, follow, continue_at_goal, path, follow_dist, directly_above, loop_path, start_full_speed, reverse_sp) 
  1994. end 
  1995.  
  1996. -- Make a helicopter fly through one or more navpoints while following a target, ignoring obstacles along the way. 
  1997. -- 
  1998. -- name:				(string) name of the helicopter 
  1999. -- speed:			(float) spead to fly at, in m/s (-1 to use default movement speed) 
  2000. -- target:			(string) name of target to follow 
  2001. -- path:				(string) name of a scripted_path, or single navpoint 
  2002. -- follow_dist:	(number) distance at which to follow 
  2003. -- directly_above:(bool) whether the helicopter should be directly above the target vehicle 
  2004. -- 
  2005. -- Use the function only when you are absolutely sure there are no obstacles between waypoints. The helicopter will not move around them when using this function. 
  2006. -- 
  2007. function helicopter_fly_to_direct_follow(name, speed, target, path, follow_dist, directly_above) 
  2008. 	local direct = true 
  2009. 	local follow = target 
  2010. 	local continue_at_goal = false 
  2011. 	local loop_path = false 
  2012. 	local start_full_speed = false 
  2013. 	local reverse_sp = false 
  2014. 	return helicopter_fly_to_internal(name, speed, direct, follow, continue_at_goal, path, follow_dist, directly_above, loop_path, start_full_speed, reverse_sp) 
  2015. end 
  2016.  
  2017. -- Make a helicopter fly through one or more navpoints while following a target, ignoring obstacles along the way and without stopping. 
  2018. -- 
  2019. -- name:				(string) name of the helicopter 
  2020. -- speed:			(float) spead to fly at, in m/s (-1 to use default movement speed) 
  2021. -- target:			(string) name of target to follow 
  2022. -- path:				(string) name of a scripted_path, or single navpoint  
  2023. -- follow_dist:	(number) distance at which to follow 
  2024. -- directly_above:(bool) whether the helicopter should be directly above the target vehicle 
  2025. -- 
  2026. -- Use the function only when you are absolutely sure there are no obstacles between waypoints. The helicopter will not move around them when using this function. 
  2027. -- 
  2028. function helicopter_fly_to_direct_follow_dont_stop(name, speed, target, path, follow_dist, directly_above) 
  2029. 	local direct = true 
  2030. 	local follow = target 
  2031. 	local continue_at_goal = true 
  2032. 	local loop_path = false 
  2033. 	local start_full_speed = false 
  2034. 	local reverse_sp = false 
  2035. 	return helicopter_fly_to_internal(name, speed, direct, follow, continue_at_goal, path, follow_dist, directly_above, loop_path, start_full_speed, reverse_sp) 
  2036. end 
  2037.  
  2038. -- Make a helicopter fly through one or more navpoints without stopping 
  2039. -- 
  2040. -- name:			(string) name of the helicopter 
  2041. -- speed:		(float) spead to fly at, in m/s (-1 to use default movement speed) 
  2042. -- path:		(string) name of a scripted_path, or single navpoint  
  2043. -- 
  2044. -- The helicopter will pathfind through the specified points, avoiding buildings and other obstacles along the way. 
  2045. -- 
  2046. function helicopter_fly_to_dont_stop(name, speed, path) 
  2047. 	local direct = false 
  2048. 	local follow = "" 
  2049. 	local continue_at_goal = true 
  2050. 	local follow_dist = 0.0 
  2051. 	local directly_above = false 
  2052. 	local loop_path = false 
  2053. 	local start_full_speed = false 
  2054. 	local reverse_sp = false 
  2055. 	return helicopter_fly_to_internal(name, speed, direct, follow, continue_at_goal, path, follow_dist, directly_above, loop_path, start_full_speed, reverse_sp) 
  2056. end 
  2057.  
  2058. -- Add an item to a character's inventory. 
  2059. -- 
  2060. -- item_name:	(string) name of the item 
  2061. -- count:		(integer, optional) number of the item to give, or ammount of reserve ammo to give in the case of weapons (default = 1) 
  2062. -- character:	(string, optional) character to add item to (defaults to the local player) 
  2063. -- equip_now:	(boolean, optional) set to true to force the item to be immediately equipped (defaults to false) 
  2064. -- upgrade_flags: (integer, optional) upgrade flags to be applied to the weaopn (WEAPON_LEVEL2, WEAPON_LEVEL3, WEAPON_LEVEL4) (defaults to 0) 
  2065. --  
  2066. -- 
  2067. function inv_item_add(item_name, count, character, equip_now, upgrade_flags)	 
  2068. 	if (type(item_name) == "table" ) then 
  2069. 		local size = sizeof_table(item_name) 
  2070. 		 
  2071. 		for x=1, size, 1 do 
  2072. 			inv_item_add_do(item_name[x], count[x], character, equip_now, upgrade_flags[x]) 
  2073. 		end	 
  2074. 	else 
  2075. 		inv_item_add_do(item_name, count, character, equip_now, upgrade_flags) 
  2076. 	end 
  2077. end 
  2078.  
  2079. -- Check if a script tag refers to a player. 
  2080. -- 
  2081. -- tag:		(string) tag to check 
  2082. -- 
  2083. -- returns:	(boolean) true if the tag refers to a player, else false 
  2084. -- 
  2085. function is_player_tag(tag) 
  2086. 	-- Search the "closest" tags 
  2087. 	if tag == CLOSEST_PLAYER or tag == CLOSEST_TEAM1 or tag == CLOSEST_TEAM2 then 
  2088. 		return true 
  2089. 	end 
  2090. 	 
  2091. 	-- Loop through the player tags 
  2092. 	for i, player in pairs(PLAYER_TAG_LIST) do 
  2093. 		if tag == player then 
  2094. 			return true 
  2095. 		end 
  2096. 	end 
  2097. 	 
  2098. 	return false 
  2099. end 
  2100.  
  2101. -- Toggle level lights on or off 
  2102. -- 
  2103. -- enable:			(bool) whether to enable or disable all level lights 
  2104. -- toggle_style:	(enumeration, optional) method by which to toggle the level lights 
  2105. -- 
  2106. function level_lights_toggle_all(enable, toggle_style) 
  2107. 	if (toggle_style == nil) then 
  2108. 		toggle_style = LEVEL_LIGHT_TOGGLE_STYLE_FADE 
  2109. 	end 
  2110.  
  2111. 	level_light_enable_all_do(enable, toggle_style) 
  2112. end 
  2113.  
  2114. -- Check line of sight between two human-types 
  2115. -- 
  2116. -- name_one, name_two:  Names of the people to check los between 
  2117. -- 
  2118.  
  2119. -- Check for line-of-sight between two characters. 
  2120. -- 
  2121. -- name_one:	(string) name of the first character 
  2122. -- name_two:	(string) name of the second character 
  2123. -- 
  2124. -- returns:		(boolean) true if there is line-of-sight between the characters, or false if there is not 
  2125. -- 
  2126. -- Note that this function may take up to a 100 frames before returning a result and will block in the meantime. 
  2127. -- 
  2128. function los_check(name_one, name_two) 
  2129. 	local retval = false 
  2130. 	local current_los_result = -1 
  2131. 	local num_retries = 0 
  2132. 	-- It's possible for the los check to continually get deleted intead of processed 
  2133. 	-- For example, if one of the humans is hidden.  So only try re-issuing 100 times. 
  2134. 	while (current_los_result == -1 and num_retries < 100) do 
  2135. 		current_los_result = los_check_do(name_one, name_two) 
  2136. 		thread_yield() 
  2137. 		num_retries = num_retries + 1 
  2138. 	end 
  2139. 	if (current_los_result == 0) then 
  2140. 		return false 
  2141. 	end 
  2142. 	if (current_los_result == 1) then 
  2143. 		return true 
  2144. 	end 
  2145. 	return false 
  2146. end 
  2147.  
  2148. -- Add a minimap marker and object indicator to a table (or single object) of navpoints, players, or script objects. 
  2149. -- 
  2150. -- object_name:				(table or string) table of objects (or a single object) to add object indicators to 
  2151. -- minimap_icon_name:		(string) name of the minimap icon 
  2152. -- object_indicator_id:		(integer) ID of the object indicator asset to use 
  2153. -- object_indicator_flags:	(integer, optional) flags for the object indicator (defaults to OI_FLAGS_DEFAULT) 
  2154. -- sync_type:				(enumeration, optional) synchronization type (SYNC_LOCAL = affects local player, SYNC_REMOTE = affects remote player, or SYNC_ALL = affects both players; defaults to SYNC_ALL) 
  2155. -- fade_dist:				(float, optional) distance to start fading if the OI_FLAG_FADE flag is specified (default, 100.0) 
  2156. -- tag_name:				(string, optional) name of the object tag to use to position the object indicator, or nil to use default obj position (default, nil) 
  2157. -- 
  2158. -- Returns the number of objects that were found (markers successfully added) 
  2159. -- 
  2160. function marker_add(object_name, minimap_icon_name, object_indicator_id, object_indicator_flags, sync_type, fade_dist, tag_name) 
  2161. 	local num_added = 0 
  2162.  
  2163. 	if (type(object_name) == "table") then 
  2164. 		for i,obj in pairs(object_name) do 
  2165. 			num_added = num_added + marker_add(obj, minimap_icon_name, object_indicator_id, object_indicator_flags, sync_type, tag_name) 
  2166. 		end 
  2167. 	elseif (type(object_name) == "string") then 
  2168. 		if (object_indicator_flags == nil) then 
  2169. 			object_indicator_flags = OI_FLAGS_DEFAULT 
  2170. 		end 
  2171.  
  2172. 		if (sync_type == nil) then 
  2173. 			sync_type = SYNC_ALL 
  2174. 		end 
  2175. 		 
  2176. 		if (fade_dist == nil) then 
  2177. 			fade_dist = 100.0 
  2178. 		end 
  2179.  
  2180. 		minimap_icon_add_do( object_name, minimap_icon_name, "", 0, sync_type ) 
  2181. 		-- If the object was found and the object indicator was added, increase the number by 1 
  2182. 		if (object_indicator_add_do( object_name, object_indicator_id, object_indicator_flags, sync_type, fade_dist, tag_name ) == true) then 
  2183. 			num_added = num_added + 1 
  2184. 		end 
  2185. 	end 
  2186.  
  2187. 	return num_added 
  2188. end 
  2189.  
  2190. -- Add a minimap marker and ingame effect to all objects in a script group. 
  2191. -- 
  2192. -- group:						(string or table) name of a script group, or a script group table with a "name" field 
  2193. -- minimap_icon_name:		(string) name of the minimap icon 
  2194. -- object_indicator_id:		(integer) ID of the object indicator asset to use 
  2195. -- object_indicator_flags:	(integer, optional) flags for the object indicator (defaults to OI_FLAGS_DEFAULT) 
  2196. -- sync_type:					(enumeration, optional) synchronization type (SYNC_LOCAL = affects local player, SYNC_REMOTE = affects remote player, or SYNC_ALL = affects both players; defaults to SYNC_ALL) 
  2197. -- 
  2198. function marker_add_script_group( group, minimap_icon_name, object_indicator_id, object_indicator_flags, sync_type ) 
  2199. 	if (object_indicator_flags == nil) then 
  2200. 		object_indicator_flags = OI_FLAGS_DEFAULT 
  2201. 	end 
  2202.  
  2203. 	if (sync_type == nil) then 
  2204. 		sync_type = SYNC_ALL 
  2205. 	end 
  2206.  
  2207. 	local group_name = group 
  2208.  
  2209. 	if (type(group) == "table" and type(group.name) == "string") then 
  2210. 		group_name = group.name 
  2211. 	end 
  2212.  
  2213. 	minimap_icon_add_script_group_do( group_name, minimap_icon_name, "", 0, sync_type ) 
  2214. 	object_indicator_add_script_group_do( group_name, object_indicator_id, object_indicator_flags, sync_type ) 
  2215. end 
  2216.  
  2217. -- Add an object indicator to the npc in the script group closest to the target. 
  2218. -- 
  2219. -- target_name:				(string) name of the target to find the npc closest to 
  2220. -- group:						(string or table) name of a script group, or a script group table with a "name" field 
  2221. -- object_indicator_id:		(integer) ID of the object indicator asset to use 
  2222. -- object_indicator_flags:	(integer, optional) flags for the object indicator (defaults to OI_FLAGS_DEFAULT) 
  2223. -- sync_type:					(enumeration, optional) synchronization type (SYNC_LOCAL = affects local player, SYNC_REMOTE = affects remote player, or SYNC_ALL = affects both players; defaults to SYNC_ALL) 
  2224. -- 
  2225. -- returns:						(string) the name of the npc that got the marker, or "" if none. 
  2226. -- 
  2227. function marker_add_closest_to_target( target_name, group, object_indicator_id, object_indicator_flags, sync_type ) 
  2228. 	if (object_indicator_flags == nil) then 
  2229. 		object_indicator_flags = OI_FLAGS_DEFAULT 
  2230. 	end 
  2231.  
  2232. 	if (sync_type == nil) then 
  2233. 		sync_type = SYNC_ALL 
  2234. 	end 
  2235.  
  2236. 	local group_name = group 
  2237.  
  2238. 	if (type(group) == "table" and type(group.name) == "string") then 
  2239. 		group_name = group.name 
  2240. 	end 
  2241. 	 
  2242. 	return add_object_indicator_to_closest_npc( target_name, group_name, object_indicator_id, object_indicator_flags, sync_type ) 
  2243. end 
  2244.  
  2245. -- Add a minimap marker and ingame effect to a script trigger. 
  2246. -- 
  2247. -- trigger_name:				(string) name of the script trigger 
  2248. -- minimap_icon_name:		(string) name of the minimap icon 
  2249. -- ingame_effect_name:		(string, optional) name of ingame effect (defaults to nil) 
  2250. -- object_indicator_id:		(integer, optional) ID of the object indicator asset to use (defaults to nil) 
  2251. -- object_indicator_flags:	(integer, optional) flags for the object indicator (defaults to OI_FLAGS_LOCATION) 
  2252. -- sync_type:					(enumeration, optional) synchronization type (SYNC_LOCAL = affects local player, SYNC_REMOTE = affects remote player, or SYNC_ALL = affects both players; defaults to SYNC_ALL) 
  2253. -- fade_dist:					(float, optional) distance to start fading if the OI_FLAG_FADE flag is specified (default, 100.0) 
  2254. -- 
  2255. function marker_add_trigger( trigger_name, minimap_icon_name, ingame_effect_name, object_indicator_id, object_indicator_flags, sync_type, fade_dist ) 
  2256. 	if (sync_type == nil) then 
  2257. 		sync_type = SYNC_ALL 
  2258. 	end 
  2259. 	 
  2260. 	if (fade_dist == nil) then 
  2261. 		fade_dist = 100.0 
  2262. 	end 
  2263.  
  2264. 	minimap_icon_add_do(trigger_name, minimap_icon_name, "", 0, sync_type) 
  2265.  
  2266. 	if (ingame_effect_name ~= nil) then 
  2267. 		ingame_effect_add_trigger(trigger_name, ingame_effect_name, sync_type) 
  2268. 	end 
  2269.  
  2270. 	if (object_indicator_id ~= nil) then 
  2271. 		if (object_indicator_flags == nil) then 
  2272. 			object_indicator_flags = OI_FLAGS_LOCATION 
  2273. 		end 
  2274. 		object_indicator_add_do(trigger_name, object_indicator_id, object_indicator_flags, sync_type, fade_dist) 
  2275. 	end 
  2276. end 
  2277.  
  2278. -- Remove a minimap marker and ingame effect from a table of objects or a single object 
  2279. -- 
  2280. -- object_name:(table or string) table of objects (or a single object) to remove markers and effects from 
  2281. -- sync_type:	(enumeration, optional) synchronization type (SYNC_LOCAL = affects local player, SYNC_REMOTE = affects remote player, or SYNC_ALL = affects both players; defaults to SYNC_ALL) 
  2282. -- 
  2283. function marker_remove(object_name, sync_type) 
  2284. 		 
  2285. 	if (type(object_name) == "table") then 
  2286. 		for i,obj in pairs(object_name) do 
  2287. 			marker_remove(obj, sync_type) 
  2288. 		end 
  2289. 	elseif (type(object_name) == "string") then 
  2290. 		if (sync_type == nil) then 
  2291. 			sync_type = SYNC_ALL 
  2292. 		end 
  2293.  
  2294. 		if object_name ~= nil and object_name ~= "" then 
  2295. 			minimap_icon_remove_do( object_name, sync_type ) 
  2296. 			object_indicator_remove_do( object_name, sync_type ) 
  2297. 		end 
  2298. 	end 
  2299. 		 
  2300. end 
  2301.  
  2302. -- Remove a minimap marker and ingame effect from a script group. 
  2303. -- 
  2304. -- group:		(string or table) name of a script group, or a script group table with a "name" field 
  2305. -- sync_type:	(enumeration, optional) synchronization type (SYNC_LOCAL = affects local player, SYNC_REMOTE = affects remote player, or SYNC_ALL = affects both players; defaults to SYNC_ALL) 
  2306. -- 
  2307. function marker_remove_script_group( group, sync_type ) 
  2308. 	if (sync_type == nil) then 
  2309. 		sync_type = SYNC_ALL 
  2310. 	end 
  2311.  
  2312. 	local group_name = group 
  2313.  
  2314. 	if (type(group) == "table" and type(group.name) == "string") then 
  2315. 		group_name = group.name 
  2316. 	end 
  2317. 	 
  2318. 	minimap_icon_remove_script_group_do( group_name, sync_type ) 
  2319. 	object_indicator_remove_script_group_do( group_name, sync_type ) 
  2320. end 
  2321.  
  2322. -- Remove a minimap marker and ingame effect from a script trigger. 
  2323. -- 
  2324. -- trigger_name:	(string) name of the script trigger 
  2325. -- sync_type:		(enumeration, optional) synchronization type (SYNC_LOCAL = affects local player, SYNC_REMOTE = affects remote player, or SYNC_ALL = affects both players; defaults to SYNC_ALL) 
  2326. -- 
  2327. function marker_remove_trigger( trigger_name, sync_type ) 
  2328. 	if (sync_type == nil) then 
  2329. 		sync_type = SYNC_ALL 
  2330. 	end 
  2331. 	 
  2332. 	minimap_icon_remove_do(trigger_name, sync_type) 
  2333. 	ingame_effect_remove_trigger(trigger_name, sync_type) 
  2334. 	object_indicator_remove_do(trigger_name, sync_type) 
  2335. end 
  2336.  
  2337. -- Add a minimap marker to a trigger, navpoint, player, or script object, with an optional radius around the marker. 
  2338. -- 
  2339. -- object_name:			(string or table) name of the object or a nested table of names 
  2340. -- minimap_icon_name:	(string) name of the minimap icon 
  2341. -- bitmap_glow_name:		(string, optional) name of minimap icon glow (defaults to nil) 
  2342. -- radius:					(float, optional) radius of the minimap marker, in meters (defaults to 0.0) 
  2343. -- sync_type:				(enumeration, optional) synchronization type (SYNC_LOCAL = affects local player, SYNC_REMOTE = affects remote player, or SYNC_ALL = affects both players; defaults to SYNC_ALL) 
  2344. -- 
  2345. function minimap_icon_add(object_name, minimap_icon_name, bitmap_glow_name, radius, sync_type) 
  2346. 	if (type(object_name) == "string") then 
  2347. 		minimap_icon_add_do( object_name, minimap_icon_name, bitmap_glow_name, radius, sync_type ) 
  2348. 	elseif (type(object_name) == "table") then 
  2349. 		for i,obj in pairs(object_name) do 
  2350. 			minimap_icon_add(obj, minimap_icon_name, bitmap_glow_name, radius, sync_type) 
  2351. 		end 
  2352. 	end 
  2353. end 
  2354.  
  2355. -- Add a minimap radius around an object. 
  2356. -- 
  2357. -- object_name:(string or table) name of the object (can be a navpoint, trigger, or mover) or a nested table of names 
  2358. -- radius:		(float, optional) radius of the minimap marker, in meters (defaults to 0.0) 
  2359. -- sync_type:	(enumeration, optional) synchronization type (SYNC_LOCAL = affects local player, SYNC_REMOTE = affects remote player, or SYNC_ALL = affects both players; defaults to SYNC_ALL) 
  2360. -- 
  2361. function minimap_icon_add_radius(object_name, radius, sync_type) 
  2362. 	if (type(object_name) == "string") then 
  2363. 		minimap_icon_add_radius_do( object_name, radius, sync_type ) 
  2364. 	elseif (type(object_name) == "table") then 
  2365. 		for i,obj in pairs(object_name) do 
  2366. 			minimap_icon_add_radius(obj, radius, sync_type) 
  2367. 		end 
  2368. 	end 
  2369. end 
  2370.  
  2371. -- Add a minimap marker to all objects in a script group, with an optional radius around the marker. 
  2372. -- 
  2373. -- group:					(string or table) name of a script group, or a script group table with a "name" field 
  2374. -- minimap_icon_name:	(string) name of the minimap icon 
  2375. -- bitmap_glow_name:		(string, optional) name of minimap icon glow (defaults to nil) 
  2376. -- radius:					(float, optional) radius of the minimap marker, in meters (defaults to 0.0) 
  2377. -- sync_type:				(enumeration, optional) synchronization type (SYNC_LOCAL = affects local player, SYNC_REMOTE = affects remote player, or SYNC_ALL = affects both players; defaults to SYNC_ALL) 
  2378. -- 
  2379. function minimap_icon_add_script_group(group, minimap_icon_name, bitmap_glow_name, radius, sync_type) 
  2380. 	local group_name = group 
  2381.  
  2382. 	if (type(group) == "table" and type(group.name) == "string") then 
  2383. 		group_name = group.name 
  2384. 	end 
  2385.  
  2386. 	minimap_icon_add_script_group_do(group_name, minimap_icon_name, bitmap_glow_name, radius, sync_type) 
  2387. end 
  2388.  
  2389. -- Remove the minimap marker from a trigger, navpoint, player, or script object. 
  2390. -- 
  2391. -- object_name:	(string or table) name of the object or a nested table of names 
  2392. -- sync_type:		(enumeration, optional) synchronization type (SYNC_LOCAL = affects local player, SYNC_REMOTE = affects remote player, or SYNC_ALL = affects both players; defaults to SYNC_ALL) 
  2393. -- 
  2394. function minimap_icon_remove(object_name, sync_type) 
  2395. 	if (type(object_name) == "string") then 
  2396. 		minimap_icon_remove_do(object_name, sync_type) 
  2397. 	elseif (type(object_name) == "table") then 
  2398. 		for i,obj in pairs(object_name) do 
  2399. 			minimap_icon_remove(obj, sync_type) 
  2400. 		end 
  2401. 	end 
  2402. end 
  2403.  
  2404. -- Remove a minimap radius from an object. 
  2405. -- 
  2406. -- object_name:	(string or table) name of the object (can be a navpoint, trigger, or mover) or a nested table of names 
  2407. -- sync_type:		(enumeration, optional) synchronization type (SYNC_LOCAL = affects local player, SYNC_REMOTE = affects remote player, or SYNC_ALL = affects both players; defaults to SYNC_ALL) 
  2408. -- 
  2409. function minimap_icon_remove_radius(object_name, sync_type) 
  2410. 	if (type(object_name) == "string") then 
  2411. 		minimap_icon_remove_radius_do( object_name, sync_type ) 
  2412. 	elseif (type(object_name) == "table") then 
  2413. 		for i,obj in pairs(object_name) do 
  2414. 			minimap_icon_remove_radius(obj, sync_type) 
  2415. 		end 
  2416. 	end 
  2417. end 
  2418.  
  2419. -- Remove a minimap marker from all objects in a script group. 
  2420. -- 
  2421. -- group:		(string or table) name of a script group, or a script group table with a "name" field 
  2422. -- sync_type:	(enumeration, optional) synchronization type (SYNC_LOCAL = affects local player, SYNC_REMOTE = affects remote player, or SYNC_ALL = affects both players; defaults to SYNC_ALL) 
  2423. -- 
  2424. function minimap_icon_remove_script_group(group, sync_type) 
  2425. 	local group_name = group 
  2426.  
  2427. 	if (type(group) == "table" and type(group.name) == "string") then 
  2428. 		group_name = group.name 
  2429. 	end 
  2430.  
  2431. 	minimap_icon_remove_script_group_do(group_name, sync_type) 
  2432. end 
  2433.  
  2434. -- Re-enable player controls if they have been disabled by a mission start fade-in. 
  2435. -- 
  2436. -- Should be called in mission cleanup by all missions that use mission_start_fade_in / mission_start_fade_out. 
  2437. -- 
  2438. function mission_cleanup_maybe_reenable_player_controls() 
  2439.    if ( Player_controls_disabled_by_mission_start_fadeout ) then 
  2440.       player_controls_enable( LOCAL_PLAYER ) 
  2441.       if ( coop_is_active() ) then 
  2442.          player_controls_enable( REMOTE_PLAYER ) 
  2443.       end 
  2444.       Player_controls_disabled_by_mission_start_fadeout = false 
  2445.    end 
  2446. end 
  2447.  
  2448. -- Generates a mission help message and updates the Objectives screen. 
  2449. -- 
  2450. -- tag:		(string) name of help text to display (from mission_help.xtbl) 
  2451. -- string1:	(string, optional) first replacement string 
  2452. -- string2:	(string, optional) second replacement string 
  2453. -- sync:		(enumeration, optional) synchronization type (SYNC_LOCAL = affects local player, SYNC_REMOTE = affects remote player, or SYNC_ALL = affects both players; defaults to SYNC_ALL) 
  2454. -- 
  2455. -- Displays a localized help string in the help text area of the HUD. 
  2456. -- There are two replacement strings available which will replace up to 
  2457. -- instances of %s in the table text. 
  2458. -- 
  2459. -- The duration of the text is specified in the mission_help.xtbl file.  If 
  2460. -- a value of 0.0 is specified, the default duration is 5 seconds. 
  2461. -- 
  2462. -- Example: 
  2463. -- 
  2464. -- Entry in the mission_help.xtbl file has name of "KillGangsta" and text of 
  2465. -- "Kill %s more %s members!" 
  2466. -- 
  2467. -- Executing the lua statement 'mission_help_table("KillGangsta", 5, "Vice King")' 
  2468. -- results in the help output "Kill 5 more Vice King members!"  
  2469. -- 
  2470. function mission_help_table(tag, string1, string2, sync) 
  2471. 	mission_help_table_do(tag, true, false, string1, string2, sync, 0) 
  2472. end 
  2473.  
  2474. -- Generates a mission help nag message, but does not update the Objectives screen. 
  2475. -- 
  2476. -- tag:		(string) name of help text to display (from mission_help.xtbl) 
  2477. -- string1:	(string, optional) first replacement string 
  2478. -- string2:	(string, optional) second replacement string 
  2479. -- sync:		(enumeration, optional) synchronization type (SYNC_LOCAL = affects local player, SYNC_REMOTE = affects remote player, or SYNC_ALL = affects both players; defaults to SYNC_ALL) 
  2480. -- 
  2481. function mission_help_table_nag(tag, string1, string2, sync) 
  2482. 	mission_help_table_do(tag, false, false, string1, string2, sync, 0) 
  2483. end 
  2484.  
  2485. -- Enables player controls and fades in the screen. 
  2486. -- 
  2487. -- Should be used when the mission is loading groups at start. Prevents the player from moving or seeing anything happening. Use in conjunction with mission_start_fade_out. 
  2488. -- 
  2489. -- unlock_controls:		(boolean, optional) Set to TRUE to unlock player controls, FALSE to keep player controls locked (must be unlocked manually) [defaults to true] 
  2490. -- 
  2491. function mission_start_fade_in(unlock_controls) 
  2492. 	if (unlock_controls == nil) then 
  2493. 		unlock_controls = true 
  2494. 	end 
  2495.  
  2496. 	mip_streaming_pause(false, "mission_start_fade_in") 
  2497. 	object_spawn_pause(false, "mission_start_fade_in") 
  2498.      
  2499. 	fade_in( START_FADE_IN_TIME ) 
  2500. 	fade_in_block() 
  2501. 	 
  2502. 	if (unlock_controls) then 
  2503. 		player_controls_enable( LOCAL_PLAYER ) 
  2504. 		if ( coop_is_active() ) then 
  2505. 			player_controls_enable( REMOTE_PLAYER ) 
  2506. 		end 
  2507. 		Player_controls_disabled_by_mission_start_fadeout = false 
  2508. 	end 
  2509. end 
  2510.  
  2511. -- Disables player controls and instantly fades out the screen. 
  2512. -- 
  2513. -- Should be used when the mission is loading groups at start. Prevents the player from moving or seeing anything happening. Use in conjunction with mission_start_fade_in. 
  2514. -- 
  2515. function mission_start_fade_out(fade_time) 
  2516. 	if (fade_time == nil) then 
  2517. 		fade_time = START_FADE_OUT_TIME 
  2518. 	end 
  2519. 	 
  2520. 	fade_out( fade_time ) 
  2521. 	player_controls_disable( LOCAL_PLAYER ) 
  2522. 	if ( coop_is_active() ) then 
  2523. 		player_controls_disable( REMOTE_PLAYER ) 
  2524. 	end 
  2525. 	Player_controls_disabled_by_mission_start_fadeout = true 
  2526. 	fade_out_block() 
  2527.  
  2528. 	mip_streaming_pause(true, "mission_start_fade_out") 
  2529. 	object_spawn_pause(true, "mission_start_fade_out") 
  2530. end 
  2531.  
  2532. -- Add a mission waypoint at a navpoint. 
  2533. -- 
  2534. -- navpoint:	(string) name of navpoint, NPC, vehicle, or trigger 
  2535. -- sync_type:	(enumeration, optional) synchronization type (SYNC_LOCAL = affects local player, SYNC_REMOTE = affects remote player, or SYNC_ALL = affects both players; defaults to SYNC_ALL) 
  2536. -- 
  2537. -- If a mission waypoint currently exists, it will be removed and replaced by this call. 
  2538. -- 
  2539. function mission_waypoint_add(navpoint, sync_type) 
  2540. 	mission_waypoint_remove(sync_type) 
  2541. 	Mission_waypoint = waypoint_add(navpoint, sync_type) 
  2542. end 
  2543.  
  2544. -- Remove the current mission waypoint. 
  2545. -- 
  2546. -- sync_type:	(enumeration, optional) synchronization type (SYNC_LOCAL = affects local player, SYNC_REMOTE = affects remote player, or SYNC_ALL = affects both players; defaults to SYNC_ALL) 
  2547. -- 
  2548. function mission_waypoint_remove(sync_type) 
  2549. 	if (Mission_waypoint ~= -1) then	 
  2550. 		waypoint_remove(sync_type) 
  2551. 		Mission_waypoint = -1 
  2552. 	end 
  2553. end 
  2554.  
  2555. -- move_to speed defines 
  2556. MOVE_TO_WALK = 1 
  2557. MOVE_TO_RUN = 2 
  2558. MOVE_TO_SPRINT = 3 
  2559.  
  2560. -- Make a character pathfind through one or more navpoints. 
  2561. --  
  2562. -- name:					(string) name of the character 
  2563. -- dest:					(string) name of the scripted_path spline to follow, or navpoint to go to 
  2564. -- speed:				(integer, optional) movement speed (1 = walk, 2 = run, 3 = sprint; defaults to 1) 
  2565. -- retry_on_failure:	(boolean, optional) set to true to keep retrying if path calculation fails (defaults to false) 
  2566. -- move_and_fire:		(boolean, optional) set to true to allow the NPC to fire on the move (defaults to false) 
  2567. -- 
  2568. -- This function blocks until the character has finished pathfinding. 
  2569.  
  2570. -- 
  2571. function move_to(name, dest, ...) 
  2572. 	local num_args, speed, retry_on_failure, move_and_fire, path_index 
  2573.  
  2574. 	-- Wait until the resource is loaded. 
  2575. 	character_wait_for_loaded_resource(name) 
  2576. 			 
  2577. 	num_args = arg.n 
  2578.  
  2579. 	-- get move and fire 
  2580. 	if ( (num_args >= 3) and (type(arg[num_args]) == "boolean") ) then 
  2581. 		move_and_fire = arg[num_args] 
  2582. 		num_args = num_args - 1 
  2583. 	else 
  2584. 		move_and_fire = false 
  2585. 	end 
  2586.  
  2587. 	-- get retry 
  2588. 	if ( (num_args >= 2) and (type(arg[num_args]) == "boolean") ) then 
  2589. 		retry_on_failure = arg[num_args] 
  2590. 		num_args = num_args - 1 
  2591. 	else 
  2592. 		retry_on_failure = false 
  2593. 	end 
  2594. 	 
  2595. 	-- get speed 
  2596. 	if ( (num_args >= 1) and (type(arg[num_args]) == "number") ) then 
  2597. 		speed = arg[num_args] 
  2598. 	else 
  2599. 		speed = 1 
  2600. 	end 
  2601. 	 
  2602. 	while( not character_is_ready( name ) ) do 
  2603. 		thread_yield() 
  2604. 	end 
  2605. 	 
  2606. 	if (type(dest) == "string") then 
  2607. 		-- Is it a scripted_path or a single navpoint? 
  2608. 		if ( path_name_is_path(dest)) then 
  2609. 			local	idx 
  2610.  
  2611. 			idx = 0 
  2612. 			while (1) do 
  2613. 				path_index = move_to_do(name, dest, speed, retry_on_failure, move_and_fire, true, idx) 
  2614. 				if (not (path_index == 0)) then 
  2615. 					-- Keep checking for done until the character dies or reaches the destination 
  2616. 					while ( character_is_dead( name ) == false and 
  2617. 						not( move_to_check_done(path_index,  name, dest, speed, retry_on_failure, move_and_fire, true, idx ) ) ) do 
  2618. 						thread_yield() 
  2619. 					end 
  2620.  
  2621. 					idx = idx + 1 
  2622. 				else 
  2623. 					return false 
  2624. 				end 
  2625. 			end 
  2626. 		else 
  2627. 			path_index = move_to_do(name, dest, speed, retry_on_failure, move_and_fire, false, 0) 
  2628. 			if (not (path_index == 0)) then 
  2629. 			-- Keep checking for done until the character dies or reaches the destination 
  2630. 				while ( character_is_dead( name ) == false and 
  2631. 					not( move_to_check_done(path_index,  name, dest, speed, retry_on_failure, move_and_fire, false, 0 ) ) ) do 
  2632. 					thread_yield() 
  2633. 				end 
  2634. 			else 
  2635. 				return false 
  2636. 			end 
  2637. 		end 
  2638. 	end 
  2639. 	 
  2640. 	return (not character_is_dead( name )) 
  2641. end 
  2642.  
  2643. -- Make a character pathfind through one or more navpoints. Returns if at any point the character dies. 
  2644. --  
  2645. -- name:				(string) name of the character 
  2646. -- dest:				(string) name of the scripted_path spline to follow, or navpoint to go to 
  2647. -- speed:				(integer, optional) movement speed (1 = walk, 2 = run, 3 = sprint; defaults to 1) 
  2648. -- retry_on_failure:	(boolean, optional) set to true to keep retrying if path calculation fails (defaults to false) 
  2649. -- move_and_fire:		(booelan, optional) set to true to allow the NPC to fire on the move (defaults to false) 
  2650. -- 
  2651. -- This function blocks until the character has finished pathfinding, or until the character dies. This function otherwise behaves exactly like move_to. 
  2652. -- 
  2653. function move_to_safe(name, dest, ...) 
  2654.  
  2655.    -- If the character is dead, then forget about pathfinding 
  2656.    if ( character_is_dead( name ) == true ) then 
  2657.       return false 
  2658.    end 
  2659.  
  2660. 	local num_args, speed, retry_on_failure, move_and_fire, path_index 
  2661.  
  2662. 	-- Wait until the resource is loaded. 
  2663. 	character_wait_for_loaded_resource(name) 
  2664. 			 
  2665. 	num_args = arg.n 
  2666.  
  2667. 	-- get move and fire 
  2668. 	if ( (num_args >= 3) and (type(arg[num_args]) == "boolean") ) then 
  2669. 		move_and_fire = arg[num_args] 
  2670. 		num_args = num_args - 1 
  2671. 	else 
  2672. 		move_and_fire = false 
  2673. 	end 
  2674.  
  2675. 	-- get retry 
  2676. 	if ( (num_args >= 2) and (type(arg[num_args]) == "boolean") ) then 
  2677. 		retry_on_failure = arg[num_args] 
  2678. 		num_args = num_args - 1 
  2679. 	else 
  2680. 		retry_on_failure = false 
  2681. 	end 
  2682. 	 
  2683. 	-- get speed 
  2684. 	if ( (num_args >= 1) and (type(arg[num_args]) == "number") ) then 
  2685. 		speed = arg[num_args] 
  2686. 	else 
  2687. 		speed = 1 
  2688. 	end 
  2689. 	 
  2690. 	while( not character_is_ready( name )) do 
  2691. 		thread_yield() 
  2692.  
  2693. 		-- Don't pathfind if character is dead or entered a vehicle 
  2694. 		if (character_is_dead(name) or character_is_in_vehicle( name )) then 
  2695. 			return false 
  2696. 		end 
  2697. 	end 
  2698.  
  2699. 	-- Character may have entered a vehicle in the same frame that it became ready. 
  2700. 		if (character_is_in_vehicle( name )) then 
  2701. 			return false 
  2702. 		end 
  2703.  
  2704. 	if (type(dest) == "string") then 
  2705. 		-- Is it a path list of navpoints are a single navpoint? 
  2706. 		if (path_name_is_path(dest)) then 
  2707. 			local	idx 
  2708.  
  2709. 			idx = 0 
  2710. 			while (1) do 
  2711. 				path_index = move_to_do(name, dest, speed, retry_on_failure, move_and_fire, true, idx) 
  2712. 				if (not (path_index == 0)) then 
  2713. 					while(not(move_to_check_done(path_index, name, dest, speed, retry_on_failure, move_and_fire, true, idx))) do 
  2714. 						thread_yield() 
  2715.  
  2716. 						-- Don't pathfind if character is dead or entered a vehicle 
  2717. 						if (character_is_dead(name) or character_is_in_vehicle( name )) then 
  2718. 							return false 
  2719. 						end 
  2720. 					end 
  2721.  
  2722. 					idx = idx + 1 
  2723. 				else 
  2724. 					return false 
  2725. 				end 
  2726. 			end 
  2727. 		else 
  2728. 			path_index = move_to_do(name, dest, speed, retry_on_failure, move_and_fire, false, 0) 
  2729. 			if (not (path_index == 0)) then 
  2730. 				while(not(move_to_check_done(path_index, name, dest, speed, retry_on_failure, move_and_fire, false, 0))) do 
  2731. 					thread_yield() 
  2732.  
  2733. 					-- Don't pathfind if character is dead or entered a vehicle 
  2734. 					if (character_is_dead(name) or character_is_in_vehicle( name )) then 
  2735. 						return false 
  2736. 					end 
  2737. 				end 
  2738. 			else 
  2739. 				return false 
  2740. 			end 
  2741. 		end 
  2742. 	end 
  2743. 	 
  2744. 	return true 
  2745. end 
  2746.  
  2747. -- Add object indicators to a table (or single object) of NPCs, vehicles, items, or anything else that's set up in object_indicator.h 
  2748. -- 
  2749. -- object_name:(table or string) table of names of the objects to add indicators to (or a single object, table of tables, etc.) 
  2750. -- asset_id:	(int) ID of the indicator asset to use 
  2751. -- flags:		(int, optional) flags for the object indicator (defaults to OI_FLAGS_DEFAULT) 
  2752. -- sync_type:	(enumeration, optional) synchronization type (SYNC_LOCAL = affects local player, SYNC_REMOTE = affects remote player, or SYNC_ALL = affects both players; defaults to SYNC_ALL) 
  2753. -- fade_dist:					(float, optional) distance to start fading if the OI_FLAG_FADE flag is specified (default, 100.0) 
  2754. -- 
  2755. -- Returns the number of object indicators that were added 
  2756. -- 
  2757. function object_indicator_add(object_name, asset_id, flags, sync_type, fade_dist) 
  2758. 	local num_added = 0 
  2759. 	if (type(object_name) == "table") then 
  2760. 		for i,obj in pairs(object_name) do 
  2761. 			num_added = num_added + object_indicator_add(obj, asset_id, flags, sync_type) 
  2762. 		end 
  2763. 	elseif (type(object_name) == "string") then 
  2764. 		if (sync_type == nil) then 
  2765. 			sync_type = SYNC_ALL 
  2766. 		end 
  2767. 		 
  2768. 		if (fade_dist == nil) then 
  2769. 			fade_dist = 100.0 
  2770. 		end 
  2771.  
  2772. 		if (flags == nil) then 
  2773. 			flags = OI_FLAGS_DEFAULT 
  2774. 		end 
  2775.  
  2776. 		-- If the object was found, and the indicator was added, increase the number by 1 
  2777. 		if (object_indicator_add_do(object_name, asset_id, flags, sync_type, fade_dist) == true) then 
  2778. 			num_added = num_added + 1 
  2779. 		end 
  2780. 	end 
  2781.  
  2782. 	return num_added 
  2783. end 
  2784.  
  2785. -- Add an object indicator to each object in a group of script objects 
  2786. -- 
  2787. -- group:		(string or table) name of a script group, or a script group table with a "name" field 
  2788. -- asset_id:	(integer) ID of the object indicator asset to use 
  2789. -- flags:		(integer, optional) flags for the object indicator (defaults to OI_FLAGS_DEFAULT) 
  2790. -- sync_type:	(enumeration, optional) synchronization type (SYNC_LOCAL = affects local player, SYNC_REMOTE = affects remote player, or SYNC_ALL = affects both players; defaults to SYNC_ALL) 
  2791. -- 
  2792. function object_indicator_add_script_group(group, asset_id, flags, sync_type) 
  2793. 	local group_name = group 
  2794.  
  2795. 	if (type(group) == "table" and type(group.name) == "string") then 
  2796. 		group_name = group.name 
  2797. 	end 
  2798.  
  2799. 	if (flags == nil) then 
  2800. 		flags = OI_FLAGS_DEFAULT 
  2801. 	end 
  2802.  
  2803. 	if (sync_type == nil) then 
  2804. 		sync_type = SYNC_ALL 
  2805. 	end 
  2806. 	 
  2807. 	object_indicator_add_script_group_do(group_name, asset_id, flags, sync_type) 
  2808. end 
  2809.  
  2810. -- Remove object indicators from a table (or single object) of NPCs, vehicles, items, or anything else that's set up in object_indicator.h 
  2811. -- 
  2812. -- object_name:(table or string) table of names of the objects to remove indicators from (or a single object, table of tables, etc.) 
  2813. -- sync_type:	(enumeration, optional) synchronization type (SYNC_LOCAL = affects local player, SYNC_REMOTE = affects remote player, or SYNC_ALL = affects both players; defaults to SYNC_ALL) 
  2814. -- 
  2815. function object_indicator_remove(object_name, sync_type) 
  2816. 	if (type(object_name) == "table") then 
  2817. 		for i,obj in pairs(object_name) do 
  2818. 			object_indicator_remove(obj, sync_type) 
  2819. 		end 
  2820. 	elseif (type(object_name) == "string") then 
  2821. 		if (sync_type == nil) then 
  2822. 			sync_type = SYNC_ALL 
  2823. 		end 
  2824.  
  2825. 		object_indicator_remove_do(object_name, sync_type) 
  2826. 	end 
  2827. end 
  2828.  
  2829. -- Removes an object indicator from each object in a group of script objects 
  2830. -- 
  2831. -- group:		(string or table) name of a script group, or a script group table with a "name" field 
  2832. -- sync_type:	(enumeration, optional) synchronization type (SYNC_LOCAL = affects local player, SYNC_REMOTE = affects remote player, or SYNC_ALL = affects both players; defaults to SYNC_ALL) 
  2833. -- 
  2834. function object_indicator_remove_script_group(group, sync_type) 
  2835. 	local group_name = group 
  2836.  
  2837. 	if (type(group) == "table" and type(group.name) == "string") then 
  2838. 		group_name = group.name 
  2839. 	end 
  2840.  
  2841. 	if (sync_type == nil) then 
  2842. 		sync_type = SYNC_ALL 
  2843. 	end 
  2844. 	 
  2845. 	object_indicator_remove_script_group_do(group_name, sync_type) 
  2846. end 
  2847.  
  2848. -- Register a callback function for when any human is killed 
  2849. -- 
  2850. -- function_name:	(string) name of the function 
  2851. -- 
  2852. -- When the callback is executed, the following parameters are passed to it: 
  2853. --  - (string) name of the attacker 
  2854. --  - (string) name of the team of the victim 
  2855. -- 
  2856. function on_random_human_killed( function_name ) 
  2857. 	on_random_obj_killed_do( function_name, 1 ) 
  2858. end 
  2859.  
  2860. -- Register a callback function for when any mover is killed 
  2861. -- 
  2862. -- function_name:	(string) name of the function 
  2863. -- 
  2864. -- When the callback is executed, the following parameters are passed to it: 
  2865. --  - (string) name of the attacker 
  2866. --  - (string) property name (from levels.xtbl) of the mover destroyed 
  2867. -- 
  2868. function on_random_mover_killed( function_name, mission_name ) 
  2869. 	on_random_obj_killed_do( function_name, 2 ) 
  2870. end 
  2871.  
  2872. -- Register a callback function for when any object in an object destroyed script is destroyed during a mission. 
  2873. -- 
  2874. -- function_name:	(string) name of the function 
  2875. -- 
  2876. -- The object destroyed script is generated by Art. It contains the chunk number (all three digits, including leading zeroes) 
  2877. -- and the object name. The file is named exactly the same as the mission/stronghold/activity and has a ".ods" file extension. 
  2878. -- 
  2879. function on_random_ods_killed( function_name ) 
  2880. 	on_random_obj_killed_do( function_name, 4 ) 
  2881. end 
  2882.  
  2883. -- Register a callback function for when any vehicle is destroyed 
  2884. -- 
  2885. -- function_name:	(string) name of the function 
  2886. -- 
  2887. -- When the callback is executed, the following parameters are passed to it: 
  2888. --  - (string) name of the attacker 
  2889. --  - (string) name of the team of the vehicle's driver 
  2890. -- 
  2891. function on_random_vehicle_killed( function_name ) 
  2892. 	on_random_obj_killed_do( function_name, 3 ) 
  2893. end 
  2894.  
  2895. -- Open an interface dialog box. 
  2896. -- 
  2897. -- title_tag:	(string) identifying tag for the title text 
  2898. -- body_tag:	(string) identifying tag for the body text 
  2899. -- tag1:		(string) identifying tag for selection 1 text 
  2900. -- tag2:		(string) identifying tag for selection 2 text 
  2901. -- 
  2902. -- returns:		(integer) index corresponding to which option was selected (0 corresponds to the first option, 1 corresponds to the second option, or -1 if the dialog was forced closed) 
  2903. -- 
  2904. function open_vint_dialog(title_tag, body_tag, tag1, tag2) 
  2905. 	open_vint_dialog_do(title_tag, body_tag, tag1, tag2) 
  2906.  
  2907. 	local		check_value = open_vint_dialog_check_done() 
  2908.  
  2909. 	while (check_value == -2) do 
  2910. 		thread_yield() 
  2911. 		check_value = open_vint_dialog_check_done() 
  2912. 	end 
  2913.  
  2914. 	return check_value 
  2915. end 
  2916.  
  2917. -- Add members to the player's party. 
  2918. -- 
  2919. -- names:	(one or more strings) names of NPCs to add to the player's party 
  2920. -- player:	(string, optional) name of the player to add party members to (defaults to closest player) 
  2921. -- 
  2922. -- This function will automatically dismiss followers to make room for the specified NPCs. 
  2923. -- 
  2924. -- Example: 
  2925. -- 
  2926. --		party_add("NPC1", "NPC2", "NPC3") 
  2927. -- 
  2928. -- Adds three NPCs to the closeset player�s party, "NPC1", "NPC2", and "NPC3". 
  2929. -- 
  2930. function party_add(...) 
  2931. 	local player = CLOSEST_PLAYER 
  2932. 	 
  2933. 	if is_player_tag(arg[arg.n]) then 
  2934. 		player = arg[arg.n] 
  2935. 		arg.n = arg.n - 1 
  2936. 	end 
  2937. 		 
  2938. 	party_add_do(player, arg, false) 
  2939. end 
  2940.  
  2941. -- Add members to the player's party, but only if there is room. 
  2942. -- 
  2943. -- names:	(one or more strings) names of NPCs to add to the player's party 
  2944. -- player:	(string, optional) name of the player to add party members to (defaults to closest player) 
  2945. -- 
  2946. function party_add_optional(...) 
  2947. 	local player = CLOSEST_PLAYER 
  2948. 	 
  2949. 	if is_player_tag(arg[arg.n]) then 
  2950. 		player = arg[arg.n] 
  2951. 		arg.n = arg.n - 1 
  2952. 	end 
  2953. 		 
  2954. 	party_add_do(player, arg, true) 
  2955. end 
  2956.  
  2957. function party_add_ignore_limits(...) 
  2958. 	local player = CLOSEST_PLAYER 
  2959. 	 
  2960. 	if is_player_tag(arg[arg.n]) then 
  2961. 		player = arg[arg.n] 
  2962. 		arg.n = arg.n - 1 
  2963. 	end 
  2964. 		 
  2965. 	party_add_do(player, arg, false, true) 
  2966. end 
  2967.  
  2968.  
  2969. -- Dismiss members from the player's party 
  2970. -- 
  2971. -- names:	(one or more strings) names of NPCs to remove from the player's party 
  2972. -- 
  2973. -- Example: 
  2974. -- 
  2975. --		party_dismiss("NPC1", "NPC2", "NPC3") 
  2976. -- 
  2977. -- Dismisses three NPCs from the player�s party, "NPC1", "NPC2", and "NPC3". 
  2978. -- 
  2979. function party_dismiss(...) 
  2980. 	party_dismiss_do(arg) 
  2981. end 
  2982.  
  2983. -- Override an NPC's persona on a per-situation basis. 
  2984. -- 
  2985. -- name:			(string) name of the NPC 
  2986. -- situation:	(string, or table of strings) persona situation(s) to override (as defined in persona_situations.xtbl) 
  2987. -- audio:		(string, optional) audio file to force play, or "" to override with silence (defaults to "") 
  2988. -- count:		(integer, optional) number of times the override should occur, or -1 to override indefinitely (defaults to -1) 
  2989. -- 
  2990. -- The specified audio will play in the specified situation instead of the default voice line(s) defined in persona.xtbl. 
  2991. -- 
  2992. function persona_override_character_start(character, situation, audio, count) 
  2993.  
  2994. 	if type(situation) == "table" then 
  2995. 		for i, persona_situation in pairs(situation) do 
  2996. 			local trigger_prefix = persona_trigger_get_player_prefix(character) 
  2997. 			persona_override_character_start_do(character, persona_situation, trigger_prefix .. audio, count) 
  2998. 		end 
  2999. 	else 
  3000. 		local trigger_prefix = persona_trigger_get_player_prefix(character) 
  3001. 		persona_override_character_start_do(character, situation, trigger_prefix .. audio, count) 
  3002. 	end 
  3003.  
  3004. end 
  3005.  
  3006. -- Reset the situational persona overrides for an NPC. 
  3007. -- 
  3008. -- name:			(string) name of the NPC 
  3009. -- situation:	(string, or table of strings) persona situation(s) to reset back to normal (as defined in persona_situations.xtbl) 
  3010. -- 
  3011. function persona_override_character_stop(character, situation) 
  3012.  
  3013. 	if type(situation) == "table" then 
  3014. 		for i, persona_situation in pairs(situation) do 
  3015. 			persona_override_character_stop_do(character, persona_situation) 
  3016. 		end 
  3017. 	else 
  3018. 		persona_override_character_stop_do(character, situation) 
  3019. 	end 
  3020.  
  3021. end 
  3022.  
  3023. -- Override a group of personas for a single situation. 
  3024. -- 
  3025. -- persona_list:	(string, or table of strings) names of personas to override 
  3026. -- situation:		(string, or table of strings) persona situation(s) to override (as defined in persona_situations.xtbl) 
  3027. -- tag_suffix:		(string) common trigger suffix 
  3028. -- 
  3029. -- Example: 
  3030. -- 
  3031. --	The following 3 lines: 
  3032. -- 
  3033. --		EX_PERSONAS	=	{	["AM_Gang1"]	=	"AMGNG1"; 
  3034. --								["AM_Gang2"]	=	"AMGNG2"; 
  3035. --							} 
  3036. --		persona_override_group(EX_PERSONAS, POT_SITUATIONS[POT_ATTACK], "EX01_ATTACK") 
  3037. -- 
  3038. --	Are equivalent to: 
  3039. -- 
  3040. --		persona_override_persona_start("AM_Gang1", "threat - alert (group attack)",	"AMGNG1_EX01_ATTACK") 
  3041. --		persona_override_persona_start("AM_Gang1", "threat - alert (solo attack)",		"AFGNG1_EX01_ATTACK") 
  3042. --		persona_override_persona_start("AM_Gang2", "threat - alert (group attack)",	"AMGNG2_EX01_ATTACK") 
  3043. --		persona_override_persona_start("AM_Gang2", "threat - alert (solo attack)",		"AFGNG2_EX01_ATTACK") 
  3044. -- 
  3045. -- Generally this function will be used with one of 4 predefined gang persona tables: 
  3046. -- 
  3047. --		BROTHERHOOD_PERSONAS 
  3048. --		RONIN_PERSONAS 
  3049. --		SAINTS_PERSONAS 
  3050. --		SAMEDI_PERSONAS 
  3051. -- 
  3052. function persona_override_group_start(persona_list, situation, tag_suffix) 
  3053. 	for persona, tag_prefix in pairs(persona_list) do 
  3054. 		persona_override_persona_start(persona, situation, tag_prefix .. "_" .. tag_suffix) 
  3055. 	end 
  3056. end 
  3057.  
  3058. -- Reset the situational override for a group of personas. 
  3059. -- 
  3060. -- persona_list:	(string, or table of strings) names of personas to override 
  3061. -- situation:		(string, or table of strings) persona situation(s) to override (as defined in persona_situations.xtbl) 
  3062. -- 
  3063. function persona_override_group_stop(persona_list, situation) 
  3064. 	for persona, tag_prefix in pairs(persona_list) do 
  3065. 		persona_override_persona_stop(persona, situation) 
  3066. 	end 
  3067. end 
  3068.  
  3069. -- Override all script NPCs with a particular persona in a given situation (or situations). 
  3070. -- 
  3071. -- persona:		(string) name of the persona 
  3072. -- situation:	(string, or table of strings) persona situation(s) to override (as defined in persona_situations.xtbl) 
  3073. -- audio:		(string, optional) audio file to force play, or "" to override with silence (defaults to "") 
  3074. -- count:		(integer, optional) number of times the override should occur, or -1 to override indefinitely (defaults to -1) 
  3075. -- 
  3076. function persona_override_persona_start_old(persona, situation, audio, count) 
  3077.  
  3078. 	if type(situation) == "table" then 
  3079. 		for i, persona_situation in pairs(situation) do 
  3080. 			persona_override_persona_start_do(persona, persona_situation, audio, count) 
  3081. 		end 
  3082. 	else 
  3083. 		persona_override_persona_start_do(persona, situation) 
  3084. 	end 
  3085.  
  3086. end 
  3087.  
  3088. -- Reset all script NPCs with a particular persona in a given situation (or situations). 
  3089. -- 
  3090. -- persona:		(string) name of the persona 
  3091. -- situation:	(string, or table of strings) persona situation(s) to reset (as defined in persona_situations.xtbl) 
  3092. -- 
  3093. function persona_override_persona_stop_old(persona, situation) 
  3094.  
  3095. 	if type(situation) == "table" then 
  3096. 		for i, persona_situation in pairs(situation) do 
  3097. 			persona_override_persona_stop_do(persona, persona_situation) 
  3098. 		end 
  3099. 	else 
  3100. 		persona_override_persona_stop_do(persona, situation) 
  3101. 	end 
  3102.  
  3103. end 
  3104.  
  3105. -- Get the prefix that should be prepended to the character's persona triggers. 
  3106. -- 
  3107. -- name:		(string) name of the character 
  3108. -- 
  3109. --	returns:	(string) prefix to prepend to the trigger 
  3110. --  
  3111. function persona_trigger_get_player_prefix(name) 
  3112.  
  3113. 	local voice_prefixes = {[0] = "WM", [1] = "BM", [2] = "WMA", [3] = "WF", [4] = "BF", [5] = "HF", [6] = "Z"} 
  3114. 	local trigger_prefix = "" 
  3115.  
  3116. 	if(character_is_player(name)) then 
  3117. 		local player_voice_prefix = voice_prefixes[player_get_custom_voice(name)] 
  3118. 		if(player_voice_prefix ~= nil) then 
  3119. 			trigger_prefix = player_voice_prefix 
  3120. 		end 
  3121. 	end 
  3122.  
  3123. 	return trigger_prefix 
  3124.  
  3125. end 
  3126.  
  3127. -- Make a player take another character as a human shield. 
  3128. -- 
  3129. -- player:		(string) name of the player that will take a human shield 
  3130. -- victim:		(string) name of target 
  3131. -- tele_victim: (bool, optional) Teleport the victim in range if necessary? (default true) 
  3132. -- 
  3133. -- returns:		(bool) true if the grab worked, false if it failed. 
  3134. function player_take_human_shield( player, victim, tele_victim ) 
  3135. 	 
  3136. 	if (player == nil or player == "" or victim == nil or victim == "") then 
  3137. 		return false 
  3138. 	end 
  3139. 	 
  3140. 	if not player_take_human_shield_do( player, victim, tele_victim ) then 
  3141. 		return false 
  3142. 	end 
  3143.  
  3144.    -- loop as long as grabber and grabee are alive until we've succeeded 
  3145.    while ( character_is_dead( player ) == false and 
  3146.            character_is_dead( victim ) == false and 
  3147. 	   character_take_human_shield_check_done( player, victim) == false) do 
  3148.       thread_yield(); 
  3149.    end 
  3150.     
  3151.    return character_has_specific_human_shield( player, victim ) 
  3152. end 
  3153.  
  3154. -- Take a screenshot and stores the output file on the kit. 
  3155. -- 
  3156. -- filename:	(string, optional) filename to use for screenshot, excluding the file extension (default filename is MMDD_screenNNN, where MM is the month, DD is the date, and NNN is an incrementing count) 
  3157. -- 
  3158. function screenshot(...) 
  3159. 	if (arg.n > 0) then 
  3160. 		screenshot_do(arg[1]) 
  3161. 	else 
  3162. 		screenshot_do("") 
  3163. 	end 
  3164.  
  3165. 	while (not(screenshot_check_done())) do 
  3166. 		thread_yield() 
  3167. 	end 
  3168. end 
  3169.  
  3170. -- Determine the synchronization type from a player name. 
  3171. -- 
  3172. -- player_name:	(string) name of the player 
  3173. -- 
  3174. -- returns:			(enumeration) SYNC_REMOTE, if the player is REMOTE_PLAYER; SYNC_LOCAL, if the player is LOCAL_PLAYER; else SYNC_ALL 
  3175. -- 
  3176. function sync_from_player(player_name) 
  3177. 	if player_name == REMOTE_PLAYER then 
  3178. 		return SYNC_REMOTE 
  3179. 	end 
  3180. 	if player_name == LOCAL_PLAYER then 
  3181. 		return SYNC_LOCAL 
  3182. 	end 
  3183. 	 
  3184. 	return SYNC_ALL 
  3185. end 
  3186.  
  3187. -- Teleport both the local and remote players. 
  3188. -- 
  3189. -- local_player_nav:		(string) name of the navpoint to teleport the local player to 
  3190. -- remote_player_nav:	(string) name of the navpoint to teleport the remote player to 
  3191. -- exit_vehicles:			(boolean, optional) set to true to force the players to exit from whatever vehicle they are in (defaults to false) 
  3192. -- check_for_obstacles:	(boolean, optional) set to true to check for obstacles in the way at the spawn location, false otherwise. Only valid for NPCs. (IF SET TO FALSE, THE HUMAN MAY BE TELEPORTED INTERSECTING WITH ANOTHER OBJECT) (defaults to true)  
  3193. -- stick_to_ground:		(boolean, optional) Set to true if the character (NPC only) should be stuck to the ground when teleporting. Only set to false in special case situations, if you're unsure you probably want to use the default. (defaults to true) 
  3194. -- 
  3195. function teleport_coop( local_player_nav, remote_player_nav, exit_vehicles, check_for_obstacles, stick_to_ground ) 
  3196.  
  3197. 	--assert_screen_is_faded_out() -- Assert that the screen is completely faded out at this point - mission responsibility. 
  3198. 	 
  3199. 	local reset_camera_orient = true 
  3200. 	local offset_x = 0 
  3201. 	local offset_y = 0 
  3202. 	local offset_z = 0 
  3203.  
  3204. 	if (coop_is_active()) then 
  3205. 		teleport( REMOTE_PLAYER, remote_player_nav, exit_vehicles, reset_camera_orient, offset_x, 
  3206. 			offset_y, offset_z, check_for_obstacles, stick_to_ground ) 
  3207. 	end 
  3208.  
  3209. 	teleport( LOCAL_PLAYER, local_player_nav, exit_vehicles, reset_camera_orient, offset_x, 
  3210. 			offset_y, offset_z, check_for_obstacles, stick_to_ground ) 
  3211.  
  3212. 	if (coop_is_active()) then 
  3213. 		waiting_for_player_dialog( true ) 
  3214. 		repeat thread_yield() until (teleport_check_done(REMOTE_PLAYER) or coop_is_active() == false) 
  3215. 		waiting_for_player_dialog( false ) 
  3216. 	end		 
  3217. 	 
  3218. 	repeat thread_yield() until teleport_check_done(LOCAL_PLAYER) 
  3219. end 
  3220.  
  3221. -- Block until a single thread or table of threads has completed processing 
  3222. -- 
  3223. -- thread_handle:	(number or table) handle to a thread, table of handles to a thread, table of tables, etc... 
  3224. -- 
  3225. function threads_wait_for_completion(thread_handle) 
  3226. 	local ret_val = thread_handle 
  3227.  
  3228. 	if (type(thread_handle) == "number") then 
  3229. 		while (not thread_check_done(thread_handle)) do 
  3230. 			thread_yield() 
  3231. 		end 
  3232. 		ret_val = INVALID_THREAD_HANDLE 
  3233. 	elseif (type(thread_handle) == "table") then 
  3234. 		for i,handle in pairs(thread_handle) do 
  3235. 			ret_val[i] = threads_wait_for_completion(handle) 
  3236. 		end 
  3237. 	end 
  3238.  
  3239. 	-- Returns a copy with the completed threads set to INVALID_THREAD_HANDLE 
  3240. 	return ret_val 
  3241. end 
  3242.  
  3243. -- Make a character turn to face an object (or turn to face the same direction as the object). 
  3244. -- 
  3245. -- name:		(string) name of the character 
  3246. -- target:	(string) name of the object (can be a navpoint, or character, or other scripted object) 
  3247. -- orient:	(boolean, optional) set to true to make the character face the same direction that the object is facing, or false to make the character face the object (defaults to false) 
  3248. -- 
  3249. -- This function blocks until the character has finished turning. 
  3250. -- 
  3251. function turn_to(name, target, orient) 
  3252. 	while (not(character_is_ready(name))) do 
  3253. 		thread_yield() 
  3254. 	end 
  3255. 	 
  3256. 	turn_to_do(name, target, orient) 
  3257.  
  3258. 	while (not(turn_to_check_done(name))) do 
  3259. 		thread_yield() 
  3260. 	end 
  3261. end 
  3262.  
  3263. -- Make a character enter vehicle. 
  3264. -- 
  3265. -- name:							(string) name of the character 
  3266. -- vehicle_name:				(string) name of the vehicle 
  3267. -- seat:							(integer, optional) index of the seat to enter (defaults to 0, the driver's seat) 
  3268. -- block:						(boolean, optional) set to true to block until vehicle entry is finished (defaults to true) 
  3269. -- force_hijack_success:	(boolean, optional) set to true to force any hijacks to automatically succeed (defaults to false) 
  3270. -- block_until_visual:		(boolean, optional) if blocking, only block until the human is visualy in vehicle instead of waiting until the enter is completely finished (defaults to false) 
  3271. -- override_action:			(string, optional) action to play instead of standard vehicle entry actions 
  3272. -- special_entry:				(boolean, optional) if this is set, the special_entry flag is required for the seat used.  This can be used to differentiate seats that should only be used in scripted situations. 
  3273. -- skip_ai_entry_mode:		(boolean, optional) defaults to false 
  3274. -- skip_pathfind:			(boolean, optional) defaults to false 
  3275. -- hop_over:				(boolean, optional) defaults to false 
  3276. function vehicle_enter(name, vehicle_name, seat, block, force_hijack_success, block_until_visual, override_action, special_entry, skip_ai_entry_mode, skip_pathfind, hop_over) 
  3277.    if ( force_hijack_success == nil ) then 
  3278.       force_hijack_success = false 
  3279.    end 
  3280. 	local s = vehicle_enter_do(name, vehicle_name, false, seat, force_hijack_success, override_action, special_entry, skip_ai_entry_mode, skip_pathfind, hop_over) 
  3281. 	local r 
  3282. 	 
  3283. 	-- don't bother checking if it was successful unless the request was successful  
  3284. 	if (s and (block or (block == nil))) then 
  3285. 		repeat 
  3286. 			thread_yield() 
  3287. 			r = vehicle_enter_check_done(name, block_until_visual, vehicle_name) 
  3288. 		until r ~= 0 
  3289. 	else 
  3290. 		return s 
  3291. 	end 
  3292. 	 
  3293. 	if r == 2 then 
  3294. 		return false 
  3295. 	else 
  3296. 		return true 
  3297. 	end 
  3298. end 
  3299.  
  3300. -- Make a group of NPCs enter a vehicle. 
  3301. -- 
  3302. -- names:			(string, or table of strings) names of characters entering the vehicle 
  3303. -- vehicle_name:	(string) name of vehicle to enter 
  3304. --  
  3305. function vehicle_enter_group(...) 
  3306. 	local npcs = {} 
  3307. 	local vehicle_name 
  3308.  
  3309. 	if type(arg[1]) == "table" then 
  3310. 		npcs = { unpack(arg[1]) } 
  3311. 		npcs[ "n" ] = sizeof_table( npcs ) 
  3312. 		 
  3313. 		vehicle_name = arg[2] 
  3314. 	else		 
  3315. 		vehicle_name = arg[ arg.n ] 
  3316. 		 
  3317. 		npcs = arg; 
  3318. 		npcs.n = npcs.n - 1 
  3319. 	end 
  3320.  
  3321. 	if (vehicle_enter_group_do(vehicle_name, false, npcs)) then 
  3322. 		while (not(vehicle_enter_group_check_done(vehicle_name, false, npcs))) do 
  3323. 			thread_yield() 
  3324. 		end 
  3325. 	end 
  3326. end 
  3327.  
  3328. -- Teleport a group of NPCs directly into a vehicle 
  3329. -- 
  3330. -- names:			(string, or table of strings) names of characters to teleport 
  3331. -- vehicle_name:	(string) name of vehicle 
  3332. -- 
  3333. -- This function blocks until all the NPCs have finished teleporting. 
  3334. --  
  3335. function vehicle_enter_group_teleport(...) 
  3336. 	local npcs = {} 
  3337. 	local vehicle_name 
  3338.  
  3339. 	if type(arg[1]) == "table" then 
  3340. 		npcs = { unpack(arg[1]) } 
  3341. 		npcs[ "n" ] = sizeof_table( npcs ) 
  3342. 		 
  3343. 		vehicle_name = arg[2] 
  3344. 	else		 
  3345. 		vehicle_name = arg[ arg.n ] 
  3346. 		 
  3347. 		npcs = arg; 
  3348. 		npcs.n = npcs.n - 1 
  3349. 	end 
  3350. 	 
  3351. 	if (vehicle_enter_group_do(vehicle_name, true, npcs)) then 
  3352. 		while (not(vehicle_enter_group_check_done(vehicle_name, true, npcs))) do 
  3353. 			thread_yield() 
  3354. 		end 
  3355. 	end 
  3356. end 
  3357.  
  3358. -- Teleport a character directly into a vehicle. 
  3359. -- 
  3360. -- name:				(string) name of the character 
  3361. -- vehicle_name:	(string) name of the vehicle 
  3362. -- seat:				(integer, optional) index of the seat to enter (defaults to 0, the driver's seat) 
  3363. -- block:			(boolean, optional) set to true to block until vehicle entry is finished (defaults to true) 
  3364. -- exit_current:	(boolean, optional) set to true if the human should vacate their current vehicle (requires blocking) (defaults to true) 
  3365. -- special_entry:	(boolean, optional) if this is set, the special_entry flag is required for the seat used.  This can be used to differentiate seats that should only be used in scripted situations. 
  3366. -- 
  3367. function vehicle_enter_teleport(name, vehicle_name, seat, block, exit_current, special_entry) 
  3368. 	if (block == nil) then 
  3369. 		block = true 
  3370. 	end 
  3371.  
  3372. 	if (exit_current == nil) then 
  3373. 		exit_current = true 
  3374. 	end 
  3375.  
  3376. 	if (exit_current and block) then 
  3377. 		if character_is_entering_vehicle(name) then 
  3378. 			vehicle_enter_cancel(name) 
  3379. 			while character_is_entering_vehicle(name) do 
  3380. 				thread_yield() 
  3381. 			end 
  3382. 		elseif character_is_exiting_vehicle(name) then 
  3383. 			while (not(vehicle_exit_check_done(name))) do 
  3384. 				thread_yield() 
  3385. 			end 
  3386. 		end 
  3387. 	 
  3388. 		local current_name = get_char_vehicle_name(name) 
  3389. 		if (current_name ~= vehicle_name) then 
  3390. 			-- this blocks 
  3391. 			vehicle_exit_teleport(name, false) 
  3392. 		end 
  3393. 	end 
  3394.  
  3395. 	local s = vehicle_enter_do(name, vehicle_name, true, seat, false, nil, special_entry) 
  3396. 	local r 
  3397. 	 
  3398. 	-- don't bother checking if it was successful unless the request was successful 
  3399. 	if (s and block) then 
  3400. 		repeat 
  3401. 			thread_yield() 
  3402. 			r = vehicle_enter_check_done(name, false, vehicle_name) 
  3403. 		until r ~= 0 
  3404. 	else 
  3405. 		return s 
  3406. 	end 
  3407. 	 
  3408. 	if r == 2 then 
  3409. 		return false 
  3410. 	else 
  3411. 		return true 
  3412. 	end 
  3413. end 
  3414.  
  3415. -- Make a character exit a vehicle. 
  3416. -- 
  3417. -- name:				(string) name of the character 
  3418. -- not_enterable:		(boolean, optional) set to true to make the vehicle unenterable (defaults to false) 
  3419. -- override_action:		(string, optional) action to play instead of standard vehicle entry actions 
  3420. -- 
  3421. -- This function blocks until the character has exited the vehicle. 
  3422. -- 
  3423. function vehicle_exit(name, not_enterable, override_action) 
  3424. 	if (vehicle_exit_do(name, false, not_enterable, false, override_action)) then 
  3425. 		while (not(vehicle_exit_check_done(name))) do 
  3426. 			thread_yield() 
  3427. 		end 
  3428. 	end 
  3429. end 
  3430.  
  3431. -- Make a character exit a vehicle by diving. 
  3432. -- 
  3433. -- name:				(string) name of the character 
  3434. -- not_enterable:	(boolean, optional) set to true to make the vehicle unenterable (defaults to false) 
  3435. -- 
  3436. -- This function blocks until the character has exited the vehicle. 
  3437. -- 
  3438. function vehicle_exit_dive(name, not_enterable) 
  3439. 	if (vehicle_exit_do(name, false, not_enterable, true)) then 
  3440. 		while (not(vehicle_exit_check_done(name))) do 
  3441. 			thread_yield() 
  3442. 		end 
  3443. 	end 
  3444. end 
  3445.  
  3446. -- Make a character exit a vehicle by teleporting. 
  3447. -- 
  3448. -- name:				(string) name of the character 
  3449. -- not_enterable:	(boolean, optional) set to true to make the vehicle unenterable (defaults to false) 
  3450. -- 
  3451. -- This function blocks until the character has exited the vehicle. 
  3452. -- 
  3453. function vehicle_exit_teleport(name, not_enterable) 
  3454. 	if (vehicle_exit_do(name, true, not_enterable, false)) then 
  3455. 		while (not(vehicle_exit_check_done(name))) do 
  3456. 			thread_yield() 
  3457. 		end 
  3458. 	end 
  3459. end 
  3460.  
  3461. -- Make a group of NPCs exit a vehicle. 
  3462. -- 
  3463. -- npc_group:	(table of strings) names of characters exiting the vehicle 
  3464. --  
  3465. function vehicle_exit_group(npc_group, not_enterable) 
  3466. 	if (vehicle_exit_group_do(false, false, not_enterable, npc_group)) then 
  3467. 		while (not(vehicle_exit_group_check_done(npc_group))) do 
  3468. 			thread_yield() 
  3469. 		end 
  3470. 	end 
  3471. end 
  3472.  
  3473. -- Make a group of NPCs dive out of a vehicle. 
  3474. -- 
  3475. -- npc_group:	(table of strings) names of characters exiting the vehicle 
  3476. --  
  3477. function vehicle_exit_group_dive(npc_group, not_enterable) 
  3478. 	if (vehicle_exit_group_do(false, true, not_enterable, npc_group)) then 
  3479. 		while (not(vehicle_exit_group_check_done(npc_group))) do 
  3480. 			thread_yield() 
  3481. 		end 
  3482. 	end 
  3483. end 
  3484.  
  3485. -- Teleport a group of NPCs directly out of a vehicle 
  3486. -- 
  3487. -- npc_group:	(table of strings) names of characters to teleport 
  3488. --  
  3489. function vehicle_exit_group_teleport(npc_group, not_enterable) 
  3490. 	if (vehicle_exit_group_do(true, false, not_enterable, npc_group)) then 
  3491. 		while (not(vehicle_exit_group_check_done(npc_group))) do 
  3492. 			thread_yield() 
  3493. 		end 
  3494. 	end 
  3495. end 
  3496.  
  3497. -- Make a vehicle pathfind through a series of navpoints. 
  3498. -- 
  3499. -- name:					(string) name of the vehicle 
  3500. -- path:					(string) name of scripted path or navpoint to pathfind through 
  3501. -- use_navmesh:		(boolean, optional) set to true if the car should pathfind using the navmesh, or false if it should pathfind using traffic splines (defaults to false) 
  3502. -- stop_at_goal:		(boolean, optional) set to true if the vehicle should stop upon reaching the final destination (defaults to true) 
  3503. -- force_path:			(boolean, optional) set to true to ignore the current position to support looping (defaults to false) 
  3504. -- suppress_errors:	(boolean, optional) set to true to suppress errors (defaults to false) 
  3505. -- 
  3506. function vehicle_pathfind_to(name, path, use_navmesh, stop_at_goal, force_path, suppress_errors) 
  3507. 	if (use_navmesh == nil) then 
  3508. 		use_navmesh = false; 
  3509. 	end 
  3510.  
  3511. 	if (stop_at_goal == nil) then 
  3512. 		stop_at_goal = true 
  3513. 	end 
  3514. 	 
  3515. 	if (force_path == nil) then 
  3516. 		force_path = false 
  3517. 	end 
  3518. 	 
  3519. 	if (suppress_errors == nil) then 
  3520. 		suppress_errors = false; 
  3521. 	end 
  3522.  
  3523. 	if (use_navmesh) then 
  3524. 		if (not vehicle_pathfind_navmesh_do(name, path, force_path, stop_at_goal, suppress_errors, 0)) then 
  3525. 			return false 
  3526. 		end 
  3527. 	else 
  3528. 		if (not vehicle_pathfind_to_do(name, path, stop_at_goal, suppress_errors)) then 
  3529. 			return false 
  3530. 		end 
  3531. 	end 
  3532.  
  3533. 	local check_done = vehicle_pathfind_check_done(name) 
  3534.  
  3535. 	while ( check_done == 0) do 
  3536. 		thread_yield() 
  3537. 		check_done = vehicle_pathfind_check_done(name) 
  3538. 	end 
  3539.  
  3540. 	return check_done == 1 
  3541. end 
  3542.  
  3543. -- Make a vehicle pathfind through a series of navpoints (using the navmesh), starting from a specific point along the path. 
  3544. -- 
  3545. -- name:					(string) name of the vehicle 
  3546. -- start_index:		(integer) index into the path to start from 
  3547. -- path:					(string) name of scripted path or navpoint to pathfind through 
  3548. -- stop_at_goal:		(boolean, optional) set to true if the vehicle should stop upon reaching the final destination (defaults to true) 
  3549. -- force_path:			(boolean, optional) set to true to ignore the current position to support looping (defaults to false) 
  3550. -- suppress_errors:	(boolean, optional) set to true to suppress errors (defaults to false) 
  3551. -- 
  3552. function vehicle_navmesh_pathfind_to_starting_from(name, start_index, path, stop_at_goal, force_path, suppress_errors) 
  3553.  
  3554. 	if (stop_at_goal == nil) then 
  3555. 		stop_at_goal = true 
  3556. 	end 
  3557.  
  3558. 	if (force_path == nil) then 
  3559. 		force_path = false 
  3560. 	end 
  3561.  
  3562. 	if (suppress_errors == nil) then 
  3563. 		suppress_errors = false 
  3564. 	end 
  3565.  
  3566. 	if (not vehicle_pathfind_navmesh_do(name, path, force_path, stop_at_goal, suppress_errors, start_index)) then 
  3567. 		return false 
  3568. 	end 
  3569.  
  3570. 	local check_done = vehicle_pathfind_check_done(name) 
  3571.  
  3572. 	while ( check_done == 0) do 
  3573. 		thread_yield() 
  3574. 		check_done = vehicle_pathfind_check_done(name) 
  3575. 	end 
  3576.  
  3577. 	return check_done == 1 
  3578. end 
  3579.  
  3580. -- Make the vehicle follow the given path 
  3581. -- 
  3582. -- vehicle:				(string) name of vehicle 
  3583. -- destination:			(string) navpoint name 
  3584. -- use_navmesh:			(boolean, optional) if true navmesh will be used for pathfinding, if false will only use traffic splines (defaults to false)  
  3585. -- mission_critical: 	(boolean, optional) if true vehicle will be teleported to destination if pathfinding fails (defaults to true) 
  3586. -- 
  3587. function vehicle_drive_path(vehicle, destination, use_navmesh, mission_critical) 
  3588. 	local success = true 
  3589. 	local stop_at_goal = false 
  3590. 	local pathfind_success = false 
  3591. 	 
  3592. 	if use_navmesh then 
  3593. 		pathfind_success = vehicle_pathfind_to(vehicle, destination, use_navmesh, stop_at_goal) 
  3594. 	else 
  3595. 		pathfind_success = vehicle_turret_base_to(vehicle, destination, stop_at_goal) 
  3596. 	end 
  3597. 	 
  3598. 	if pathfind_success == false then 
  3599. 		local number_of_failures = 1 
  3600. 		local max_number_of_failures = 3 
  3601. 		-- if the first pathfind fails lets try a few more times 
  3602. 		while number_of_failures < max_number_of_failures do 
  3603. 			if use_navmesh then 
  3604. 				pathfind_success = vehicle_pathfind_to(vehicle, destination, use_navmesh, stop_at_goal) 
  3605. 			else 
  3606. 				pathfind_success = vehicle_turret_base_to(vehicle, destination, stop_at_goal) 
  3607. 			end 
  3608. 			 
  3609. 			if pathfind_success == true then 
  3610. 				break 
  3611. 			else 
  3612. 				number_of_failures = number_of_failures + 1 
  3613. 				delay(1.0) 
  3614. 			end 
  3615. 		end 
  3616. 		if number_of_failures >= max_number_of_failures then 
  3617. 			if mission_critical == nil or mission_critical then 
  3618. 				 -- pathfind failed so just teleport to the next stop 
  3619. 				teleport_vehicle(vehicle, destination) 
  3620. 			else 
  3621. 				-- we couldn't pathfind to the destination and we didn't teleport, this isn't good 
  3622. 				success = false  
  3623. 			end 
  3624. 		end 
  3625. 	end 
  3626. 	return success 
  3627. end 
  3628.  
  3629. -- Make a vehicle come to a stop. 
  3630. -- 
  3631. -- name:			(string) name of the vehicle 
  3632. -- dont_block:	(boolean, optional) set to true if the function should not block while the vehicle is coming to a stop (defaults to false) 
  3633. -- 
  3634. function vehicle_stop( name, dont_block ) 
  3635.  
  3636. 	if( (name == nil) or (not vehicle_exists(name)) or  (vehicle_is_destroyed(name)) ) then 
  3637. 		return 
  3638. 	end 
  3639.  
  3640. 	vehicle_stop_do( name ) 
  3641. 	 
  3642. 	while( (not dont_block) and get_vehicle_speed(name) > 0 ) do 
  3643. 		thread_yield() 
  3644. 	end 
  3645. end 
  3646.  
  3647. -- Make a vehicle use turret mode to move along a path or to a navpoint. 
  3648. --  
  3649. -- name:			(string) name of the vehicle 
  3650. -- path:			(string) name of scripted_path to follow or navpoint to go to 
  3651. -- stop_at_goal:	(boolean, optional) set to true if the vehicle should stop upon reaching the final destination (defaults to true) 
  3652. -- 
  3653. -- A driver must be added to the car before calling vehicle_turret_base_to(). If the vehicle does not start on a rail, 
  3654. -- it will transition to rail and continue pathing from that position. 
  3655. -- 
  3656. -- Example: 
  3657. -- 
  3658. --		vehicle_turret_base_to("car", "heli_path 001", true) 
  3659. -- 
  3660. -- Sets "car" driving to navp1, and then on to navp2, stopping at goal. 
  3661. -- 
  3662. function vehicle_turret_base_to(name, path, stop_at_goal) 
  3663. 	 
  3664. 	-- Wait until the resource is loaded. 
  3665. 	-- character_wait_for_loaded_resource(name) 
  3666. 				 
  3667. 	if (vehicle_turret_base_to_do(name, path, stop_at_goal)) then 
  3668. 		local check_done = vehicle_pathfind_check_done(name) 
  3669. 		 
  3670. 		while ( check_done == 0) do 
  3671. 			thread_yield() 
  3672. 			check_done = vehicle_pathfind_check_done(name) 
  3673. 		end 
  3674. 		 
  3675. 		return check_done == 1 
  3676. 	else 
  3677. 		return false 
  3678. 	end 
  3679. end 
  3680.  
  3681. -- This function blocks until all player have entered the specified vehicle 
  3682. -- 
  3683. -- vehicle_name:	(string) Name of the vehicle to wait for the players to enter 
  3684. -- lock_players_in:	(boolean, optional) Set to TRUE if the players should not be allowed to exit the vehicle once both players are inside. 
  3685. -- 
  3686. -- NOTE:	If lock_players_in is set to TRUE, all players will be flagged as not able to exit vehicles when  
  3687. --			this function returns. 
  3688. --			- Make sure to re-enable vehicle exiting for players before mission exit, with set_player_can_exit_vehicles() 
  3689. --					 
  3690. function vehicle_wait_for_players_to_enter(vehicle_name, lock_players_in) 
  3691. 	while(vehicle_is_destroyed(vehicle_name) == false) do 
  3692. 		-- Check if all players are in the vehicle 
  3693. 		local all_players_in_vehicle = true 
  3694. 		if (not character_is_in_vehicle(LOCAL_PLAYER, vehicle_name)) then 
  3695. 			all_players_in_vehicle = false 
  3696. 		else 
  3697. 			if (coop_is_active() and not character_is_in_vehicle(REMOTE_PLAYER, vehicle_name)) then 
  3698. 				all_players_in_vehicle = false 
  3699. 			end 
  3700. 		end 
  3701. 		 
  3702. 		-- If all players are in the vehicle, return 
  3703. 		if (all_players_in_vehicle) then 
  3704. 			break 
  3705. 		end 
  3706. 		 
  3707. 		thread_yield() 
  3708. 	end 
  3709. 	 
  3710. 	-- Maybe lock the players into the vehicle 
  3711. 	if (lock_players_in == true) then 
  3712. 		local seat = nil 
  3713. 		local block = false 
  3714. 		local exit_current = true 
  3715. 	 
  3716. 		-- Disable vehicle exit for the players and teleport them into the vehicle to ensure they are indeed in the vehicle 
  3717. 		set_player_can_exit_vehicles(LOCAL_PLAYER, false) 
  3718. 		vehicle_enter_teleport(LOCAL_PLAYER, vehicle_name, seat, block, exit_current) 
  3719. 		if (coop_is_active()) then 
  3720. 			set_player_can_exit_vehicles(REMOTE_PLAYER, false) 
  3721. 			vehicle_enter_teleport(REMOTE_PLAYER, vehicle_name, seat, block, exit_current) 
  3722. 		end 
  3723. 	end 
  3724. end 
  3725.  
  3726. --[[ 
  3727. 	process enemy set (depricated - use kill_list) 
  3728. 	Ver. 1.1 
  3729. 			- moved setup into its own function.  This can be called independently for greater flexability. 
  3730. 			- added cleanup call.  This will cleanup callbacks and kill markers.  This can stop calls in progress. 
  3731. 	Ver. 1.00 
  3732. 	 
  3733. 	Mark all enemies with target markers. (not yet implemented) 
  3734. 	Keep a count of total enemies and enemies killed. 
  3735. 	Continue when all enemies are killed. 
  3736. 	 
  3737. 	Setup: 
  3738. 	a list of all of the enemies that need to be killed 
  3739. 		_GROUP_TABLE	= {	"Script_NPC 001", "Script_NPC 002", "Script_NPC 003", 
  3740. 													"Script_NPC 004" } 
  3741. 	 
  3742. 	After the enemies are spawned, call the function (runs until all are killed) 
  3743. 		Process_enemy_set(_GROUP_TABLE) 
  3744. 	 
  3745. 	Cleanup enemies on your own 
  3746. ]]-- 
  3747.  
  3748. -- *** Defines 
  3749. 	Process_enemy_set_cleared		= false 
  3750. 	Num_enemies_alive					= 0 
  3751. 	Num_enemies_to_kill				= 0 
  3752. 	Process_enemy_set_objective_helptext	= "" 
  3753. 	 
  3754. -- *** Functions 
  3755.  
  3756. -- Wait until a group of enemies is killed before continuing 
  3757. -- 
  3758. -- enemy_table:			(strings, or table of strings) list of enemies to kill 
  3759. -- mission_helptext:		(string, optional) mission help to display 
  3760. -- objective_helptext:	(string, optional) X/Y helptext to display 
  3761. -- 
  3762. function process_enemy_set(enemy_table, mission_helptext, objective_helptext) 
  3763. 	 
  3764. 	enemy_set_setup(enemy_table, true) 
  3765.  
  3766. 	-- Display the help text 
  3767. 	if(mission_helptext) then 
  3768. 		mission_help_table(mission_helptext) 
  3769. 	end 
  3770. 	 
  3771. 	-- Display the objective text 
  3772. 	if(objective_helptext) then 
  3773. 		Process_enemy_set_objective_helptext = objective_helptext 
  3774. 		objective_text(0, Process_enemy_set_objective_helptext, Num_enemies_to_kill - Num_enemies_alive, Num_enemies_to_kill) 
  3775. 	end 
  3776. 	 
  3777. 	while (not Process_enemy_set_cleared) do 
  3778. 		thread_yield() 
  3779. 	end 
  3780. 	 
  3781. 	-- make sure everything is cleaned up 
  3782. 	enemy_set_cleanup(enemy_table) 
  3783.  
  3784. end 
  3785.  
  3786. -- Setup all of the enemies to be killed 
  3787. -- 
  3788. -- enemy_table:				(strings, or table of strings) list of enemies to kill 
  3789. -- target_closest_player	(bool)	if true, then every enemy in the set will target the closest player 
  3790. -- 
  3791. function enemy_set_setup(enemy_table, target_closest_player) 
  3792. 	Process_enemy_set_cleared = false 
  3793.  
  3794. 	-- Assign enemy callbacks 
  3795. 	Num_enemies_alive = 0 
  3796. 	for i, enemy in pairs(enemy_table) do 
  3797. 		if(not character_is_dead(enemy)) then 
  3798. 			-- set a callback to know when the enemy is killed 
  3799. 			on_death("process_enemy_set_killed", enemy) 
  3800. 			marker_add(enemy, MINIMAP_ICON_KILL, OI_ASSET_KILL, OI_FLAGS_DEFAULT, SYNC_ALL) 
  3801. 			if (target_closest_player) then 
  3802. 				ai_add_enemy_target(enemy, CLOSEST_PLAYER, 2) 
  3803. 			end 
  3804. 			Num_enemies_alive = Num_enemies_alive + 1 
  3805. 		end 
  3806. 	end 
  3807. 	 
  3808. 	-- Check the edge condition if all the enemies are already dead 
  3809. 	if (Num_enemies_alive == 0) then 
  3810. 		Process_enemy_set_cleared = true 
  3811. 	end 
  3812.  
  3813. 	-- Setup kill tracking numbers 
  3814. 	Num_enemies_to_kill = sizeof_table(enemy_table) 
  3815. end 
  3816.  
  3817. -- Remove callbacks and markers on the enemy set 
  3818. -- 
  3819. -- enemy_table:			(strings, or table of strings) list of enemies to kill 
  3820. -- 
  3821. function enemy_set_cleanup(enemy_table) 
  3822. 	-- Clear enemy callbacks 
  3823. 	for i, enemy in pairs(enemy_table) do 
  3824. 		-- cleanup the callback 
  3825. 		on_death("", enemy) 
  3826. 		marker_remove(enemy, SYNC_ALL) 
  3827. 	end 
  3828. 	Process_enemy_set_cleared = false 
  3829. end 
  3830.  
  3831. -- *** Callbacks 
  3832. -- Enemy killed callback (counts dead enemies) 
  3833. -- 
  3834. -- enemy:	(string) name of killed NPC 
  3835. -- 
  3836. function process_enemy_set_killed(enemy) 
  3837. 	marker_remove(enemy) 
  3838. 	on_death("",enemy) 
  3839. 	Num_enemies_alive = Num_enemies_alive - 1 
  3840. 	if (Num_enemies_alive < 1) then 
  3841. 		Process_enemy_set_cleared = true 
  3842. 		if (Process_enemy_set_objective_helptext ~= "") then 
  3843. 			objective_text_clear(0) 
  3844. 		end 
  3845. 		Process_enemy_set_objective_helptext = "" 
  3846. 	else 
  3847. 		if (Process_enemy_set_objective_helptext ~= "") then 
  3848. 			objective_text(0, Process_enemy_set_objective_helptext, Num_enemies_to_kill - Num_enemies_alive, Num_enemies_to_kill) 
  3849. 		end 
  3850. 	end 
  3851. end 
  3852.  
  3853. --[[ 
  3854. 	END process enemy set 
  3855. ]]-- 
  3856.  
  3857. -------------------------------------------------------------------------------------------------- 
  3858. 								--[[**********************]]-- 
  3859. 								--[[                      ]]-- 
  3860. 								--[[  Trigger functions   ]]-- 
  3861. 								--[[                      ]]-- 
  3862. 								--[[ NOTE:                ]]-- 
  3863. 								--[[   uses convo system  ]]-- 
  3864. 								--[[**********************]]-- 
  3865. 				 
  3866. 	--[[	Trigger Data template 
  3867. 	_trigger = { 
  3868. 		-- = { 
  3869. 		--	name = "_trigger", 
  3870. 		--	hit = false, 
  3871. 		-- 	last_hit_by = nil (set to the last human to enter the trigger in the default trigger callback) 
  3872. 		--  (optional)callback = "_function_name_cb" or "" for no callback 
  3873. 		--	(optional)exit_callback = "_function_name_cb" (defaults to no callback) 
  3874. 		--	(optional)marker = TRIGGER_LOCATION or TRIGGER_USE or custom or don't include for no marker 
  3875. 		--  (optional)waypoint = true, 
  3876. 		--  (optional)teleport_to = { 
  3877. 		--						host = "host_nav", 
  3878. 		--						client = "client_nav"  
  3879. 		--					},		 
  3880. 		--	(optional)conversation = _convo.convo_name  -- play a conversation 
  3881. 		--	(optional)next_trigger = "next_trigger_name" sets up next trigger when triggered (breadcrumbs) 
  3882. 		--}, 
  3883. 	} 
  3884. 	]] 
  3885. 		 
  3886. 	TRIGGER_LOCATION = {  
  3887. 		minimap_icon_name = MINIMAP_ICON_LOCATION, 
  3888. 		ingame_effect_name = INGAME_EFFECT_LOCATION, 
  3889. 		object_indicator_id = OI_ASSET_LOCATION, 
  3890. 		object_indicator_flags = OI_FLAGS_LOCATION, 
  3891. 		sync_type = SYNC_ALL, 
  3892. 		-- (nil for default) fade_dist 
  3893. 	} 
  3894. 	TRIGGER_USE = {  
  3895. 		minimap_icon_name = MINIMAP_ICON_USE, 
  3896. 		ingame_effect_name = INGAME_EFFECT_CHECKPOINT, 
  3897. 		object_indicator_id = OI_ASSET_USE, 
  3898. 		object_indicator_flags = OI_FLAGS_FULL, 
  3899. 		sync_type = SYNC_ALL, 
  3900. 		-- (nil for default) fade_dist 
  3901. 	} 
  3902. Current_trigger_list = {} 
  3903.  
  3904. -- Setup the list of triggers 
  3905. function triggers_startup(trigger_list) 
  3906. 	Current_trigger_list = trigger_list 
  3907. end 
  3908. -- Shut down all triggers and clear the list 
  3909. function triggers_shutdown() 
  3910. 	trigger_clear_all() 
  3911. 	Current_trigger_list = {} 
  3912. end 
  3913.  
  3914. -- Enable a trigger and set any markers/waypoints needed 
  3915. -- 
  3916. -- trigger_table:		(table) information about how to setup this trigger 
  3917. --							 
  3918. function trigger_setup( trigger_table ) 
  3919.  
  3920. 	-- clear hit flag 
  3921. 	trigger_table.hit = false 
  3922. 	trigger_table.last_hit_by = nil 
  3923. 	 
  3924. 	-- set callback (explicitly setting "" will serve as no callback) 
  3925. 	if trigger_table.callback ~= nil then 
  3926. 		on_trigger(trigger_table.callback, trigger_table.name) 
  3927. 	else 
  3928. 		on_trigger("trigger_cb", trigger_table.name)	 
  3929. 	end 
  3930. 	 
  3931. 	-- set exit callback (if there is one) 
  3932. 	if trigger_table.exit_callback ~= nil and trigger_table.exit_callback ~= "" then 
  3933. 		on_trigger_exit(trigger_table.exit_callback, trigger_table.name) 
  3934. 	end 
  3935. 	 
  3936. 	-- enable the trigger 
  3937. 	trigger_enable(trigger_table.name, true) 
  3938. 	 
  3939. 	-- set marker information 
  3940. 	if trigger_table.marker ~= nil then 
  3941. 		marker_add_trigger(trigger_table.name, trigger_table.marker.minimap_icon_name, trigger_table.marker.ingame_effect_name, trigger_table.marker.object_indicator_id, trigger_table.marker.object_indicator_flags, trigger_table.marker.sync_type, trigger_table.marker.fade_dist) 
  3942. 	end 
  3943. 	 
  3944. 	-- set a waypoint 
  3945. 	if trigger_table.waypoint == true then 
  3946. 		mission_waypoint_add(trigger_table.name) 
  3947. 	end 
  3948. end 
  3949.  
  3950. -- Disable trigger and cleanup any markers on the trigger 
  3951. -- 
  3952. -- trigger:		(string) name of trigger to cleanup 
  3953. -- 
  3954. function trigger_clear(trigger) 
  3955. 	on_trigger("", trigger) 
  3956. 	on_trigger_exit("", trigger) 
  3957. 	trigger_enable(trigger, false) 
  3958. 	marker_remove_trigger(trigger, SYNC_ALL) 
  3959. end 
  3960.  
  3961. -- clear all triggers 
  3962. function trigger_clear_all() 
  3963. 	for i,trigger_table in pairs(Current_trigger_list) do 
  3964. 		trigger_clear(trigger_table.name) 
  3965. 	end 
  3966. 	mission_waypoint_remove() 
  3967. end 
  3968.  
  3969. -- get the trigger table from the trigger name 
  3970. -- 
  3971. -- trigger:		(string) trigger name 
  3972. -- 
  3973. function trigger_get_table(trigger) 
  3974. 	local trigger_table 
  3975. 	for i,trig in pairs(Current_trigger_list) do 
  3976. 		if trig.name == trigger then 
  3977. 			trigger_table = trig 
  3978. 		end 
  3979. 	end 
  3980. 	return trigger_table 
  3981. end 
  3982.  
  3983. -- basic trigger callback 
  3984. -- NOTE:  linked to conversation system 
  3985. -- 
  3986. -- human:		(string) name of human that tripped the trigger 
  3987. -- trigger:		(string) name of the trigger 
  3988. -- 
  3989. function trigger_cb(human, trigger) 
  3990. 	-- This may be called multiple times in the same frame.  Never create groups in a trigger callback.  Use show group instead. 
  3991. 	 
  3992. 	-- find this trigger 
  3993. 	local trigger_table = trigger_get_table(trigger) 
  3994. 	 
  3995. 	if trigger_table ~= nil then 
  3996. 		if trigger_table.hit == true then 
  3997. 			return 
  3998. 		end 
  3999. 		trigger_table.hit = true 
  4000. 		trigger_table.last_hit_by = human 
  4001. 		 
  4002. 		trigger_clear(trigger_table.name) 
  4003. 		 
  4004. 		if trigger_table.teleport_to ~= nil then 
  4005. 			mission_start_fade_out() 
  4006. 			teleport_coop( trigger_table.teleport_to.host, trigger_table.teleport_to.client, true )	 
  4007. 			mission_start_fade_in()			 
  4008. 		end 
  4009. 		 
  4010. 		if trigger_table.waypoint == true then 
  4011. 			mission_waypoint_remove() 
  4012. 		end 
  4013. 		 
  4014. 		-- Conversation system link 
  4015. 		if trigger_table.conversation ~= nil and trigger_table.conversation ~= "" then 
  4016. 			convo_start(trigger_table.conversation) 
  4017. 		end 
  4018. 		 
  4019. 		-- setup the next trigger (breadcrumbs) 
  4020. 		if trigger_table.next_trigger ~= nil then 
  4021. 			-- get the next trigger 
  4022. 			local next_trigger_table = trigger_get_table(trigger_table.next_trigger) 
  4023. 			 
  4024. 			if next_trigger_table ~= nil then 
  4025. 				-- setup the next trigger 
  4026. 				trigger_setup(next_trigger_table) 
  4027. 			end 
  4028. 		end 
  4029. 	end 
  4030. end 
  4031.  
  4032. -------------------------------------------------------------------------------------------------- 
  4033. 								--[[**********************]]-- 
  4034. 								--[[                      ]]-- 
  4035. 								--[[  Persona functions   ]]-- 
  4036. 								--[[                      ]]-- 
  4037. 								--[[**********************]]-- 
  4038. 	--[[	Conversation data template 
  4039. 	_persona = { 
  4040. 		 = { 
  4041. 			persona_name = "", 
  4042. 			persona_id = INVALID_PERSONA_HANDLE, 
  4043. 		}, 
  4044. 	} 
  4045. 	]]-- 
  4046. 	 
  4047. Persona_list = {} 
  4048. 								 
  4049. -- load a 2d persona 
  4050. -- 
  4051. -- persona_data:	(table) table containing persona_name and persona_id to load 
  4052. -- 
  4053. function load_persona(persona_data) 
  4054. 	persona_data.persona_id = audio_persona_load_2d(persona_data.persona_name) 
  4055. 	Persona_list[persona_data.persona_name] = persona_data 
  4056. end 
  4057.  
  4058. -- clear a specific persona 
  4059. -- 
  4060. -- persona_data:	(table) table containing persona_name and persona_id to clear 
  4061. -- 
  4062. function clear_persona(persona_data) 
  4063. 	if (persona_data.persona_id ~= INVALID_PERSONA_HANDLE) then 
  4064. 		audio_persona_remove_2d(persona_data.persona_id) 
  4065. 		persona_data.persona_id = INVALID_PERSONA_HANDLE 
  4066. 	end 
  4067. 	Persona_list[persona_data.persona_name] = nil 
  4068. end 
  4069.  
  4070. -- clear all loaded personas 
  4071. function clear_all_personas() 
  4072. 	for i, persona_data in pairs( Persona_list ) do 
  4073. 		clear_persona(persona_data) 
  4074. 	end 
  4075. end 
  4076.  
  4077. -------------------------------------------------------------------------------------------------- 
  4078. 								--[[**********************]]-- 
  4079. 								--[[                      ]]-- 
  4080. 								--[[Conversation functions]]-- 
  4081. 								--[[                      ]]-- 
  4082. 								--[[**********************]]-- 
  4083. 								 
  4084. 	--[[	Conversation data template 
  4085. 	_convo = { 
  4086. 		 = { 
  4087. 			name = "file_name without voice (_bm, _wm, _bf...", 
  4088. 			player_talks = true or false, 
  4089. 			handle = INVALID_CONVERSATION_HANDLE, 
  4090. 			convo_thread = INVALID_THREAD_HANDLE, 
  4091. 			max_wait_seconds = 60,	-- if the conversation doesn't complete before this time, kill it 
  4092. 			timer_thread = INVALID_THREAD_HANDLE, 
  4093. 			priority = CONVO_PRIORITY_HIGH or CONVO_PRIORITY_NORMAL or CONVO_PRIORITY_OPTIONAL 
  4094. 			(optional) persona_line = true,	-- this is a single line 
  4095. 			(required if persona_line) speaker_name = "name of speaker",	-- single line speaker (might be set before call to play is made?) 
  4096. 			(optional) persona_2d_line = true,	-- this is a single line played in 2d (disembodied voice)  NOTE:  Always waits for max_wait_seconds and persona must be loaded 
  4097. 			(required if persona_2d_line) speaker_persona_table = persona,	-- persona table of speaker 
  4098. 			(optional)phone_call = true,  -- this is a phone conversation (phone persona must be preloaded) 
  4099. 			(required if phone_call) receiving_call = true or false  -- auto-answer is always true in missions (until proven otherwise) 
  4100. 			 
  4101. 		}, 
  4102. 	} 
  4103. 	]] 
  4104. 	 
  4105. 	--[[	Conversation queue data template 
  4106. 		_convo_queue = { 
  4107. 		start_drive_queue = {  
  4108. 			{ delay = 2.0, convo = _convo.goto_ }, 
  4109. 			{ delay = 4.0, convo = _convo.goto_2 }, 
  4110. 			{ delay = 3.0, convo = _convo.goto_3 }, 
  4111. 			{ delay = 5.0, convo = _convo.goto_4 } 
  4112. 		}, 
  4113. 		 
  4114. 	} 
  4115. 	]] 
  4116. 								 
  4117. Current_convo_list = {} 
  4118. convo_queue_thread = INVALID_THREAD_HANDLE 
  4119. convo_phone_complete = false 
  4120. convo_playing = ""	-- name of currently playing conversation 
  4121.  
  4122. -- DEFINED VALUES 
  4123. CONVO_PRIORITY_HIGH = 1 
  4124. CONVO_PRIORITY_NORMAL = 2 
  4125. CONVO_PRIORITY_OPTIONAL = 3 
  4126.  
  4127. -- setup conversation list 
  4128. function convo_startup(convo_list) 
  4129. 	convo_queue_thread = INVALID_THREAD_HANDLE 
  4130. 	convo_phone_complete = false 
  4131. 	convo_playing = "" 
  4132. 	Current_convo_list = convo_list 
  4133. end 
  4134. -- end all conversations and clear the list 
  4135. function convo_shutdown() 
  4136. 	convo_end_all() 
  4137. 	Current_convo_list = {} 
  4138. end 
  4139.  
  4140. -- spawn the convo play thread for this conversation 
  4141. -- 
  4142. -- convo_table:		(table) conversation information 
  4143. -- 
  4144. function convo_start(convo_table) 
  4145. 	convo_table.convo_thread = thread_new("convo_play_thread", convo_table) 
  4146. end 
  4147.  
  4148. -- end the conversation and kill any threads playing the conversation 
  4149. -- 
  4150. -- convo_table:		(table) conversation information 
  4151. -- 
  4152. function convo_end(convo_table) 
  4153. 	-- kill any threads that might be running 
  4154. 	thread_kill(convo_table.convo_thread) 
  4155. 	thread_kill(convo_table.timer_thread) 
  4156. 	 
  4157. 	if convo_table.handle ~= INVALID_CONVERSATION_HANDLE and (convo_table.sync == nil or convo_table.sync == SYNC_LOCAL or convo_table.sync ==SYNC_ALL)  then 
  4158. 		audio_conversation_end(convo_table.handle,convo_table.sync) 
  4159. 		convo_table.handle = INVALID_CONVERSATION_HANDLE 
  4160. 		convo_playing = "" 
  4161. 	end 
  4162. 	if convo_table.sync ~= nil and convo_table.sync == SYNC_REMOTE and convo_table.handle_remote  ~= nil and convo_table.handle_remote ~= INVALID_CONVERSATION_HANDLE then 
  4163. 		audio_conversation_end(convo_table.handle_remote,convo_table.sync) 
  4164. 		convo_table.handle_remote = INVALID_CONVERSATION_HANDLE 
  4165. 	end 
  4166. 	 
  4167. 	if convo_table.phone_call == true then 
  4168. 		audio_remove_mission_cellphone(convo_table.name) 
  4169. 	end 
  4170. 	 
  4171. 	if convo_table.persona_2d_line == true or convo_table.persona_line == true then 
  4172. 		if (convo_table.play_id ~= nil) then 
  4173. 			audio_stop(convo_table.play_id) 
  4174. 		end 
  4175. 	end 
  4176. 	 
  4177. end 
  4178.  
  4179. -- end all of the conversations 
  4180. function convo_end_all() 
  4181. 	-- kill queue first so we don't start new conversations 
  4182. 	thread_kill(convo_queue_thread) 
  4183. 	convo_queue_thread = INVALID_THREAD_HANDLE 
  4184. 	 
  4185. 	for i,convo_table in pairs(Current_convo_list) do 
  4186. 		convo_end(convo_table) 
  4187. 	end 
  4188. 	convo_phone_complete = false 
  4189. 	 
  4190. 	convo_playing = "" 
  4191. end 
  4192.  
  4193. -- callback for when a phone call conversation is complete 
  4194. function call_ended_cb() 
  4195. 	convo_phone_complete = true 
  4196. end 
  4197.  
  4198. -- Determine if a conversation is playing 
  4199. -- 
  4200. -- returns:		true if playing or false if not 
  4201. -- 
  4202. function convo_is_playing() 
  4203. 	local playing_conversation = false 
  4204. 	if convo_playing ~= nil and convo_playing ~= "" then 
  4205. 		playing_conversation = true 
  4206. 	end 
  4207. 	return playing_conversation 
  4208. end 
  4209.  
  4210. -- Wait for conversation to complete 
  4211. -- (this may not work as desired with multiple conversations queued) 
  4212. -- 
  4213. function convo_wait_for_end() 
  4214. 	while convo_is_playing() do 
  4215. 		delay(1.0) 
  4216. 	end 
  4217. end 
  4218.  
  4219. -- Start a list of conversations 
  4220. -- 
  4221. -- queue_table:		(table) list of times and conversations to play in order 
  4222. -- 
  4223. function convo_queue_start( queue_table ) 
  4224. 	-- Multiple queues complicates things.  For now, this is not supported 
  4225. 	if convo_queue_thread ~= INVALID_THREAD_HANDLE then 
  4226. 		return 
  4227. 	end 
  4228. 	 
  4229. 	convo_queue_thread = thread_new("convo_queue_play_thread", queue_table) 
  4230. end 
  4231.  
  4232. -- stall until all conversations in the convo queue have been played 
  4233. function convo_queue_wait_for_end() 
  4234. 	while not thread_check_done(convo_queue_thread) do 
  4235. 		delay(1.0) 
  4236. 	end 
  4237. end 
  4238.  
  4239. -- Thread to play all of the items in a conversation queue 
  4240. -- 
  4241. -- queue_table:		(table) list of times and conversations to play in order 
  4242. -- 
  4243. function convo_queue_play_thread(queue_table) 
  4244. 	for i, conversation in pairs(queue_table) do 
  4245. 		delay(conversation.delay) 
  4246. 		convo_start(conversation.convo) 
  4247. 		convo_wait_for_end() 
  4248. 	end 
  4249. 	convo_queue_thread = INVALID_THREAD_HANDLE 
  4250. end 
  4251.  
  4252. -- Thread to play the conversation with emergency kill timer 
  4253. -- 
  4254. -- convo_table:		(table) conversation information 
  4255. -- 
  4256. function convo_play_thread(convo_table) 
  4257. 	-- determine priority 
  4258. 	if not(convo_table.sync == SYNC_REMOTE) then 
  4259. 		if convo_table.priority == CONVO_PRIORITY_HIGH then 
  4260. 			-- priority conversation 
  4261. 			-- kill any running conversation 
  4262. 			if convo_is_playing() then 
  4263. 				convo_end(convo_playing) 
  4264. 			end 
  4265. 		elseif convo_table.priority == CONVO_PRIORITY_NORMAL then 
  4266. 			-- normal conversation 
  4267. 			-- wait for currently playing conversation 
  4268. 			while convo_is_playing() do 
  4269. 				thread_yield() 
  4270. 			end 
  4271. 		else -- optional conversation 
  4272. 			-- if another conversation is playing, exit 
  4273. 			if convo_is_playing() then 
  4274. 				return 
  4275. 			end 
  4276. 		end 
  4277. 	 
  4278. 	 
  4279. 	-- Set conversation as playing 
  4280. 	convo_playing = convo_table 
  4281. 	end 
  4282. 	-- start the backup timer thread 
  4283. 	convo_table.timer_thread = thread_new("delay", convo_table.max_wait_seconds) 
  4284. 	 
  4285. 	if convo_table.persona_2d_line == true then 
  4286. 		-- play the line 
  4287. 		convo_table.play_id = audio_play_persona_line_2d(convo_table.speaker_persona_table.persona_id, convo_table.name) 
  4288. 		thread_yield() 
  4289. 		-- we don't have a good check for done, so just wait out the timer 
  4290. 		delay(convo_table.max_wait_seconds) 
  4291. 	elseif convo_table.persona_line == true then 
  4292. 		-- play the line 
  4293. 		convo_table.play_id = audio_play_persona_line(convo_table.speaker_name, convo_table.name) 
  4294. 		thread_yield() 
  4295. 		while audio_persona_line_playing(convo_table.speaker_name) and (not thread_check_done(convo_table.timer_thread)) do 
  4296. 			thread_yield() 
  4297. 		end 
  4298. 	elseif convo_table.phone_call == true then 
  4299. 		-- do a phone call 
  4300. 		local auto_answer = true  -- missions always auto-answer 
  4301. 		convo_phone_complete = false 
  4302. 		audio_play_for_mission_cellphone(convo_table.name, convo_table.receiving_call, auto_answer, "", "call_ended_cb") 
  4303. 		 
  4304. 		while not convo_phone_complete and (not thread_check_done(convo_table.timer_thread)) do 
  4305. 			thread_yield() 
  4306. 		end 
  4307. 		 
  4308. 		audio_remove_mission_cellphone(convo_table.name) 
  4309. 	else -- conversation 
  4310. 		if(convo_table.sync == SYNC_REMOTE) then 
  4311. 			convo_table.handle_remote = audio_conversation_load_direct(convo_table.name, convo_table.player_talks, convo_table.sync) 
  4312. 			audio_conversation_play(convo_table.handle_remote, convo_table.sync) 
  4313. 		else 
  4314. 			convo_table.handle = audio_conversation_load_direct(convo_table.name, convo_table.player_talks, convo_table.sync) 
  4315. 			audio_conversation_play(convo_table.handle, convo_table.sync) 
  4316. 		end 
  4317. 		 
  4318. 		 
  4319. 		thread_yield() 
  4320. 		 
  4321. 		-- Wait for the conversation to end 
  4322. 		while audio_conversation_playing(convo_table.handle) and (not thread_check_done(convo_table.timer_thread)) do 
  4323. 			thread_yield() 
  4324. 		end 
  4325. 		if convo_table.sync ~= nil and (convo_table.sync == SYNC_LOCAL or convo_table.sync == SYNC_ALL) then 
  4326. 			audio_conversation_end(convo_table.handle) 
  4327. 		end 
  4328. 		convo_table.handle = INVALID_CONVERSATION_HANDLE 
  4329. 	end 
  4330. 	 
  4331. 	-- clear the playing conversation 
  4332. 	convo_playing = "" 
  4333. end 
  4334.  
  4335. -- attempt to play all loaded conversations 
  4336. function convo_test_all() 
  4337. 	for i, convo in pairs(Current_convo_list) do 
  4338. 		message("PLAYING "..convo.name, 3.0, false) 
  4339. 		convo_start(convo) 
  4340. 		convo_wait_for_end() 
  4341. 	end 
  4342. end 
  4343.  
  4344. -------------------------------------------------------------------------------------------------- 
  4345. 								--[[**********************]]-- 
  4346. 								--[[                      ]]-- 
  4347. 								--[[ Kill List functions  ]]-- 
  4348. 								--[[                      ]]-- 
  4349. 								--[[**********************]]-- 
  4350.  
  4351. Current_kill_list = {} 
  4352. Current_vehicle_kill_list = {} 
  4353.  
  4354. -- setup kill list 
  4355. function kill_list_startup() 
  4356. 	Current_kill_list = {} 
  4357. 	Current_vehicle_kill_list = {} 
  4358. end 
  4359. -- shut down kill list and clear list 
  4360. function kill_list_shutdown() 
  4361. 	kill_list_clear_all() 
  4362. 	Current_kill_list = {} 
  4363. 	Current_vehicle_kill_list = {} 
  4364. end 
  4365.  
  4366.  
  4367. function kill_list_get_members() 
  4368. 	return Current_kill_list 
  4369. end 
  4370.  
  4371. -- Add a single person or a table of people to list to be killed 
  4372. -- 
  4373. -- npc_name:		(table or string) table of names or single name of character to add to the kill_list 
  4374. -- icon_type:		(string) OI_ASSET_KILL or OI_ASSET_KILL_FULL 
  4375. -- 
  4376. function kill_list_add( npc_name, icon_type ) 
  4377. 	-- Recursive call to add individual members 
  4378. 	if (type(npc_name) == "table") then 
  4379. 		for i,member in pairs(npc_name) do 
  4380. 			kill_list_add( member, icon_type ) 
  4381. 		end 
  4382. 		return 
  4383. 	end 
  4384. 	 
  4385. 	-- make sure it is still alive 
  4386. 	if character_is_dead(npc_name) then 
  4387. 		return 
  4388. 	end 
  4389. 		 
  4390. 	if icon_type == OI_ASSET_KILL then 
  4391. 		marker_add(npc_name, MINIMAP_ICON_KILL, OI_ASSET_KILL, OI_FLAGS_DEFAULT, SYNC_ALL) 
  4392. 	elseif icon_type == OI_ASSET_KILL_FULL then 
  4393. 		marker_add(npc_name, MINIMAP_ICON_KILL, OI_ASSET_KILL_FULL, OI_FLAGS_FULL, SYNC_ALL) 
  4394. 	else 
  4395. 		-- FAIL!  We won't know which guy to kill 
  4396. 		return 
  4397. 	end 
  4398. 	on_death("kill_list_member_dead_cb", npc_name) 
  4399. 	 
  4400. 	-- add the name to the kill_list 
  4401. 	Current_kill_list[ npc_name ] = npc_name 
  4402. end 
  4403.  
  4404. -- Add a single vehicle to list to be killed 
  4405. -- NOTE: Passengers should be teleported into the vehicle before calling this. 
  4406. --		Passengers will be made invulnerable and not allowed to leave.  If an NPC does manage to get out, he will forever be invulnerable. 
  4407. --		The vehicle will be set to unjackable. 
  4408. --		All passengers will be killed on destruction. Don't fill the vehicle with NPCs (too many ragdolls). 
  4409. --		Do not add the NPCs to the kill list. 
  4410. -- 
  4411. -- vehicle_name:	(string) single name of vehicle to add to the kill_list (no recursive call) 
  4412. -- icon_type:		(string) OI_ASSET_KILL or OI_ASSET_KILL_FULL 
  4413. -- 
  4414. function kill_list_vehicle_add( vehicle_name, icon_type ) 
  4415. 	 
  4416. 	-- make sure it is still alive 
  4417. 	if vehicle_is_destroyed(vehicle_name) then 
  4418. 		return 
  4419. 	end 
  4420. 	 
  4421. 	vehicle_suppress_npc_exit(vehicle_name) 
  4422. 	set_unjackable_flag(vehicle_name, true) 
  4423. 	 
  4424. 	-- loop through each of the seats and set character as invulnerable 
  4425. 	local num_seats = vehicle_get_num_seats(vehicle_name) 
  4426. 	for seat = 0, num_seats-1, 1 do 
  4427. 		local npc = get_char_in_vehicle(vehicle_name, seat) 
  4428. 		if npc ~= nil then 
  4429. 			turn_invulnerable(npc, true) 
  4430. 			set_seatbelt_flag(npc, true)	-- don't go through windshield 
  4431. 		end 
  4432. 	end 
  4433. 		 
  4434. 	if icon_type == OI_ASSET_KILL then 
  4435. 		marker_add(vehicle_name, MINIMAP_ICON_KILL, OI_ASSET_KILL, OI_FLAGS_DEFAULT, SYNC_ALL) 
  4436. 	elseif icon_type == OI_ASSET_KILL_FULL then 
  4437. 		marker_add(vehicle_name, MINIMAP_ICON_KILL, OI_ASSET_KILL_FULL, OI_FLAGS_FULL, SYNC_ALL) 
  4438. 	else 
  4439. 		-- FAIL!  We won't know which vehicle to kill 
  4440. 		return 
  4441. 	end 
  4442. 	on_vehicle_destroyed("kill_list_vehicle_dead_cb", vehicle_name) 
  4443. 	on_vehicle_enter_water("kill_list_vehicle_dead_cb", vehicle_name)  -- in water is same as dead 
  4444. 	 
  4445. 	-- add the name to the kill_list 
  4446. 	Current_vehicle_kill_list[ vehicle_name ] = vehicle_name 
  4447. end 
  4448.  
  4449. -- remove an npc from the kill list and make sure it has markers and callbacks cleaned up 
  4450. -- 
  4451. -- npc_name:		(string) name of npc to remove from the kill_list 
  4452. -- 
  4453. function kill_list_clear(npc_name) 
  4454. 	marker_remove(npc_name) 
  4455. 	on_death("", npc_name) 
  4456. 	Current_kill_list[ npc_name ] = nil 
  4457. end 
  4458.  
  4459. -- remove a vehicle from the kill list and make sure it has markers and callbacks cleaned up 
  4460. -- 
  4461. -- vehicle_name:		(string) name of vehicle to remove from the kill_list 
  4462. -- 
  4463. function kill_list_vehicle_clear(vehicle_name) 
  4464. 	marker_remove(vehicle_name) 
  4465. 	on_vehicle_destroyed("", vehicle_name) 
  4466. 	on_vehicle_enter_water("", vehicle_name) 
  4467. 	Current_vehicle_kill_list[ vehicle_name ] = nil 
  4468. 	 
  4469. 	-- turn passengers vulnerable again (may have been cleared without being destroyed) 
  4470. 	local num_seats = vehicle_get_num_seats(vehicle_name) 
  4471. 	for seat = 0, num_seats, 1 do 
  4472. 		local npc = get_char_in_vehicle(vehicle_name, seat) 
  4473. 		if npc ~= nil then 
  4474. 			turn_vulnerable(npc, true) 
  4475. 		end 
  4476. 	end 
  4477. end 
  4478.  
  4479. -- remove all entries in the kill list and make sure all markers/callbacks are cleaned up 
  4480. function kill_list_clear_all() 
  4481. 	for i, npc_name in pairs( Current_kill_list ) do 
  4482. 		kill_list_clear(npc_name) 
  4483. 	end 
  4484. 	for i, vehicle_name in pairs( Current_vehicle_kill_list ) do 
  4485. 		kill_list_vehicle_clear(vehicle_name) 
  4486. 	end 
  4487. end 
  4488.  
  4489. -- Return number of npcs in the kill list 
  4490. function kill_list_get_count() 
  4491. 	local kill_list_size = sizeof_table(Current_kill_list) 
  4492. 	local kill_list_vehicle_size = sizeof_table(Current_vehicle_kill_list) 
  4493. 	return kill_list_size + kill_list_vehicle_size 
  4494. end 
  4495.  
  4496. -- wait for everyone in the kill list to be killed (don't call this until everyone you want to include has been spawned and added) 
  4497. function kill_list_wait_for_complete() 
  4498. 	local npcs_alive = true 
  4499. 	 
  4500. 	while npcs_alive do 
  4501. 		npcs_alive = false 
  4502. 		for i, npc_name in pairs( Current_kill_list ) do 
  4503. 			if character_is_dead(npc_name) then 
  4504. 				-- remove it 
  4505. 				kill_list_clear(npc_name) 
  4506. 			else 
  4507. 				npcs_alive = true 
  4508. 				thread_yield() 
  4509. 			end 
  4510. 		end 
  4511. 		for j, vehicle_name in pairs( Current_vehicle_kill_list ) do 
  4512. 			if vehicle_is_destroyed(vehicle_name) then 
  4513. 				-- remove it 
  4514. 				kill_list_vehicle_clear(vehicle_name) 
  4515. 			else 
  4516. 				npcs_alive = true 
  4517. 				thread_yield() 
  4518. 			end 
  4519. 		end 
  4520. 		thread_yield() 
  4521. 	end 
  4522. 	 
  4523. end 
  4524.  
  4525. -- callback for kill_list member 
  4526. -- 
  4527. -- npc_killed:	(string) name of killed NPC 
  4528. -- 
  4529. function kill_list_member_dead_cb(npc_killed) 
  4530. 	kill_list_clear(npc_killed) 
  4531. end 
  4532.  
  4533. -- callback for kill_list_vehicle member 
  4534. -- 
  4535. -- vehicle_killed:	(string) name of killed vehicle 
  4536. -- 
  4537. function kill_list_vehicle_dead_cb(vehicle_killed)	 
  4538. 	kill_list_vehicle_clear(vehicle_killed) 
  4539. 	 
  4540. 	-- kill our passengers 
  4541. 	local num_seats = vehicle_get_num_seats(vehicle_killed) 
  4542. 	for seat = 0, num_seats, 1 do 
  4543. 		local npc = get_char_in_vehicle(vehicle_killed, seat) 
  4544. 		if npc ~= nil then 
  4545. 			character_kill(npc) 
  4546. 		end 
  4547. 	end 
  4548. end 
  4549.  
  4550. -------------------------------------------------------------------------------------------------- 
  4551. 								--[[**********************]]-- 
  4552. 								--[[                      ]]-- 
  4553. 								--[[  Interrogate Target  ]]-- 
  4554. 								--[[      functions       ]]-- 
  4555. 								--[[                      ]]--								 
  4556. 								--[[**********************]]-- 
  4557. 								 
  4558. 	--[[	Interrogate Target data template 
  4559. 	_interrogate = { 
  4560. 		leader = { 
  4561. 			target = _group.friendly_fire.owner, 
  4562. 			persona = "Interrogation", 
  4563. 			objective = "_INTERROGATE_OWNER", 
  4564. 		--	(optional)conversation = _convo.convo_name  -- play a conversation while interrogating 
  4565. 		}, 
  4566. 	} 
  4567. 	]] 
  4568. 							 
  4569. Current_interrogate_list = {} 
  4570. -- Startup interrogation system (not automatic) 
  4571. function interrogate_startup(interrogate_list) 
  4572. 	Current_interrogate_list = interrogate_list 
  4573. end 
  4574. -- Shutdown interrogation 
  4575. function interrogate_shutdown() 
  4576. 	interrogate_cleanup() 
  4577. end 
  4578. 							 
  4579. -- Set all necessary flags and mark target for interrogation 
  4580. -- Returns when interrogation is complete 
  4581. -- 
  4582. -- interrogate_data:	(table) information about person to interrogate 
  4583. -- 
  4584. function interrogate_target(interrogate_data) 
  4585. 	-- set persona (defaults to interrogate) 
  4586. 	if interrogate_data.persona ~= nil then 
  4587. 		persona_override_persona_start(interrogate_data.target, interrogate_data.persona) 
  4588. 	end 
  4589. 	-- set flags on the target 
  4590. 	character_set_counter_on_grabbed_by_player(interrogate_data.target, false) 
  4591. 	-- set icon 
  4592. 	objective_text_clear(0) 
  4593. 	marker_remove(interrogate_data.target, SYNC_ALL) 
  4594. 	marker_add(interrogate_data.target, MINIMAP_ICON_USE, OI_ASSET_USE, OI_FLAG_STICKY + OI_FLAG_DISPLAY_DISTANCE, SYNC_ALL) 
  4595.  
  4596. 	-- set objective 
  4597. 	objective_text(0, interrogate_data.objective, "", "", SYNC_ALL, OI_ASSET_USE) 
  4598. 	 
  4599. 	-- wait for grab 
  4600. 	local hostage_taken = false 
  4601. 	local attacker = LOCAL_PLAYER 
  4602. 	while not hostage_taken do 
  4603. 		if character_has_specific_human_shield(LOCAL_PLAYER, interrogate_data.target) then 
  4604. 			hostage_taken = true 
  4605. 		elseif (coop_is_active() and character_has_specific_human_shield(REMOTE_PLAYER, interrogate_data.target)) then 
  4606. 			hostage_taken = true 
  4607. 			attacker = REMOTE_PLAYER 
  4608. 		end 
  4609. 		thread_yield() 
  4610. 	end 
  4611. 	 
  4612. 	-- make player and target invulnerable 
  4613. 	turn_invulnerable(interrogate_data.target) 
  4614. 	turn_invulnerable(attacker) 
  4615. 	 
  4616. 	-- no ragdolling 
  4617. 	character_allow_ragdoll(attacker, false) 
  4618. 	character_allow_ragdoll(interrogate_data.target, false) 
  4619. 	character_prevent_flinching(attacker, true) 
  4620. 	character_prevent_flinching(interrogate_data.target, true) 
  4621.  
  4622. 	-- Block controls until the interrogation is complete 
  4623. 	player_human_shield_lock(attacker, true) 
  4624. 	delay(1) 
  4625. 	-- play a synced interrogate animation 
  4626. 	action_play_synced_state(attacker, interrogate_data.target, "Gat Interrogation State") 
  4627. 	action_play_synced(attacker, interrogate_data.target, "Gat Interrogation Entry") 
  4628. 	 
  4629. 	-- Play the interrogation conversation 
  4630. 	if interrogate_data.conversation ~= nil then 
  4631. 		convo_start(interrogate_data.conversation) 
  4632. 		convo_wait_for_end() 
  4633. 	else 
  4634. 		-- eh...just wait a few seconds 
  4635. 		delay(3.0) 
  4636. 	end 
  4637. 	 
  4638. 	-- end interrogate animation 
  4639. 	action_play_synced_state(attacker, interrogate_data.target, "HS_Stand") 
  4640. 	action_play_synced(attacker, interrogate_data.target, "Gat Interrogation Return") 
  4641. 		 
  4642. 	-- Restore control 
  4643. 	player_human_shield_lock(attacker, false) 
  4644. 	action_stop_synced_state(attacker, true) 
  4645. 	 
  4646. 	if interrogate_data.persona ~= nil then 
  4647. 		persona_override_persona_stop(interrogate_data.target) 
  4648. 	end 
  4649.  
  4650. 	-- Clear invulnerability 
  4651. 	turn_vulnerable(interrogate_data.target) 
  4652. 	turn_vulnerable(attacker) 
  4653. 	character_prevent_flinching(attacker, false) 
  4654. 	character_prevent_flinching(interrogate_data.target, false) 
  4655. 	character_allow_ragdoll(attacker, true) 
  4656. 	character_allow_ragdoll(interrogate_data.target, true) 
  4657. 	character_prevent_explosion_fling(interrogate_data.target, false) 
  4658.  
  4659. 	-- Clear objective 
  4660. 	marker_remove(interrogate_data.target, SYNC_ALL) 
  4661. 	objective_text_clear(0) 
  4662. 	 
  4663. end 
  4664.  
  4665. -- clear any icons and make sure player states are restored 
  4666. function interrogate_cleanup() 
  4667. 	for i,data in pairs(Current_interrogate_list) do 
  4668. 		-- remove any icons 
  4669. 		marker_remove(data.target, SYNC_ALL) 
  4670. 	end 
  4671. 	 
  4672. 	-- clear possible player states 
  4673. 	turn_vulnerable(LOCAL_PLAYER) 
  4674. 	character_prevent_flinching(LOCAL_PLAYER, false) 
  4675. 	character_allow_ragdoll(LOCAL_PLAYER, true) 
  4676. 	 
  4677. 	if coop_is_active() then 
  4678. 		turn_vulnerable(REMOTE_PLAYER) 
  4679. 		character_prevent_flinching(REMOTE_PLAYER, false) 
  4680. 		character_allow_ragdoll(REMOTE_PLAYER, true) 
  4681. 	end 
  4682. end 
  4683.  
  4684. -------------------------------------------------------------------------------------------------- 
  4685. 								--[[**********************]]-- 
  4686. 								--[[                      ]]-- 
  4687. 								--[[    Common Mission    ]]-- 
  4688. 								--[[      Functions       ]]-- 
  4689. 								--[[                      ]]--								 
  4690. 								--[[**********************]]-- 
  4691.  
  4692. -- Prep global systems for mission use 
  4693. -- 
  4694. -- trigger_list:		(table) List of table data 
  4695. -- convo_list:			(table) List of conversation data 
  4696. -- 
  4697. function mission_startup(trigger_list, convo_list) 
  4698. 	triggers_startup(trigger_list) 
  4699. 	convo_startup(convo_list) 
  4700. 	kill_list_startup() 
  4701. 	-- not common - requires manual setup in script interrogate_startup(interrogate_list) 
  4702. end 
  4703.  
  4704. -- Critical shutdown of common systems. This should always be called on cleanup. 
  4705. -- 
  4706. function mission_shutdown() 
  4707. 	triggers_shutdown() 
  4708. 	convo_shutdown() 
  4709. 	kill_list_shutdown() 
  4710. 	 
  4711. 	-- even though we don't auto-setup, we can auto-shutdown 
  4712. 	interrogate_shutdown() 
  4713. 	rail_shutdown() 
  4714. end 
  4715.  
  4716. -- Initializes a specific checkpoint during mission start. 
  4717. -- 
  4718. -- mission_checkpoints: (table) The table containing the mission's checkpoints. 
  4719. -- checkpoint_name:     (string) The name of the checkpoint to initialize. 
  4720. -- 
  4721. function checkpoint_init(mission_checkpoints, checkpoint_name) 
  4722. 	local checkpoint_table = get_table_by_name(mission_checkpoints, checkpoint_name) 
  4723. 	if checkpoint_table ~= nil then	 
  4724. 		-- move the player's vehicles if needed 
  4725. 		if checkpoint_table.p1_car_nav ~= nil and checkpoint_table.p1_car_nav ~= "" then 
  4726. 			teleport_player_vehicles(checkpoint_table.p1_car_nav, checkpoint_table.p2_car_nav) 
  4727. 		end 
  4728.  
  4729. 		-- spawn any starting groups 
  4730. 		group_create_list(checkpoint_table.start_groups) 
  4731. 		group_create_list(checkpoint_table.cp_only_groups) 
  4732.  
  4733. 		-- teleport players if not at starting checkpoint 
  4734. 		if checkpoint_table.name ~= MISSION_START_CHECKPOINT and checkpoint_table.no_cp_teleport ~= true then 
  4735. 			local exit_vehicles = true 
  4736. 			local check_for_obstacles = true 
  4737. 			teleport_coop(checkpoint_table.host_start, checkpoint_table.client_start, exit_vehicles, check_for_obstacles, checkpoint_table.check_up) 
  4738. 		end 
  4739.  
  4740. 		-- Execute the checkpoint's init function. 
  4741. 		local mission_start = true 
  4742. 		if checkpoint_table.init ~= nil then 
  4743. 			_G[checkpoint_table.init](mission_start) 
  4744. 		end 
  4745. 	end 
  4746. end 
  4747.  
  4748. -- Processes a mission's checkpoints in the order defined in the checkpoint table  
  4749. -- until the mission ends. 
  4750. -- 
  4751. -- mission_checkpoints:   (table) The table containing the mission's checkpoints. 
  4752. -- first_checkpoint_name: (string) The name of the checkpoint to start the mission at. 
  4753. -- 
  4754. function checkpoint_run_mission(mission_checkpoints, first_checkpoint_name) 
  4755. 	local cur_checkpoint = get_table_by_name(mission_checkpoints, first_checkpoint_name) 
  4756. 	local prev_checkpoint = nil 
  4757. 	 
  4758. 	while cur_checkpoint ~= nil do 
  4759. 		-- Initialize the checkpoint, but only if it's not our first checkpoint, that's 
  4760. 		-- initialized by the mission start. 
  4761. 		if cur_checkpoint.name ~= first_checkpoint_name then 
  4762. 			if cur_checkpoint.init ~= nil then 
  4763. 				_G[cur_checkpoint.init](false) 
  4764. 			end 
  4765. 		end 
  4766. 	 
  4767. 		-- Execute the checkpoint's run function. 
  4768. 		_G[cur_checkpoint.run]() 
  4769. 		 
  4770. 		-- Move to the next checkpoint or exit the mission. 
  4771. 		prev_checkpoint = cur_checkpoint 
  4772. 		cur_checkpoint = get_table_by_name(mission_checkpoints, cur_checkpoint.next_checkpoint) 
  4773. 		if cur_checkpoint == nil then 
  4774. 			break 
  4775. 		end 
  4776. 		 
  4777. 		-- Set the mission checkpoint, if this isn't a script debug checkpoint 
  4778. 		if (cur_checkpoint.debug_checkpoint ~= true) then 
  4779. 			mission_set_checkpoint(cur_checkpoint.name, cur_checkpoint.ignore_vehicles, cur_checkpoint.ignore_notoriety) 
  4780. 		end 
  4781.  
  4782. 		-- Create any groups for the next checkpoint 
  4783. 		group_create_list(cur_checkpoint.start_groups) 
  4784. 		 
  4785. 		-- Clean up the previous checkpoint. 
  4786. 		if prev_checkpoint.cleanup ~= nil then 
  4787. 			_G[prev_checkpoint.cleanup](false) 
  4788. 		end 
  4789. 	end 
  4790. end				 
  4791. 								 
  4792. 								 
  4793. -- Run the cleanup function for each checkpoint listed starting with the MISSION_START_CHECKPOINT 
  4794. -- NOTE: Out of order checkpoints/branching checkpoints need to call their own cleanups 
  4795. -- 
  4796. -- checkpoints:		(table) table of checkpoint information 
  4797. -- 
  4798. function checkpoint_cleanup_mission(checkpoints)	 
  4799. 	local mission_exit = true 
  4800. 	 
  4801. 	for i, checkpoint in pairs(checkpoints) do 
  4802. 		if checkpoint.cleanup ~= nil then 
  4803. 			_G[checkpoint.cleanup](mission_exit) 
  4804. 		end 
  4805. 	end 
  4806. end 
  4807.  
  4808.  
  4809. -------------------------------------------------------------------------------------------------- 
  4810.  
  4811. --[[ 
  4812. 	temp weapon loadout 
  4813. 	Ver. 1.00 
  4814. 	 
  4815. 	Equip all players with temporary loadout 
  4816. 	Equip the last weapon provided 
  4817. 	 
  4818. 	Setup: 
  4819. 	a list of the weapons to equip the player with 
  4820. 		_PLAYER_LOADOUT	= {	"Gal43", "m16" } 
  4821. 	 
  4822. 	Equipment goes to the player and coop player 
  4823. 		inv_add_temp_loadout( _PLAYER_LOADOUT ) 
  4824. 		 
  4825. 	Make sure you cleanup (will only run if add was called) 
  4826. 		inv_remove_temp_loadout( _PLAYER_LOADOUT ) 
  4827. ]]-- 
  4828.  
  4829. -- *** Defines 
  4830. 	Players_have_temp_loadout		= false 
  4831. 	 
  4832. -- *** Functions 
  4833. -- Add temp weapons with unlimited ammo 
  4834. -- 
  4835. -- weapon_table:	(strings, or table of strings) list of weapons to equip 
  4836. -- restrict_to:	(string, optional) player to restrict loadout to (defaults to both players (if available)) 
  4837. -- 
  4838. function inv_add_temp_loadout(weapon_table, restrict_to) 
  4839. 	local equip_local = true 
  4840. 	local equip_remote = true 
  4841. 	if (restrict_to == LOCAL_PLAYER) then 
  4842. 		equip_remote = false 
  4843. 	end 
  4844. 	if (restrict_to == REMOTE_PLAYER) then 
  4845. 		equip_local = false 
  4846. 	end 
  4847. 		 
  4848. 	local last_weapon = "" 
  4849. 	local in_coop = equip_remote and coop_is_active() 
  4850. 	-- Assign weapons 
  4851. 	for i, weapon in pairs(weapon_table) do 
  4852. 		if (equip_local) then 
  4853. 			inv_weapon_add_temporary(LOCAL_PLAYER, weapon, 1, true) 
  4854. 		end 
  4855. 		if (in_coop) then 
  4856. 			inv_weapon_add_temporary(REMOTE_PLAYER, weapon, 1, true) 
  4857. 		end 
  4858. 		last_weapon = weapon 
  4859. 	end 
  4860. 	 
  4861. 	if (last_weapon ~= "") then 
  4862. 		if (equip_local) then 
  4863. 			inv_item_equip( last_weapon, LOCAL_PLAYER ) 
  4864. 		end 
  4865. 		if (in_coop) then 
  4866. 			inv_item_equip( last_weapon, REMOTE_PLAYER ) 
  4867. 		end 
  4868. 	end 
  4869. 	 
  4870. 	Players_have_temp_loadout = true 
  4871.  
  4872. end 
  4873.  
  4874.  
  4875. -- remove temp weapons 
  4876. -- 
  4877. -- weapon_table:		(strings, or table of strings) list of weapons to remove 
  4878. -- restrict_to:		(string, optional) player to restrict loadout to (defaults to both players (if available)) 
  4879. -- 
  4880. function inv_remove_temp_loadout(weapon_table, restrict_to) 
  4881. 	local equip_local = true 
  4882. 	local equip_remote = true 
  4883. 	if (restrict_to == LOCAL_PLAYER) then 
  4884. 		equip_remote = false 
  4885. 	end 
  4886. 	if (restrict_to == REMOTE_PLAYER) then 
  4887. 		equip_local = false 
  4888. 	end 
  4889. 	 
  4890. 	local in_coop = equip_remote and coop_is_active() 
  4891. 	if (Players_have_temp_loadout) then 
  4892. 		-- remove weapons 
  4893. 		for i, weapon in pairs(weapon_table) do 
  4894. 			if (equip_local) then 
  4895. 				inv_weapon_remove_temporary(LOCAL_PLAYER, weapon) 
  4896. 			end 
  4897. 			if (in_coop) then 
  4898. 				inv_weapon_remove_temporary(REMOTE_PLAYER, weapon) 
  4899. 			end 
  4900. 		end 
  4901. 	end 
  4902. 	 
  4903. 	Players_have_temp_loadout = false 
  4904. end 
  4905.  
  4906. --[[ 
  4907. 	END temp weapon loadout 
  4908. ]]-- 
  4909.  
  4910. -------------------------------------------------------------------------------------------------- 
  4911. 								--[[**********************]]-- 
  4912. 								--[[                      ]]-- 
  4913. 								--[[   Rail functions     ]]-- 
  4914. 								--[[                      ]]-- 
  4915. 								--[[**********************]]-- 
  4916. 	--[[	Rail data template 
  4917. 		_rail = { 
  4918. 			_rail = { 
  4919. 				vehicle = "", 
  4920. 			 
  4921. 				(optional)mission_critical = true defaults to true 
  4922. 				 
  4923. 				(optional)npcs_enter_vehicle_timeout = 10.0, this timeout is how long we will wait for npcs to get into the vehicle after the players before teleporting them 
  4924. 				seats = { 
  4925. 					{ character = "", seat_idx = 0 }, 
  4926. 				}, 
  4927. 				coop_seats = { 
  4928. 					{ character = "", seat_idx = 0 }, 
  4929. 				}, 
  4930. 			}, 
  4931. 		} 
  4932. 	--]] 
  4933. 	--[[	Path data template 
  4934. 		_path = { 
  4935. 			 = { 
  4936. 				data = {"", ""} This can be Navpoints 
  4937. 				use_navmesh = false, 
  4938. 				callback = "", function to call when this segment is completed 
  4939. 				}, 
  4940. 			}, 
  4941. 		} 
  4942. 	--]] 
  4943. 								 
  4944. -- Setup the vehicle, npcs, and players to start a rail sequence. This includes setting all of the neccassary vehicle 
  4945. -- flags, npcs flags, player flags, and telling the player and npcs to get in the vehicle or teleport them in if teleport is true. 
  4946. -- 
  4947. -- rail_table:		(table) rail information 
  4948. -- teleport:		(boolean) if true teleports the player and npcs into the vehicle  
  4949. -- 
  4950. -- NOTE:		Call rail_vehicle_setup or your own vehicle setup function before calling this function.  
  4951. --				-If the rail vehicle is vulnerable set the on_destroyed callback before calling this function as  
  4952. --				the vehicle could be destroyed during this function. 
  4953. --				- Any speed overrides will be cleared during this function so set those after this returns.  
  4954. --				this was done to prevent vehicles from driving off. 
  4955. -- 
  4956. function rail_setup(rail_table, teleport) 
  4957. 	if not teleport then 
  4958. 		marker_add(rail_table.vehicle, MINIMAP_ICON_LOCATION, OI_ASSET_LOCATION) 
  4959. 	end 
  4960. 	 
  4961. 	vehicle_speed_cancel(rail_table.vehicle) 
  4962. 	 
  4963. 	local seats = nil 
  4964. 	if coop_is_active() then 
  4965. 		seats = rail_table.coop_seats 
  4966. 	else 
  4967. 		seats = rail_table.seats 
  4968. 	end 
  4969. 	 
  4970. 	local npcs = { } 
  4971. 	local npc_count = 0 
  4972. 	 
  4973. 	for index, seat in pairs(seats) do 
  4974. 		if seat.character == LOCAL_PLAYER or seat.character == REMOTE_PLAYER then -- setup player 
  4975. 			player_force_vehicle_seat(seat.character, seat.seat_idx, rail_table.vehicle) 
  4976. 		else -- setup npc 
  4977. 			local npc_is_independent = true 
  4978. 			follower_make_independent(seat.character, npc_is_independent) 
  4979. 			local npc_stay_in_car = true 
  4980. 			follower_remain_in_car(seat.character, npc_stay_in_car) 
  4981. 			set_seatbelt_flag(seat.character) 
  4982. 			if not teleport then 
  4983. 				local block = false 
  4984. 				vehicle_enter(seat.character, rail_table.vehicle, seat.seat_idx, block) 
  4985. 			end 
  4986. 			-- set ignore ai while we wait for the player to get in, otherwise the npc could take off 
  4987. 			set_ignore_ai_flag(seat.character, true) 
  4988. 			npc_count = npc_count + 1 
  4989. 			npcs[npc_count] = seat.character 
  4990. 		end 
  4991. 		if teleport then 
  4992. 			local block = false 
  4993. 			local exit_current = true 
  4994. 			vehicle_enter_teleport(seat.character, rail_table.vehicle, seat.seat_idx, block, exit_current) 
  4995. 		end 
  4996. 	end 
  4997. 	 
  4998. 	local lock_players_in = true 
  4999. 	vehicle_wait_for_players_to_enter(rail_table.vehicle, lock_players_in) 
  5000. 	 
  5001. 	if npc_count > 0 then 
  5002. 		-- turn ai back on 
  5003. 		for index = 1, npc_count, 1 do 
  5004. 			set_ignore_ai_flag(npcs[index], false) 
  5005. 		end 
  5006. 	end 
  5007. 	 
  5008. 	--Make sure every npc is in the car if they are not in after max_wait_time teleport them 
  5009. 	--Players are already in the car and locked in by this point 
  5010. 	local ready = false 
  5011. 	local elapsed_time = 0.0 
  5012. 	local max_wait_time = 10.0 
  5013. 	if rail_table.npcs_enter_vehicle_timeout ~= nil and rail_table.npcs_enter_vehicle_timeout > 0 then 
  5014. 		max_wait_time = rail_table.npcs_enter_vehicle_timeout 
  5015. 	end	 
  5016. 	while(ready == false) do 
  5017. 		ready = true 
  5018. 		-- Check if any characters are not in the vehicle 
  5019. 		for index, seat in pairs(seats) do 
  5020. 			if (character_is_in_vehicle(seat.character, rail_table.vehicle) == false) then 
  5021. 				if elapsed_time >= max_wait_time then 
  5022. 					local block = true 
  5023. 					local exit_current = true 
  5024. 					vehicle_enter_teleport(seat.character, rail_table.vehicle, seat.seat_idx, block, exit_current) 
  5025. 				else 
  5026. 					ready = false 
  5027. 					break 
  5028. 				end 
  5029. 			end 
  5030. 		end 
  5031. 		thread_yield() 
  5032. 		elapsed_time = elapsed_time + get_frame_time() 
  5033. 	end 
  5034. 	 
  5035. 	--Make the npcs invincible since they are in the car 
  5036. 	for index, seat in pairs(seats) do 
  5037. 		if seat.character ~= LOCAL_PLAYER and seat.character ~= REMOTE_PLAYER then 
  5038. 			turn_invulnerable(seat.character) 
  5039. 		end 
  5040. 	end 
  5041. 	 
  5042. 	set_unjackable_flag(rail_table.vehicle, true) 
  5043. 	 
  5044. 	marker_remove(rail_table.vehicle) 
  5045. end 
  5046.  
  5047. -- Start the rail segment 
  5048. -- 
  5049. -- rail_table:		(table) rail information 
  5050. -- car_path:		(table) holds list of navs to pathfind to, if navmesh should be used, and a callback for when pathfinding is complete 
  5051. -- 
  5052. function rail_play(rail_table, car_path) 
  5053. 	if Rail_data[rail_table.vehicle] ~= nil then 
  5054. 		rail_segment_cleanup(rail_table) 
  5055. 	end 
  5056. 	 
  5057. 	Rail_data[rail_table.vehicle] = {} 
  5058. 	Rail_data[rail_table.vehicle].index = 1 
  5059. 	Rail_data[rail_table.vehicle].path = car_path 
  5060. 	Rail_data[rail_table.vehicle].rail = rail_table 
  5061. 	Rail_data[rail_table.vehicle].paused = false 
  5062. 	Rail_data[rail_table.vehicle].path_thread = thread_new("rail_drive_thread", rail_table, Rail_data[rail_table.vehicle].path) 
  5063. 	Rail_data[rail_table.vehicle].callback_thread = INVALID_THREAD_HANDLE 
  5064. end 
  5065.  
  5066. -- Pause the rail segment 
  5067. -- 
  5068. -- rail_table:		(table) rail information 
  5069. -- 
  5070. function rail_pause(rail_table) 
  5071. 	if Rail_data[rail_table.vehicle] ~= nil and Rail_data[rail_table.vehicle].path_thread ~= INVALID_THREAD_HANDLE then 
  5072. 		thread_kill(Rail_data[rail_table.vehicle].path_thread) 
  5073. 		Rail_data[rail_table.vehicle].path_thread = INVALID_THREAD_HANDLE 
  5074. 		local dont_block = true 
  5075. 		vehicle_stop(rail_table.vehicle, dont_block) 
  5076. 		Rail_data[rail_table.vehicle].paused = true 
  5077. 	end 
  5078. end 
  5079.  
  5080. -- Resume the rail segment 
  5081. -- 
  5082. -- rail_table:		(table) rail information 
  5083. -- 
  5084. function rail_resume(rail_table) 
  5085. 	if Rail_data[rail_table.vehicle] ~= nil and Rail_data[rail_table.vehicle].paused == true then 
  5086. 		Rail_data[rail_table.vehicle].paused = false 
  5087. 		Rail_data[rail_table.vehicle].path_thread = thread_new("rail_drive_thread", rail_table, Rail_data[rail_table.vehicle].path) 
  5088. 	end 
  5089. end 
  5090.  
  5091. -- Cleanup any global data used by a rail segment 
  5092. -- 
  5093. -- rail_table:		(table) rail information 
  5094. -- 
  5095. function rail_segment_cleanup(rail_table) 
  5096. 	if Rail_data[rail_table.vehicle] ~= nil then 
  5097. 		thread_kill(Rail_data[rail_table.vehicle].path_thread) 
  5098. 		thread_kill(Rail_data[rail_table.vehicle].callback_thread) 
  5099. 		Rail_data[rail_table.vehicle] = nil 
  5100. 	end 
  5101. end 
  5102.  
  5103. -- Cleanup the entire rail including segments and undo any player changes 
  5104. -- 
  5105. -- rail_table:		(table) rail information 
  5106. -- 
  5107. function rail_cleanup(rail_table) 
  5108. 	rail_segment_cleanup(rail_table) 
  5109. 	marker_remove(rail_table.vehicle) 
  5110. 	 
  5111. 	local seats = nil 
  5112. 	if coop_is_active() then 
  5113. 		seats = rail_table.coop_seats 
  5114. 	else 
  5115. 		seats = rail_table.seats 
  5116. 	end 
  5117. 	 
  5118. 	for index, seat in pairs(seats) do 
  5119. 		if seat.character == LOCAL_PLAYER or seat.character == REMOTE_PLAYER then 
  5120. 			player_force_vehicle_seat(seat.character, -1) 
  5121. 			set_player_can_exit_vehicles(seat.character, true) 
  5122. 		else 
  5123. 			local npc_is_independent = false 
  5124. 			follower_make_independent(seat.character, npc_is_independent) 
  5125. 			turn_vulnerable(seat.character) 
  5126. 			local npc_stay_in_car = false 
  5127. 			follower_remain_in_car(seat.character, npc_stay_in_car) 
  5128. 			local uses_seatbelt = false 
  5129. 			set_seatbelt_flag(seat.character, uses_seatbelt) 
  5130. 		end 
  5131. 	end 
  5132. end 
  5133.  
  5134. -- Cleanup any data that is still left the global Rail_data table 
  5135. -- 
  5136. function rail_shutdown() 
  5137. 	for index, rail_info in pairs(Rail_data) do 
  5138. 		rail_cleanup(rail_info.rail) 
  5139. 	end 
  5140. end 
  5141.  
  5142. -- Setup the rail vehicle, this is the defualt function if one is not given in rail_table 
  5143. -- 
  5144. -- vehicle:		(string) name of vehicle 
  5145. -- 
  5146. function rail_vehicle_setup(vehicle) 
  5147. 	vehicle_disable_chase(vehicle, true) 
  5148. 	vehicle_disable_flee(vehicle, true) 
  5149. 	vehicle_ignore_repulsors(vehicle, true) 
  5150. 	-- Don't make tanks have infinite mass, it upsets the Havok programmers. 
  5151. 	if not vehicle_is_tank(vehicle) then 
  5152. 		vehicle_infinite_mass(vehicle, true) 
  5153. 	end 
  5154. 	vehicle_prevent_explosion_fling(vehicle, true) 
  5155. 	vehicle_prevent_transition_to_ambient(vehicle, true) 
  5156. 	vehicle_set_allow_ram_ped(vehicle, true) 
  5157. 	vehicle_set_ignore_rail_obstacles(vehicle, true) 
  5158. 	vehicle_set_obey_traffic_lights(vehicle, false) 
  5159. 	vehicle_set_use_short_cuts(vehicle, true) 
  5160. 	vehicle_set_invulnerable(vehicle) 
  5161. 	vehicle_suppress_flipping(vehicle, true) 
  5162. 	vehicle_set_invulnerable_to_telekinesis(vehicle, true)	 
  5163. end 
  5164.  
  5165. -- Make the vehicle follow all of the rail's paths 
  5166. -- 
  5167. -- rail_table:		(table) rail information 
  5168. -- path:			(table) holds list of navs to pathfind to, if navmesh should be used, and a callback for when pathfinding is complete 
  5169. -- 
  5170. function rail_drive_thread(rail_table, path) 
  5171. 	local success = true 
  5172. 	while path.data[Rail_data[rail_table.vehicle].index] ~= nil do 
  5173. 		success = vehicle_drive_path(rail_table.vehicle, path.data[Rail_data[rail_table.vehicle].index], path.use_navmesh, rail_table.mission_critical) 
  5174. 		if not success then 
  5175. 			break 
  5176. 		end 
  5177. 		Rail_data[rail_table.vehicle].index = Rail_data[rail_table.vehicle].index + 1 
  5178. 	end 
  5179. 	Rail_data[rail_table.vehicle].callback_thread = thread_new(path.callback, success) 
  5180. end 
  5181.  
  5182. -------------------------------------------End of Rail functions------------------------------------------------------- 
  5183.  
  5184. -------------------------------------------------------------------------------------------------- 
  5185. 								--[[**************************************]]-- 
  5186. 								--[[                     				                            ]]-- 
  5187. 								--[[   Disable Generator functions         ]]-- 
  5188. 								--[[                                                               ]]-- 
  5189. 								--[[**************************************]]-- 
  5190. --[[ Disable Generator data template 
  5191. 	_generators = { 
  5192. 		{ 
  5193. 			trigger = trigger_table, table for the trigger that should be used to disable a generator(warning  callback set in this  table will be overwritten) 
  5194. 			time_to_disable = 4, time in seconds it should take for generator to be disabled 
  5195. 			objective = "", objective message that should be displayed next to progress bar 
  5196. 			disabled = false, wether or not this generator has been disabled 
  5197. 			(optional)anim_nav = "", navpoint that  anim should be orientied to 
  5198. 		}, 
  5199. 	} 
  5200.  
  5201. ]]--								 
  5202. -- Handles setting up triggers for disabling generators 
  5203. -- 
  5204. -- generators:	(table) table of generators that should be setup 
  5205. -- objective:	(string, optional) objective msg that should be used when not disabling generators(defualts to "" which means no objective will show when not disabling generators) 
  5206. -- 
  5207. function disable_generators_run(generators, objective) 
  5208. 	Generator_data = generators 
  5209. 	Generator_objective = objective 
  5210. 	 
  5211. 	for i, generator in pairs(Generator_data) do 
  5212. 		-- Add some data to generator table 
  5213. 		generator.progress = 0 
  5214. 		generator.player = nil 
  5215. 		generator.monitor_thread = INVALID_THREAD_HANDLE 
  5216. 		 
  5217. 		-- override trigger callback  
  5218. 		generator.trigger.callback = "disable_generators_cb" 
  5219. 		 
  5220. 		--setup trigger 
  5221. 		trigger_setup(generator.trigger) 
  5222. 		-- HVS_EC  Changed trigger rate to 100 ms to better handle low-framerate issues. 
  5223. 		-- HVS_EC  (The ideal fix would be to make everything run off the real-time clock...) 
  5224. 		trigger_set_delay_between_activations(generator.trigger.name, 100) 
  5225. 		trigger_set_hold_to_repeat(generator.trigger.name) 
  5226. 	end 
  5227. 	 
  5228. 	hud_gsi_supress_popout(true) 
  5229. 	if Generator_objective ~= nil and Generator_objective ~= "" then 
  5230. 		objective_text(0, Generator_objective, nil, nil, SYNC_ALL, OI_ASSET_USE) 
  5231. 	end 
  5232. end 
  5233.  
  5234. -- Cleanup any triggers and threads being used  for diabling generators 
  5235. -- 
  5236. function disable_generators_cleanup() 
  5237. 	 
  5238. 	hud_gsi_supress_popout(false) 
  5239. 	 
  5240. 	-- no table has been set so just return 
  5241. 	if sizeof_table(Generator_data) == 0 then 
  5242. 		return 
  5243. 	end 
  5244. 	 
  5245. 	for i, generator in pairs(Generator_data) do 
  5246. 		trigger_clear(generator.trigger.name) 
  5247. 		 
  5248. 		if generator.monitor_thread ~= INVALID_THREAD_HANDLE then 
  5249. 			thread_kill(generator.monitor_thread) 
  5250. 		end 
  5251. 		generator.progress = 0 
  5252. 		generator.player = nil 
  5253. 		generator.monitor_thread = INVALID_THREAD_HANDLE 
  5254. 	end 
  5255. 	 
  5256. 	Generator_data = { } 
  5257. 	Generator_objective = "" 
  5258. end 
  5259.  
  5260. -- Callback for entering trigger 
  5261. -- 
  5262. -- char_name:	(string) name of character that entered trigger 
  5263. -- trigger_name:	(string) name of trigger that was entered 
  5264. -- 
  5265. function disable_generators_cb(char_name, trigger_name) 
  5266. 	local generator = diable_generators_get_generator_by_trigger(trigger_name) 
  5267. 	 
  5268. 	-- if we didn't find a generator something went wrong just return 
  5269. 	if generator == nil then 
  5270. 		return 
  5271. 	end 
  5272. 	 
  5273. 	-- the character that acivated the trigger isn't the local or remote player... what happened? 
  5274. 	if not (char_name == LOCAL_PLAYER or char_name == REMOTE_PLAYER) then 
  5275. 		return 
  5276. 	end 
  5277. 	 
  5278. 	if generator.player == nil then 
  5279. 		generator.player = char_name 
  5280. 		generator.progress = 0 
  5281. 	end 
  5282. 	 
  5283. 	if generator.player ~= char_name then 
  5284. 		return 
  5285. 	end 
  5286. 	 
  5287. 	local force_play = false 
  5288. 	local percent_done = 1.0 
  5289. 	local stand_still = true 
  5290. 	local zero_movement = true 
  5291. 	 
  5292. 	local start_anim = "disable tech start" 
  5293. 	local state_anim = "disable tech state" 
  5294. 	local exit_anim = "disable tech exit" 
  5295. 	 
  5296. 	local hud_index = 0 
  5297. 	local sync = SYNC_LOCAL 
  5298. 	-- HVS_EC  Variables for scaling the generator ticks to display ticks. 
  5299. 	local last_progress_display = 0 
  5300. 	local next_progress_display = 0 
  5301. 	if generator.player == REMOTE_PLAYER then 
  5302. 		hud_index = 1 
  5303. 		sync = SYNC_REMOTE 
  5304. 	end 
  5305. 	 
  5306. 	-- HVS_EC  Changed trigger cycle from 500ms to 100ms 
  5307. 	-- we are updating every 100ms so target progress should be 10x the amount of seconds we want this to last 
  5308. 	local target_progress =  generator.time_to_disable*10 
  5309. 	 
  5310. 	if generator.progress == 0 then 
  5311. 		camera_set_hide_ui_during_animated(false) 
  5312. 		action_play_non_blocking(char_name, start_anim, nil, force_play, stand_still, zero_movement, generator.anim_nav,  generator.anim_nav) 
  5313. 		set_animation_state(char_name, state_anim,  generator.anim_nav) 
  5314. 		repeat 
  5315. 			thread_yield() 
  5316. 		until action_play_is_finished(char_name, percent_done) 
  5317. 		 
  5318. 		-- only continue if the player is still in the disable tech state 
  5319. 		if check_animation_state(generator.player, "disable tech state") then 
  5320. 			player_movement_disable(char_name) 
  5321. 			generator.monitor_thread = thread_new("disable_generators_monitor_thread", generator) 
  5322. 			generator.progress = generator.progress + 1 
  5323. 		 
  5324. 		else 
  5325. 			clear_animation_state(char_name) 
  5326. 			generator.progress = 0 
  5327. 			generator.player = nil 
  5328. 			generator.monitor_thread = INVALID_THREAD_HANDLE 
  5329. 		end 
  5330. 		 
  5331. 		 
  5332. 	elseif generator.progress >= target_progress then 
  5333. 		trigger_cb(char_name, trigger_name) 
  5334. 		trigger_clear(trigger_name) 
  5335. 		thread_kill(generator.monitor_thread) 
  5336. 		generator.monitor_thread = INVALID_THREAD_HANDLE 
  5337. 		 
  5338. 		action_play_non_blocking(char_name, exit_anim, nil, force_play, stand_still, zero_movement, generator.anim_nav,  generator.anim_nav) 
  5339. 		clear_animation_state(char_name) 
  5340. 		repeat 
  5341. 			thread_yield() 
  5342. 		until action_play_is_finished(char_name, percent_done) 
  5343. 		 
  5344. 		player_movement_enable(char_name) 
  5345. 		generator.disabled = true 
  5346. 		camera_set_hide_ui_during_animated(true) 
  5347. 		hud_bar_off(hud_index) 
  5348. 		if Generator_objective ~= nil and Generator_objective ~= "" then 
  5349. 			objective_text(0, Generator_objective, nil, nil, sync, OI_ASSET_USE) 
  5350. 		end 
  5351. 	 
  5352. 	else 
  5353. 		-- HVS_EC  The HUD updates every 500 ms.  This callback updates every 100 ms.  So we update the HUD once every 5 ticks. 
  5354. 		last_progress_display = generator.progress / 5 
  5355. 		next_progress_display = (generator.progress + 1) / 5 
  5356. 		generator.progress = generator.progress + 1 
  5357. 		if generator.progress <= target_progress then 
  5358. 			if last_progress_display < next_progress_display then 
  5359. 				hud_bar_set_value(hud_index,  next_progress_display, sync) 
  5360. 			end 
  5361. 		end 
  5362. 	end 
  5363. 	 
  5364. end	 
  5365.  
  5366. -- Monitors disable progress and updates hud bar as neccassary 
  5367. -- generator:	(table) generator to monitor 
  5368. -- 
  5369. function disable_generators_monitor_thread(generator)					 
  5370. 	local prev_progress = generator.progress 
  5371. 	 
  5372. 	objective_text_clear(0) 
  5373. 	local hud_index = 0 
  5374. 	local sync = SYNC_LOCAL 
  5375. 	if generator.player == REMOTE_PLAYER then 
  5376. 		hud_index = 1 
  5377. 		sync = SYNC_REMOTE 
  5378. 		if Generator_objective ~= nil and Generator_objective ~= "" then 
  5379. 			objective_text(0, Generator_objective, nil, nil, SYNC_LOCAL, OI_ASSET_USE) 
  5380. 		end 
  5381. 	elseif Generator_objective ~= nil and Generator_objective ~= "" then 
  5382. 		objective_text(0, Generator_objective, nil, nil, SYNC_REMOTE, OI_ASSET_USE) 
  5383. 	end 
  5384. 	 
  5385. 	-- we are updating every 500ms so target progress should be double the amount of seconds we want this to last 
  5386. 	local target_progress =  generator.time_to_disable*2 
  5387. 	 
  5388. 	hud_bar_on(hud_index, "Default", generator.objective, target_progress, sync, OI_ASSET_USE) 
  5389. 	 
  5390. 	while true do 
  5391. 		delay(0.5) 
  5392. 		 
  5393. 		if generator.progress <= prev_progress then 
  5394. 			-- no progress was made so break out and kill it 
  5395. 			break 
  5396. 		end 
  5397. 		 
  5398. 		if not check_animation_state(generator.player, "disable tech state") then 
  5399. 			-- the player got knocked out of the state fail the disable 
  5400. 			-- also disable the trigger for 2seconds so the player doesn't instatnly re-enter animation if they are holding down y when they get hit 
  5401. 			hud_bar_off(hud_index) 
  5402. 			trigger_enable(generator.trigger.name, false) 
  5403. 			delay(2.0) 
  5404. 			trigger_enable(generator.trigger.name) 
  5405. 			break 
  5406. 		end 
  5407. 		prev_progress = generator.progress 
  5408. 	end 
  5409. 	 
  5410. 	hud_bar_off(hud_index) 
  5411. 	if Generator_objective ~= nil and Generator_objective ~= "" then 
  5412. 		objective_text(0, Generator_objective, nil, nil, sync, OI_ASSET_USE) 
  5413. 	end 
  5414. 	 
  5415. 	if generator.player ~= nil then 
  5416. 		player_movement_enable(generator.player) 
  5417. 		clear_animation_state(generator.player) 
  5418. 	end 
  5419. 	 
  5420. 	generator.progress = 0 
  5421. 	generator.player = nil 
  5422. 	generator.monitor_thread = INVALID_THREAD_HANDLE 
  5423. end 
  5424.  
  5425. -- Get the generator table from the trigger name 
  5426. -- 
  5427. -- tirgger:	(string) name of the trigger to look for 
  5428. -- 
  5429. -- returns: (table) generator table with matching trigger 
  5430. -- 
  5431. function diable_generators_get_generator_by_trigger(trigger) 
  5432. 	for i, generator in pairs(Generator_data) do 
  5433. 		if generator.trigger.name == trigger then 
  5434. 			return generator 
  5435. 		end 
  5436. 	end 
  5437. 	return nil 
  5438. end		 
  5439. 								 
  5440. 								 
  5441. -------------------------------------------End of disable generator functions-------------------------------------------------------								 
  5442.  
  5443. function crib_ship_nemo_chair_exit_setup( ) 
  5444. 	crib_ship_nemo_chair_exit_setup_do( ) 
  5445.  
  5446. 	while (crib_ship_nemo_chair_enter_check_done() == false) do 
  5447. 		thread_yield( ) 
  5448. 	end 
  5449. end 
  5450.  
  5451. function crib_ship_nemo_chair_exit( ) 
  5452. 	crib_ship_nemo_chair_exit_do( ) 
  5453.  
  5454. 	while (crib_ship_nemo_chair_exit_check_done() == false) do 
  5455. 		thread_yield( ) 
  5456. 	end 
  5457. end 
  5458.  
  5459. function crib_ship_nemo_chair_enter( ) 
  5460. 	crib_ship_nemo_chair_enter_do( ) 
  5461.  
  5462. 	while (crib_ship_nemo_chair_exit_check_done() == false) do 
  5463. 		thread_yield( ) 
  5464. 	end 
  5465. end 
  5466.  
  5467. --This function should correctly apply the ship suit for any players in the player list 
  5468. function mission_apply_ship_suit_to_players() 
  5469. 	local player_list = player_names_get_all() 
  5470. 	local add_to_wardrobe = false 
  5471. 	 
  5472. 	--Remove all clothing before we put on the correct clothes 
  5473. 	players_naked(true) 
  5474. 	 
  5475. 	-- Wait until everyone is good and nekkid before we proceed 
  5476. 	for i, player in pairs(player_list) do 
  5477. 		while player_customization_is_finalized(player) == false do 
  5478. 			thread_yield() 
  5479. 		end 
  5480. 	end 
  5481. 	 
  5482. 	-- Put on your clothes. 
  5483. 	for i, player in pairs(player_list) do 
  5484. 		local sync_flags = SYNC_LOCAL 
  5485. 		if player == REMOTE_PLAYER then 
  5486. 			sync_flags = SYNC_REMOTE 
  5487. 		end 
  5488. 		 
  5489. 		if character_get_gender(player) == GENDER_TYPE_MALE then 
  5490. 			local item_name = "cm_suit_jumpsuit01" 
  5491. 			local wear_option = "cm_suit_jumpsuit01.cmeshx" 
  5492. 			local variant = "defaultMat" 
  5493. 			local clear_facewear = true 
  5494. 			customization_item_wear(item_name, wear_option, variant, add_to_wardrobe, sync_flags, clear_facewear) 
  5495. 		else 
  5496. 			local item_name = "cf_suit_jumpsuit02" 
  5497. 			local wear_option = "cm_suit_jumpsuit02.cmeshx" 
  5498. 			local variant = "defaultMat" 
  5499. 			local clear_facewear = true 
  5500. 			customization_item_wear(item_name, wear_option, variant, add_to_wardrobe, sync_flags, clear_facewear) 
  5501. 		end 
  5502. 	end 
  5503. 	 
  5504. 	-- Wait until everything is ready to show. 
  5505. 	for i, player in pairs(player_list) do 
  5506. 		while player_customization_is_finalized(player) == false do 
  5507. 			delay(0.25) 
  5508. 		end 
  5509. 	end 
  5510. end 
  5511.  
  5512.