// 2 players 
PLAYER_PED player1 = (102.0, 134.0, 2.0) 25 0
PLAYER_PED player2 = (104.0, 134.0, 2.0) 25 0

COUNTER true = 1
COUNTER car_unattached = 0
COUNTER targetcar_created = 0
COUNTER exploded = 0

// Current mission
COUNTER curmis = 0

// Mission complete flags
COUNTER m1_complete = 0
COUNTER m2_complete = 0

// Variables for MISSION 1 (blue phone) - Destroying icecream vans
COUNTER ice1pos = 1 // Current van spawn position
ONSCREEN_COUNTER m1_display1 
COUNTER iceleft = 20 // Number of vans must be destroyed in first mission

// Player cars
CAR_DATA m1_car1 
CAR_DATA m1_car2 

// Icecream van for mission #1
CAR_DATA ice1

GENERATOR m1_gun1 = ( 144.0 , 136.0 , 2.0 ) 359 COLLECT_18 400 500 15
GENERATOR m1_gun2 = ( 144.0 , 88.0 , 2.0 )  359 COLLECT_18 400 500 15
GENERATOR m1_gun3 = ( 89.0 , 88.0 , 2.0 )   359 COLLECT_18 400 500 15
GENERATOR m1_gun4 = ( 89.0 , 117.0 , 2.0 )  359 COLLECT_18 400 500 15
GENERATOR m1_gun5 = ( 127.0 , 109.0 , 2.0 ) 359 COLLECT_18 400 500 15
GENERATOR m1_mines = ( 132.0 , 89.0 , 2.0 )  359 COLLECT_17 400 500 15
// ADD_ONSCREEN_COUNTER  ( m1_display1 , iceleft )





// crazy bots

COUNTER bot1_resp_pos = 0
COUNTER bot2_resp_pos = 0






LEVELSTART
// =============================   Level Start ==================================

CRANE_DATA homecrane =  (91.5 , 134.5) 215 NO_HOMECRANE FIRST ( 87.5 , 134.5 ) 270
CRANE_DATA islandcrane1 =  (130.5 , 151.5) 45 NO_HOMECRANE 
CRANE_DATA islandcrane2 =  (151.5 , 155.5) 315 NO_HOMECRANE 

OBJ_DATA  case1     =  ( 100.5 , 108.5, 3.0 ) 0 BRIEFCASE
OBJ_DATA  case2_tower     =  ( 125.5 , 116.5, 7.0 ) 0 BRIEFCASE

//OBJ_DATA  phone1    =  ( 102.0 , 127.0, 3.0 ) 0 PHONE
OBJ_DATA  phone2    =  ( 106.5 , 126.5, 3.0 ) 0 GREEN_PHONE
OBJ_DATA  phone1    =  ( 108.5 , 126.5, 3.0 ) 0 PHONE_RINGING
//OBJ_DATA  phone4    =  ( 95.5 , 136.5, 4.0 ) 0 RED_PHONE
//OBJ_DATA  phone5    =  ( 111.5 , 134.5, 3.0 ) 0 RED_PHONE

ARROW_DATA phone_ar
POINT_ARROW_AT ( phone_ar , phone1 )


//    PERMAMENT WEAPONS   

GENERATOR rocket_01 = ( 105.0 , 112.0 , 3.0 ) 359 COLLECT_02 700 800 6
SWITCH_GENERATOR ( rocket_01 , ON )

GENERATOR macgun_01 = ( 129.5 , 135.5 , 2.0 ) 359 COLLECT_09 600 700 25
SWITCH_GENERATOR ( macgun_01 , ON )
GENERATOR macgun_02 = ( 120.5 , 121.5 , 2.0 ) 359 COLLECT_09 600 700 25
SWITCH_GENERATOR ( macgun_02 , ON )

GENERATOR base_01 = ( 106.5 , 129.5 , 2.0 ) 359 COLLECT_31 600 700 50
SWITCH_GENERATOR ( base_01 , ON )
GENERATOR base_02 = ( 105.5 , 129.5 , 2.0 ) 359 COLLECT_30 600 700 50
SWITCH_GENERATOR ( base_02 , ON )
GENERATOR base_03 = ( 108.5 , 129.5 , 2.0 ) 359 COLLECT_31 600 700 50
SWITCH_GENERATOR ( base_03 , ON )
GENERATOR base_04 = ( 109.5 , 129.5 , 2.0 ) 359 COLLECT_30 600 700 50
SWITCH_GENERATOR ( base_04 , ON )

GENERATOR electro_01 = ( 125.0 , 129.0 , 2.0 ) 359 COLLECT_03 400 500 15
SWITCH_GENERATOR ( electro_01 , ON )

