Guest User

missions.pwn

a guest
Dec 20th, 2025
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 38.16 KB | None | 0 0
  1. /* ---------------------------------
  2.      FCNPC Plugin missions FS
  3.  
  4. - File: missions.pwn
  5. - Author: OrMisicL
  6. - Contributor: ziggi
  7. ---------------------------------*/
  8.  
  9. #define FILTERSCRIPT
  10.  
  11. #include <a_samp>
  12. #include <omp_npc>
  13.  
  14. #define COLOR_GREY 0xAFAFAFAA
  15. #define COLOR_RED  0xB35959AA
  16.  
  17. // General definitions
  18. #define MAX_MISSIONS            10
  19. #define MAX_MISSION_PLAYERS     3
  20. #define MAX_MISSION_VEHICLES    12
  21. #define MAX_MISSION_NPCS        16
  22. #define MAX_MISSION_CUTSCENES   3
  23. #define INVALID_MISSION         (-1)
  24. // NOTE: Each mission will take 3 players and 16 NPCs (19 player slots), so adjust the values above to
  25. // suit your server max players (19 slots per mission / 10 missions: 19 * 10 = 190 slots used ny this script)
  26. // Same goes for vehicles (11 vehicles per mission = 110 vehicle slots used)
  27.  
  28. forward StartMission(slotid, starterid);
  29. forward EndMission(mission, const reason[], bool:success);
  30. forward JoinMission(playerid, mission, slot);
  31. forward LeaveMission(playerid);
  32. forward BeginMission(mission);
  33. forward PlayCutscene(mission);
  34. forward EndCutscene(mission);
  35.  
  36. // Timers
  37. forward BeginMissionTimer(mission);
  38. forward ProcessMissionTimer(mission);
  39. forward LockCameraTimer(mission, playerid, type);
  40.  
  41. enum EMission
  42. {
  43.     bool:started,
  44.     players[MAX_MISSION_PLAYERS],
  45.     vehicles[MAX_MISSION_VEHICLES],
  46.     npcs[MAX_MISSION_NPCS],
  47.     npc_target[MAX_MISSION_NPCS],
  48.     player_dead[MAX_MISSION_PLAYERS],
  49.     level,
  50.     bool:cutscene,
  51.     bool:cutscene_process,
  52.     cutscene_stage,
  53.     cutscene_stages[MAX_MISSION_CUTSCENES]
  54. };
  55.  
  56. new Mission[MAX_MISSIONS][EMission];
  57.  
  58. new MissionsStarted;
  59.  
  60. new PlayerMission[MAX_PLAYERS];
  61. new PlayerCreatedMission[MAX_PLAYERS];
  62.  
  63. // NPCs informations
  64. new Float:MissionSpawns[][4] =
  65. {
  66.     {1463.8781, -1025.8901, 23.8281, 177.3026},
  67.     {1460.9760, -1010.1360, 26.8438, 87.2448},
  68.     {2366.9006, -1653.1716, 13.5469, 89.7455},
  69.     {2367.0542, -1656.4420, 13.3828, 87.8655},
  70.     {2372.5830, -1667.2329, 13.5469, 5.4815},
  71.     {2386.1616, -1654.5337, 13.3828, 101.0490},
  72.     {2390.4465, -1664.4171, 13.5469, 78.4888},
  73.     {2409.3940, -1669.2445, 13.5534, 16.3482},
  74.     {2465.8904, -1669.7217, 13.4757, 83.0888},
  75.     {2466.5623, -1651.0841, 13.4711, 143.5627},
  76.     {2486.7644, -1649.5516, 13.4841, 151.3961},
  77.     {2473.6099, -1680.3300, 13.3624, 42.7424},
  78.     {2494.7471, -1687.3690, 13.5147, 49.8751},
  79.     {2494.2883, -1693.6166, 23.6947, 20.7349},
  80.     {2494.2883, -1693.6166, 23.6947, 20.7349},
  81.     {2482.8660, -1644.3629, 22.8124, 179.9096}
  82. };
  83.  
  84. // Skin, Weapon, WeaponSkill
  85. new MissionNPCInfo[][3] =
  86. {
  87.     {149, 0, 0},
  88.     {174, 0, 0},
  89.     {174, 22, WEAPONSKILL_PISTOL},
  90.     {174, 28, WEAPONSKILL_MICRO_UZI},
  91.     {174, 24, WEAPONSKILL_DESERT_EAGLE},
  92.     {174, 32, WEAPONSKILL_MICRO_UZI},
  93.     {174, 22, WEAPONSKILL_PISTOL},
  94.     {174, 31, WEAPONSKILL_M4},
  95.     {174, 30, WEAPONSKILL_AK47},
  96.     {174, 30, WEAPONSKILL_AK47},
  97.     {174, 31, WEAPONSKILL_M4},
  98.     {174, 29, WEAPONSKILL_MP5},
  99.     {174, 31, WEAPONSKILL_M4},
  100.     {174, 30, WEAPONSKILL_AK47},
  101.     {174, 34, WEAPONSKILL_SNIPERRIFLE},
  102.     {174, 34, WEAPONSKILL_SNIPERRIFLE}
  103. };
  104.  
  105. // Players informations
  106. new Float:MissionPlayerAttackPos[][4] =
  107. {
  108.     {2293.7493, -1670.5682, 14.7908, 283.9182},
  109.     {2293.5847, -1673.4008, 14.5787, 281.0981},
  110.     {2293.8721, -1676.2352, 14.3766, 281.0981}
  111. };
  112.  
  113. new Float:MissionPlayerSpawns[][4] =
  114. {
  115.     {1515.6289, -1058.1167, 25.0625, 40.3945},
  116.     {1512.8232, -1058.4934, 25.0625, 87.2448},
  117.     {1509.7125, -1058.9824, 25.0625, 40.3945}
  118. };
  119.  
  120. new Float:MissionPlayerEndPos[][4] =
  121. {
  122.     {2494.6973, -1674.1779, 13.3359, 296.0828},
  123.     {2494.1831, -1671.6985, 13.3359, 292.6360},
  124.     {2494.6003, -1668.9293, 13.3359, 273.2092}
  125. };
  126.  
  127. // Model, Weapon
  128. new MissionPlayerInfo[][2] =
  129. {
  130.     {124, 29},
  131.     {126, 30},
  132.     {122, 31}
  133. };
  134.  
  135. // Vehicles informations
  136. new Float:MissionVehicles[][4] =
  137. {
  138.     {1463.5126, -1039.6022, 23.3640, 89.8247},
  139.     {1508.3071, -1041.3304, 23.5849, 83.8528},
  140.     {2365.5054, -1655.3934, 13.3611, 180.7228},
  141.     {2368.7273, -1666.5074, 13.4219, 55.3572},
  142.     {2382.8577, -1653.9227, 13.2437, 222.8567},
  143.     {2464.4875, -1654.3873, 13.1641, 174.4650},
  144.     {2481.8472, -1684.1266, 13.1947, 264.2903},
  145.     {2468.4878, -1671.1930, 13.1756, 4.5945},
  146.     {2492.7986, -1651.0204, 13.2758, 85.8759},
  147.     {2431.0161, -1656.5094, 13.1642, 119.9113},
  148.     {2441.7739, -1666.8046, 13.2742, 303.8073},
  149.     {2474.2739, -1678.2626, 13.2145, 104.4158}
  150. };
  151.  
  152. // Model, color1, color2
  153. new MissionVehicleInfo[][3] =
  154. {
  155.     {411, 1, 0},
  156.     {492, 0, 0},
  157.     {492, 2, 0},
  158.     {566, 6, 0},
  159.     {566, 2, 0},
  160.     {492, 8, 0},
  161.     {566, 0, 0},
  162.     {492, 1, 0},
  163.     {492, 11, 0},
  164.     {492, 7, 0},
  165.     {566, 0, 0},
  166.     {566, 4, 0}
  167. };
  168.  
  169. // Cutscenes informations
  170. new MissionCutscenes[][160] =
  171. {
  172.     {""},
  173.     {"He is coming out right now, should we assasinate him ?"},
  174.     {"Yes, we will have to shoot him before he enters the vehicle."},
  175.     {"No, i think we should follow him to his gang base"},
  176.     {"He will have full protection there, it will become impossible ~n~for us to kill him"},
  177.     {"What if we kill them all !"},
  178.     {"Thats suicide !"},
  179.     {"No, we are highly trained assasins, we can kill the entire gang"},
  180.     {"What do you guys think ?"},
  181.     {"I started to like the idea, even that it sounds stupid"},
  182.     {"Hmm ... well, should we do it then ?"},
  183.     {"Lets go for it"},
  184.     {""}
  185. };
  186.  
  187. new Float:MissionCutsceneStart[][4] =
  188. {
  189.     {1515.6289, -1058.1167, 25.0625, 40.3945},
  190.     {1516.2162, -1056.0927, 25.0625, 114.0285},
  191.     {1513.0555, -1055.5886, 25.0625, 241.5564},
  192.     {1513.0546, -1058.7903, 25.0625, 313.9370}
  193. };
  194.  
  195. // Time, Player
  196. new MissionCutsceneInfo[][2] =
  197. {
  198.     {5000, 0},
  199.     {5000, 0},
  200.     {6000, 1},
  201.     {5000, 2},
  202.     {7000, 1},
  203.     {4000, 2},
  204.     {3000, 1},
  205.     {5000, 2},
  206.     {3000, 0},
  207.     {5000, 1},
  208.     {3000, 2},
  209.     {2000, 0},
  210.     {2000, 0}
  211. };
  212.  
  213. new Text:TextdrawBox, Text:TextdrawBox2, Text:TextdrawBoxText;
  214. new Text:TextdrawText;
  215. new Text:TextdrawFollow;
  216.  
  217. public OnFilterScriptInit()
  218. {
  219.     printf("");
  220.     printf("-------------------------------------------------");
  221.     printf("     FCNPC - Fully Controllable NPC");
  222.     printf("");
  223.     printf("- Author: OrMisicL");
  224.     printf("- File: Missions script");
  225.     printf("-------------------------------------------------");
  226.     printf("");
  227.     // Reset missions
  228.     for (new i = 0; i < MAX_PLAYERS; i++)
  229.     {
  230.         PlayerMission[i] = INVALID_MISSION;
  231.         PlayerCreatedMission[i] = INVALID_MISSION;
  232.     }
  233.     for (new i = 0; i < 4; i++)
  234.     {
  235.         Mission[i][started] = false;
  236.         for (new j = 0; j < MAX_MISSION_PLAYERS; j++)
  237.         {
  238.             Mission[i][players][j] = INVALID_PLAYER_ID;
  239.             Mission[i][player_dead][j] = false;
  240.         }
  241.         for (new j = 0; j < MAX_MISSION_NPCS; j++)
  242.         {
  243.             Mission[i][npcs][j] = INVALID_PLAYER_ID;
  244.             Mission[i][npc_target][j] = INVALID_PLAYER_ID;
  245.         }
  246.         Mission[i][level] = 0;
  247.         Mission[i][cutscene] = false;
  248.         Mission[i][cutscene_process] = false;
  249.         Mission[i][cutscene_stage] = 0;
  250.     }
  251.     MissionsStarted = 0;
  252.     // Create texdraws
  253.     TextdrawBox = TextDrawCreate(2.000000, 1.500000, "usebox");
  254.     TextDrawLetterSize(TextdrawBox, 0.000000, 13.040371);
  255.     TextDrawTextSize(TextdrawBox, 637.199951, 0.000000);
  256.     TextDrawAlignment(TextdrawBox, 1);
  257.     TextDrawColor(TextdrawBox, 0);
  258.     TextDrawUseBox(TextdrawBox, true);
  259.     TextDrawBoxColor(TextdrawBox, 255);
  260.     TextDrawSetShadow(TextdrawBox, 0);
  261.     TextDrawSetOutline(TextdrawBox, 0);
  262.     TextDrawFont(TextdrawBox, 0);
  263.  
  264.     TextdrawBox2 = TextDrawCreate(2.000000, 342.726654, "usebox");
  265.     TextDrawLetterSize(TextdrawBox2, 0.000000, 11.464075);
  266.     TextDrawTextSize(TextdrawBox2, 637.199951, 0.000000);
  267.     TextDrawAlignment(TextdrawBox2, 1);
  268.     TextDrawColor(TextdrawBox2, 0);
  269.     TextDrawUseBox(TextdrawBox2, true);
  270.     TextDrawBoxColor(TextdrawBox2, 255);
  271.     TextDrawSetShadow(TextdrawBox2, 0);
  272.     TextDrawSetOutline(TextdrawBox2, 0);
  273.     TextDrawBackgroundColor(TextdrawBox2, 16777215);
  274.     TextDrawFont(TextdrawBox2, 0);
  275.  
  276.     TextdrawBoxText = TextDrawCreate(304.800048, 29.866661, "~b~Mission 1:~n~~w~Kill the boss");
  277.     TextDrawLetterSize(TextdrawBoxText, 0.647601, 1.749333);
  278.     TextDrawAlignment(TextdrawBoxText, 2);
  279.     TextDrawColor(TextdrawBoxText, -1);
  280.     TextDrawSetShadow(TextdrawBoxText, 0);
  281.     TextDrawSetOutline(TextdrawBoxText, 1);
  282.     TextDrawBackgroundColor(TextdrawBoxText, 51);
  283.     TextDrawFont(TextdrawBoxText, 1);
  284.     TextDrawSetProportional(TextdrawBoxText, 1);
  285.  
  286.     TextdrawText = TextDrawCreate(30.000000, 372.400085, "");
  287.     TextDrawLetterSize(TextdrawText, 0.449999, 1.600000);
  288.     TextDrawAlignment(TextdrawText, 1);
  289.     TextDrawColor(TextdrawText, -1);
  290.     TextDrawSetShadow(TextdrawText, 0);
  291.     TextDrawSetOutline(TextdrawText, 1);
  292.     TextDrawBackgroundColor(TextdrawText, 51);
  293.     TextDrawFont(TextdrawText, 1);
  294.     TextDrawSetProportional(TextdrawText, 1);
  295.  
  296.     TextdrawFollow = TextDrawCreate(323.200042, 414.400054, "");
  297.     TextDrawLetterSize(TextdrawFollow, 0.449999, 1.600000);
  298.     TextDrawAlignment(TextdrawFollow, 2);
  299.     TextDrawColor(TextdrawFollow, -1);
  300.     TextDrawSetShadow(TextdrawFollow, 0);
  301.     TextDrawSetOutline(TextdrawFollow, 1);
  302.     TextDrawBackgroundColor(TextdrawFollow, 51);
  303.     TextDrawFont(TextdrawFollow, 1);
  304.     TextDrawSetProportional(TextdrawFollow, 1);
  305.     return 1;
  306. }
  307.  
  308. public OnFilterScriptExit()
  309. {
  310.     for (new i = 0; i < MAX_PLAYERS; i++)
  311.     {
  312.         LeaveMission(i);
  313.     }
  314. }
  315.  
  316. public OnPlayerConnect(playerid)
  317. {
  318.     PlayerMission[playerid] = INVALID_MISSION;
  319.     PlayerCreatedMission[playerid] = INVALID_MISSION;
  320. }
  321.  
  322. strtok(const string[], &index)
  323. {
  324.     new length = strlen(string);
  325.     while ((index < length) && (string[index] <= ' '))
  326.     {
  327.         index++;
  328.     }
  329.  
  330.     new offset = index;
  331.     new result[20];
  332.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  333.     {
  334.         result[index - offset] = string[index];
  335.         index++;
  336.     }
  337.     result[index - offset] = EOS;
  338.     return result;
  339. }
  340.  
  341. public OnPlayerCommandText(playerid, cmdtext[])
  342. {
  343.     new cmd[128];
  344.     new idx;
  345.     new tmp[64];
  346.     cmd = strtok(cmdtext, idx);
  347.     if (!strcmp(cmd, "/suic", true))
  348.     {
  349.         SetPlayerHealth(playerid, 0.0);
  350.         return 1;
  351.     }
  352.     if (!strcmp(cmd, "/mission", true))
  353.     {
  354.         // Get the options
  355.         tmp = strtok(cmdtext, idx);
  356.         // Check params
  357.         if (!strlen(tmp))
  358.         {
  359.             SendClientMessage(playerid, COLOR_GREY, "Use: /mission [option]");
  360.             SendClientMessage(playerid, COLOR_GREY, "start, join, leave, invite");
  361.             return 1;
  362.         }
  363.         // Start mission
  364.         if (!strcmp(tmp, "start", true))
  365.         {
  366.             if (PlayerMission[playerid] != INVALID_MISSION || PlayerCreatedMission[playerid] != INVALID_MISSION)
  367.             {
  368.                 SendClientMessage(playerid, COLOR_RED, "You are already in a mission !");
  369.                 return 1;
  370.             }
  371.             // Verify mission slots
  372.             if (MissionsStarted == MAX_MISSIONS)
  373.             {
  374.                 SendClientMessage(playerid, COLOR_RED, "No mission slots available !");
  375.                 return 1;
  376.             }
  377.             // Get a free mission slot
  378.             new slot = FindFreeMissionSlot();
  379.             if (slot == INVALID_MISSION)
  380.             {
  381.                 SendClientMessage(playerid, COLOR_RED, "No mission slots available !");
  382.                 return 1;
  383.             }
  384.             // Start a new mission
  385.             if (!StartMission(slot, playerid))
  386.             {
  387.                 SendClientMessage(playerid, COLOR_RED, "Failed to start the mission !");
  388.                 return 1;
  389.             }
  390.             // Join the mission
  391.             JoinMission(playerid, slot, 0);
  392.             // Send confirmation message
  393.             new msg[64];
  394.             format(msg, sizeof(msg), "You have successfully created a mission (ID: %d)", slot);
  395.             SendClientMessage(playerid, COLOR_GREY, msg);
  396.             SendClientMessage(playerid, COLOR_GREY, "Use </mission invite> to invite players to it");
  397.             return 1;
  398.         }
  399.  
  400.         // Join mission
  401.         if (!strcmp(tmp, "join", true))
  402.         {
  403.             if (PlayerMission[playerid] != INVALID_MISSION || PlayerCreatedMission[playerid] != INVALID_MISSION)
  404.             {
  405.                 SendClientMessage(playerid, COLOR_RED, "You are already in a mission !");
  406.                 return 1;
  407.             }
  408.             // Verify mission slots
  409.             if (MissionsStarted == 0)
  410.             {
  411.                 SendClientMessage(playerid, COLOR_RED, "No missions available !");
  412.                 return 1;
  413.             }
  414.             // Get the mission id
  415.             tmp = strtok(cmdtext, idx);
  416.             if (!strlen(tmp))
  417.             {
  418.                 SendClientMessage(playerid, COLOR_GREY, "Use: /mission join [id]");
  419.                 return 1;
  420.             }
  421.             // Get a free mission player slot
  422.             new slot = FindFreeMissionPlayerSlot(strval(tmp));
  423.             if (slot == INVALID_MISSION)
  424.             {
  425.                 SendClientMessage(playerid, COLOR_RED, "No players slots available for that mission !");
  426.                 return 1;
  427.             }
  428.             // Join the mission
  429.             JoinMission(playerid, strval(tmp), slot);
  430.             return 1;
  431.         }
  432.  
  433.         // Leave mission
  434.         if (!strcmp(tmp, "leave", true))
  435.         {
  436.             if (PlayerMission[playerid] == INVALID_MISSION)
  437.             {
  438.                 SendClientMessage(playerid, COLOR_RED, "You are not in a mission !");
  439.                 return 1;
  440.             }
  441.             // Leave the mission
  442.             LeaveMission(playerid);
  443.             SendClientMessage(playerid, COLOR_GREY, "You have left the mission");
  444.             return 1;
  445.         }
  446.  
  447.         // Invite to mission
  448.         if (!strcmp(tmp, "invite", true))
  449.         {
  450.             if (PlayerMission[playerid] == INVALID_MISSION || PlayerCreatedMission[playerid] == INVALID_MISSION)
  451.             {
  452.                 SendClientMessage(playerid, COLOR_RED, "You haven't created any mission !");
  453.                 return 1;
  454.             }
  455.             // Get the mission id
  456.             tmp = strtok(cmdtext, idx);
  457.             if (!strlen(tmp))
  458.             {
  459.                 SendClientMessage(playerid, COLOR_GREY, "Use: /mission invite [id]");
  460.                 return 1;
  461.             }
  462.             // Validate the player
  463.             if (!IsPlayerConnected(strval(tmp)))
  464.             {
  465.                 SendClientMessage(playerid, COLOR_RED, "Invalid player !");
  466.                 return 1;
  467.             }
  468.             // Invite the player
  469.             new msg[128], name[MAX_PLAYER_NAME + 1];
  470.             GetPlayerName(playerid, name, sizeof(name));
  471.             format(msg, sizeof(msg), "%s has invited you to join his mission", name);
  472.             SendClientMessage(strval(tmp), COLOR_GREY, msg);
  473.             format(msg, sizeof(msg), "Use </mission join %d> to join it.", PlayerMission[playerid]);
  474.             SendClientMessage(strval(tmp), COLOR_GREY, msg);
  475.             return 1;
  476.         }
  477.     }
  478.     return 0;
  479. }
  480.  
  481. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  482. {
  483.     if(!NPC_IsValid(playerid)) return 1;
  484.  
  485.     // Get the NPC mission
  486.     new mission = GetNPCMission(playerid);
  487.     if (mission == INVALID_MISSION)
  488.     {
  489.         return 1;
  490.     }
  491.  
  492.     if (Mission[mission][level] == 1)
  493.     {
  494.         // Stop the cutscene
  495.         EndCutscene(mission);
  496.         // Start the playback
  497.         NPC_StartPlayback(Mission[mission][npcs][1], "mission_1");
  498.     }
  499.     return 1;
  500. }
  501.  
  502. public OnPlayerExitVehicle(playerid, vehicleid)
  503. {
  504.     if(!NPC_IsValid(playerid)) return 1;
  505.  
  506.     // Get the NPC mission
  507.     new mission = GetNPCMission(playerid);
  508.     if (mission == INVALID_MISSION)
  509.     {
  510.         return 1;
  511.     }
  512.  
  513.     if (Mission[mission][level] == 4)
  514.     {
  515.         PlayCutscene(mission);
  516.     }
  517.     return 1;
  518. }
  519.  
  520. public OnNPCFinishMove(npcid)
  521. {
  522.     // Get the NPC mission
  523.     new mission = GetNPCMission(npcid);
  524.     if (mission == INVALID_MISSION)
  525.     {
  526.         return 1;
  527.     }
  528.  
  529.     if (Mission[mission][level] == 2 || Mission[mission][level] == 3 || Mission[mission][level] == 4 || Mission[mission][level] == 5)
  530.         // Stop the cutscene
  531.         EndCutscene(mission);
  532.  
  533.     return 1;
  534. }
  535.  
  536. stock FindFreeMissionSlot()
  537. {
  538.     for (new i = 0; i < MAX_MISSIONS; i++)
  539.     {
  540.         if (!Mission[i][started])
  541.         {
  542.             return i;
  543.         }
  544.     }
  545.     return INVALID_MISSION;
  546. }
  547.  
  548. stock FindFreeMissionPlayerSlot(mission)
  549. {
  550.     for (new i = 0; i < MAX_MISSION_PLAYERS; i++)
  551.     {
  552.         if (Mission[mission][players][i] == INVALID_PLAYER_ID)
  553.         {
  554.             return i;
  555.         }
  556.     }
  557.     return INVALID_MISSION;
  558. }
  559.  
  560. stock GetMissionPlayers(mission)
  561. {
  562.     new p = 0;
  563.     if (mission == INVALID_MISSION)
  564.     {
  565.         return p;
  566.     }
  567.     for (new i = 0; i < MAX_MISSION_PLAYERS; i++)
  568.     {
  569.         if (Mission[mission][players][i] != INVALID_PLAYER_ID)
  570.         {
  571.             p++;
  572.         }
  573.     }
  574.     return p;
  575. }
  576.  
  577. stock GetPlayerMissionSlot(playerid)
  578. {
  579.     new mission = PlayerMission[playerid];
  580.     if (mission == INVALID_MISSION)
  581.     {
  582.         return INVALID_PLAYER_ID;
  583.     }
  584.     for (new i = 0; i < MAX_MISSION_PLAYERS; i++)
  585.     {
  586.         if (Mission[mission][players][i] == playerid)
  587.         {
  588.             return i;
  589.         }
  590.     }
  591.     return INVALID_PLAYER_ID;
  592. }
  593.  
  594. stock IsAnyPlayerInRange(mission, npc)
  595. {
  596.     new Float:x, Float:y, Float:z;
  597.     NPC_GetPos(npc, x, y, z);
  598.     new bool:range = false;
  599.     for (new i = 0; i < MAX_MISSION_PLAYERS; i++)
  600.     {
  601.         if (IsPlayerConnected(Mission[mission][players][i]) && IsPlayerInRangeOfPoint(Mission[mission][players][i], 50.0, x, y, z))
  602.         {
  603.             range = true;
  604.             break;
  605.         }
  606.     }
  607.     return range;
  608. }
  609.  
  610. stock GetRandomMissionPlayerToShoot(mission, npc)
  611. {
  612.     if (!IsAnyPlayerInRange(mission, npc))
  613.         return INVALID_PLAYER_ID;
  614.  
  615.     new Float:x, Float:y, Float:z;
  616.     NPC_GetPos(npc, x, y, z);
  617.     // Choose a random id
  618.     new id = random(MAX_MISSION_PLAYERS);
  619.     // Check if he is in range
  620.     while (!IsPlayerConnected(Mission[mission][players][id]) || !IsPlayerInRangeOfPoint(Mission[mission][players][id], 50.0, x, y, z))
  621.     {
  622.         id = random(MAX_MISSION_PLAYERS);
  623.     }
  624.  
  625.     return id;
  626. }
  627.  
  628. stock MarkDead(playerid, mission)
  629. {
  630.     for (new i = 0; i < MAX_MISSION_PLAYERS; i++)
  631.     {
  632.         if (IsPlayerConnected(Mission[mission][players][i]) && Mission[mission][players][i] == playerid)
  633.         {
  634.             Mission[mission][player_dead][i] = true;
  635.             break;
  636.         }
  637.     }
  638. }
  639.  
  640. stock GetRandomMissionPlayerSpectace(mission)
  641. {
  642.     new bool:alive = false;
  643.     for (new i = 0; i < MAX_MISSION_PLAYERS; i++)
  644.     {
  645.         if (IsPlayerConnected(Mission[mission][players][i]) && !Mission[mission][player_dead][i])
  646.         {
  647.             printf("found that %d", Mission[mission][players][i]);
  648.             alive = true;
  649.             break;
  650.         }
  651.     }
  652.     if (!alive)
  653.     {
  654.         return INVALID_PLAYER_ID;
  655.     }
  656.  
  657.     new player = random(MAX_MISSION_PLAYERS);
  658.     while (!IsPlayerConnected(Mission[mission][players][player]) || Mission[mission][player_dead][player])
  659.     {
  660.         player = random(MAX_MISSION_PLAYERS);
  661.     }
  662.  
  663.     return Mission[mission][players][player];
  664. }
  665.  
  666. stock GetNPCMission(npcid)
  667. {
  668.     // Validate the NPC
  669.     if (!NPC_IsSpawned(npcid))
  670.     {
  671.         return INVALID_MISSION;
  672.     }
  673.  
  674.     for (new i = 0; i < MAX_MISSIONS; i++)
  675.     {
  676.         for (new j = 0; j < MAX_MISSION_NPCS; j++)
  677.         {
  678.             if (Mission[i][npcs][j] == npcid)
  679.             {
  680.                 return i;
  681.             }
  682.         }
  683.     }
  684.     return INVALID_MISSION;
  685. }
  686.  
  687. stock GetNPCAlive(mission)
  688. {
  689.     new a = 0;
  690.     for (new i = 0; i < MAX_MISSION_NPCS; i++)
  691.     {
  692.         if (!NPC_IsDead(Mission[mission][npcs][i]))
  693.         {
  694.             a++;
  695.         }
  696.     }
  697.     return a;
  698. }
  699.  
  700. new missiontimer[MAX_MISSIONS];
  701.  
  702. public BeginMissionTimer(mission)
  703. {
  704.     // Begin the mission
  705.     BeginMission(mission);
  706.     // Loop through all the players
  707.     for (new i = 0; i < MAX_MISSION_PLAYERS; i++)
  708.     {
  709.         GameTextForPlayer(Mission[mission][players][i], "~b~Mission started.", 3000, 0);
  710.     }
  711.  
  712.     // Start the actual mission timer
  713.     missiontimer[mission] = SetTimerEx("ProcessMissionTimer", 100, true, "i", mission);
  714.     return 1;
  715. }
  716.  
  717. new LastCutsceneTick;
  718. new LastBossTick;
  719.  
  720. public ProcessMissionTimer(mission)
  721. {
  722.     // Process cutscene
  723.     if (Mission[mission][cutscene] && Mission[mission][cutscene_process])
  724.     {
  725.         // Process cutscene from its level
  726.         if (Mission[mission][level] == 0)
  727.         {
  728.             // Get the stage
  729.             new stage = Mission[mission][cutscene_stage];
  730.             // End the cutscene if we finished all its stages
  731.             if (stage >= Mission[mission][cutscene_stages][Mission[mission][level]])
  732.             {
  733.                 // End the cutscene
  734.                 EndCutscene(mission);
  735.             }
  736.             else
  737.             {
  738.                 // Do we need to change the text ?
  739.                 if ((GetTickCount() - LastCutsceneTick) >= MissionCutsceneInfo[stage][0])
  740.                 {
  741.                     Mission[mission][cutscene_stage]++;
  742.                     // Reset the player animation
  743.                     if (stage > 0)
  744.                     {
  745.                         // Get the playerid
  746.                         new lplayer = MissionCutsceneInfo[stage-1][1];
  747.                         new lplayerid = Mission[mission][players][lplayer];
  748.                         ClearAnimations(lplayerid);
  749.                     }
  750.                     // Get the playerid
  751.                     new player = MissionCutsceneInfo[stage][1];
  752.                     new playerid = Mission[mission][players][player];
  753.                     // Make him talk
  754.                     ApplyAnimation(playerid, "PED", "IDLE_CHAT", 4.1 , 1, 1, 1, 1, 0);
  755.                     // Format the sending text
  756.                     new msg[190], name[MAX_PLAYER_NAME + 1];
  757.                     GetPlayerName(playerid, name, sizeof(name));
  758.                     format(msg, sizeof(msg), "~g~%s: ~w~%s", name, MissionCutscenes[stage]);
  759.                     // Set textdraw for all the mission players
  760.                     TextDrawSetString(TextdrawText, msg);
  761.                     // Update stage
  762.                     LastCutsceneTick = GetTickCount();
  763.                 }
  764.             }
  765.         }
  766.     }
  767.     // Process NPCs
  768.     if (Mission[mission][level] != 6)
  769.     {
  770.         for (new i = 2; i < MAX_MISSION_NPCS; i++)
  771.         {
  772.             // Validate the NPC
  773.             if (Mission[mission][npcs][i] != INVALID_PLAYER_ID && NPC_IsSpawned(Mission[mission][npcs][i]) && !NPC_IsDead(Mission[mission][npcs][i]))
  774.             {
  775.                 // Is he not shooting ?
  776.                 if (Mission[mission][npc_target][i] == INVALID_PLAYER_ID)
  777.                 {
  778.                     // Get a random mission player to shoot
  779.                     new target = GetRandomMissionPlayerToShoot(mission, Mission[mission][npcs][i]);
  780.                     if (target != INVALID_PLAYER_ID)
  781.                     {
  782.                         // Get target position
  783.                         new Float:x, Float:y, Float:z;
  784.                         GetPlayerPos(target, x, y, z);
  785.                         // Shoot him
  786.                         NPC_AimAt(Mission[mission][npcs][i], x, y, z, true);
  787.                         // Mark as shooting
  788.                         Mission[mission][npc_target][i] = target;
  789.                     }
  790.                 }
  791.                 else
  792.                 {
  793.                     // Get NPC position
  794.                     new Float:x, Float:y, Float:z;
  795.                     NPC_GetPos(Mission[mission][npcs][i], x, y, z);
  796.                     // Validate the target
  797.                     if (IsPlayerInRangeOfPoint(Mission[mission][npc_target][i], 20.0, x, y, z))
  798.                     {
  799.                         // Shoot him
  800.                         GetPlayerPos(Mission[mission][npc_target][i], x, y, z);
  801.                         NPC_AimAt(Mission[mission][npcs][i], x, y, z, true);
  802.                     }
  803.                     else
  804.                     {
  805.                         NPC_StopAim(Mission[mission][npcs][i]);
  806.                         Mission[mission][npc_target][i] = INVALID_PLAYER_ID;
  807.                     }
  808.                 }
  809.             }
  810.         }
  811.     }
  812.     // Process following
  813.     if (Mission[mission][level] == 2)
  814.     {
  815.         new Float:x, Float:y, Float:z;
  816.         NPC_GetPos(Mission[mission][npcs][0], x, y, z);
  817.         // Process players
  818.         for (new i = 0; i < MAX_MISSION_PLAYERS; i++)
  819.         {
  820.             if (!IsPlayerConnected(Mission[mission][players][i]))
  821.             {
  822.                 continue;
  823.             }
  824.  
  825.             new Float:distance = GetPlayerDistanceFromPoint(Mission[mission][players][i], x, y, z);
  826.             if (distance > 150.0)
  827.             {
  828.                 // End the mission
  829.                 EndMission(mission, "You lost the target", false);
  830.                 break;
  831.             }
  832.             else if (distance > 110.0)
  833.             {
  834.                 TextDrawSetString(TextdrawFollow, "~r~Status:~n~~w~You're loosing the target");
  835.             }
  836.             else if (distance < 25.0)
  837.             {
  838.                 // End the mission
  839.                 EndMission(mission, "You got too close", false);
  840.                 break;
  841.             }
  842.             else if (distance < 55.0)
  843.             {
  844.                 TextDrawSetString(TextdrawFollow, "~r~Status:~n~~w~The target has started to feel your presence");
  845.             }
  846.             else
  847.             {
  848.                 TextDrawSetString(TextdrawFollow, "~r~Status:~n~~w~Safe");
  849.             }
  850.         }
  851.     }
  852.     // Process boss fighting
  853.     if (Mission[mission][level] == 6)
  854.     {
  855.         // Is he not shooting ?
  856.         if (Mission[mission][npc_target][0] == INVALID_PLAYER_ID || Mission[mission][player_dead][Mission[mission][npc_target][0]] ||
  857.             (GetTickCount() - LastBossTick) >= 4000)
  858.         {
  859.             // Get a random mission player to shoot
  860.             new target = GetRandomMissionPlayerToShoot(mission, Mission[mission][npcs][0]);
  861.             if (target != INVALID_PLAYER_ID)
  862.             {
  863.                 // Get target position
  864.                 new Float:x, Float:y, Float:z;
  865.                 GetPlayerPos(target, x, y, z);
  866.                 // Shoot him
  867.                 NPC_AimAt(Mission[mission][npcs][0], x, y, z, true);
  868.                 // Mark as shooting
  869.                 Mission[mission][npc_target][0] = target;
  870.                 LastBossTick = GetTickCount();
  871.             }
  872.         }
  873.         else
  874.         {
  875.             // Get NPC position
  876.             new Float:x, Float:y, Float:z;
  877.             NPC_GetPos(Mission[mission][npcs][0], x, y, z);
  878.             // Validate the target
  879.             if (IsPlayerInRangeOfPoint(Mission[mission][npc_target][0], 20.0, x, y, z))
  880.             {
  881.                 // Shoot him
  882.                 GetPlayerPos(Mission[mission][npc_target][0], x, y, z);
  883.                 NPC_AimAt(Mission[mission][npcs][0], x, y, z, true);
  884.             }
  885.             else
  886.             {
  887.                 NPC_StopAim(Mission[mission][npcs][0]);
  888.                 Mission[mission][npc_target][0] = INVALID_PLAYER_ID;
  889.             }
  890.         }
  891.     }
  892.     return 1;
  893. }
  894.  
  895. public StartMission(slotid, starterid)
  896. {
  897.     // Create mission NPCs
  898.     for (new i = 0; i < MAX_MISSION_NPCS; i++)
  899.     {
  900.         // Generate a name
  901.         new name[24];
  902.         format(name, sizeof(name), "mission_%d_%d", slotid, i);
  903.         // Create the NPC
  904.         Mission[slotid][npcs][i] = NPC_Create(name);
  905.         if (Mission[slotid][npcs][i] == INVALID_PLAYER_ID)
  906.         {
  907.             return false;
  908.         }
  909.  
  910.         // Spawn the NPC and set his angle
  911.         NPC_Spawn(Mission[slotid][npcs][i]);
  912.         NPC_SetSkin(Mission[slotid][npcs][i], MissionNPCInfo[i][0]);
  913.         NPC_SetPos(Mission[slotid][npcs][i], MissionSpawns[i][0], MissionSpawns[i][1], MissionSpawns[i][2]);
  914.         NPC_SetFacingAngle(Mission[slotid][npcs][i], MissionSpawns[i][3]);
  915.         // Give him a weapon
  916.         NPC_SetWeapon(Mission[slotid][npcs][i], MissionNPCInfo[i][1]);
  917.         NPC_SetAmmo(Mission[slotid][npcs][i], 10000);
  918.         SetPlayerSkillLevel(Mission[slotid][npcs][i], MissionNPCInfo[i][2], 1);
  919.         // Set him to the mission virtual world
  920.         SetPlayerVirtualWorld(Mission[slotid][npcs][i], slotid + 1);
  921.     }
  922.     // Create mission vehicles
  923.     for (new i = 0; i < MAX_MISSION_VEHICLES; i++)
  924.     {
  925.         Mission[slotid][vehicles][i] = CreateVehicle(MissionVehicleInfo[i][0], MissionVehicles[i][0], MissionVehicles[i][1],
  926.             MissionVehicles[i][2], MissionVehicles[i][3], MissionVehicleInfo[i][1], MissionVehicleInfo[i][2], -1);
  927.  
  928.         // Set it to the mission virtual world
  929.         SetVehicleVirtualWorld(Mission[slotid][vehicles][i], slotid + 1);
  930.     }
  931.     // Put player into vehicle
  932.     NPC_PutInVehicle(Mission[slotid][npcs][1], Mission[slotid][vehicles][0], 0);
  933.     NPC_SetFacingAngle(Mission[slotid][npcs][1], MissionVehicles[0][3]);
  934.     // Mark mission as started and initialize its values
  935.     Mission[slotid][started] = true;
  936.     Mission[slotid][players][0] = starterid;
  937.     // Increase missions count
  938.     MissionsStarted++;
  939.     // Set player created mission
  940.     PlayerCreatedMission[starterid] = slotid;
  941.     return true;
  942. }
  943.  
  944. public EndMission(mission, const reason[], bool:success)
  945. {
  946.     if (mission == INVALID_MISSION)
  947.     {
  948.         return;
  949.     }
  950.     KillTimer(missiontimer[mission]);
  951.     FreeCamera(mission);
  952.     // Reset missions
  953.     Mission[mission][started] = false;
  954.     for (new j = 0; j < MAX_MISSION_PLAYERS; j++)
  955.     {
  956.         if (!IsPlayerConnected(Mission[mission][players][j]))
  957.         {
  958.             continue;
  959.         }
  960.  
  961.         TextDrawHideForPlayer(Mission[mission][players][j], TextdrawBox);
  962.         TextDrawHideForPlayer(Mission[mission][players][j], TextdrawBox2);
  963.         TextDrawHideForPlayer(Mission[mission][players][j], TextdrawBoxText);
  964.         TextDrawHideForPlayer(Mission[mission][players][j], TextdrawText);
  965.         TextDrawHideForPlayer(Mission[mission][players][j], TextdrawFollow);
  966.         TogglePlayerSpectating(Mission[mission][players][j], 0);
  967.         TogglePlayerControllable(Mission[mission][players][j], 1);
  968.         SetPlayerVirtualWorld(Mission[mission][players][j], 0);
  969.         if (!success)
  970.         {
  971.             new reas[164];
  972.             format(reas, sizeof(reas), "~r~Mission failed !~n~~w~%s", reason);
  973.             GameTextForPlayer(Mission[mission][players][j], reas, 5000, 0);
  974.         }
  975.         else
  976.         {
  977.             GameTextForPlayer(Mission[mission][players][j], reason, 5000, 0);
  978.         }
  979.  
  980.         PlayerMission[Mission[mission][players][j]] = INVALID_MISSION;
  981.         PlayerCreatedMission[Mission[mission][players][j]] = INVALID_MISSION;
  982.         Mission[mission][players][j] = INVALID_PLAYER_ID;
  983.         Mission[mission][player_dead][j] = false;
  984.     }
  985.     for (new j = 0; j < MAX_MISSION_NPCS; j++)
  986.     {
  987.         NPC_Destroy(Mission[mission][npcs][j]);
  988.         Mission[mission][npcs][j] = INVALID_PLAYER_ID;
  989.         Mission[mission][npc_target][j] = INVALID_PLAYER_ID;
  990.     }
  991.     for (new j = 0; j < MAX_MISSION_VEHICLES; j++)
  992.     {
  993.         DestroyVehicle(Mission[mission][vehicles][j]);
  994.     }
  995.     Mission[mission][level] = 0;
  996.     Mission[mission][cutscene] = false;
  997.     Mission[mission][cutscene_process] = false;
  998.     Mission[mission][cutscene_stage] = 0;
  999.     // Decrease missions count
  1000.     MissionsStarted--;
  1001. }
  1002.  
  1003. public JoinMission(playerid, mission, slot)
  1004. {
  1005.     // Set the player mission
  1006.     PlayerMission[playerid] = mission;
  1007.     Mission[mission][players][slot] = playerid;
  1008.     // Set the player position and skin
  1009.     SetPlayerSkin(playerid, MissionPlayerInfo[slot][0]);
  1010.     SetPlayerPos(playerid, MissionPlayerSpawns[slot][0], MissionPlayerSpawns[slot][1], MissionPlayerSpawns[slot][2]);
  1011.     SetPlayerFacingAngle(playerid, MissionPlayerSpawns[slot][3]);
  1012.     // Set the player camera position at the mission start
  1013.     SetPlayerCameraPos(playerid, 1522.93, -1050.27, 26.27);
  1014.     SetPlayerCameraLookAt(playerid, 1518.88, -1053.20, 25.89);
  1015.     TogglePlayerControllable(playerid, 0);
  1016.     // Give him a weapon
  1017.     GivePlayerWeapon(playerid, MissionPlayerInfo[slot][1], 5000);
  1018.     // Set his virtual world
  1019.     SetPlayerVirtualWorld(playerid, mission + 1);
  1020.     // Display message
  1021.     if (GetMissionPlayers(mission) < MAX_MISSION_PLAYERS)
  1022.     {
  1023.         GameTextForPlayer(playerid, "~w~Joined mission ~n~~r~Waiting for players ...", 4000, 0);
  1024.     }
  1025.     else
  1026.     {
  1027.         GameTextForPlayer(playerid, "~w~Joined mission ~n~~b~Starting ...", 4000, 0);
  1028.         SetTimerEx("BeginMissionTimer", 5000, 0, "i", mission);
  1029.     }
  1030.     // Notify others about the player join
  1031.     new msg[64], name[MAX_PLAYER_NAME];
  1032.     GetPlayerName(playerid, name, sizeof(name));
  1033.     format(msg, sizeof(msg), "~b~%s~n~~w~has joined the mission", name);
  1034.     for (new i = 0; i < MAX_MISSION_PLAYERS; i++)
  1035.     {
  1036.         if (!IsPlayerConnected(Mission[mission][players][i]) || i == slot)
  1037.         {
  1038.             continue;
  1039.         }
  1040.  
  1041.         GameTextForPlayer(Mission[mission][players][i], msg, 3000, 3);
  1042.     }
  1043. }
  1044.  
  1045. public LeaveMission(playerid)
  1046. {
  1047.     // Get the player slot in the mission
  1048.     new slot = GetPlayerMissionSlot(playerid);
  1049.     // Reset the player mission
  1050.     new mission = PlayerMission[playerid];
  1051.     if (mission != INVALID_MISSION)
  1052.     {
  1053.         Mission[mission][players][slot] = INVALID_PLAYER_ID;
  1054.         Mission[mission][player_dead][slot] = false;
  1055.     }
  1056.     PlayerMission[playerid] = INVALID_MISSION;
  1057.     PlayerCreatedMission[playerid] = INVALID_MISSION;
  1058.     // Reset player stats
  1059.     TogglePlayerSpectating(playerid, 0);
  1060.     SetCameraBehindPlayer(playerid);
  1061.     TogglePlayerControllable(playerid, 1);
  1062.     TextDrawHideForPlayer(playerid, TextdrawBox);
  1063.     TextDrawHideForPlayer(playerid, TextdrawText);
  1064.     TextDrawHideForPlayer(playerid, TextdrawBox2);
  1065.     TextDrawHideForPlayer(playerid, TextdrawBoxText);
  1066.     TextDrawHideForPlayer(playerid, TextdrawFollow);
  1067.     ClearAnimations(playerid);
  1068.     SetPlayerVirtualWorld(playerid, 0);
  1069.     // Check the players available
  1070.     if (GetMissionPlayers(mission) <= 1)
  1071.     {
  1072.         EndMission(mission, "not enough players", false);
  1073.     }
  1074.     else
  1075.     {
  1076.         // Notify others about the player leave
  1077.         new msg[64], name[MAX_PLAYER_NAME + 1];
  1078.         GetPlayerName(playerid, name, sizeof(name));
  1079.         format(msg, sizeof(msg), "~b~%s~n~~w~has left the mission", name);
  1080.         for (new i = 0; i < MAX_MISSION_PLAYERS; i++)
  1081.         {
  1082.             if (!IsPlayerConnected(Mission[PlayerMission[playerid]][players][i]) || Mission[PlayerMission[playerid]][players][i] == playerid)
  1083.             {
  1084.                 continue;
  1085.             }
  1086.  
  1087.             GameTextForPlayer(Mission[PlayerMission[playerid]][players][i], msg, 3000, 3);
  1088.         }
  1089.     }
  1090. }
  1091.  
  1092. public BeginMission(mission)
  1093. {
  1094.     // Start the first cutscene
  1095.     PlayCutscene(mission);
  1096. }
  1097.  
  1098. public PlayCutscene(mission)
  1099. {
  1100.     // Play the mission cutsecene depending on the level
  1101.     if (Mission[mission][level] == 0)
  1102.     {
  1103.         for (new i = 0; i < MAX_MISSION_PLAYERS; i++)
  1104.         {
  1105.             // Set him to his starting position
  1106.             SetPlayerPos(Mission[mission][players][i], MissionCutsceneStart[i][0], MissionCutsceneStart[i][1], MissionCutsceneStart[i][2]);
  1107.             SetPlayerFacingAngle(Mission[mission][players][i], MissionCutsceneStart[i][3]);
  1108.             SetPlayerCameraPos(Mission[mission][players][i], 1522.28, -1052.47, 27.05);
  1109.             SetPlayerCameraLookAt(Mission[mission][players][i], 1517.86, -1054.71, 26.41);
  1110.             TogglePlayerControllable(Mission[mission][players][i], 0);
  1111.             // Show the textdraw box for the player
  1112.             TextDrawShowForPlayer(Mission[mission][players][i], TextdrawBox);
  1113.             TextDrawShowForPlayer(Mission[mission][players][i], TextdrawText);
  1114.             TextDrawShowForPlayer(Mission[mission][players][i], TextdrawBox2);
  1115.             TextDrawShowForPlayer(Mission[mission][players][i], TextdrawBoxText);
  1116.             Mission[mission][cutscene_stages][0] = 13;
  1117.             Mission[mission][cutscene_process] = true;
  1118.         }
  1119.     }
  1120.     else if (Mission[mission][level] == 1)
  1121.     {
  1122.         for (new i = 0; i < MAX_MISSION_PLAYERS; i++)
  1123.         {
  1124.             SetPlayerCameraPos(Mission[mission][players][i], 1479.23, -1024.99, 31.18);
  1125.             SetPlayerCameraLookAt(Mission[mission][players][i], 1475.30, -1027.52, 29.42);
  1126.         }
  1127.         // Make the first player enter the vehicle
  1128.         NPC_EnterVehicle(Mission[mission][npcs][0], Mission[mission][vehicles][0], 1, NPC_MOVE_TYPE_WALK);
  1129.         Mission[mission][cutscene_stages][1] = 0;
  1130.         Mission[mission][cutscene_process] = false;
  1131.     }
  1132.     else if (Mission[mission][level] == 3)
  1133.     {
  1134.         // Start the playback
  1135.         NPC_StartPlayback(Mission[mission][npcs][1], "mission_2");
  1136.         for (new i = 0; i < MAX_MISSION_PLAYERS; i++)
  1137.         {
  1138.             TextDrawHideForPlayer(Mission[mission][players][i], TextdrawFollow);
  1139.             RemovePlayerFromVehicle(Mission[mission][players][i]);
  1140.             TogglePlayerControllable(Mission[mission][players][i], 0);
  1141.             SetPlayerPos(Mission[mission][players][i], MissionPlayerAttackPos[i][0], MissionPlayerAttackPos[i][1], MissionPlayerAttackPos[i][2]);
  1142.             SetPlayerFacingAngle(Mission[mission][players][i], MissionPlayerAttackPos[i][3]);
  1143.             // Lock their vehicle
  1144.             SetVehicleParamsForPlayer(Mission[mission][vehicles][1], Mission[mission][players][i], 0, 1);
  1145.         }
  1146.         // Lock camera on player
  1147.         LockCameraOn(mission, Mission[mission][npcs][0], 0);
  1148.         Mission[mission][cutscene_process] = false;
  1149.     }
  1150.     else if (Mission[mission][level] == 4)
  1151.     {
  1152.         NPC_StartPlayback(Mission[mission][npcs][0], "mission_3");
  1153.     }
  1154.     else if (Mission[mission][level] == 5)
  1155.     {
  1156.         SetPlayerVirtualWorld(Mission[mission][npcs][0], mission + 1);
  1157.         NPC_SetArmour(Mission[mission][npcs][0], 100.0);
  1158.         NPC_SetWeapon(Mission[mission][npcs][0], 38);
  1159.         NPC_SetAmmo(Mission[mission][npcs][0], 20000);
  1160.         NPC_StartPlayback(Mission[mission][npcs][0], "mission_4");
  1161.         LockCameraOn(mission, Mission[mission][npcs][0], 1);
  1162.     }
  1163.     else if (Mission[mission][level] == 6)
  1164.     {
  1165.         for (new i = 0; i < MAX_MISSION_PLAYERS; i++)
  1166.         {
  1167.             TogglePlayerSpectating(Mission[mission][players][i], 0);
  1168.             SetPlayerPos(Mission[mission][players][i], MissionPlayerEndPos[i][0], MissionPlayerEndPos[i][1], MissionPlayerEndPos[i][2]);
  1169.             SetPlayerFacingAngle(Mission[mission][players][i], MissionPlayerEndPos[i][2]);
  1170.         }
  1171.         EndMission(mission, "~b~mission accomplished", true);
  1172.     }
  1173.     // Start the tick count
  1174.     LastCutsceneTick = GetTickCount();
  1175.     // Mark cutscene as started
  1176.     Mission[mission][cutscene_stage] = 1;
  1177.     Mission[mission][cutscene] = true;
  1178. }
  1179.  
  1180. public EndCutscene(mission)
  1181. {
  1182.     // Mark cutscene as not started
  1183.     Mission[mission][cutscene_stage] = 0;
  1184.     Mission[mission][cutscene] = false;
  1185.     Mission[mission][cutscene_process] = false;
  1186.     // Increase the mission level
  1187.     Mission[mission][level]++;
  1188.     // Start the next cutscene if we should
  1189.     if (Mission[mission][level] - 1 == 0)
  1190.     {
  1191.         for (new i = 0; i < MAX_MISSION_PLAYERS; i++)
  1192.         {
  1193.             ClearAnimations(Mission[mission][players][i], 1);
  1194.             // Hide the textdraws for the player
  1195.             TextDrawHideForPlayer(Mission[mission][players][i], TextdrawBox);
  1196.             TextDrawHideForPlayer(Mission[mission][players][i], TextdrawText);
  1197.             TextDrawHideForPlayer(Mission[mission][players][i], TextdrawBox2);
  1198.             TextDrawHideForPlayer(Mission[mission][players][i], TextdrawBoxText);
  1199.         }
  1200.         PlayCutscene(mission);
  1201.     }
  1202.     else if (Mission[mission][level] - 1 == 1)
  1203.     {
  1204.         for (new i = 0; i < MAX_MISSION_PLAYERS; i++)
  1205.         {
  1206.             SetCameraBehindPlayer(Mission[mission][players][i]);
  1207.             TogglePlayerControllable(Mission[mission][players][i], 1);
  1208.             GameTextForPlayer(Mission[mission][players][i], "~r~Follow him !", 2500, 4);
  1209.             TextDrawShowForPlayer(Mission[mission][players][i], TextdrawFollow);
  1210.         }
  1211.     }
  1212.     else if (Mission[mission][level] - 1 == 2)
  1213.     {
  1214.         PlayCutscene(mission);
  1215.     }
  1216.     else if (Mission[mission][level] - 1 == 3)
  1217.     {
  1218.         NPC_ExitVehicle(Mission[mission][npcs][0]);
  1219.     }
  1220.     else if (Mission[mission][level] - 1 == 4)
  1221.     {
  1222.         FreeCamera(mission);
  1223.         for (new i = 0; i < MAX_MISSION_PLAYERS; i++)
  1224.         {
  1225.             SetCameraBehindPlayer(Mission[mission][players][i]);
  1226.             TogglePlayerControllable(Mission[mission][players][i], 1);
  1227.             GameTextForPlayer(Mission[mission][players][i], "~r~Kill them all !", 3500, 4);
  1228.         }
  1229.         // Delete the driver NPC
  1230.         NPC_Destroy(Mission[mission][npcs][1]);
  1231.         SetPlayerVirtualWorld(Mission[mission][npcs][0], 255);
  1232.     }
  1233.     else if (Mission[mission][level] - 1 == 5)
  1234.     {
  1235.         LastBossTick = GetTickCount();
  1236.         FreeCamera(mission);
  1237.         for (new i = 0; i < MAX_MISSION_PLAYERS; i++)
  1238.         {
  1239.             if (Mission[mission][player_dead][i])
  1240.             {
  1241.                 TogglePlayerSpectating(Mission[mission][players][i], 1);
  1242.                 PlayerSpectatePlayer(Mission[mission][players][i], GetRandomMissionPlayerSpectace(PlayerMission[Mission[mission][players][i]]), SPECTATE_MODE_NORMAL);
  1243.             }
  1244.             SetCameraBehindPlayer(Mission[mission][players][i]);
  1245.             TogglePlayerControllable(Mission[mission][players][i], 1);
  1246.             GameTextForPlayer(Mission[mission][players][i], "~r~Kill him !", 3500, 4);
  1247.         }
  1248.     }
  1249. }
  1250.  
  1251. new locktimer[MAX_MISSIONS];
  1252.  
  1253. public LockCameraTimer(mission, playerid, type)
  1254. {
  1255.     new Float:x, Float:y, Float:z;
  1256.     GetPlayerPos(playerid, x, y, z);
  1257.     for (new i = 0; i < MAX_MISSION_PLAYERS; i++)
  1258.     {
  1259.         if (type == 0)
  1260.         {
  1261.             SetPlayerCameraPos(Mission[mission][players][i], x + 12.0, y - 12.0, z + 12.0);
  1262.         }
  1263.         else
  1264.         {
  1265.             SetPlayerCameraPos(Mission[mission][players][i], x - 4.0, y, z + 0.2);
  1266.         }
  1267.  
  1268.         SetPlayerCameraLookAt(Mission[mission][players][i], x, y, z);
  1269.     }
  1270. }
  1271.  
  1272. stock LockCameraOn(mission, playerid, type)
  1273. {
  1274.     // Start camera lock timer
  1275.     locktimer[mission] = SetTimerEx("LockCameraTimer", 50, true, "iii", mission, playerid, type);
  1276. }
  1277.  
  1278. stock FreeCamera(mission)
  1279. {
  1280.     // Kill camera lock timer
  1281.     KillTimer(locktimer[mission]);
  1282. }
  1283.  
  1284. public OnPlayerDeath(playerid, killerid, reason)
  1285. {
  1286.     // Is he a mission player
  1287.     if (PlayerMission[playerid] != INVALID_MISSION)
  1288.     {
  1289.         // Mark the player dead
  1290.         MarkDead(playerid, PlayerMission[playerid]);
  1291.         // Is he the last one ?
  1292.         new spec = GetRandomMissionPlayerSpectace(PlayerMission[playerid]);
  1293.         if (spec != INVALID_PLAYER_ID)
  1294.         {
  1295.             TogglePlayerSpectating(playerid, 1);
  1296.             PlayerSpectatePlayer(playerid, spec, SPECTATE_MODE_NORMAL);
  1297.             new msg[64], name[MAX_PLAYER_NAME + 1];
  1298.             GetPlayerName(playerid, name, sizeof(name));
  1299.             format(msg, sizeof(msg), "~b~%s~n~~w~has died", name);
  1300.             for (new i = 0; i < MAX_MISSION_PLAYERS; i++)
  1301.             {
  1302.                 if (!IsPlayerConnected(Mission[PlayerMission[playerid]][players][i]) || Mission[PlayerMission[playerid]][players][i] == playerid)
  1303.                 {
  1304.                     continue;
  1305.                 }
  1306.  
  1307.                 GameTextForPlayer(Mission[PlayerMission[playerid]][players][i], msg, 3000, 3);
  1308.             }
  1309.         }
  1310.         else
  1311.         {
  1312.             EndMission(PlayerMission[playerid], "all players dead", false);
  1313.         }
  1314.  
  1315.         // Send a death message
  1316.         SendDeathMessage(killerid, playerid, reason);
  1317.     }
  1318. }
  1319.  
  1320. public OnNPCDeath(npcid, killerid, reason)
  1321. {
  1322.     // Is he a mission NPC ?
  1323.     new mission = GetNPCMission(npcid);
  1324.     if (mission != INVALID_MISSION)
  1325.     {
  1326.         // Did they finished killing all the NPCS ?
  1327.         new alive = GetNPCAlive(mission);
  1328.         if (alive == 2 || alive == 1)
  1329.         {
  1330.             // Play the next cutscene
  1331.             PlayCutscene(mission);
  1332.         }
  1333.  
  1334.         // Send a death message
  1335.         SendDeathMessage(killerid, npcid, reason);
  1336.  
  1337.     }
  1338.     return 1;
  1339. }
Add Comment
Please, Sign In to add comment