missions.pwn 37 KB

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