GENERATOR molotovs_01 = ( 124.5 , 116.5 , 2.0 ) 359 COLLECT_04 400 500 10
SWITCH_GENERATOR ( molotovs_01 , ON )
GENERATOR molotovs_02 = ( 126.5 , 116.5 , 2.0 ) 359 COLLECT_04 400 500 10
SWITCH_GENERATOR ( molotovs_02 , ON )

GENERATOR dual_01 = ( 91.0 , 115.0 , 2.0 ) 359 COLLECT_10 400 500 25
SWITCH_GENERATOR ( dual_01 , ON )
GENERATOR dual_02 = ( 91.0 , 90.0 , 2.0 ) 359 COLLECT_10 400 500 25
SWITCH_GENERATOR ( dual_02 , ON )

GENERATOR shotgun_01 = ( 98.5 , 108.5 , 3.0 ) 359 COLLECT_06 400 500 16
SWITCH_GENERATOR ( shotgun_01 , ON )

GENERATOR flame_01 = ( 104.5 , 96.5 , 3.0 ) 359 COLLECT_08 400 500 20
SWITCH_GENERATOR ( flame_01 , ON )
GENERATOR flame_02 = ( 111.5 , 93.5 , 3.0 ) 359 COLLECT_08 400 500 20
SWITCH_GENERATOR ( flame_02 , ON )

//   DEFAULT   C A R S   

CAR_DATA test = (134.5, 151.5, 3.0) 13 45 SPIDER

CAR_DATA car0 = (101.0, 136.0, 2.0) 7 180 VTYPE
CAR_DATA car1 = (102.0, 136.0, 2.0) 7 180 VTYPE
CAR_DATA car2 = (103.0, 136.0, 2.0) 11 180 MERC
CAR_DATA car3 = (104.0, 136.0, 2.0) 14 180 AMDB4
CAR_DATA car4 = (105.0, 136.0, 2.0) 17 180 WBTWIN
CAR_DATA car5 = (106.0, 136.0, 2.0) 16 180 XK120
CAR_DATA car6 = (107.0, 136.0, 2.0) 2 180 SPIDER
CAR_DATA car7 = (108.0, 136.0, 2.0) 9 180 TBIRD
CAR_DATA car8 = (109.0, 136.0, 2.0) 6 180 VTYPE

CAR_DATA trailer2 = (99.0, 132.0, 2.0) 20 0 TRUKTRNS ZCX5


//     PSYCHO  BOTS   (PART I, preparing)   

   CHAR_DATA bot1 = ( 104.0, 130.0  ) 17 45 CRIMINAL_TYPE1 
   CHAR_DATA bot2 = ( 108.0, 134.0  ) 22 45 CRIMINAL_TYPE1 
   
   GIVE_WEAPON ( bot1 , ROCKET_LAUNCHER , 120 )
   SET_CHAR_THREAT_SEARCH ( bot1 , AREA )
   SET_CHAR_THREAT_REACTION ( bot1 , REACT_AS_NORMAL )
   SET_CHAR_SHOOTING_SKILL ( bot1 , CRACK_SHOT )
   SET_CHAR_OBJECTIVE ( bot1 , KILL_CHAR_ANY_MEANS , bot2 )
   SET_FAVOURITE_MODEL  ( bot1 , ZCX5 ) 
   
   GIVE_WEAPON ( bot2 , ROCKET_LAUNCHER , 120 )
   SET_CHAR_THREAT_SEARCH ( bot2 , AREA )
   SET_CHAR_THREAT_REACTION ( bot2 , REACT_AS_NORMAL )
   SET_CHAR_SHOOTING_SKILL ( bot2 , CRACK_SHOT )
   SET_CHAR_OBJECTIVE ( bot2 , KILL_CHAR_ANY_MEANS , bot1 )
   SET_FAVOURITE_MODEL  ( bot2 , VTYPE ) 
   
   

