sr2lua/ss05.lua

  1. -- ss05.lua 
  2. -- SR2 mission script 
  3. -- 3/28/07 
  4. -- Mission help table text tags 
  5.    HT_DISPLAY_NAME = "ss05_display_name" 
  6.    HT_GO_TO_FIRST_LAB = "ss05_go_to_first_lab" 
  7.    HT_X_OF_Y_DUST_CONTAINERS_DESTROYED = "ss05_x_of_y_dust_containers_destroyed" 
  8.    HT_X_OF_Y_DUST_CONTAINERS_DESTROYED_HT = "ss05_x_of_y_dust_containers_destroyed_ht" 
  9.  
  10.    HT_X_OF_Y_LABS_DESTROYED = "ss05_x_of_y_labs_destroyed" 
  11.    HT_HEAD_TO_SECOND_LAB = "ss05_head_to_second_lab" 
  12.    HT_DESTROY_THIRD_LAB = "ss05_destroy_third_lab" 
  13.    HT_DOOR_LOCKED = "ss05_door_locked" 
  14.    HT_LOCKED_SOMEONE_HAS_KEY = "ss05_locked_someone_has_key" 
  15.    HT_PICK_UP_KEY = "ss05_pick_up_key" 
  16.    HT_DESTROY_FOURTH_LAB = "ss05_destroy_fourth_lab" 
  17.    HT_X_OF_Y_TECHS_KILLED = "ss05_x_of_y_techs_killed" 
  18.    HT_X_OF_Y_TECHS_KILLED_HT = "ss05_x_of_y_techs_killed_ht" 
  19.    HT_CHASE_DOWN_TECH = "ss05_chase_down_tech" 
  20.    HT_TECH_ESCAPING = "ss05_tech_escaping" 
  21.    HT_TECH_ESCAPED = "ss05_tech_escaped" 
  22.    HT_KILL_SAMEDI_TECHS = "ss05_kill_samedi_techs" 
  23.    HT_DESTROY_STORAGE_CONTAINERS = "ss05_destroy_storage_containers" 
  24.  
  25. -- Mission states 
  26.    MS_TRAVEL_TO_FIRST_LAB = 0 
  27.    MS_REACHED_FIRST_LAB = 1 
  28.    MS_DESTROYED_FIRST_LAB = 2 
  29.    MS_TRAVEL_TO_SECOND_LAB = 3 
  30.    MS_REACHED_SECOND_LAB = 4 
  31.    MS_CAPTURED_SECOND_LAB_TECH = 5 
  32.    MS_DROP_OFF_CAPTURED_TECH = 6 
  33.    MS_DESTROYED_SECOND_LAB = 7 
  34.    MS_TRAVEL_TO_THIRD_LAB = 8 
  35.    MS_REACHED_THIRD_LAB = 9 
  36.    MS_DESTROYED_THIRD_LAB = 10 
  37.    MS_TRAVEL_TO_FOURTH_LAB = 12 
  38.    MS_REACHED_FOURTH_LAB = 13 
  39.    MS_TECH_ESCAPING = 14 
  40.    MS_VICTORY = 15 
  41.  
  42.    MS_FIRST_LAB_CHECKPOINT = 16 
  43.    MS_SECOND_LAB_CHECKPOINT = 17 
  44.    MS_THIRD_LAB_CHECKPOINT = 18 
  45.    MS_FOURTH_LAB_CHECKPOINT = 19 
  46.  
  47. -- Groups, NPCs, vehicles, navpoints, and other names 
  48.    -- Mission constant names 
  49.    MISSION_NAME = "ss05" 
  50.    -- ( Mission Prefix ) 
  51.    MP = MISSION_NAME.."_$" 
  52.    ENEMY_GANG = "samedi" 
  53.  
  54.    LAB_FOUR_KEY = "keys" 
  55.  
  56.    -- Chunk swap sequences for the fires 
  57.    FIRE_1 = "Chunk_Fire_1" 
  58.    FIRE_2 = "Chunk_Fire_2" 
  59.    LAB_FIRE_1 = "Lab_Fire_1" 
  60.    LAB_FIRE_2 = "Lab_Fire_2" 
  61.    LAB_FIRE_3 = "Lab_Fire_3" 
  62.    CHUNK_SWAP_FIRES = { FIRE_1, FIRE_2, LAB_FIRE_1, LAB_FIRE_2, LAB_FIRE_3 } 
  63.  
  64.    -- Checkpoints 
  65.    CP_REACHED_LAB_ONE = "Lab_One_Reached" 
  66.    CP_REACHED_LAB_TWO = "Lab_Two_Reached" 
  67.    CP_REACHED_LAB_THREE = "Lab_Three_Reached" 
  68.    CP_REACHED_LAB_FOUR = "Lab_Four_Reached" 
  69.  
  70.    -- Groups 
  71.    STARTER_VEHICLE_GROUP_NAME = MP.."Starter_Vehicle" 
  72.    STARTER_VEHICLE_COOP_GROUP_NAME = MP.."Starter_Vehicle_Coop" 
  73.  
  74.    LAB_ONE_OUTSIDE_GROUP = MP.."L1_Outside_Attackers" 
  75.    LAB_ONE_INSIDE_GROUP = MP.."L1_Inside_Attackers" 
  76.  
  77.    LAB_TWO_FLOOR_ONE_ATTACKERS = MP.."L2_Floor1_Attackers" 
  78.    LAB_TWO_FLOOR_TWO_ATTACKERS = MP.."L2_Floor2_Attackers" 
  79.  
  80.    LAB_THREE_INITIAL_DEFENDERS_GROUP = MP.."L3_Initial_Defenders" 
  81.    LAB_THREE_ENCLOSED_LAB_GROUP = MP.."L3_Enclosed_Lab_Gang_Members" 
  82.    LAB_THREE_DEFENDERS_GROUP = MP.."L3_Defenders" 
  83.    LAB_THREE_AFTER_LAB_ATTACK_GROUP = MP.."L3_After_Lab_Attackers" 
  84.  
  85.    LAB_FOUR_OUTSIDE_GROUP = MP.."L4_Outside_Defenders" 
  86.    LAB_FOUR_DEFENDERS_GROUP = MP.."L4_Defenders" 
  87.    LAB_FOUR_TECHS_GROUP = MP.."L4_Techs" 
  88.    LAB_FOUR_ESCAPING_TECH_GROUP = MP.."L4_Escapee_and_Car" 
  89.    LAB_FOUR_PLAYERS_CAR_GROUP = MP.."L4_Player_chase_car" 
  90.  
  91.    -- NPC names 
  92.    LAB_ONE_OUTSIDE_GROUP_MEMBERS = { MP.."L1_Outside_M01", MP.."L1_Outside_M02", MP.."L1_Outside_M03" } 
  93.    LAB_ONE_INSIDE_GROUP_MEMBERS = { MP.."L1_Inside_M01", MP.."L1_Inside_M02", MP.."L1_Inside_M03", 
  94.                                     MP.."L1_Inside_M04", MP.."L1_Inside_M05" } 
  95.  
  96.    LAB_TWO_LOBBY_GUARD = MP.."L2_Lobby_Guard" 
  97.    LAB_TWO_DEFENDER_MEMBERS = { MP.."L2_M01", MP.."L2_M02", MP.."L2_M03", MP.."L2_M04", MP.."L2_M05", MP.."L2_M06", 
  98.                                 MP.."L2_M07", MP.."L2_M08", MP.."L2_M09", MP.."L2_M10", MP.."L2_M11", MP.."L2_M12", 
  99.                                 MP.."L2_M13" } 
  100.  
  101.    LAB_THREE_INITIAL_DEFENDER_MEMBERS = { MP.."L3_Initial_Defender01", MP.."L3_Initial_Defender02", 
  102.                                           MP.."L3_Initial_Defender03" } 
  103.    LAB_THREE_DEFENDER_MEMBERS = { MP.."L3_Defender01", MP.."L3_Defender02", MP.."L3_Defender03", 
  104.                                   MP.."L3_Defender04", MP.."L3_Defender05", MP.."L3_Defender06", 
  105.                                   MP.."L3_Defender07" } 
  106.    LAB_THREE_ENCLOSED_LAB_MEMBERS = { MP.."L3_EL_M01", MP.."L3_EL_M02" } 
  107.  
  108.    LAB_THREE_AFTER_LAB_ATTACK_MEMBERS = { MP.."L3_ALA_01", MP.."L3_ALA_02", MP.."L3_ALA_03", MP.."L3_ALA_04" } 
  109.  
  110.    LAB_FOUR_DEFENDER_MEMBERS = { MP.."L4_M01", MP.."L4_M02", MP.."L4_M03", MP.."L4_M04", MP.."L4_M05", 
  111.                                  MP.."L4_M06", MP.."L4_M07", MP.."L4_M08", MP.."L4_M09", MP.."L4_M10", 
  112.                                  MP.."L4_M11", MP.."L4_M12" } 
  113.  
  114.    LAB_FOUR_ENTRYWAY_DEFENDERS = { LAB_FOUR_DEFENDER_MEMBERS[3], LAB_FOUR_DEFENDER_MEMBERS[4] } 
  115.  
  116.    LAB_FOUR_TECH_MEMBERS = { MP.."L4_Tech_M01", MP.."L4_Tech_M02", MP.."L4_Tech_M03" } 
  117.  
  118.    LAB_FOUR_ENTRYWAY_TECH_NAME = LAB_FOUR_TECH_MEMBERS[2] 
  119.  
  120.    LAB_FOUR_ESCAPEE_TECH = MP.."L4_Escapee" 
  121.  
  122.    FIRETRUCKS_FIREFIGHTERS = { { MP.."FF_01", MP.."FF_02" }, 
  123.                                { MP.."FF2_01", MP.."FF2_02" }, 
  124.                                { MP.."FF3_01", MP.."FF3_02" }, 
  125.                                { MP.."FF4_01", MP.."FF4_02" } } 
  126.  
  127.    -- Vehicle names 
  128.    LAB_THREE_AFTER_LAB_ATTACK_VEHICLE = MP.."L3_ALA_V" 
  129.  
  130.    LAB_FOUR_ESCAPE_VEHICLE = MP.."Escape_Car" 
  131.  
  132.    PLAYER_CHASE_CAR = MP.."Player_Chase_Car" 
  133.  
  134.    FIRETRUCK_NAMES = { MP.."Firetruck", MP.."Firetruck02", MP.."Firetruck03", MP.."Firetruck04" } 
  135.  
  136.    -- Navpoints 
  137.    REMOTE_PLAYER_START = MP.."Remote_Player_Start" 
  138.  
  139.    LAB_TWO_SAINTS_HQ_PATH = { MP.."HQ01", MP.."HQ02", MP.."HQ03", MP.."HQ04", 
  140.                               MP.."HQ05", MP.."HQ06", MP.."HQ07", MP.."HQ08" } 
  141.    LAB_TWO_SAINTS_HQ_LOCATION = MP.."Saints_HQ" 
  142.  
  143.    LAB_THREE_SMOKE_SOURCE = MP.."Smoke_Source" 
  144.    LAB_THREE_CLEAR_OF_ROOM = MP.."Clear_of_Room" 
  145.  
  146.    LAB_FOUR_ESCAPE_PATHS = { MP.."Escape_Path", MP.."Escape_Path_02", MP.."Escape_Path_03", MP.."Escape_Path_04", MP.."Escape_Path_05" } 
  147.  
  148.    FIRETRUCK_PATHS = { MP.."Firetruck_Path", MP.."Firetruck_Path02", MP.."Firetruck_Path03", MP.."Firetruck_Path04" } 
  149.    POST_CHUNK_SWAP_WARP_POSITIONS = { [LOCAL_PLAYER] = MP.."Local_Player_Post_Swap_Warp", 
  150.                                       [REMOTE_PLAYER] = MP.."Remote_Player_Post_Swap_Warp" } 
  151.  
  152.    -- Triggers 
  153.    LAB_ONE_LOCATION_TRIGGER = MP.."Lab1_Location" 
  154.    LAB_ONE_SAMPLE_COLLECTION_TRIGGER = MP.."Get_sample_trigger" 
  155.    LAB_ONE_LIGHT_DRUG_EFFECT_TRIGGER = MP.."L1_Light_Drug_Effect" 
  156.    LAB_ONE_MEDIUM_DRUG_EFFECT_TRIGGER = MP.."L1_Medium_Drug_Effect" 
  157.  
  158.    LAB_TWO_LOCATION_TRIGGER = MP.."Lab2_Location" 
  159.    LAB_TWO_ENTRANCE_TRIGGER = MP.."Lab2_Location" 
  160.    LAB_TWO_LIGHT_DRUG_EFFECT_TRIGGER = MP.."L1_Light_Drug_Effect" 
  161.    LAB_TWO_MEDIUM_DRUG_EFFECT_TRIGGER = MP.."L1_Medium_Drug_Effect" 
  162.  
  163.    LAB_THREE_ENTRANCE_TRIGGER = MP.."Lab3_Entrance" 
  164.    LAB_THREE_LOCATION_TRIGGER = MP.."Lab3_Location" 
  165.    LAB_THREE_AREA_TRIGGER = MP.."Lab_Three_Area" 
  166.    LAB_THREE_TOP_OF_STAIRS_TRIGGER = MP.."L3_Top_of_Stairs" 
  167.    LAB_THREE_ENCLOSED_LAB_ENTRANCE_TRIGGER = MP.."L3_Enclosed_Lab_Entrance" 
  168.    LAB_THREE_FLUSH_OUT_SWITCH = MP.."Flush_Out_Switch" 
  169.    LAB_THREE_LIGHT_DRUG_EFFECT_TRIGGER = MP.."L1_Light_Drug_Effect" 
  170.    LAB_THREE_MEDIUM_DRUG_EFFECT_TRIGGER = MP.."L1_Medium_Drug_Effect" 
  171.  
  172.    LAB_FOUR_NEAR_TRIGGER = MP.."Near_Lab_Four" 
  173.  
  174.    LAB_FOUR_GUIDE_TRIGGERS = { MP.."Lab4_Guide01", MP.."Lab4_Guide02" } 
  175.  
  176.    LAB_FOUR_LOCATION_TRIGGER = MP.."Lab4_Location" 
  177.    LAB_FOUR_CHUNK_SWAP_TRIGGER = MP.."Lab4_Chunk_Swap" 
  178.    LAB_FOUR_TECH_ESCAPE_TRIGGER = MP.."Lab4_Tech_Escape" 
  179.    LAB_FOUR_AREA1 = MP.."L4_Area1" 
  180.    LAB_FOUR_AREA2 = MP.."L4_Area2" 
  181.    LAB_FOUR_LIGHT_DRUG_EFFECT_TRIGGER = MP.."L1_Light_Drug_Effect" 
  182.    LAB_FOUR_MEDIUM_DRUG_EFFECT_TRIGGER = MP.."L1_Medium_Drug_Effect" 
  183.    LAB_FOUR_BEFORE_DOOR_UNLOCKED_TRIGGER = MP.."L4_Before_Door_Unlocked" 
  184.    LAB_FOUR_UNLOCK_DOOR_TRIGGER = MP.."L4_Unlock_Door" 
  185.    LAB_FOUR_POWER_FAILURE_TRIGGER = MP.."L4_Power_Failure" 
  186. 	LAB_FOUR_EXIT_COOP_TRIGGER = MP.."L4_Coop_Exit" 
  187.  
  188.    LAB_LIGHT_DRUG_EFFECT_TRIGGERS = { LAB_ONE_LIGHT_DRUG_EFFECT_TRIGGER, LAB_TWO_LIGHT_DRUG_EFFECT_TRIGGER, 
  189.                                       LAB_THREE_LIGHT_DRUG_EFFECT_TRIGGER, LAB_FOUR_LIGHT_DRUG_EFFECT_TRIGGER } 
  190.  
  191.    LAB_MEDIUM_DRUG_EFFECT_TRIGGERS = { LAB_ONE_MEDIUM_DRUG_EFFECT_TRIGGER, LAB_TWO_MEDIUM_DRUG_EFFECT_TRIGGER, 
  192.                                        LAB_THREE_MEDIUM_DRUG_EFFECT_TRIGGER, LAB_FOUR_MEDIUM_DRUG_EFFECT_TRIGGER } 
  193.  
  194.    FIRETRUCK_START_PATH_TRIGGER = MP.."Firetruck_Start_Path_Trigger" 
  195.    FIRETRUCK_MID_PATH_TRIGGER = MP.."Mid_Chase_Firetruck_Trigger" 
  196.    FIRETRUCK_END_PATHS_TRIGGER = MP.."Firetrucks_End_Paths_Trigger" 
  197.  
  198.    -- Movers 
  199.    LAB_ONE_STORAGE_NAMES = { MP.."L1_Barrel01", MP.."L1_Barrel02" } 
  200.  
  201.    LAB_TWO_STORAGE_NAMES = { MP.."L2_Voodo_Lab" } 
  202.  
  203.    LAB_TWO_ENTRANCE_DOORS = { MP.."L2_Entrance_Door_01", MP.."L2_Entrance_Door_02" } 
  204.  
  205.    LAB_THREE_DOOR_NAME = MP.."L3_Enclosed_Lab_Door" 
  206.    LAB_THREE_STORAGE_NAMES = { MP.."L3_Barrel01", MP.."L3_Voodo_Lab_02" } 
  207.  
  208.    LAB_THREE_ENCLOSED_LAB_BARREL_NAME = MP.."L3_Barrel02" 
  209.  
  210.    LAB_FOUR_ENTRANCE_DOOR = MP.."L4_Entrance_Door" 
  211.    LAB_FOUR_MIDDLE_DOOR = MP.."L4_Middle_Door" 
  212.    LAB_FOUR_DOOR_NEAR_BARREL = MP.."L4_Door_Near_Barrel" 
  213.    LAB_FOUR_EXIT_DOOR = MP.."L4_Exit_Door" 
  214.    LAB_FOUR_STORAGE_NAMES = { MP.."L4_Barrel01" } 
  215.  
  216.  
  217.    -- Barrel Effect Navpoints 
  218.    BARREL_FIRE_EFFECT_LOCATIONS = { [LAB_ONE_STORAGE_NAMES[1]] = { MP.."L1_B1_Fire01", MP.."L1_B1_Fire02" }, 
  219.                                     [LAB_ONE_STORAGE_NAMES[2]] = { MP.."L1_B2_Fire01", MP.."L1_B2_Fire02" }, 
  220.  
  221.                                     [LAB_TWO_STORAGE_NAMES[1]] = { MP.."L2_B1_Fire01", MP.."L2_B1_Fire02", MP.."L2_B1_Fire03", MP.."L2_B1_Fire04" }, 
  222.  
  223.                                     [LAB_THREE_STORAGE_NAMES[1]] = { MP.."L3_B1_Fire01", MP.."L3_B1_Fire02", MP.."L3_B1_Fire03" }, 
  224.                                     [LAB_THREE_STORAGE_NAMES[2]] = { MP.."L3_B2_Fire01", MP.."L3_B2_Fire02" }, 
  225.  
  226.                                     [LAB_FOUR_STORAGE_NAMES[1]] = { MP.."L4_B1_Fire01", MP.."L4_B1_Fire02" } } 
  227.  
  228.    BARREL_SMALL_FIRE_EFFECT_LOCATIONS = { [LAB_ONE_STORAGE_NAMES[1]] = { MP.."L1_B1_SF01", MP.."L1_B1_SF02", MP.."L1_B1_SF03" }, 
  229.                                           [LAB_ONE_STORAGE_NAMES[2]] = { MP.."L1_B2_SF01", MP.."L1_B2_SF02" }, 
  230.  
  231.                                           [LAB_TWO_STORAGE_NAMES[1]] = { MP.."L2_B1_SF01", MP.."L2_B1_SF02", MP.."L2_B1_SF03", MP.."L2_B1_SF04" }, 
  232.  
  233.                                           [LAB_THREE_STORAGE_NAMES[1]] = { MP.."L3_B1_SF01", MP.."L3_B1_SF02", MP.."L3_B1_SF03" }, 
  234.                                           [LAB_THREE_STORAGE_NAMES[2]] = { MP.."L3_B2_SF01", MP.."L3_B2_SF02" }, 
  235.  
  236.                                           [LAB_FOUR_STORAGE_NAMES[1]] = { MP.."L4_B1_SF01", MP.."L4_B1_SF02", MP.."L4_B1_SF03" } } 
  237.  
  238.  
  239.    -- Effects and animation states 
  240.    LAB_THREE_SMOKE_EFFECT = "smoke_grenade" 
  241.    COUGH_ANIMATION = "TearGassed" 
  242.    LIGHT_DRUG_EFFECT = 1 
  243.    MEDIUM_DRUG_EFFECT = 2 
  244.    BOOZE_INDEX = 1 
  245.    WEED_INDEX = 2 
  246.  
  247.    LARGE_FIRE = "fire_sticky" 
  248.    SMALL_FIRES = { "fire_sticky_sm", "fire_sticky_sm02" } 
  249. 	BUILDING_SHAKE_BUILDING_TWO = "SS_building_shake" 
  250. 	WINDOW_EXPLODE = "exp_fire_window" 
  251. 	BIG_SIDE_EXPOSION = "mission_ss05_exp_side" 
  252.  
  253. 	 
  254.  
  255.  
  256.    -- Cutscenes 
  257.    CT_INTRO = "ss05-01" 
  258.    CT_OUTRO = "ss05-02" 
  259.  
  260. -- Sound 
  261.    -- Persona overrides 
  262.  
  263.    -- Lines/Dialog Stream 
  264.    LAB_THREE_HIDE_IN_THE_LAB = "SOS5_LAB_3_L1" 
  265.    LAB_THREE_HIDING_TECHS_PLAYER_DIALOG_STREAM = 
  266.    { 
  267.    { "SOS5_LAB_3_L2", LOCAL_PLAYER, 0 } 
  268.    } 
  269.  
  270.    LAB_THREE_HIDING_TECHS_TECH_DIALOG_STREAM = 
  271.    { 
  272.    { "SOS5_LAB_3_L3", LAB_THREE_ENCLOSED_LAB_MEMBERS[1], 0 } 
  273.    } 
  274.  
  275.    LAB_THREE_FINAL_TECH_FLEE = "BMFRAT_SOS5_FLEE" 
  276.    LAB_THREE_ENCLOSED_LAB_SWITCH_AUDIO = "PLAYER_SOS5_GAS_SHUTOFF_01" 
  277.    LAB_FOUR_POWER_FAILURE_AUDIO = "PLAYER_SOS5_LIGHTS_OUT_01" 
  278.    LAB_FOUR_EXIT_LAB = "PLAYER_SOS5_LAB_DOOR_01" 
  279.  
  280.    -- Sound effects 
  281.    LOCKED_DOOR_SOUND = "SFX_SS05_DOOR_LOCKED" 
  282.  
  283. -- Distances 
  284.    LAB_TECH_CHASE_DISTANCE_METERS = 50 
  285.    LOBBY_GUARD_WANDER_RADIUS_METERS = 4.875 
  286.  
  287.    LAB_FOUR_ENTRYWAY_NPCS_WANDER_RADIUS_METERS = 4.0 
  288.  
  289. -- Speeds 
  290.    LAB_TECH_CHASE_INITIAL_SPEED_MPH = 25 
  291.    LAB_TECH_CHASE_NORMAL_SPEED_MPH = 40 
  292.  
  293. -- Percents and multipliers 
  294.    LIGHT_DRUG_EFFECT_STRENGTHS = { [BOOZE_INDEX] = .0, [WEED_INDEX] = .25 } 
  295.    MEDIUM_DRUG_EFFECT_STRENGTHS = { [BOOZE_INDEX] = .0, [WEED_INDEX] = .70 } 
  296.  
  297.    DRUG_EFFECT_STRENGTHS = { [LIGHT_DRUG_EFFECT] = LIGHT_DRUG_EFFECT_STRENGTHS, 
  298.                              [MEDIUM_DRUG_EFFECT] = MEDIUM_DRUG_EFFECT_STRENGTHS } 
  299.  
  300. -- Time values 
  301.    TIME_TO_CATCH_UP_WITH_TECH_MS = 20000 
  302.  
  303.    DRUG_EFFECT_FADE_TIME = { [LIGHT_DRUG_EFFECT] = 3.0, [MEDIUM_DRUG_EFFECT] = 10.0 } 
  304.    BEFORE_BACKUP_SPAWN_DELAY_SECONDS = 5.0 
  305.    LAB_DESTROYED_OBJECTIVE_UPDATE_DELAY_SECONDS = 5.0 
  306.    TECHS_KILLED_OBJECTIVE_UPDATE_DELAY_SECONDS = 3.0 
  307.    MISSION_BEGIN_FADE_IN_TIME_SECONDS = 2.0 
  308.    LAB_FOUR_TECH_LEAVE_DELAY_SECONDS = 2.0 
  309.  
  310. -- Constant values and counts 
  311.    FIRST_LAB_MIN_NOTORIETY_LEVEL = 1 
  312.    MIN_NOTORIETY_LEVEL = 2 
  313.    LAB_COUNT = 4 
  314.    INITIAL_LAB_CHEM_STORAGE_COUNT = { sizeof_table( LAB_ONE_STORAGE_NAMES ), sizeof_table( LAB_TWO_STORAGE_NAMES ), 
  315.                                       sizeof_table( LAB_THREE_STORAGE_NAMES ), sizeof_table( LAB_FOUR_STORAGE_NAMES ) } 
  316.  
  317.    LAB_THREE_DEFENDERS_COUNT = sizeof_table( LAB_THREE_INITIAL_DEFENDER_MEMBERS ) + 
  318.                                sizeof_table( LAB_THREE_DEFENDER_MEMBERS ) + 
  319.                                sizeof_table( LAB_THREE_ENCLOSED_LAB_MEMBERS ) 
  320.  
  321.    LAB_FOUR_INITIAL_TECH_COUNT = sizeof_table( LAB_FOUR_TECH_MEMBERS ) 
  322.  
  323.  
  324. -- Global variables 
  325.  
  326.    Labs_chem_storage_remaining = { INITIAL_LAB_CHEM_STORAGE_COUNT[1], INITIAL_LAB_CHEM_STORAGE_COUNT[2], 
  327.                                    INITIAL_LAB_CHEM_STORAGE_COUNT[3], INITIAL_LAB_CHEM_STORAGE_COUNT[4] } 
  328.    Lab_one_sample_collected = false 
  329.    Lab_one_sample_is_destroyed = { false, false } 
  330.  
  331.    Players_in_Lab4_Area1 = { [LOCAL_PLAYER] = false, [REMOTE_PLAYER] = false } 
  332.    Players_in_Lab4_Area2 = { [LOCAL_PLAYER] = false, [REMOTE_PLAYER] = false } 
  333.  
  334.    Players_in_Lab3_Area = { [LOCAL_PLAYER] = false, [REMOTE_PLAYER] = false } 
  335.  
  336.    Players_drug_effect_rampoff_thread_handles = { [LOCAL_PLAYER] = INVALID_THREAD_HANDLE, 
  337.                                                   [REMOTE_PLAYER] = INVALID_THREAD_HANDLE } 
  338.  
  339.    Lab_two_tech_captured = false 
  340.  
  341.    Lab_four_techs_remaining = LAB_FOUR_INITIAL_TECH_COUNT 
  342.    Swap_sequences_enabled = { [FIRE_1] = false, [FIRE_2] = false } 
  343.    Mission_won = false 
  344.    Lab_three_defenders_remaining = LAB_THREE_DEFENDERS_COUNT 
  345.    Lab_three_after_lab_attackers_spawned = false 
  346.    Players_locked_in_lab_four = false 
  347.    Mission_being_replayed = false 
  348.     
  349.    Player_controls_disabled = false 
  350.  
  351.    Num_barrel_fire_effects = 0 
  352.    Barrel_fire_effect_handles = {} 
  353.  
  354.  
  355. function ss05_fire_chase_explsions() 
  356. delay(2) 
  357. effect_play(BIG_SIDE_EXPOSION, "ss05_$nEffect_Trigger_One",false) 
  358. delay(.1) 
  359. effect_play(WINDOW_EXPLODE, "ss05_$nEffect_Trigger_One (0)",false) 
  360. delay(.1) 
  361. effect_play(BIG_SIDE_EXPOSION, "ss05_$nEffect_Trigger_One (1)",false) 
  362. delay(.5) 
  363. effect_play(WINDOW_EXPLODE, "ss05_$nEffect_Trigger_One (2)",false) 
  364. delay(.5) 
  365. effect_play(BIG_SIDE_EXPOSION, "ss05_$nEffect_Trigger_One (3)",false) 
  366. delay(.5) 
  367. effect_play(WINDOW_EXPLODE, "ss05_$nEffect_Trigger_One (4)",false) 
  368. delay(.5) 
  369. effect_play(BIG_SIDE_EXPOSION, "ss05_$nEffect_Trigger_One (5)",false) 
  370. delay(.5) 
  371. effect_play(WINDOW_EXPLODE, "ss05_$nEffect_Trigger_One (6)",false) 
  372.  
  373. end 
  374.  
  375.  
  376. -- Called when a player enters the lab area - updates 
  377. -- location tracking 
  378. -- 
  379. function ss05_entered_lab3_area( triggerer_name, trigger_name ) 
  380.    Players_in_Lab3_Area[triggerer_name] = true 
  381.    mission_debug( triggerer_name.." entered lab 3 area" ) 
  382. end 
  383.  
  384. -- Called when a player leaves the lab area - updates 
  385. -- location tracking 
  386. -- 
  387. function ss05_left_lab3_area( triggerer_name, trigger_name ) 
  388.    Players_in_Lab3_Area[triggerer_name] = false 
  389.    mission_debug( triggerer_name.." left lab 3 area" ) 
  390.  
  391.    -- If we've cleared the third lab and this function is called, 
  392.    -- it means notoriety spawning hasn't been enabled - so enable 
  393.    -- it and clear the callbacks 
  394.    if ( Labs_chem_storage_remaining[3] == 0 ) then 
  395.       notoriety_force_no_spawn( ENEMY_GANG, false ) 
  396.       ss05_clear_lab3_area_trigger() 
  397.       mission_debug( "enabled notoriety spawning" ) 
  398.    end 
  399. end 
  400.  
  401. -- Returns true if all players playing are inside lab 3, 
  402. -- false otherwise. 
  403. -- 
  404. function ss05_both_players_in_lab3_area() 
  405.    -- If the local player's in the area  
  406.    if ( Players_in_Lab3_Area[LOCAL_PLAYER] ) then 
  407.       -- Check to see if we should check the remote player 
  408.       if ( coop_is_active() ) then 
  409.         if ( Players_in_Lab3_Area[REMOTE_PLAYER] ) then 
  410.            return true 
  411.         end 
  412.       -- If not, then everyone who's playing is in the area 
  413.       else 
  414.          return true 
  415.       end 
  416.    end 
  417.    -- Otherwise, if the local player's not even there, exit 
  418.    return false 
  419. end 
  420.  
  421. -- Sets up the triggers that track if players have entered 
  422. -- lab three's general area. 
  423. -- 
  424. function ss05_setup_lab3_area_trigger() 
  425.    mission_debug( "lab three area trigger setup" ) 
  426.    trigger_enable( LAB_THREE_AREA_TRIGGER, true ) 
  427.    on_trigger( "ss05_entered_lab3_area", LAB_THREE_AREA_TRIGGER ) 
  428.    on_trigger_exit( "ss05_left_lab3_area", LAB_THREE_AREA_TRIGGER ) 
  429. end 
  430.  
  431. -- Clear the triggers that track if players have entered 
  432. -- lab three's general area. 
  433. -- 
  434. function ss05_clear_lab3_area_trigger() 
  435.    on_trigger( "", LAB_THREE_AREA_TRIGGER ) 
  436.    on_trigger_exit( "", LAB_THREE_AREA_TRIGGER ) 
  437.    trigger_enable( LAB_THREE_AREA_TRIGGER, false ) 
  438. end 
  439.  
  440. -- Callback when a player enters area 1 of lab 4. 
  441. -- Used to track what areas the players are in 
  442. -- to lock them in this lab. 
  443. -- 
  444. function ss05_entered_lab4_area1( triggerer_name, trigger_name ) 
  445.    Players_in_Lab4_Area1[triggerer_name] = true 
  446.    ss05_maybe_lock_players_in_lab_4() 
  447. end 
  448.  
  449. -- Callback when a player enters area 2 of lab 4. 
  450. -- Used to track what areas the players are in 
  451. -- to lock them in this lab. 
  452. -- 
  453. function ss05_entered_lab4_area2( triggerer_name, trigger_name ) 
  454.    Players_in_Lab4_Area2[triggerer_name] = true 
  455.    ss05_maybe_lock_players_in_lab_4() 
  456. end 
  457.  
  458. -- Callback when a player leaves area 1 of lab 4. 
  459. -- Used to track what areas the players are in 
  460. -- to lock them in this lab. 
  461. -- 
  462. function ss05_left_lab4_area1( triggerer_name, trigger_name ) 
  463.    Players_in_Lab4_Area1[triggerer_name] = false 
  464. end 
  465.  
  466. -- Callback when a player leaves area 2 of lab 4. 
  467. -- Used to track what areas the players are in 
  468. -- to lock them in this lab. 
  469. -- 
  470. function ss05_left_lab4_area2( triggerer_name, trigger_name ) 
  471.    Players_in_Lab4_Area2[triggerer_name] = false 
  472. end 
  473.  
  474. -- Returns true if the player specified is in the first half 
  475. -- of the lab. Areas 1 and 2 cover this first half. 
  476. -- 
  477. function ss05_player_in_lab4_first_half( player_name ) 
  478.    if ( Players_in_Lab4_Area1[player_name] or 
  479.         Players_in_Lab4_Area2[player_name] ) then 
  480.       return true; 
  481.    end 
  482.  
  483.    return false; 
  484. end 
  485.  
  486. -- Returns true if both players are in the first half 
  487. -- of the lab. Areas 1 and 2 cover this first half. 
  488. -- 
  489. function ss05_all_players_in_lab4_first_half() 
  490.  
  491.    -- Check to see if the local player is in the warehouse 
  492.    if ( ss05_player_in_lab4_first_half( LOCAL_PLAYER ) ) then 
  493.       -- If coop is on, also check the remote player. 
  494.       if ( coop_is_active() ) then 
  495.          if ( ss05_player_in_lab4_first_half( REMOTE_PLAYER ) ) then 
  496. 	    -- If both are in, we've met our condition. 
  497. 	    return true 
  498. 	 end 
  499.       -- If it's single player and the local player is in the warehouse, 
  500. 	   -- then all players are in 
  501.       else 
  502.          return true 
  503.       end 
  504.    end 
  505.  
  506.    return false; 
  507. end 
  508.  
  509. -- Locks the players in the first half of lab 4 if 
  510. -- they're both inside. 
  511. -- 
  512. function ss05_maybe_lock_players_in_lab_4() 
  513.    if ( ss05_all_players_in_lab4_first_half() ) then 
  514.       trigger_enable( LAB_FOUR_AREA1, false ); 
  515.       trigger_enable( LAB_FOUR_AREA2, false ); 
  516.  
  517.       while ( door_close( LAB_FOUR_ENTRANCE_DOOR ) == false ) do 
  518.          thread_yield() 
  519.       end 
  520.       delay( 0 ) 
  521. 		if ( coop_is_active() == false ) then 
  522. 	      door_lock( LAB_FOUR_ENTRANCE_DOOR, true ) 
  523. 		end 
  524.       Players_locked_in_lab_four = true 
  525.    end 
  526. end 
  527.  
  528. function ss05_lock_all_lab_exterior_doors() 
  529.    ss05_lock_lab_two_entrances( true ) 
  530.    ss05_lock_enclosed_lab_door( true ) 
  531.    ss05_lock_lab_four_exterior_doors( true ) 
  532. end 
  533.  
  534. function ss05_lock_lab_two_entrances( lock ) 
  535.    for index, door_name in pairs( LAB_TWO_ENTRANCE_DOORS ) do 
  536.       door_lock( door_name, lock ) 
  537.    end 
  538. end 
  539.  
  540. function ss05_lock_enclosed_lab_door( lock ) 
  541.    door_lock( LAB_THREE_DOOR_NAME, lock ) 
  542. end 
  543.  
  544. function ss05_lock_lab_four_exterior_doors( lock ) 
  545.    door_lock( LAB_FOUR_ENTRANCE_DOOR, lock ) 
  546.    door_lock( LAB_FOUR_EXIT_DOOR, lock ) 
  547. end 
  548.  
  549. function ss05_start( checkpoint_name, is_restart ) 
  550.    -- Start trigger is hit...the activate button was hit 
  551.    set_mission_author("Brad Johnson and Mark Gabby") 
  552.  
  553.    if ( mission_is_complete( MISSION_NAME ) ) then 
  554.       Mission_being_replayed = true 
  555.       mission_debug( "mission being replayed" ) 
  556.    end 
  557.  
  558.    -- TEMP -- uncomment this section to go to last lab and chunk swap. 
  559. 	--cutscene_play("IG_SS05_scene1") 
  560.    --checkpoint_name = CP_REACHED_LAB_FOUR 
  561.    -- END TEMP 
  562.  
  563.    mission_start_fade_out() 
  564.    if ( checkpoint_name == MISSION_START_CHECKPOINT ) then 
  565. 		local starter_groups = { STARTER_VEHICLE_GROUP_NAME, LAB_ONE_OUTSIDE_GROUP, LAB_ONE_INSIDE_GROUP } 
  566. 		if ( coop_is_active() ) then 
  567. 			starter_groups = { STARTER_VEHICLE_GROUP_NAME, LAB_ONE_OUTSIDE_GROUP, LAB_ONE_INSIDE_GROUP, STARTER_VEHICLE_COOP_GROUP_NAME } 
  568. 		end 
  569.  
  570. 		if (not is_restart) then 
  571. 			cutscene_play( CT_INTRO, starter_groups, {"mission_start_sr2_city_$ss05", REMOTE_PLAYER_START}, false ) 
  572. 			for index, group_name in pairs( starter_groups ) do 
  573. 				group_show( group_name ) 
  574. 			end 
  575. 		else 
  576. 			for index, group_name in pairs( starter_groups ) do 
  577. 				group_create( group_name, true ) 
  578. 			end 
  579.  
  580. 			-- Teleport the player last to improve loading times 
  581. 			teleport_coop( "mission_start_sr2_city_$ss05", REMOTE_PLAYER_START ) 
  582. 		end 
  583.    end 
  584.  
  585.    ss05_lock_all_lab_exterior_doors( true ) 
  586.  
  587.    set_weather( 0, true ) 
  588.    local state_to_setup 
  589.  
  590.    -- If the mission is being replayed, temporarily revert the swap sequences 
  591.    if ( Mission_being_replayed ) then 
  592.       ss05_save_game_current_swaps() 
  593.    end 
  594.  
  595.    if ( checkpoint_name == MISSION_START_CHECKPOINT ) then 
  596.       state_to_setup = MS_TRAVEL_TO_FIRST_LAB 
  597.    elseif ( checkpoint_name == CP_REACHED_LAB_ONE ) then 
  598.       -- Create the first lab's groups - make sure they're visible at start 
  599.       group_create( LAB_ONE_OUTSIDE_GROUP, true ) 
  600.       group_create( LAB_ONE_INSIDE_GROUP, true ) 
  601.  
  602.       state_to_setup = MS_FIRST_LAB_CHECKPOINT 
  603.    elseif ( checkpoint_name == CP_REACHED_LAB_TWO ) then 
  604.       -- Create the second lab's groups 
  605.       group_create( LAB_TWO_FLOOR_ONE_ATTACKERS, true ) 
  606.       group_create( LAB_TWO_FLOOR_TWO_ATTACKERS, true ) 
  607.       wander_start( LAB_TWO_LOBBY_GUARD, LAB_TWO_LOBBY_GUARD, LOBBY_GUARD_WANDER_RADIUS_METERS ) 
  608.  
  609.       for index, name in pairs ( LAB_ONE_STORAGE_NAMES ) do 
  610.          mesh_mover_hide( name ) 
  611.       end 
  612.  
  613.       ss05_lock_lab_two_entrances( false ) 
  614.  
  615.       state_to_setup = MS_SECOND_LAB_CHECKPOINT 
  616.    elseif ( checkpoint_name == CP_REACHED_LAB_THREE ) then 
  617.       -- Create the third lab's groups 
  618.       group_create( LAB_THREE_INITIAL_DEFENDERS_GROUP, true ) 
  619.       group_create( LAB_THREE_ENCLOSED_LAB_GROUP, true ) 
  620.       group_create( LAB_THREE_DEFENDERS_GROUP, true ) 
  621.       group_create_hidden( LAB_THREE_AFTER_LAB_ATTACK_GROUP, true ) 
  622.  
  623.       -- Add callbacks for the members dying 
  624.       for index, name in pairs( LAB_THREE_INITIAL_DEFENDER_MEMBERS ) do 
  625.          on_death( "ss05_lab_three_defender_died", name ) 
  626.       end 
  627.  
  628.       for index, name in pairs ( LAB_ONE_STORAGE_NAMES ) do 
  629.          mesh_mover_hide( name ) 
  630.       end 
  631.       for index, name in pairs ( LAB_TWO_STORAGE_NAMES ) do 
  632.          mesh_mover_hide( name ) 
  633.       end 
  634.       state_to_setup = MS_THIRD_LAB_CHECKPOINT 
  635.    elseif ( checkpoint_name == CP_REACHED_LAB_FOUR ) then 
  636.       -- Create the final lab's groups 
  637. 	   group_create( LAB_FOUR_OUTSIDE_GROUP, true ) 
  638.       group_create_hidden( LAB_FOUR_ESCAPING_TECH_GROUP, true ) 
  639.       group_create_hidden( LAB_FOUR_PLAYERS_CAR_GROUP, true ) 
  640.       group_create_hidden( LAB_FOUR_DEFENDERS_GROUP, true ) 
  641.       group_create_hidden( LAB_FOUR_TECHS_GROUP, true ) 
  642.       for index, name in pairs ( LAB_ONE_STORAGE_NAMES ) do 
  643.          mesh_mover_hide( name ) 
  644.       end 
  645.       for index, name in pairs ( LAB_TWO_STORAGE_NAMES ) do 
  646.          mesh_mover_hide( name ) 
  647.       end 
  648.       for index, name in pairs ( LAB_THREE_STORAGE_NAMES ) do 
  649.          mesh_mover_hide( name ) 
  650.       end 
  651.       state_to_setup = MS_FOURTH_LAB_CHECKPOINT 
  652.  
  653.       door_lock( LAB_FOUR_ENTRANCE_DOOR, false ) 
  654.    end 
  655.    mission_start_fade_in() 
  656.  
  657. 	-- Create the outside guards at lab 4. It always makes sense to spawn these guys at mission start. 
  658. 	-- However, only load them blocking if we're at lab four. 
  659. 	if ( checkpoint_name ~= CP_REACHED_LAB_FOUR ) then 
  660. 	   group_create( LAB_FOUR_OUTSIDE_GROUP ) 
  661. 	end 
  662.  
  663.    ss05_switch_state( state_to_setup ) 
  664. end 
  665.  
  666. -- Activates the light drug effect on the player who wanders near a lab. 
  667. -- 
  668. function ss05_activate_light_drug_effect( triggerer_name ) 
  669.    local sync_type = sync_from_player( triggerer_name ) 
  670.  
  671.    -- Stop any rampoff that might be enabled 
  672.    if ( Players_drug_effect_rampoff_thread_handles[triggerer_name] ~= INVALID_THREAD_HANDLE ) then 
  673.       thread_kill( Players_drug_effect_rampoff_thread_handles[triggerer_name] ) 
  674.       Players_drug_effect_rampoff_thread_handles[triggerer_name] = INVALID_THREAD_HANDLE 
  675.    end 
  676.  
  677.    -- Enable the override 
  678.    drug_enable_disable_effect_override( true, sync_type ) 
  679.  
  680.    drug_effect_set_override_values( LIGHT_DRUG_EFFECT_STRENGTHS[BOOZE_INDEX], 
  681.                                     LIGHT_DRUG_EFFECT_STRENGTHS[WEED_INDEX], sync_type ) 
  682. end 
  683.  
  684. -- Activates the medium drug effect on the player who wanders near a lab. 
  685. -- 
  686. function ss05_activate_medium_drug_effect( triggerer_name ) 
  687.    local sync_type = sync_from_player( triggerer_name ) 
  688.  
  689.    -- Stop any rampoff that might be enabled 
  690.    if ( Players_drug_effect_rampoff_thread_handles[triggerer_name] ~= INVALID_THREAD_HANDLE ) then 
  691.       thread_kill( Players_drug_effect_rampoff_thread_handles[triggerer_name] ) 
  692.       Players_drug_effect_rampoff_thread_handles[triggerer_name] = INVALID_THREAD_HANDLE 
  693.    end 
  694.  
  695.    -- Enable the override 
  696.    drug_enable_disable_effect_override( true, sync_type ) 
  697.  
  698.    drug_effect_set_override_values( MEDIUM_DRUG_EFFECT_STRENGTHS[BOOZE_INDEX], 
  699.                                     MEDIUM_DRUG_EFFECT_STRENGTHS[WEED_INDEX], sync_type ) 
  700. end 
  701.  
  702. -- Activates the light drug effect rampoff for the player who wanders out of the light 
  703. -- drug radius. 
  704. -- 
  705. function ss05_start_light_drug_effect_rampoff( triggerer_name ) 
  706.    -- Check to see if the player already has a rampoff turned on... 
  707.    -- If so, then kill the thread 
  708.    if ( Players_drug_effect_rampoff_thread_handles[triggerer_name] ~= INVALID_THREAD_HANDLE ) then 
  709.       thread_kill( Players_drug_effect_rampoff_thread_handles[triggerer_name] ) 
  710.       Players_drug_effect_rampoff_thread_handles[triggerer_name] = INVALID_THREAD_HANDLE 
  711.    end 
  712.  
  713.    local sync_type = sync_from_player( triggerer_name ) 
  714.  
  715.    -- Start a new rampoff thread 
  716.    Players_drug_effect_rampoff_thread_handles[triggerer_name] = thread_new( "ss05_drug_rampoff", LIGHT_DRUG_EFFECT, sync_type )									     
  717. end 
  718.  
  719. -- Activates the medium drug effect rampoff for the player who wanders out of the medium 
  720. -- drug radius. 
  721. -- 
  722. function ss05_start_medium_drug_effect_rampoff( triggerer_name ) 
  723.    -- Check to see if the player already has a rampoff turned on... 
  724.    -- If so, then kill the thread 
  725.    if ( Players_drug_effect_rampoff_thread_handles[triggerer_name] ~= INVALID_THREAD_HANDLE ) then 
  726.       thread_kill( Players_drug_effect_rampoff_thread_handles[triggerer_name] ) 
  727.       Players_drug_effect_rampoff_thread_handles[triggerer_name] = INVALID_THREAD_HANDLE 
  728.    end 
  729.  
  730.    local sync_type = sync_from_player( triggerer_name ) 
  731.  
  732.    -- Start a new rampoff thread 
  733.    Players_drug_effect_rampoff_thread_handles[triggerer_name] = thread_new( "ss05_drug_rampoff", MEDIUM_DRUG_EFFECT, sync_type ) 
  734. end 
  735.  
  736. -- This function does the drug rampoff for a drug effect on a player. 
  737. -- 
  738. -- drug_initial_effect_type: Not booze or weed - light or medium drug effects. 
  739. -- 
  740. function ss05_drug_rampoff( drug_initial_effect_type, sync_type ) 
  741.    -- Get the starting strength values for the rampoff 
  742.    local initial_strengths = { [BOOZE_INDEX] = DRUG_EFFECT_STRENGTHS[drug_initial_effect_type][BOOZE_INDEX], 
  743.                                [WEED_INDEX] = DRUG_EFFECT_STRENGTHS[drug_initial_effect_type][WEED_INDEX] } 
  744.  
  745.    local cur_strengths = { [BOOZE_INDEX] = initial_strengths[BOOZE_INDEX], [WEED_INDEX] = initial_strengths[WEED_INDEX] } 
  746.  
  747.    -- Find out how many units of strength drop per second 
  748.    local dropoffs_per_second = { [BOOZE_INDEX] = initial_strengths[BOOZE_INDEX] / DRUG_EFFECT_FADE_TIME[drug_initial_effect_type], 
  749.                                  [WEED_INDEX] = initial_strengths[WEED_INDEX] / DRUG_EFFECT_FADE_TIME[drug_initial_effect_type] } 
  750.  
  751.    local dropoff_time_remaining = DRUG_EFFECT_FADE_TIME[drug_initial_effect_type] 
  752.  
  753.    while ( dropoff_time_remaining > 0 ) do 
  754.       local frametime = get_frame_time() 
  755.  
  756.       cur_strengths[BOOZE_INDEX] = cur_strengths[BOOZE_INDEX] - ( dropoffs_per_second[BOOZE_INDEX] * frametime ) 
  757.       cur_strengths[WEED_INDEX] = cur_strengths[WEED_INDEX] - ( dropoffs_per_second[WEED_INDEX] * frametime ) 
  758.  
  759.       if ( cur_strengths[BOOZE_INDEX] < 0 ) then 
  760.          cur_strengths[BOOZE_INDEX] = 0 
  761.       end 
  762.       if ( cur_strengths[WEED_INDEX] < 0 ) then 
  763.          cur_strengths[WEED_INDEX] = 0 
  764.       end 
  765.  
  766.       drug_effect_set_override_values( cur_strengths[BOOZE_INDEX], cur_strengths[WEED_INDEX], sync_type ) 
  767.  
  768.       dropoff_time_remaining = dropoff_time_remaining - frametime 
  769.       delay( 0 ) 
  770.    end 
  771.  
  772.    -- Disable the override; we've ramped off completely 
  773.    drug_enable_disable_effect_override( false, sync_type ) 
  774. end 
  775.  
  776. -- Sets up a lab's light drug effect radius. 
  777. -- 
  778. -- lab_index: The index of the lab whose light drug effect we want to enable. 
  779. -- 
  780. function ss05_set_light_drug_effect( lab_index ) 
  781.    -- Activate the light drug effect trigger for this lab 
  782.    trigger_enable( LAB_LIGHT_DRUG_EFFECT_TRIGGERS[lab_index], true ) 
  783.    on_trigger( "ss05_activate_light_drug_effect", LAB_LIGHT_DRUG_EFFECT_TRIGGERS[lab_index] ) 
  784.    on_trigger_exit( "ss05_start_light_drug_effect_rampoff", LAB_LIGHT_DRUG_EFFECT_TRIGGERS[lab_index] ) 
  785. end 
  786.  
  787. -- Sets up a lab's medium drug effect radius. Disables the light drug effect for this lab. 
  788. -- 
  789. -- lab_index: The index of the lab whose medium drug effect we want to enable. 
  790. -- 
  791. function ss05_set_medium_drug_effect( lab_index ) 
  792.    -- Disable the light drug effect trigger and enable the medium drug effect trigger for this lab 
  793.    trigger_enable( LAB_LIGHT_DRUG_EFFECT_TRIGGERS[lab_index], false ) 
  794.  
  795.    trigger_enable( LAB_MEDIUM_DRUG_EFFECT_TRIGGERS[lab_index], true ) 
  796.    on_trigger( "ss05_activate_medium_drug_effect", LAB_MEDIUM_DRUG_EFFECT_TRIGGERS[lab_index] ) 
  797.    on_trigger_exit( "ss05_start_medium_drug_effect_rampoff", LAB_MEDIUM_DRUG_EFFECT_TRIGGERS[lab_index] ) 
  798. end 
  799.  
  800. function ss05_setup_first_lab_interior() 
  801.    -- Add callbacks for the chemical storage tanks 
  802.    for index, name in LAB_ONE_STORAGE_NAMES do 
  803.       mesh_mover_reset( name ) 
  804.       on_mover_destroyed( "ss05_lab_one_storage_destroyed", name ) 
  805.       marker_add_mover( name, MINIMAP_ICON_KILL, INGAME_EFFECT_KILL, SYNC_ALL ) 
  806.    end 
  807.  
  808.    -- No notoriety spawns during lab attack 
  809.    notoriety_force_no_spawn( ENEMY_GANG, true ) 
  810. end 
  811.  
  812. function ss05_setup_second_lab_interior() 
  813.      -- Reset the chem storage barrels, mark them, and add callbacks for their destruction 
  814.    for index, name in LAB_TWO_STORAGE_NAMES do 
  815.       mesh_mover_reset( name ) 
  816.       on_mover_destroyed( "ss05_lab_two_storage_destroyed", name ) 
  817.       marker_add_mover( name, MINIMAP_ICON_KILL, INGAME_EFFECT_KILL, SYNC_ALL ) 
  818.    end 
  819.  
  820.     -- No notoriety spawns during lab attack 
  821.    notoriety_force_no_spawn( ENEMY_GANG, true ) 
  822. end 
  823.  
  824. function ss05_setup_third_lab_interior() 
  825.    for index, name in pairs( LAB_THREE_DEFENDER_MEMBERS ) do 
  826.       on_death( "ss05_lab_three_defender_died", name ) 
  827.    end 
  828.    for index, name in pairs( LAB_THREE_ENCLOSED_LAB_MEMBERS ) do 
  829.       on_death( "ss05_lab_three_defender_died", name ) 
  830.    end 
  831.    -- Enable the next trigger to guide the player to the main area 
  832.    marker_remove_trigger( LAB_THREE_ENTRANCE_TRIGGER, SYNC_ALL ) 
  833.    trigger_enable( LAB_THREE_LOCATION_TRIGGER, true ) 
  834.    on_trigger( "ss05_inside_lab_three", LAB_THREE_LOCATION_TRIGGER ) 
  835.    marker_add_trigger( LAB_THREE_LOCATION_TRIGGER, MINIMAP_ICON_LOCATION, INGAME_EFFECT_VEHICLE_LOCATION, SYNC_ALL ) 
  836.    waypoint_add( LAB_THREE_LOCATION_TRIGGER, SYNC_ALL ) 
  837.  
  838.    -- Enable the trigger at the top of the stairs - the player hears the Samedi planning to lock the door 
  839.    trigger_enable( LAB_THREE_TOP_OF_STAIRS_TRIGGER, true ) 
  840.    on_trigger( "ss05_play_lab_techs_hiding_dialog", LAB_THREE_TOP_OF_STAIRS_TRIGGER ) 
  841.  
  842.    -- Enable the "Flush out the room" trigger 
  843.    trigger_enable( LAB_THREE_FLUSH_OUT_SWITCH, true ) 
  844.    on_trigger( "ss05_activated_flush_out_switch", LAB_THREE_FLUSH_OUT_SWITCH ) 
  845.  
  846.    -- Enable the enclosed lab trigger, which will let the player he needs to flush out the 
  847.    -- gang members in the enclosed lab 
  848.    trigger_enable( LAB_THREE_ENCLOSED_LAB_ENTRANCE_TRIGGER, true ) 
  849.    on_trigger( "ss05_reached_enclosed_lab_entrance", LAB_THREE_ENCLOSED_LAB_ENTRANCE_TRIGGER ) 
  850.    -- Lock the door 
  851.    door_lock( LAB_THREE_DOOR_NAME, true ) 
  852.  
  853.    -- This is used to prevent notoriety spawns from resuming unless the players 
  854.    -- leave the lab 
  855.    ss05_setup_lab3_area_trigger() 
  856.  
  857.    -- No notoriety spawns during lab attack 
  858.    notoriety_force_no_spawn( ENEMY_GANG, true ) 
  859. end 
  860.  
  861. function ss05_setup_fourth_lab_interior() 
  862.    trigger_enable( LAB_FOUR_AREA1, true ) 
  863.    trigger_enable( LAB_FOUR_AREA2, true ) 
  864.    on_trigger( "ss05_entered_lab4_area1", LAB_FOUR_AREA1 ) 
  865.    on_trigger_exit( "ss05_left_lab4_area1", LAB_FOUR_AREA1 ) 
  866.    on_trigger( "ss05_entered_lab4_area2", LAB_FOUR_AREA2 ) 
  867.    on_trigger_exit( "ss05_left_lab4_area2", LAB_FOUR_AREA2 ) 
  868.  
  869.    -- Setup the locked door trigger to let the player know that it's locked 
  870.    trigger_enable( LAB_FOUR_BEFORE_DOOR_UNLOCKED_TRIGGER, true ) 
  871.    on_trigger( "ss05_door_locked", LAB_FOUR_BEFORE_DOOR_UNLOCKED_TRIGGER ) 
  872.  
  873.    -- Lock the exit door and the door to the drug room 
  874.    door_lock( LAB_FOUR_EXIT_DOOR, true ) 
  875.    door_close( LAB_FOUR_MIDDLE_DOOR ) 
  876.    door_lock( LAB_FOUR_MIDDLE_DOOR, true ) 
  877.    door_lock( LAB_FOUR_DOOR_NEAR_BARREL, true ) 
  878.  
  879.    -- TODO: Activate callback for reaching the inside of the building to lock both doors 
  880.    -- and do the chunk swapping. 
  881.    -- trigger_enable( LAB_FOUR_CHUNK_SWAP_TRIGGER, true ) 
  882.    -- on_trigger( "start_fire", LAB_FOUR_CHUNK_SWAP_TRIGGER ) 
  883.  
  884.    -- Add callback on death for all of the techs 
  885.    for index, name in LAB_FOUR_TECH_MEMBERS do 
  886.       npc_leash_set_unbreakable( name, true ) 
  887.       on_death( "ss05_lab_four_tech_killed", name ) 
  888.    end 
  889.  
  890.    -- Enable the guide triggers 
  891.    for trigger_index, trigger_name in pairs( LAB_FOUR_GUIDE_TRIGGERS ) do 
  892.       trigger_enable( trigger_name, true ) 
  893.       on_trigger( "ss05_reached_guide_trigger0"..trigger_index, trigger_name ) 
  894.    end 
  895.    -- Mark the first guide trigger 
  896.    marker_add_trigger( LAB_FOUR_GUIDE_TRIGGERS[1], MINIMAP_ICON_LOCATION, INGAME_EFFECT_VEHICLE_LOCATION, SYNC_ALL ) 
  897.  
  898.    trigger_enable( LAB_FOUR_LOCATION_TRIGGER, true ) 
  899.    on_trigger( "ss05_reached_lab_four_entrance", LAB_FOUR_LOCATION_TRIGGER ) 
  900. end 
  901.  
  902. function ss05_reached_guide_trigger01( triggerer_name, trigger_name ) 
  903.    -- Disable and unmark this trigger 
  904.    marker_remove_trigger( trigger_name, SYNC_ALL ) 
  905.    trigger_enable( trigger_name, false ) 
  906.  
  907.    -- Mark the next trigger 
  908.    marker_add_trigger( LAB_FOUR_GUIDE_TRIGGERS[2], MINIMAP_ICON_LOCATION, INGAME_EFFECT_LOCATION, SYNC_ALL ) 
  909.  
  910.    -- Disable notoriety here, possibly 
  911.    notoriety_force_no_spawn( ENEMY_GANG, true ) 
  912. end 
  913. function ss05_reached_guide_trigger02( triggerer_name, trigger_name ) 
  914.    -- Disable and unmark this trigger 
  915.    marker_remove_trigger( trigger_name, SYNC_ALL ) 
  916.    trigger_enable( trigger_name, false ) 
  917.  
  918.    -- Disable and unmark the previous trigger in case we hit this one first 
  919.    marker_remove_trigger( LAB_FOUR_GUIDE_TRIGGERS[1], SYNC_ALL ) 
  920.    trigger_enable( LAB_FOUR_GUIDE_TRIGGERS[1], false ) 
  921.  
  922.    -- Mark the next trigger 
  923.    marker_add_trigger( LAB_FOUR_LOCATION_TRIGGER, MINIMAP_ICON_LOCATION, INGAME_EFFECT_LOCATION, SYNC_ALL ) 
  924.  
  925.    -- Disable notoriety here, possibly 
  926.    notoriety_force_no_spawn( ENEMY_GANG, true ) 
  927. end 
  928.  
  929. function ss05_unleash_all( member_names ) 
  930.    for index, member_name in pairs( member_names ) do 
  931.       if ( character_is_dead( member_name ) == false ) then 
  932.          npc_leash_remove( member_name ) 
  933.       end 
  934.    end 
  935. end 
  936.  
  937. function ss05_maybe_release_group( group_name ) 
  938.    if ( group_is_loaded( group_name ) ) then 
  939.       release_to_world( group_name ) 
  940.    end 
  941. end 
  942.  
  943. function ss05_maybe_release_lab_groups( lab_index ) 
  944.    if ( lab_index == 1 ) then 
  945.       ss05_maybe_release_group( LAB_ONE_OUTSIDE_GROUP ) 
  946.       ss05_maybe_release_group( LAB_ONE_INSIDE_GROUP ) 
  947.    elseif ( lab_index == 2 ) then 
  948.       ss05_maybe_release_group( LAB_TWO_FLOOR_ONE_ATTACKERS ) 
  949.       ss05_maybe_release_group( LAB_TWO_FLOOR_TWO_ATTACKERS ) 
  950.    elseif ( lab_index == 3 ) then 
  951.       ss05_maybe_release_group( LAB_THREE_INITIAL_DEFENDERS_GROUP ) 
  952.       ss05_maybe_release_group( LAB_THREE_ENCLOSED_LAB_GROUP ) 
  953.       ss05_maybe_release_group( LAB_THREE_DEFENDERS_GROUP ) 
  954.       ss05_maybe_release_group( LAB_THREE_AFTER_LAB_ATTACK_GROUP ) 
  955.    elseif ( lab_index == 4 ) then 
  956.       ss05_maybe_release_group( LAB_FOUR_OUTSIDE_GROUP ) 
  957.       ss05_maybe_release_group( LAB_FOUR_ESCAPING_TECH_GROUP ) 
  958.       ss05_maybe_release_group( LAB_FOUR_PLAYERS_CAR_GROUP ) 
  959.       ss05_maybe_release_group( LAB_FOUR_DEFENDERS_GROUP ) 
  960.       ss05_maybe_release_group( LAB_FOUR_TECHS_GROUP ) 
  961.    end 
  962. end 
  963.  
  964. function ss05_create_lab_groups_hidden( lab_index ) 
  965.    if ( lab_index == 1 ) then 
  966.       group_create( LAB_ONE_OUTSIDE_GROUP, true ) 
  967.       group_create( LAB_ONE_INSIDE_GROUP, true ) 
  968.    elseif ( lab_index == 2 ) then 
  969.       -- Create the second lab's groups 
  970.       group_create_hidden( LAB_TWO_FLOOR_ONE_ATTACKERS, true ) 
  971.       group_create_hidden( LAB_TWO_FLOOR_TWO_ATTACKERS, true ) 
  972.    elseif ( lab_index == 3 ) then 
  973.       -- Create the third lab's groups 
  974.       group_create_hidden( LAB_THREE_INITIAL_DEFENDERS_GROUP, true ) 
  975.       group_create_hidden( LAB_THREE_ENCLOSED_LAB_GROUP, true ) 
  976.       group_create_hidden( LAB_THREE_DEFENDERS_GROUP, true ) 
  977.       group_create_hidden( LAB_THREE_AFTER_LAB_ATTACK_GROUP, true ) 
  978.    elseif ( lab_index == 4 ) then 
  979.       -- Create the final lab's groups 
  980.       group_create_hidden( LAB_FOUR_ESCAPING_TECH_GROUP, true ) 
  981.       group_create_hidden( LAB_FOUR_PLAYERS_CAR_GROUP, true ) 
  982.       group_create_hidden( LAB_FOUR_DEFENDERS_GROUP, true ) 
  983.       group_create_hidden( LAB_FOUR_TECHS_GROUP, true ) 
  984.    end 
  985. end 
  986.  
  987. -- Switches the mission to a new state. 
  988. -- 
  989. -- new_state: The state to switch to. 
  990. -- 
  991. function ss05_switch_state( new_state ) 
  992.  
  993.    -- In this state, the player is guided to the first drug lab 
  994.    if ( new_state == MS_TRAVEL_TO_FIRST_LAB ) then 
  995.       -- Create the trigger and the location, and guide the player there 
  996.       trigger_enable( LAB_ONE_LOCATION_TRIGGER, true ) 
  997.       on_trigger( "ss05_reached_lab_one", LAB_ONE_LOCATION_TRIGGER ) 
  998.       marker_add_trigger( LAB_ONE_LOCATION_TRIGGER, MINIMAP_ICON_LOCATION, "", SYNC_ALL ) 
  999.       waypoint_add( LAB_ONE_LOCATION_TRIGGER, SYNC_ALL ) 
  1000.       mission_help_table( HT_GO_TO_FIRST_LAB, "", "", SYNC_ALL ) 
  1001.       objective_text(0, HT_X_OF_Y_LABS_DESTROYED, 0, LAB_COUNT, SYNC_ALL ) 
  1002.  
  1003.    -- When the player reaches the first lab, the chemical storage tanks are marked. 
  1004.    -- Additionally, the gang members outside attack him. 
  1005.    elseif ( new_state == MS_REACHED_FIRST_LAB ) then 
  1006.       mission_help_table( HT_DESTROY_STORAGE_CONTAINERS ) 
  1007.       ss05_setup_first_lab_interior() 
  1008.  
  1009.       -- Update the player's objectives 
  1010.       waypoint_remove( SYNC_ALL ) 
  1011.       trigger_enable( LAB_ONE_LOCATION_TRIGGER, false ) 
  1012.  
  1013.       mission_set_checkpoint( CP_REACHED_LAB_ONE ) 
  1014.  
  1015.       -- Have the gang members attack the closest player 
  1016.       local distance, player = get_dist_closest_player_to_object( LAB_ONE_LOCATION_TRIGGER ) 
  1017.       for index, name in LAB_ONE_OUTSIDE_GROUP_MEMBERS do 
  1018.          attack_safe( name, player ) 
  1019.          local attack_delay = rand_float( 1, 2 ) 
  1020.          delay( attack_delay ) 
  1021.       end 
  1022.  
  1023.       notoriety_set_min( ENEMY_GANG, FIRST_LAB_MIN_NOTORIETY_LEVEL ) 
  1024.    -- When the player destroys the first lab, 
  1025.    -- update his objective text and then switch the state 
  1026.    elseif ( new_state == MS_DESTROYED_FIRST_LAB ) then 
  1027.       ss05_unleash_all( LAB_ONE_INSIDE_GROUP_MEMBERS ) 
  1028.  
  1029.       notoriety_set_min( ENEMY_GANG, MIN_NOTORIETY_LEVEL ) 
  1030.  
  1031.       delay( LAB_DESTROYED_OBJECTIVE_UPDATE_DELAY_SECONDS ) 
  1032.       objective_text(0, HT_X_OF_Y_LABS_DESTROYED, 1, LAB_COUNT, SYNC_ALL ) 
  1033.  
  1034.       -- Notoriety spawns should be on between labs 
  1035.       notoriety_force_no_spawn( ENEMY_GANG, false ) 
  1036.  
  1037.       ss05_switch_state( MS_TRAVEL_TO_SECOND_LAB ) 
  1038.    -- This state leads the player to the second lab and readies it for his arrival 
  1039.    elseif ( new_state == MS_TRAVEL_TO_SECOND_LAB ) then 
  1040.       -- Lead the player to the next objective 
  1041.       mission_help_table( HT_HEAD_TO_SECOND_LAB ) 
  1042.       waypoint_add( LAB_TWO_LOCATION_TRIGGER, SYNC_ALL ) 
  1043.  
  1044.       -- Activate the trigger so that the mission is updated when the player 
  1045.       -- reaches the second lab 
  1046.       trigger_enable( LAB_TWO_LOCATION_TRIGGER, true ) 
  1047.       on_trigger( "ss05_reached_lab_two", LAB_TWO_LOCATION_TRIGGER ) 
  1048.       marker_add_trigger( LAB_TWO_LOCATION_TRIGGER, MINIMAP_ICON_LOCATION, "", SYNC_ALL ) 
  1049.  
  1050.       -- Create the lab's groups 
  1051.       ss05_maybe_release_lab_groups( 1 ) 
  1052.       ss05_create_lab_groups_hidden( 2 ) 
  1053.       group_show( LAB_TWO_FLOOR_ONE_ATTACKERS ) 
  1054.       wander_start( LAB_TWO_LOBBY_GUARD, LAB_TWO_LOBBY_GUARD, LOBBY_GUARD_WANDER_RADIUS_METERS ) 
  1055.       ss05_lock_lab_two_entrances( false ) 
  1056.  
  1057.    -- Sets up the second lab on the player's arrival.  
  1058.    elseif ( new_state == MS_REACHED_SECOND_LAB ) then 
  1059.       ss05_setup_second_lab_interior() 
  1060.       waypoint_remove( SYNC_ALL ) 
  1061.  
  1062.       mission_help_table( HT_DESTROY_STORAGE_CONTAINERS ) 
  1063.       mission_set_checkpoint( CP_REACHED_LAB_TWO ) 
  1064.       group_show( LAB_TWO_FLOOR_TWO_ATTACKERS ) 
  1065.    -- When the player destroys the second lab, 
  1066.    -- update his objective text and then switch the state 
  1067.    elseif ( new_state == MS_DESTROYED_SECOND_LAB ) then 
  1068.       npc_leash_remove( LAB_TWO_LOBBY_GUARD ) 
  1069.       ss05_unleash_all( LAB_TWO_DEFENDER_MEMBERS ) 
  1070.  
  1071.       delay( LAB_DESTROYED_OBJECTIVE_UPDATE_DELAY_SECONDS ) 
  1072.       objective_text(0, HT_X_OF_Y_LABS_DESTROYED, 2, LAB_COUNT, SYNC_ALL ) 
  1073.  
  1074.       -- Notoriety spawns should be on between labs 
  1075.       notoriety_force_no_spawn( ENEMY_GANG, false ) 
  1076.  
  1077.       ss05_switch_state( MS_TRAVEL_TO_THIRD_LAB ) 
  1078.    -- This state leads the player to the third lab. 
  1079.    elseif ( new_state == MS_TRAVEL_TO_THIRD_LAB ) then 
  1080.       -- Guide the player to the third lab, and set up the triggers so that the mission will be updated when 
  1081.       -- the player reaches the third lab 
  1082.       waypoint_add( LAB_THREE_ENTRANCE_TRIGGER, SYNC_ALL ) 
  1083.       trigger_enable( LAB_THREE_ENTRANCE_TRIGGER, true ) 
  1084.       on_trigger( "ss05_reached_lab_three", LAB_THREE_ENTRANCE_TRIGGER ) 
  1085.       marker_add_trigger( LAB_THREE_ENTRANCE_TRIGGER, MINIMAP_ICON_LOCATION, INGAME_EFFECT_VEHICLE_LOCATION, SYNC_ALL ) 
  1086.  
  1087.       mission_help_table( HT_DESTROY_THIRD_LAB, "", "", SYNC_ALL ) 
  1088.  
  1089.       -- Create the lab's groups 
  1090.       ss05_maybe_release_lab_groups( 2 ) 
  1091.       ss05_create_lab_groups_hidden( 3 ) 
  1092.       group_show( LAB_THREE_INITIAL_DEFENDERS_GROUP ) 
  1093.  
  1094.       for index, name in pairs( LAB_THREE_INITIAL_DEFENDER_MEMBERS ) do 
  1095.          on_death( "ss05_lab_three_defender_died", name ) 
  1096.       end 
  1097.    -- When the player destroys the third lab, 
  1098.    -- update his objective text and then switch the state 
  1099.    elseif ( new_state == MS_REACHED_THIRD_LAB ) then 
  1100.       waypoint_remove( SYNC_ALL ) 
  1101.  
  1102.       -- Show the defenders 
  1103.       group_show( LAB_THREE_ENCLOSED_LAB_GROUP ) 
  1104.       group_show( LAB_THREE_DEFENDERS_GROUP ) 
  1105.  
  1106.       ss05_setup_third_lab_interior() 
  1107.  
  1108.       mission_set_checkpoint( CP_REACHED_LAB_THREE ) 
  1109.    -- When the player destroys the third lab, 
  1110.    -- update his objective text and then switch the state 
  1111.    elseif ( new_state == MS_DESTROYED_THIRD_LAB ) then 
  1112.       ss05_unleash_all( LAB_THREE_DEFENDER_MEMBERS ) 
  1113.       ss05_unleash_all( LAB_THREE_INITIAL_DEFENDER_MEMBERS ) 
  1114.  
  1115.       delay( LAB_DESTROYED_OBJECTIVE_UPDATE_DELAY_SECONDS ) 
  1116.       objective_text(0, HT_X_OF_Y_LABS_DESTROYED, 3, LAB_COUNT, SYNC_ALL ) 
  1117.  
  1118.       if ( ss05_both_players_in_lab3_area() == false ) then 
  1119.          -- Notoriety spawns should be on, because at least one player 
  1120.          -- is out of the lab 
  1121.          notoriety_force_no_spawn( ENEMY_GANG, false ) 
  1122.          ss05_clear_lab3_area_trigger() 
  1123.          mission_debug( "enabled notoriety spawning - from state" ) 
  1124.       end 
  1125.  
  1126.       ss05_switch_state( MS_TRAVEL_TO_FOURTH_LAB ) 
  1127.    elseif ( new_state == MS_TRAVEL_TO_FOURTH_LAB ) then 
  1128.       mission_help_table( HT_DESTROY_FOURTH_LAB, "", "", SYNC_ALL ) 
  1129.  
  1130.       -- Activate the "reached" trigger, and guide the player toward it 
  1131.       trigger_enable( LAB_FOUR_NEAR_TRIGGER, true ) 
  1132.       on_trigger( "ss05_reached_lab_four", LAB_FOUR_NEAR_TRIGGER ) 
  1133.       marker_add_trigger( LAB_FOUR_NEAR_TRIGGER, MINIMAP_ICON_LOCATION, "", SYNC_ALL ) 
  1134.       waypoint_add( LAB_FOUR_NEAR_TRIGGER, SYNC_ALL ) 
  1135.  
  1136.       -- Create the lab's groups 
  1137.       ss05_maybe_release_lab_groups( 3 ) 
  1138.       ss05_create_lab_groups_hidden( 4 ) 
  1139.    elseif ( new_state == MS_REACHED_FOURTH_LAB ) then 
  1140.       waypoint_remove( SYNC_ALL ) 
  1141.  
  1142.       marker_remove_trigger( LAB_FOUR_NEAR_TRIGGER ) 
  1143.  
  1144.       ss05_setup_fourth_lab_interior() 
  1145.       mission_set_checkpoint( CP_REACHED_LAB_FOUR ) 
  1146.       door_lock( LAB_FOUR_ENTRANCE_DOOR, false ) 
  1147.  
  1148.    -- The last state - chase down and kill the head tech 
  1149.    elseif ( new_state == MS_TECH_ESCAPING ) then 
  1150.       for index, firetruck_name in pairs( FIRETRUCK_NAMES ) do 
  1151.          vehicle_enter_group_teleport( FIRETRUCKS_FIREFIGHTERS[index], firetruck_name )       
  1152.       end 
  1153.       trigger_enable( FIRETRUCK_START_PATH_TRIGGER, true ) 
  1154.       trigger_enable( FIRETRUCK_MID_PATH_TRIGGER, true ) 
  1155.       trigger_enable( FIRETRUCK_END_PATHS_TRIGGER, true ) 
  1156.       on_trigger( "ss05_firetruck_start_pathing", FIRETRUCK_START_PATH_TRIGGER ) 
  1157.       on_trigger( "ss05_mid_firetruck_start_pathing", FIRETRUCK_MID_PATH_TRIGGER ) 
  1158.       on_trigger( "ss05_end_firetrucks_start_pathing", FIRETRUCK_END_PATHS_TRIGGER ) 
  1159.  
  1160.       vehicle_ignore_repulsors(LAB_FOUR_ESCAPE_VEHICLE, true) 
  1161. 		vehicle_infinite_mass(LAB_FOUR_ESCAPE_VEHICLE, true)  
  1162. 		vehicle_suppress_npc_exit( LAB_FOUR_ESCAPE_VEHICLE, true ) 
  1163.       set_ignore_ai_flag( LAB_FOUR_ESCAPEE_TECH, false ) 
  1164.  
  1165.       thread_new( "ss05_tech_escape_thread" ) 
  1166.  
  1167.       delay( 2.0 ) 
  1168.       audio_play_for_character( LAB_FOUR_EXIT_LAB, LOCAL_PLAYER, "voice", false, false ) 
  1169.    elseif ( new_state == MS_FIRST_LAB_CHECKPOINT ) then 
  1170.       mission_help_table( HT_DESTROY_STORAGE_CONTAINERS ) 
  1171.       objective_text( 0, HT_X_OF_Y_DUST_CONTAINERS_DESTROYED, 0, 
  1172.                       INITIAL_LAB_CHEM_STORAGE_COUNT[1], SYNC_ALL ) 
  1173.  
  1174.       notoriety_set_min( ENEMY_GANG, FIRST_LAB_MIN_NOTORIETY_LEVEL ) 
  1175.       ss05_setup_first_lab_interior() 
  1176.    elseif ( new_state == MS_SECOND_LAB_CHECKPOINT ) then 
  1177.       mission_help_table( HT_DESTROY_STORAGE_CONTAINERS ) 
  1178.       objective_text( 0, HT_X_OF_Y_DUST_CONTAINERS_DESTROYED, 0, 
  1179.                       INITIAL_LAB_CHEM_STORAGE_COUNT[2], SYNC_ALL ) 
  1180.  
  1181.       notoriety_set_min( ENEMY_GANG, MIN_NOTORIETY_LEVEL ) 
  1182.       ss05_setup_second_lab_interior() 
  1183.    elseif ( new_state == MS_THIRD_LAB_CHECKPOINT ) then 
  1184.       mission_help_table( HT_DESTROY_STORAGE_CONTAINERS ) 
  1185.       objective_text( 0, HT_X_OF_Y_DUST_CONTAINERS_DESTROYED, 0, 
  1186.                       INITIAL_LAB_CHEM_STORAGE_COUNT[3], SYNC_ALL ) 
  1187.  
  1188.       notoriety_set_min( ENEMY_GANG, MIN_NOTORIETY_LEVEL ) 
  1189.       ss05_setup_third_lab_interior() 
  1190.    elseif ( new_state == MS_FOURTH_LAB_CHECKPOINT ) then 
  1191.       mission_help_table( HT_DESTROY_STORAGE_CONTAINERS ) 
  1192.       objective_text(0, HT_X_OF_Y_LABS_DESTROYED, 3, LAB_COUNT, SYNC_ALL ) 
  1193.  
  1194.       notoriety_set_min( ENEMY_GANG, MIN_NOTORIETY_LEVEL ) 
  1195.        
  1196.       -- Disable notoriety so that the tech doesn't get clogged 
  1197.       notoriety_force_no_spawn( ENEMY_GANG, true ) 
  1198.       ss05_setup_fourth_lab_interior() 
  1199.    end 
  1200. end 
  1201.  
  1202. -- Has the firetruck path on its near-miss path. 
  1203. -- 
  1204. function ss05_firetruck_start_pathing( triggerer_name, trigger_name ) 
  1205.    if ( triggerer_name == LAB_FOUR_ESCAPEE_TECH ) then 
  1206.       trigger_enable( trigger_name, false ) 
  1207. 		thread_new("ss05_fire_chase_explsions") 
  1208.       ss05_firetruck_path( 1 ) 
  1209.    end 
  1210. end 
  1211.  
  1212. function ss05_mid_firetruck_start_pathing( triggerer_name, trigger_name ) 
  1213.    if ( triggerer_name == LAB_FOUR_ESCAPEE_TECH ) then 
  1214.       trigger_enable( trigger_name, false ) 
  1215.  
  1216.       ss05_firetruck_path( 4 ) 
  1217.    end 
  1218. end 
  1219.  
  1220. function ss05_end_firetrucks_start_pathing( triggerer_name, trigger_name ) 
  1221.    if ( triggerer_name == LAB_FOUR_ESCAPEE_TECH ) then 
  1222.       trigger_enable( trigger_name, false ) 
  1223.  
  1224.       thread_new( "ss05_firetruck_path", 2 ) 
  1225.       thread_new( "ss05_firetruck_path", 3 ) 
  1226.    end 
  1227. end 
  1228.  
  1229. function ss05_firetruck_path( truck_index ) 
  1230.    vehicle_pathfind_to( FIRETRUCK_NAMES[truck_index], FIRETRUCK_PATHS[truck_index], true, true ) 
  1231. end 
  1232.  
  1233.  
  1234. -- Called when a player reaches the entrance to lab 4. 
  1235. -- Guides the player to the next goal - killing all of the 
  1236. -- drug techs - by marking them. 
  1237. -- 
  1238. function ss05_reached_lab_four_entrance( triggerer_name, trigger_name ) 
  1239.    group_show( LAB_FOUR_DEFENDERS_GROUP ) 
  1240.    group_show( LAB_FOUR_TECHS_GROUP ) 
  1241.  
  1242.    for trigger_index, trigger_name in pairs( LAB_FOUR_GUIDE_TRIGGERS ) do 
  1243.       trigger_enable( trigger_name, false ) 
  1244.       marker_remove_trigger( trigger_name, SYNC_ALL ) 
  1245.    end 
  1246.  
  1247.    -- Objectives 
  1248.    mission_help_table( HT_KILL_SAMEDI_TECHS ) 
  1249.    objective_text( 0, HT_X_OF_Y_TECHS_KILLED, 
  1250.                    0, LAB_FOUR_INITIAL_TECH_COUNT, SYNC_ALL ) 
  1251.  
  1252.    wander_start( LAB_FOUR_ENTRYWAY_TECH_NAME, LAB_FOUR_ENTRYWAY_TECH_NAME, 
  1253.                  LAB_FOUR_ENTRYWAY_NPCS_WANDER_RADIUS_METERS ) 
  1254.  
  1255.    for index, name in pairs( LAB_FOUR_ENTRYWAY_DEFENDERS ) do 
  1256.       wander_start( name, name, LAB_FOUR_ENTRYWAY_NPCS_WANDER_RADIUS_METERS ) 
  1257.    end 
  1258.  
  1259.    -- Add markers for all of the techs 
  1260.    for index, name in LAB_FOUR_TECH_MEMBERS do 
  1261.       marker_add_npc( name, MINIMAP_ICON_KILL, INGAME_EFFECT_KILL, SYNC_ALL ) 
  1262.       -- dont_leave_cower = true, ignore_distance = true 
  1263.       cower( name, triggerer_name, true, true ) 
  1264.    end 
  1265.  
  1266.    waypoint_remove( SYNC_ALL ) 
  1267.    marker_remove_trigger( trigger_name, SYNC_ALL ) 
  1268.    trigger_enable( trigger_name, false ) 
  1269.  
  1270.    -- Disable notoriety here, possibly 
  1271.    notoriety_force_no_spawn( ENEMY_GANG, true ) 
  1272. end 
  1273.  
  1274. function ss05_set_chase_enter_callbacks( callback_name ) 
  1275.    on_vehicle_enter( callback_name, LOCAL_PLAYER ) 
  1276.    if ( coop_is_active() ) then 
  1277.       on_vehicle_enter( callback_name, REMOTE_PLAYER ) 
  1278.    end 
  1279.    on_vehicle_enter( callback_name, PLAYER_CHASE_CAR ) 
  1280. end 
  1281.  
  1282. function ss05_player_entered_car_chase_tech( character_name ) 
  1283.    if ( character_name == LOCAL_PLAYER or character_name == REMOTE_PLAYER ) then 
  1284.       local cur_char_dist_to_vehicle = get_dist_char_to_vehicle( character_name, LAB_FOUR_ESCAPE_VEHICLE ) 
  1285.       --  
  1286.       if ( cur_char_dist_to_vehicle < LAB_TECH_CHASE_DISTANCE_METERS ) then 
  1287.          vehicle_speed_override( LAB_FOUR_ESCAPE_VEHICLE, LAB_TECH_CHASE_NORMAL_SPEED_MPH ) 
  1288.          ss05_set_chase_enter_callbacks( "" ) 
  1289.       end 
  1290.    end 
  1291. end 
  1292.  
  1293. function ss05_tech_invincible() 
  1294. 	turn_invulnerable( LAB_FOUR_ESCAPE_VEHICLE ) 
  1295. 	turn_invulnerable( LAB_FOUR_ESCAPEE_TECH ) 
  1296. 	delay( 5.0 ) 
  1297. 	turn_vulnerable( LAB_FOUR_ESCAPE_VEHICLE ) 
  1298. 	turn_vulnerable( LAB_FOUR_ESCAPEE_TECH ) 
  1299. end 
  1300.  
  1301. function ss05_tech_vehicle_unjackable() 
  1302.    set_unjackable_flag( LAB_FOUR_ESCAPE_VEHICLE, true ) 
  1303.    delay( 15 ) 
  1304.    set_unjackable_flag( LAB_FOUR_ESCAPE_VEHICLE, false ) 
  1305. end 
  1306.  
  1307. -- This thread handles the AI for the escaping tech. 
  1308. -- 
  1309. function ss05_tech_escape_thread() 
  1310.    thread_new( "ss05_tech_vehicle_unjackable" ) 
  1311. 	thread_new( "ss05_tech_invincible" ) 
  1312.  
  1313.    audio_play_for_character( LAB_THREE_FINAL_TECH_FLEE, LAB_FOUR_ESCAPEE_TECH, "voice", false, false ) 
  1314.    on_vehicle_exit( "ss05_tech_left_car", LAB_FOUR_ESCAPE_VEHICLE ) 
  1315.  
  1316.    ss05_set_chase_enter_callbacks( "ss05_player_entered_car_chase_tech" ) 
  1317.  
  1318.    -- Add callbacks for the distance 
  1319.    distance_display_on( LAB_FOUR_ESCAPE_VEHICLE, 0, LAB_TECH_CHASE_DISTANCE_METERS, 0, LAB_TECH_CHASE_DISTANCE_METERS, SYNC_ALL ) 
  1320.    on_tailing_good( "ss05_in_range_of_tech" ) 
  1321.    on_tailing_too_far( "ss05_out_of_range_of_tech" ) 
  1322.    delay( LAB_FOUR_TECH_LEAVE_DELAY_SECONDS ) 
  1323.    vehicle_speed_override( LAB_FOUR_ESCAPE_VEHICLE, LAB_TECH_CHASE_INITIAL_SPEED_MPH ) 
  1324.  
  1325. 	local num_escape_paths = sizeof_table( LAB_FOUR_ESCAPE_PATHS ) 
  1326. 	for path_index, path_name in pairs( LAB_FOUR_ESCAPE_PATHS ) do 
  1327. 		-- Normal path - keep going 
  1328. 		if ( path_index < num_escape_paths ) then 
  1329. 		   vehicle_pathfind_to( LAB_FOUR_ESCAPE_VEHICLE, path_name, true, false ) 
  1330. 		-- Final path - stop at the end 
  1331. 		else 
  1332. 		   vehicle_pathfind_to( LAB_FOUR_ESCAPE_VEHICLE, path_name, true, true ) 
  1333. 		end 
  1334. 	end 
  1335.     
  1336.    vehicle_suppress_npc_exit( LAB_FOUR_ESCAPE_VEHICLE, false ) 
  1337.  
  1338.    vehicle_exit( LAB_FOUR_ESCAPEE_TECH ) 
  1339.  
  1340.    local distance = 0 
  1341.    local player_name = LOCAL_PLAYER 
  1342.  
  1343.    distance, player_name = get_dist_closest_player_to_object( LAB_FOUR_ESCAPEE_TECH ) 
  1344.  
  1345.    flee( LAB_FOUR_ESCAPEE_TECH, player_name ) 
  1346. end 
  1347.  
  1348. -- When the tech leaves the car, disable all distance 
  1349. -- failure conditions. 
  1350. -- 
  1351. function ss05_tech_left_car() 
  1352.    hud_timer_stop( 0 ) 
  1353.    distance_display_off(SYNC_ALL) 
  1354.    on_tailing_good( "" ) 
  1355.    on_tailing_too_far( "" ) 
  1356. end 
  1357.  
  1358. -- When the escaping tech is killed, the mission is 
  1359. -- a success. 
  1360. -- 
  1361. function ss05_escaping_tech_killed( tech_name ) 
  1362.    objective_text(0, HT_X_OF_Y_LABS_DESTROYED, 4, LAB_COUNT, SYNC_ALL ) 
  1363.    distance_display_off(SYNC_ALL) 
  1364.    marker_remove_npc( tech_name, SYNC_ALL ) 
  1365.  
  1366.    Mission_won = true 
  1367.    mission_end_success( MISSION_NAME, CT_OUTRO ) 
  1368. end 
  1369.  
  1370. -- Called when the player reaches the first drug lab 
  1371. -- 
  1372. function ss05_reached_lab_one( triggerer_name, trigger_name ) 
  1373.    objective_text( 0, HT_X_OF_Y_DUST_CONTAINERS_DESTROYED, 0, 
  1374.                    INITIAL_LAB_CHEM_STORAGE_COUNT[1], SYNC_ALL ) 
  1375.  
  1376.    trigger_enable( trigger_name, false ) 
  1377.    marker_remove_trigger( trigger_name, SYNC_ALL ) 
  1378.    ss05_switch_state( MS_REACHED_FIRST_LAB ) 
  1379. end 
  1380.  
  1381. -- Called when the player reaches the entrance of 
  1382. -- the second drug lab 
  1383. -- 
  1384. function ss05_reached_lab_two( triggerer_name, trigger_name ) 
  1385.    objective_text( 0, HT_X_OF_Y_DUST_CONTAINERS_DESTROYED, 0, 
  1386.                    INITIAL_LAB_CHEM_STORAGE_COUNT[2], SYNC_ALL ) 
  1387.  
  1388.    trigger_enable( trigger_name, false ) 
  1389.    marker_remove_trigger( trigger_name, SYNC_ALL ) 
  1390.    ss05_switch_state( MS_REACHED_SECOND_LAB ) 
  1391. end 
  1392.  
  1393. -- Called when the player reaches the entrance of 
  1394. -- the third drug lab 
  1395. -- 
  1396. function ss05_reached_lab_three( triggerer_name, trigger_name ) 
  1397.    trigger_enable( trigger_name, false ) 
  1398.    marker_remove_trigger( trigger_name, SYNC_ALL ) 
  1399.  
  1400.    -- Have the defender in the entrance attack the player 
  1401.    attack_safe( LAB_THREE_INITIAL_DEFENDER_MEMBERS[1], triggerer_name, false ) 
  1402.  
  1403.    ss05_switch_state( MS_REACHED_THIRD_LAB ) 
  1404. end 
  1405.  
  1406. -- Called when the player reaches the forth drug lab 
  1407. -- 
  1408. function ss05_reached_lab_four( triggerer_name, trigger_name ) 
  1409.    trigger_enable( trigger_name, false ) 
  1410.    ss05_switch_state( MS_REACHED_FOURTH_LAB ) 
  1411. end 
  1412.  
  1413. -- Called when the player gets to the inside of the third 
  1414. -- drug lab. 
  1415. -- 
  1416. function ss05_inside_lab_three( triggerer_name, trigger_name ) 
  1417.    -- Setup the chemical storage barrels 
  1418.    -- Reset the chem storage barrels, mark them, and add callbacks for their destruction 
  1419.    for index, name in LAB_THREE_STORAGE_NAMES do 
  1420.       mesh_mover_reset( name ) 
  1421.       on_mover_destroyed( "ss05_lab_three_storage_destroyed", name ) 
  1422.       marker_add_mover( name, MINIMAP_ICON_KILL, INGAME_EFFECT_KILL, SYNC_ALL ) 
  1423.    end 
  1424.    mission_help_table( HT_DESTROY_STORAGE_CONTAINERS ) 
  1425.    objective_text( 0, HT_X_OF_Y_DUST_CONTAINERS_DESTROYED, 0, 
  1426.                    INITIAL_LAB_CHEM_STORAGE_COUNT[3], SYNC_ALL ) 
  1427.  
  1428.    waypoint_remove( SYNC_ALL ) 
  1429.  
  1430.    trigger_enable( trigger_name, false ) 
  1431.    marker_remove_trigger( trigger_name, SYNC_ALL ) 
  1432. end 
  1433.  
  1434. -- Called when the player reaches the locked door to the enclosed lab 
  1435. -- area in the third drug labs. Guides the player to flush out the techs 
  1436. -- by pressing a switch. 
  1437. -- 
  1438. function ss05_reached_enclosed_lab_entrance( triggerer_name, trigger_name ) 
  1439.    trigger_enable( trigger_name, false ) 
  1440.    -- Play the "door is locked" sound and delay so that it's heard 
  1441.    audio_play( LOCKED_DOOR_SOUND ) 
  1442.    delay( 1.0 ) 
  1443.  
  1444.    -- Play the conversation if anyone is alive in there 
  1445.    if ( ss05_anyone_alive_in_enclosed_lab() ) then 
  1446.       audio_play_conversation( LAB_THREE_HIDING_TECHS_PLAYER_DIALOG_STREAM ) 
  1447.       ss05_living_enclosed_lab_members_taunt() 
  1448.       audio_play_conversation( LAB_THREE_HIDING_TECHS_TECH_DIALOG_STREAM ) 
  1449.    end 
  1450.    -- Offer some extra explanation in help text and then guide the player to the next objective 
  1451.    mission_help_table( HT_DOOR_LOCKED, "", "", SYNC_ALL ) 
  1452.    marker_add_trigger( LAB_THREE_FLUSH_OUT_SWITCH, MINIMAP_ICON_LOCATION, INGAME_EFFECT_LOCATION, SYNC_ALL ) 
  1453. end 
  1454.  
  1455. -- Called when the player reaches the door in lab 4 that's locked. 
  1456. -- Informs him that he needs to find a key. 
  1457. -- 
  1458. function ss05_door_locked() 
  1459.    mission_help_table( HT_LOCKED_SOMEONE_HAS_KEY ) 
  1460. end 
  1461.  
  1462. -- Plays a voice line informing the player that the lab techs are hiding in the enclosed drug lab. 
  1463. -- 
  1464. function ss05_play_lab_techs_hiding_dialog( triggerer_name, trigger_name ) 
  1465.    trigger_enable( trigger_name, false ) 
  1466.    -- Play "lock the door" on the first member that's alive 
  1467.    for index, member_name in pairs( LAB_THREE_ENCLOSED_LAB_MEMBERS ) do 
  1468.       if ( character_is_dead( member_name ) == false ) then 
  1469.          audio_play_for_character( LAB_THREE_HIDE_IN_THE_LAB, member_name, "voice", false, true ) 
  1470.          return 
  1471.       end 
  1472.    end 
  1473. end 
  1474.  
  1475. function ss05_anyone_alive_in_enclosed_lab() 
  1476.    for index, name in LAB_THREE_ENCLOSED_LAB_MEMBERS do 
  1477.       if ( character_is_dead( name ) == false ) then 
  1478.          return true 
  1479.       end 
  1480.    end 
  1481.    return false 
  1482. end 
  1483.  
  1484. function ss05_living_enclosed_lab_members_taunt() 
  1485.    for index, name in pairs ( LAB_THREE_ENCLOSED_LAB_MEMBERS ) do 
  1486.       if ( character_is_dead( name ) == false ) then 
  1487.          if ( mod( index, 2 ) == 0 ) then 
  1488.             action_play_non_blocking( name, "talk confrontational" ) 
  1489.          else 
  1490.             action_play_non_blocking( name, "talk disrespect" ) 
  1491.          end 
  1492.       end 
  1493.    end 
  1494. end 
  1495.  
  1496. -- Flushes out the techs. 
  1497. -- 
  1498. function ss05_activated_flush_out_switch( triggerer_name, trigger_name ) 
  1499.    -- Disable the "Enclosed Lab Entrance" trigger, because its message makes no 
  1500.    -- sense after this switch is activated 
  1501.    trigger_enable( LAB_THREE_ENCLOSED_LAB_ENTRANCE_TRIGGER, false ) 
  1502.  
  1503.    -- Disable the "flush out" trigger and unmark it 
  1504.    trigger_enable( trigger_name, false ) 
  1505.    marker_remove_trigger( trigger_name, SYNC_ALL ) 
  1506.  
  1507.    local any_survivors_in_enclosed_lab = ss05_anyone_alive_in_enclosed_lab() 
  1508.  
  1509.    if ( any_survivors_in_enclosed_lab ) then 
  1510.       audio_play_for_character( LAB_THREE_ENCLOSED_LAB_SWITCH_AUDIO, LOCAL_PLAYER, "voice", false, false ) 
  1511.    end 
  1512.    -- Add the smoke effect, and have the people inside play the cough animation 
  1513.    local effect_handle = effect_play( LAB_THREE_SMOKE_EFFECT, LAB_THREE_SMOKE_SOURCE, true ) 
  1514.    for index, name in LAB_THREE_ENCLOSED_LAB_MEMBERS do 
  1515.       if ( character_is_dead( name ) == false and 
  1516.            character_is_ready( name ) == true ) then 
  1517.          action_play(name, COUGH_ANIMATION, "", true, 0, true) 
  1518.       end 
  1519.    end 
  1520.    delay( 3.0 ) 
  1521.    effect_stop( effect_handle ) 
  1522.  
  1523.    -- Open the door 
  1524.    door_lock( LAB_THREE_DOOR_NAME, false ) 
  1525.    door_open( LAB_THREE_DOOR_NAME ) 
  1526.    -- Have the people inside run out 
  1527.    for index, name in LAB_THREE_ENCLOSED_LAB_MEMBERS do 
  1528.       thread_new( "ss05_lab_three_enclosed_member_escape", name ) 
  1529.    end 
  1530. end 
  1531.  
  1532. function ss05_lab_three_enclosed_member_escape( name ) 
  1533.    move_to_safe( name, LAB_THREE_CLEAR_OF_ROOM, 3, true, false ) 
  1534.    local distance, player = get_dist_closest_player_to_object( name ) 
  1535.    set_ignore_ai_flag( name, false ) 
  1536.    attack_safe( name, player ) 
  1537. end 
  1538.  
  1539. -- Called when the player picks up the key in the fourth 
  1540. -- drug lab. Marks the door as openable, and sets up the 
  1541. -- trigger correctly for it. 
  1542. -- 
  1543. function ss05_picked_up_key() 
  1544.    trigger_enable( LAB_FOUR_BEFORE_DOOR_UNLOCKED_TRIGGER, false ) 
  1545.    trigger_enable( LAB_FOUR_UNLOCK_DOOR_TRIGGER, true ) 
  1546.  
  1547.    marker_add_trigger( LAB_FOUR_UNLOCK_DOOR_TRIGGER, 
  1548.                        MINIMAP_ICON_LOCATION, INGAME_EFFECT_LOCATION, SYNC_ALL ) 
  1549.  
  1550.    on_trigger( "ss05_unlock_door", LAB_FOUR_UNLOCK_DOOR_TRIGGER ) 
  1551. end 
  1552.  
  1553. -- Called when the player hits the "unlocked the door" trigger. 
  1554. -- 
  1555. function ss05_unlock_door() 
  1556.    trigger_enable( LAB_FOUR_UNLOCK_DOOR_TRIGGER, false ) 
  1557.    door_lock( LAB_FOUR_MIDDLE_DOOR, false ) 
  1558.    door_open( LAB_FOUR_MIDDLE_DOOR ) 
  1559.  
  1560.    mission_help_table( HT_DESTROY_STORAGE_CONTAINERS ) 
  1561.    objective_text( 0, HT_X_OF_Y_DUST_CONTAINERS_DESTROYED, 0, 
  1562.                    INITIAL_LAB_CHEM_STORAGE_COUNT[4], SYNC_ALL ) 
  1563.  
  1564.    -- Setup the chemical storage barrels 
  1565.    -- Reset the chem storage barrels, mark them, and add callbacks for their destruction 
  1566.    for index, name in LAB_FOUR_STORAGE_NAMES do 
  1567.       mesh_mover_reset( name ) 
  1568.       on_mover_destroyed( "ss05_lab_four_storage_destroyed", name ) 
  1569.       marker_add_mover( name, MINIMAP_ICON_KILL, INGAME_EFFECT_KILL, SYNC_ALL ) 
  1570.    end 
  1571.  
  1572.    on_door_opened( "ss05_lab_four_tech_begin_escape", LAB_FOUR_EXIT_DOOR ) 
  1573. end 
  1574.  
  1575. -- Called when the key is dropped by the final tech - 
  1576. -- it prompts the player to pick it up. 
  1577. -- 
  1578. function ss05_key_dropped() 
  1579.    mission_help_table( HT_PICK_UP_KEY ) 
  1580. end 
  1581.  
  1582. -- Callback when a tech is killed. All techs must be killed for the 
  1583. -- mission to end successfully. 
  1584. -- 
  1585. -- tech_name: The name of the tech who was killed. 
  1586. -- 
  1587. function ss05_lab_four_tech_killed( tech_name ) 
  1588.    Lab_four_techs_remaining = Lab_four_techs_remaining - 1 
  1589.  
  1590.    marker_remove_npc( tech_name, SYNC_ALL ) 
  1591.  
  1592.    local num_killed = LAB_FOUR_INITIAL_TECH_COUNT - Lab_four_techs_remaining 
  1593.  
  1594.    objective_text( 0, HT_X_OF_Y_TECHS_KILLED, 
  1595.                    num_killed, LAB_FOUR_INITIAL_TECH_COUNT, SYNC_ALL ) 
  1596.  
  1597.    if ( Lab_four_techs_remaining == 1 ) then 
  1598.       for index, name in LAB_FOUR_TECH_MEMBERS do 
  1599.          if ( character_is_dead( name ) == false ) then 
  1600.             loot_item_add( LAB_FOUR_KEY, name ) 
  1601.             on_mission_item_pickup( "ss05_picked_up_key" ) 
  1602.             on_mission_item_drop( "ss05_key_dropped" ) 
  1603.          end 
  1604.       end 
  1605.    end 
  1606.  
  1607.    if ( Lab_four_techs_remaining == 0 ) then 
  1608.    --[[ 
  1609.       delay( TECHS_KILLED_OBJECTIVE_UPDATE_DELAY_SECONDS ) 
  1610.       mission_help_table( HT_DESTROY_STORAGE_CONTAINERS ) 
  1611.       objective_text( 0, HT_X_OF_Y_DUST_CONTAINERS_DESTROYED, 0, 
  1612.                       INITIAL_LAB_CHEM_STORAGE_COUNT[4], SYNC_ALL ) 
  1613.  
  1614.       -- Setup the chemical storage barrels 
  1615.       -- Reset the chem storage barrels, mark them, and add callbacks for their destruction 
  1616.       for index, name in LAB_FOUR_STORAGE_NAMES do 
  1617.          mesh_mover_reset( name ) 
  1618. 	      on_mover_destroyed( "ss05_lab_four_storage_destroyed", name ) 
  1619. 	      marker_add_mover( name, MINIMAP_ICON_KILL, INGAME_EFFECT_KILL, SYNC_ALL ) 
  1620.       end 
  1621.  
  1622.       on_door_opened( "ss05_lab_four_tech_begin_escape", LAB_FOUR_EXIT_DOOR ) 
  1623.       ]] 
  1624.    end 
  1625. end 
  1626.  
  1627. -- Switches the mission into the "Tech Escaping" state. 
  1628. -- 
  1629. function ss05_lab_four_tech_begin_escape() 
  1630.    fade_out( 0 ) 
  1631.  
  1632.    for index, name in pairs( CHUNK_SWAP_FIRES ) do 
  1633.       Swap_sequences_enabled[name] = true 
  1634.       chunk_swap_sequence_start( name, true ) 
  1635.    end 
  1636.  
  1637.    player_controls_disable( LOCAL_PLAYER ) 
  1638.    if ( coop_is_active() ) then 
  1639.       player_controls_disable( REMOTE_PLAYER ) 
  1640.    end 
  1641.    Player_controls_disabled = true 
  1642. 	cutscene_play("IG_SS05_scene1") 
  1643. 	group_hide("ss05_$L4_CTE_Escapee_and_Car") 
  1644. 	group_show( LAB_FOUR_ESCAPING_TECH_GROUP ) 
  1645.    teleport_coop( POST_CHUNK_SWAP_WARP_POSITIONS[LOCAL_PLAYER], 
  1646.                   POST_CHUNK_SWAP_WARP_POSITIONS[REMOTE_PLAYER] ) 
  1647. 	group_show( LAB_FOUR_ESCAPING_TECH_GROUP ) 
  1648.    player_controls_enable( LOCAL_PLAYER ) 
  1649.    if ( coop_is_active() ) then 
  1650.       player_controls_enable( REMOTE_PLAYER ) 
  1651.    end 
  1652.    Player_controls_disabled = false 
  1653.    fade_in( 1.0 ) 
  1654.    on_door_opened( "", LAB_FOUR_EXIT_DOOR ) 
  1655.    ss05_switch_state( MS_TECH_ESCAPING ) 
  1656. end 
  1657.  
  1658. -- Updates the number of storage containers left and displays 
  1659. -- HUD information about their destruction. Called when a  
  1660. -- storage container is destroyed. 
  1661. -- 
  1662. -- lab_index: The lab that said storage container belongs to. 
  1663. -- 
  1664. function ss05_update_on_storage_destroyed( lab_index, storage_barrel_name ) 
  1665.    Labs_chem_storage_remaining[lab_index] = Labs_chem_storage_remaining[lab_index] - 1 
  1666.    ss05_display_num_containers_destroyed( lab_index ) 
  1667.  
  1668.    for index, fire_location in pairs( BARREL_FIRE_EFFECT_LOCATIONS[storage_barrel_name] ) do 
  1669.       Num_barrel_fire_effects = Num_barrel_fire_effects + 1 
  1670.       -- looping = true 
  1671.       Barrel_fire_effect_handles[Num_barrel_fire_effects] = effect_play( LARGE_FIRE, fire_location, true ) 
  1672.    end 
  1673.    for index, small_fire_location in pairs( BARREL_SMALL_FIRE_EFFECT_LOCATIONS[storage_barrel_name] ) do 
  1674.       Num_barrel_fire_effects = Num_barrel_fire_effects + 1 
  1675.       local effect_index = rand_int( 1, sizeof_table( SMALL_FIRES ) ) 
  1676.       -- looping = true 
  1677.       Barrel_fire_effect_handles[Num_barrel_fire_effects] = effect_play( SMALL_FIRES[effect_index], small_fire_location, true ) 
  1678.    end 
  1679.  
  1680.    return Labs_chem_storage_remaining[lab_index] 
  1681. end 
  1682.  
  1683. -- Called when a dust storage container in this lab is killed. 
  1684. -- 
  1685. -- Updates and then switches the state if all have been killed. 
  1686. -- 
  1687. function ss05_lab_one_storage_destroyed( storage_barrel_name ) 
  1688.    local num_left = ss05_update_on_storage_destroyed( 1, storage_barrel_name ) 
  1689.  
  1690.    if ( num_left == 0 ) then 
  1691.       --[[ 
  1692.       -- Disabled by design request 
  1693.       -- Lab storage destroyed, activate the stronger drug effect 
  1694.       ss05_set_medium_drug_effect( 1 ) 
  1695.       ]] 
  1696.       ss05_switch_state( MS_DESTROYED_FIRST_LAB ) 
  1697.    end 
  1698. end 
  1699.  
  1700. -- Called when a dust storage container in this lab is killed. 
  1701. -- 
  1702. -- Updates and then switches the state if all have been killed. 
  1703. -- 
  1704. function ss05_lab_two_storage_destroyed( storage_barrel_name ) 
  1705.    local num_left = ss05_update_on_storage_destroyed( 2, storage_barrel_name ) 
  1706.  
  1707.    if ( num_left == 0 ) then 
  1708.       --[[ 
  1709.       -- Disabled by design request 
  1710.       -- Lab storage destroyed, activate the stronger drug effect 
  1711.       ss05_set_medium_drug_effect( 2 ) 
  1712.       ]] 
  1713.  
  1714. 		effect_play(BUILDING_SHAKE_BUILDING_TWO,"ss05_$nL2_interior_Effect",false) 
  1715. 		camera_shake_start(.001, 1500, 1500) 
  1716.       ss05_switch_state( MS_DESTROYED_SECOND_LAB ) 
  1717.    end 
  1718. end 
  1719.  
  1720. -- This function will spawn reinforcements for lab three 
  1721. -- when enough lab members die if said reinforcements 
  1722. -- aren't already spawned. 
  1723. -- 
  1724. function ss05_lab_three_defender_died() 
  1725.    Lab_three_defenders_remaining = Lab_three_defenders_remaining - 1 
  1726.    if ( Lab_three_defenders_remaining == 0 and 
  1727.         Lab_three_after_lab_attackers_spawned == false ) then 
  1728.       delay( BEFORE_BACKUP_SPAWN_DELAY_SECONDS ) 
  1729.       ss05_do_lab_three_after_attack() 
  1730.    end 
  1731. end 
  1732.  
  1733. --  
  1734. function ss05_do_lab_three_after_attack() 
  1735.    Lab_three_after_lab_attackers_spawned = true 
  1736.    group_show( LAB_THREE_AFTER_LAB_ATTACK_GROUP ) 
  1737.  
  1738.    vehicle_enter_group_teleport( LAB_THREE_AFTER_LAB_ATTACK_MEMBERS, 
  1739.                                  LAB_THREE_AFTER_LAB_ATTACK_VEHICLE ) 
  1740.  
  1741.    local distance, player = get_dist_closest_player_to_object( LAB_THREE_AFTER_LAB_ATTACK_VEHICLE ) 
  1742.  
  1743.    vehicle_chase( LAB_THREE_AFTER_LAB_ATTACK_VEHICLE, player ) 
  1744. end 
  1745.  
  1746. -- Called when a dust storage container in this lab is killed. 
  1747. -- 
  1748. -- Updates and then switches the state if all have been killed. 
  1749. -- 
  1750. function ss05_lab_three_storage_destroyed( storage_barrel_name ) 
  1751.    local num_left = ss05_update_on_storage_destroyed( 3, storage_barrel_name ) 
  1752.  
  1753.    -- If the player destroys the enclosed lab barrel, unmark the flush 
  1754.    -- out switch and disable the enclosed lab entrance trigger 
  1755.    -- ( in case he does it before he flushes out the characters or receives the 
  1756.    --   message to do so ) 
  1757.    if ( storage_barrel_name == LAB_THREE_ENCLOSED_LAB_BARREL_NAME ) then   
  1758.       trigger_enable( LAB_THREE_ENCLOSED_LAB_ENTRANCE_TRIGGER, false ) 
  1759.       marker_remove_trigger( LAB_THREE_FLUSH_OUT_SWITCH, SYNC_ALL ) 
  1760.    end 
  1761.  
  1762.    -- If we're at zero, this lab has been destroyed. 
  1763.    if ( num_left == 0 ) then 
  1764.       -- Spawn the after attackers, but only if players are still 
  1765.       -- in the lab 
  1766.       if ( Lab_three_after_lab_attackers_spawned == false and 
  1767.            ss05_both_players_in_lab3_area() == true ) then 
  1768.          ss05_do_lab_three_after_attack() 
  1769.       end 
  1770.       ss05_switch_state( MS_DESTROYED_THIRD_LAB ) 
  1771.    end 
  1772. end 
  1773.  
  1774. function ss05_coop_open_exit_door( triggerer_name, trigger_name ) 
  1775. 	trigger_enable( trigger_name, false ) 
  1776.  
  1777. 	on_door_opened( "", LAB_FOUR_EXIT_DOOR ) 
  1778. 	door_open( LAB_FOUR_EXIT_DOOR ) 
  1779.  
  1780. 	ss05_lab_four_tech_begin_escape() 
  1781. end 
  1782.  
  1783. -- Called when a dust storage container in this lab is killed. 
  1784. -- 
  1785. -- Updates and then switches the state if all have been killed. 
  1786. -- 
  1787. function ss05_lab_four_storage_destroyed( storage_barrel_name ) 
  1788.    local num_left = ss05_update_on_storage_destroyed( 4, storage_barrel_name ) 
  1789.  
  1790.    -- If we've destroyed the barrels, then show the last tech 
  1791.    -- He'll try to escape when we approach him. 
  1792.    if ( num_left == 0 ) then 
  1793.       door_lock( LAB_FOUR_DOOR_NEAR_BARREL, false ) 
  1794.       door_open( LAB_FOUR_DOOR_NEAR_BARREL ) 
  1795.  
  1796.       -- Let all the Samedi loose - this lab is cleared 
  1797.       ss05_unleash_all( LAB_FOUR_DEFENDER_MEMBERS ) 
  1798.  
  1799.       -- Unlock the exit door 
  1800. 		if ( coop_is_active() == false ) then 
  1801. 	      door_lock( LAB_FOUR_EXIT_DOOR, false ) 
  1802. 		-- In coop, don't unlock the door, but do add a trigger for it 
  1803. 		else 
  1804. 			trigger_enable( LAB_FOUR_EXIT_COOP_TRIGGER, true ) 
  1805. 			on_trigger( "ss05_coop_open_exit_door", LAB_FOUR_EXIT_COOP_TRIGGER ) 
  1806. 		end 
  1807.       --group_show( LAB_FOUR_ESCAPING_TECH_GROUP ) 
  1808.       group_show( LAB_FOUR_PLAYERS_CAR_GROUP ) 
  1809.       vehicle_enter_teleport( LAB_FOUR_ESCAPEE_TECH, LAB_FOUR_ESCAPE_VEHICLE ) 
  1810.       set_ignore_ai_flag( LAB_FOUR_ESCAPEE_TECH, true ) 
  1811.       on_death( "ss05_escaping_tech_killed", LAB_FOUR_ESCAPEE_TECH ) 
  1812.  
  1813.       -- Clear the objective after a few seconds, because it's been completed 
  1814.       delay( LAB_DESTROYED_OBJECTIVE_UPDATE_DELAY_SECONDS ) 
  1815.       objective_text_clear( 0 ) 
  1816.  
  1817.       -- Prompt the player to find the tech 
  1818.       mission_help_table( HT_CHASE_DOWN_TECH ) 
  1819.       marker_add_npc( LAB_FOUR_ESCAPEE_TECH, MINIMAP_ICON_KILL, INGAME_EFFECT_KILL, SYNC_ALL ) 
  1820.  
  1821.       --[[ 
  1822.       -- Disabled by design request 
  1823.       -- Lab storage destroyed, activate the stronger drug effect 
  1824.       ss05_set_medium_drug_effect( 4 ) 
  1825.       ]] 
  1826.    end 
  1827. end 
  1828.  
  1829. -- Displays the number of dust containers destroyed on the HUD. 
  1830. -- 
  1831. -- lab_index: Which lab had a container destroyed. 
  1832. -- 
  1833. function ss05_display_num_containers_destroyed( lab_index ) 
  1834.    local num_destroyed = INITIAL_LAB_CHEM_STORAGE_COUNT[lab_index] - Labs_chem_storage_remaining[lab_index]; 
  1835.  
  1836.    objective_text( 0, HT_X_OF_Y_DUST_CONTAINERS_DESTROYED, num_destroyed, 
  1837.                    INITIAL_LAB_CHEM_STORAGE_COUNT[lab_index], SYNC_ALL ) 
  1838. end 
  1839.  
  1840. -- Stops the failure timer for the chase when the tech gets in-range. 
  1841. -- 
  1842. function ss05_in_range_of_tech() 
  1843.    -- May be set multiple times - the point is just to set it once, though, when the 
  1844.    -- player initially gets in range 
  1845.    vehicle_speed_override( LAB_FOUR_ESCAPE_VEHICLE, LAB_TECH_CHASE_NORMAL_SPEED_MPH ) 
  1846.    hud_timer_stop(0); 
  1847. end 
  1848.  
  1849. -- Starts the failure timer for the chase when the tech falls out of 
  1850. -- range, and prompts the player to catch up. 
  1851. -- 
  1852. function ss05_out_of_range_of_tech() 
  1853.    mission_help_table( HT_TECH_ESCAPING, "", "", SYNC_ALL ) 
  1854.    -- Add a timer - if he doesn't catch up soon enough, he fails 
  1855.    hud_timer_set(0, TIME_TO_CATCH_UP_WITH_TECH_MS, "ss05_tech_got_away" ) 
  1856. end 
  1857.  
  1858. -- Failure when the head tech gets away during the chase at the end. 
  1859. -- 
  1860. function ss05_tech_got_away() 
  1861.    mission_end_failure( MISSION_NAME, HT_TECH_ESCAPED ) 
  1862. end 
  1863.  
  1864. -- Reverts any chunk swaps made, for example, when the mission 
  1865. -- fails. 
  1866. -- 
  1867. function ss05_revert_swaps() 
  1868.    for index, name in pairs ( CHUNK_SWAP_FIRES ) do 
  1869.       if ( Swap_sequences_enabled[name] == true ) then 
  1870.          chunk_swap_sequence_revert( name )    
  1871.       end 
  1872.    end 
  1873. end 
  1874.  
  1875. -- Saves current swaps that were already running in the game. 
  1876. -- Used if the mission is being replayed. 
  1877. -- 
  1878. function ss05_save_game_current_swaps() 
  1879.    for index, name in pairs ( CHUNK_SWAP_FIRES ) do 
  1880.       chunk_swap_sequence_save_and_revert( name ) 
  1881.    end 
  1882. end 
  1883.  
  1884. -- Restores saved swaps that were already running in the game. 
  1885. -- Used if the mission is being replayed. 
  1886. -- 
  1887. function ss05_restore_swaps() 
  1888.    for index, name in pairs ( CHUNK_SWAP_FIRES ) do 
  1889.       chunk_swap_sequence_restore_saved( name ) 
  1890.    end 
  1891. end 
  1892.  
  1893. -- Makes chunk swaps permanent. Used when the mission 
  1894. -- succeeds. 
  1895. -- 
  1896. function ss05_make_swaps_permanent() 
  1897.    for index, name in pairs ( CHUNK_SWAP_FIRES ) do 
  1898.       if ( Swap_sequences_enabled[name] == true ) then 
  1899.          chunk_swap_sequence_make_permanent( name ) 
  1900.       end 
  1901.    end 
  1902. end 
  1903.  
  1904. function ss05_stop_all_barrel_fire_effects() 
  1905.    -- Cleanup all the fire effects we started for this mission 
  1906.    for index, effect_handle in pairs( Barrel_fire_effect_handles ) do 
  1907.       if ( effect_handle ~= -1 ) then 
  1908.          effect_stop( effect_handle ) 
  1909.          Barrel_fire_effect_handles[index] = -1 
  1910.       end 
  1911.    end 
  1912.  
  1913.    Num_barrel_fire_effects = 0 
  1914. end 
  1915.  
  1916. -- Does any required cleanup, such as removing callbacks 
  1917. -- and such. 
  1918. -- Also makes chunk swaps permanent if necessary. 
  1919. -- 
  1920. function ss05_cleanup() 
  1921.    -- Cleanup mission here 
  1922.    notoriety_set_min( ENEMY_GANG, 0 ) 
  1923.    notoriety_force_no_spawn( ENEMY_GANG, false ) 
  1924.    release_to_world( STARTER_VEHICLE_GROUP_NAME ) 
  1925.    release_to_world( LAB_FOUR_PLAYERS_CAR_GROUP ) 
  1926.    on_door_opened( "", LAB_FOUR_ENTRANCE_DOOR ) 
  1927.    on_door_opened( "", LAB_FOUR_EXIT_DOOR ) 
  1928.    door_lock( LAB_FOUR_MIDDLE_DOOR, false ) 
  1929.    door_lock( LAB_FOUR_ENTRANCE_DOOR, false ) 
  1930.    door_lock( LAB_FOUR_EXIT_DOOR, false ) 
  1931.    on_tailing_good( "" ) 
  1932.    on_tailing_too_far( "" ) 
  1933.    distance_display_off(SYNC_ALL) 
  1934.    ss05_set_chase_enter_callbacks( "" ) 
  1935.     
  1936.    ss05_stop_all_barrel_fire_effects() 
  1937.  
  1938.    -- If this is the first time, 
  1939.    if ( Mission_being_replayed == false ) then 
  1940.       if ( Mission_won == false ) then 
  1941.          ss05_revert_swaps() 
  1942.       else -- Mission_won == true 
  1943.          ss05_make_swaps_permanent() 
  1944.       end 
  1945.    else -- mission is being replayed 
  1946.       -- Revert the swaps we made 
  1947.       ss05_revert_swaps() 
  1948.       -- Restore the saved swaps 
  1949.       ss05_restore_swaps() 
  1950.    end 
  1951.  
  1952.    -- End weather override 
  1953.    set_weather( -1 ) 
  1954.  
  1955.    -- Disable the override. If it's on, we need to end it because 
  1956.    -- this mission is over. 
  1957.    drug_enable_disable_effect_override( false, SYNC_ALL ) 
  1958.    --screen_blackout_end() 
  1959.  
  1960.    on_mission_item_pickup( "" ) 
  1961.    on_mission_item_drop( "" ) 
  1962.  
  1963.    if ( Player_controls_disabled ) then 
  1964.       player_controls_enable( LOCAL_PLAYER ) 
  1965.       if ( coop_is_active() ) then 
  1966.          player_controls_enable( REMOTE_PLAYER ) 
  1967.       end 
  1968.    end 
  1969.  
  1970.    hud_timer_stop(0) 
  1971.  
  1972.    mission_cleanup_maybe_reenable_player_controls() 
  1973.    ss05_lock_all_lab_exterior_doors( false ) 
  1974. end 
  1975.  
  1976. -- Called when the mission has ended with success 
  1977. function ss05_success() 
  1978.  
  1979. 	-- Post the news event 
  1980. 	radio_post_event("JANE_NEWS_SOS05", true) 
  1981.  
  1982. end 
  1983.