// ==============================  While Exec  ====================================
WHILE_EXEC (true = 1)





   //   M I S S I O N    1   
   

   // Check if blue phone (#1) was taken when no mission is running (current mission = 0)
   IF ( (curmis = 0) AND (m1_complete = 0) )
      IF ( (LOCATE_CHARACTER_ANY_MEANS ( player1 , 108.5 , 126.5, 3.0 , 1.0 , 1.0 )) or
     (LOCATE_CHARACTER_ANY_MEANS ( player2 , 108.5 , 126.5, 3.0 , 1.0 , 1.0 ))  ) 
     
           // Blue Phone taken
           // Starting mission #1
                                 
           SET curmis = 1
           STOP_PHONE ( phone1 )
           REMOVE_ARROW  ( phone_ar )
           DISPLAY_MESSAGE ( 5054 )   
           DISPLAY_BRIEF ( 5013 )
           
           m1_car1 = CREATE_CAR (109.0, 130.5, 2.0) 2 90  VTYPE END
           m1_car2 = CREATE_CAR (109.0, 131.5, 2.0) 30 90 VTYPE END
           GIVE_WEAPON ( m1_car1 , CAR_MACHINE_GUN , 15 )
           GIVE_WEAPON ( m1_car2 , CAR_MACHINE_GUN , 15 )
           
           SWITCH_GENERATOR ( m1_gun1 , ON )
           SWITCH_GENERATOR ( m1_gun2 , ON )
           SWITCH_GENERATOR ( m1_gun3 , ON )
           SWITCH_GENERATOR ( m1_gun4 , ON )
           SWITCH_GENERATOR ( m1_gun5 , ON )
           SWITCH_GENERATOR ( m1_mines , ON )
           
           ADD_ONSCREEN_COUNTER  ( m1_display1 , iceleft )
           
           ice1 = CREATE_CAR (124.5, 137.5, 2.0) 7 270 ICECREAM END
           MAKE_CAR_A_DUMMY ( ice1 )
           ARROW_DATA m1_ar1
           POINT_ARROW_AT ( m1_ar1 , ice1 )
           
     ENDIF
   ENDIF
   
   // Other missions are not implemented yet.
   // Code like this should be written here: 

   //   // Check if phone #2 was taken ...
   //   IF ( (curmis = 0) AND (m2_complete = 0) )
   //     IF ( (LOCATE_CHARACTER_ANY_MEANS ( player1 , ...at phone #2.... )) or
   //       (LOCATE_CHARACTER_ANY_MEANS ( player2 , ...at phone #2.... ))  ) 
   //           // Phone #2 was taken, start mission #2.
   //           ...
   //      ENDIF
   // ENDIF
   
   //   // Check if phone #3 was taken ...
   //   IF ( (curmis = 0) AND (m3_complete = 0) )
   //     IF ( (LOCATE_CHARACTER_ANY_MEANS ( player1 , ...at phone #3.... )) or
   //       (LOCATE_CHARACTER_ANY_MEANS ( player2 , ...at phone #3.... ))  ) 
   //           // Phone #3 was taken, start mission #3.
   //           ...
   //      ENDIF
   // ENDIF
   
   
   
   // During the mission 1
   
   IF ( curmis = 1 ) 
   
      // If van killed, spawn new van at next position
      
     IF (IS_CAR_WRECKED ( ice1 ) )
      -- iceleft
     DELETE_ITEM  ( ice1 ) 
     IF (ice1pos = 0)
        SET ice1pos = 1
        ice1 = CREATE_CAR (125.5, 85.5, 2.0) 7 90 ICECREAM END
     ELSE
        IF (ice1pos = 1)
           SET ice1pos = 2
           ice1 = CREATE_CAR (85.5, 90.5, 2.0) 7 0 ICECREAM END
        ELSE
            IF (ice1pos = 2)
               SET ice1pos = 3
               ice1 = CREATE_CAR (118.5, 118.5, 2.0) 7 180 ICECREAM END
            ELSE
                IF (ice1pos = 3)
                   SET ice1pos = 4
                   ice1 = CREATE_CAR (148.5, 128.5, 2.0) 7 180 ICECREAM END
                ELSE
                    IF (ice1pos = 4)
                       SET ice1pos = 0
                       ice1 = CREATE_CAR (100.5, 100.5, 2.0) 7 0 ICECREAM END
                    ENDIF   
                ENDIF
            ENDIF
        ENDIF
     ENDIF
     POINT_ARROW_AT ( m1_ar1 , ice1 )
     MAKE_CAR_A_DUMMY ( ice1 )
     
     // Last 10 vans will be bulletproof
     IF ( iceleft < 10 )
        SET_CAR_BULLETPROOF ( ice1 , ON )
     ENDIF
     
     // Last 5 vans will be rocketproof
     IF ( iceleft < 5 )
        SET_CAR_ROCKETPROOF ( ice1 , ON )
     ENDIF
     
     // Doors of last 3 vans will be locked
     // But I think ALL vans should be spawned with locked doors... 
     IF ( iceleft < 3 ) 
        CHANGE_CAR_LOCK ( ice1 , locked )
     ENDIF
     
    ENDIF
   
    // When all vans will be destroyed, mission 1 will be finished: 
    IF ( iceleft = 0 )
      DELETE_ITEM ( ice1 )
      SET curmis = 0
      SET m1_complete = 1
      CLEAR_ONSCREEN_COUNTER ( m1_display1 )
      REMOVE_ARROW ( m1_ar1 )
      DISPLAY_MESSAGE ( 1124 )
      DISPLAY_BRIEF ( 1006 )
      ADD_SCORE ( player1 , 40000 )
      ADD_SCORE ( player2 , 40000 )
      
      SWITCH_GENERATOR ( m1_mines , OFF )
      SWITCH_GENERATOR ( m1_gun1 , OFF )
      SWITCH_GENERATOR ( m1_gun2 , OFF )
      SWITCH_GENERATOR ( m1_gun3 , OFF )
      SWITCH_GENERATOR ( m1_gun4 , OFF )
      SWITCH_GENERATOR ( m1_gun5 , OFF )
      
      
      DELETE_ITEM ( phone2 )
      // Now phone #2 must be ringing 
      phone2 =  CREATE_OBJ ( 106.5 , 126.5, 3.0 ) 0 GREEN_PHONE_RINGING END
      
    ENDIF
   
   ENDIF
   
   // Other mission is not implemented.
   // Code like this should be here:
   
   //   IF ( curmis = 2 ) 
   //      ...
   //      // Mission #2 in-loop implementation
   //      ...
   //      IF ( mission #2 finishing condition  )
   //         // Do like in mission #1:
   //         SET curmis = 0
   //         SET m2_complete = 1
   //         // and ring the new phone
   //      ENDIF
   //   ENDIF
 
   
   //   IF ( curmis = 3 ) 
   //      ...
   //      // Mission #3 in-loop implementation
   //      ...
   //      IF ( mission #3 finishing condition  )
   //         // Do like in mission #1:
   //         SET curmis = 0
   //         SET m3_complete = 1
   //         // and ring the new phone
   //      ENDIF
   //   ENDIF
   
  

   
           /*     P S Y C H O    B O T S   (PART II, in-loop implementation)    */
   IF ( HAS_CHARACTER_DIED ( bot1 ))
     DELETE_ITEM  ( bot1 ) 
     IF (bot1_resp_pos = 0)
        bot1 = CREATE_CHAR (  88.0 ,  88.0 , 2.0 )  17  180  CRIMINAL_TYPE2 END
        SET bot1_resp_pos = 1
     ELSE 
        bot1 = CREATE_CHAR (  142.0 ,  134.0 , 2.0 )  17  180  CRIMINAL_TYPE2 END
        SET bot1_resp_pos = 0
     ENDIF
     GIVE_WEAPON ( bot1 , ROCKET_LAUNCHER )
     SET_CHAR_THREAT_SEARCH ( bot1 , AREA )
     SET_CHAR_THREAT_REACTION ( bot1 , REACT_AS_NORMAL )
     SET_CHAR_SHOOTING_SKILL ( bot1 , CRACK_SHOT )
     SET_CHAR_OBJECTIVE ( bot1 , KILL_CHAR_ANY_MEANS , bot2 )
     SET_CHAR_OBJECTIVE ( bot2 , KILL_CHAR_ANY_MEANS , bot1 )
     SET_FAVOURITE_MODEL  ( bot1 , ZCX5 ) 
     SET_FAVOURITE_MODEL  ( bot2 , VTYPE ) 
   ENDIF
   
   IF ( HAS_CHARACTER_DIED ( bot2 ))
     DELETE_ITEM  ( bot2 ) 
     IF (bot2_resp_pos = 0)
        bot2 = CREATE_CHAR (  90.0 ,  115.0 , 2.0 )  22  180  CRIMINAL_TYPE2 END
        SET bot2_resp_pos = 1
     ELSE 
        bot2 = CREATE_CHAR (  142.0 ,  89.0 , 2.0 )  22  180  CRIMINAL_TYPE2 END
        SET bot2_resp_pos = 0
     ENDIF
     GIVE_WEAPON ( bot2 , ROCKET_LAUNCHER )
     SET_CHAR_THREAT_SEARCH ( bot2 , AREA )
     SET_CHAR_THREAT_REACTION ( bot2 , REACT_AS_NORMAL )
     SET_CHAR_SHOOTING_SKILL ( bot2 , CRACK_SHOT )
     SET_CHAR_OBJECTIVE ( bot1 , KILL_CHAR_ANY_MEANS , bot2 )
     SET_CHAR_OBJECTIVE ( bot2 , KILL_CHAR_ANY_MEANS , bot1 )
     SET_FAVOURITE_MODEL  ( bot1 , ZCX5 ) 
     SET_FAVOURITE_MODEL  ( bot2 , VTYPE ) 
   ENDIF
  

ENDWHILE 

// Optimal policelevel for co-op missions is 2
DECLARE_POLICELEVEL ( 2 )

LEVELEND

