Advertisement
Y_Less

Military Hardware

Aug 15th, 2013
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 22.51 KB | None | 0 0
  1. /*
  2.    ============================================
  3.  
  4.    Military Hardware.  A team based progressive
  5.            assault script for SA:MP 0.1
  6.  
  7.            By Alex "Y_Less" Cole (2006)
  8.  
  9.     Code parts based on "Da Nang Thang" by Cam
  10.                 and "CNG" by Kyeman
  11.  
  12.    ============================================
  13.  
  14. ================================================================================
  15.  
  16.                                 IMPORTANT!
  17.                                ------------
  18.  
  19.                                 READ FIRST!
  20.                                ------------
  21.  
  22. This script supports a settings file system.  To use, create a file
  23. in samp/scriptfiles called "milhdset.txt".  There are 3 settings you can set
  24. in there, round time, capture time and military start point (from 0 - 3)
  25.  
  26. Example settings file:
  27.  
  28. captime = 10
  29. rndtime = 1200
  30. strtpnt = 0
  31.  
  32. captime and rndtime are in seconds.
  33.  
  34. ================================================================================
  35.  
  36. Story:
  37.  
  38. A group of militant fighters have stolen a piece of military
  39. technology and hidden it high up on a mountain.  Unfortunately
  40. they have AA defences in place so parachuting on is impossible,
  41. so the only way to get there is fighting up from the base.
  42.  
  43. A SWAT team have been sent in via the beach to retake the kit.
  44.  
  45. SWAT objectives:
  46.  
  47. 1) Capture the resupply and tech center in a sawmill.
  48. 2) Gain a foothold at the base of the mountain.
  49. 3) Capture the log cabin being used as a staging post.
  50. 3) Get to the top of the mountain to retake the kit.
  51.  
  52. Millitant objectives:
  53.  
  54. 1) Stop the SWAT capturing the technology and other checkpoints.
  55.  
  56. */
  57.  
  58. #include <a_samp>
  59. #include <core>
  60. #include <float>
  61. #include <file>
  62.  
  63. static gTeam[MAX_PLAYERS];
  64. new gPlayerClass[MAX_PLAYERS];
  65.  
  66. #define TEAM_SWAT 1
  67. #define TEAM_MILL 2
  68. #define TEAM_SWAT_COLOR 0x33AA33AA
  69. #define TEAM_MILL_COLOR 0x3333AAAA
  70. #define OBJECTIVE_COLOR 0xAA3333FF
  71. #define CHECK_CAP_LOOPS 10 // Time to capture in SECONDS
  72. //#define GAME_LENGTH 1200 // Seconds (900 = 15 mins)
  73.  
  74. new gPrefs[3] = {1200, 10, 0}; // Round time, Capture seconds, Start point// gRoundTime
  75. //new gPrefs[1] = 10; // gCapLoops
  76. //new gPrefs[2] = 0; // gAssaultPos
  77. new gPlayerCheck = -1;
  78. new gTimer, gGameTimer; //, gGameStart;
  79. new gMinsGone = 0;
  80. new gTimerLoops = 0;
  81. new gObjectiveReached = 0;
  82. //new File:hFile;// = fopen("coords.txt", io_readwrite);
  83.  
  84.  
  85. // Define all the spawn and check points
  86.  
  87. new Float:gTargets[4][3] =
  88. {
  89.     {-2046.0, -2391.0, 30.0},
  90.     {-2394.0, -2205.0, 33.0},
  91.     {-2816.0, -1521.0, 140.0},
  92.     {-2318.0, -1627.0, 483.0}
  93. };
  94.  
  95. new Float:gAllSpawnPoints[5][10][4] =
  96. {
  97.     {
  98.         {-2789.0, -2324.0, 5.0, -88.0},
  99.         {-2777.0, -2500.0, 4.0, -67.0},
  100.         {-2727.0, -2717.0, 2.0, -21.0},
  101.         {-2551.0, -2803.0, 4.0, 12.0},
  102.         {-2356.0, -2846.0, 1.0, 3.0},
  103.         {-2291.0, -2843.0, 2.0, -74.0},
  104.         {-2081.0, -2840.0, 3.0, 0.0},
  105.         {-1800.0, -2726.0, 2.0, -243.0},
  106.         {-1898.0, -2780.0, 5.0, -265.0},
  107.         {-2640.0, -2187.0, 3.0, -208.0}
  108.     },
  109.     {
  110.         {-1994.0, -2381.0, 31.0, -29.0},
  111.         {-2100.0, -2516.0, 31.0, 50.0},
  112.         {-2189.0, -2510.0, 32.0, -33.0},
  113.         {-2301.0, -2360.0, 36.0, 79.0},
  114.         {-2193.0, -2256.0, 31.0, -213.0},
  115.         {-2088.0, -2344.0, 31.0, -220.0},
  116.         {-2144.0, -2444.0, 31.0, -216.0},
  117.         {-2108.0, -2401.0, 32.0, -130.0},
  118.         {-2100.0, -2230.0, 31.0, -206.0},
  119.         {-2232.0, -2556.0, 32.0, 56.0}
  120.     },
  121.     {
  122.         {-2094.0, -1874.0, 111.0, -217.0},
  123.         {-2445.0, -2134.0, 60.0, -142.0},
  124.         {-2490.0, -2275.0, 30.0, -55.0},
  125.         {-2330.0, -2209.0, 33.0, -120.0},
  126.         {-2193.0, -2125.0, 51.0, -181.0},
  127.         {-2412.0, -2171.0, 33.0, -96.0},
  128.         {-2402.0, -2268.0, 16.0, -68.0},
  129.         {-2282.0, -2162.0, 37.0, -135.0},
  130.         {-2417.0, -2229.0, 34.0, -68.0},
  131.         {-2352.0, -2153.0, 48.0, -149.0}
  132.     },
  133.     {
  134.         {-2730.0, -1851.0, 149.0, -151.0},
  135.         {-2877.0, -1520.0, 138.0, -101.0},
  136.         {-2771.0, -1253.0, 125.0, -196.0},
  137.         {-2675.0, -1363.0, 251.0, -243.0},
  138.         {-2773.0, -1906.0, 118.0, -117.0},
  139.         {-2820.0, -1452.0, 136.0, -176.0},
  140.         {-2681.0, -1231.0, 161.0, -216.0},
  141.         {-2698.0, -1725.0, 254.0, -203.0},
  142.         {-2770.0, -1636.0, 142.0, -183.0},
  143.         {-2720.0, -1888.0, 136.0, -170.0}
  144.     },
  145.     {
  146.         {-2230.0, -1743.0, 481.0, 38.0},
  147.         {-2647.0, -1465.0, 312.0, 62.0},
  148.         {-2517.0, -1818.0, 380.0, 41.0},
  149.         {-2560.0, -1478.0, 361.0, -159.0},
  150.         {-2281.0, -1545.0, 433.0, -31.0},
  151.         {-2407.0, -1695.0, 456.0, 80.0},
  152.         {-2360.0, -1851.0, 418.0, -36.0},
  153.         {-2432.0, -1620.0, 527.0, -196.0},
  154.         {-2279.0, -1507.0, 407.0, 47.0},
  155.         {-2401.0, -1859.0, 408.0, 12.0}
  156.     }
  157. };
  158.  
  159. main()
  160. {
  161.     print("\n ============================================\n");//\n");
  162.     print(" Military Hardware.  A team based progressive\n");
  163.     print("         assault script for SA:MP 0.1\n");//\n");
  164.     print("         By Alex \"Y_Less\" Cole (2006)\n");//\n");
  165.     //print("  Code parts based on \"Da Nang Thang\" by Cam\n");
  166.     //print("              and \"CNG\" by Kyeman\n\n");
  167.     print(" ============================================\n");
  168. }
  169.  
  170. public OnGameModeInit()
  171. {
  172.     //print("GameModeInit()");
  173.     SetGameModeText("Military Hardware");
  174.  
  175.     // Swat classes (team 0)
  176.     AddPlayerClass(285, -2371.5, -1918.0, 0.0, 0.0, 4, 0, 23, 50, 28, 200);
  177.     AddPlayerClass(285, -2371.5, -1918.0, 0.0, 0.0, 4, 0, 23, 50, 29, 200);
  178.     AddPlayerClass(285, -2371.5, -1918.0, 0.0, 0.0, 3, 0, 22, 30, 34, 20);
  179.     AddPlayerClass(285, -2371.5, -1918.0, 0.0, 0.0, 3, 0, 22, 50, 27, 25);
  180.     AddPlayerClass(285, -2371.5, -1918.0, 0.0, 0.0, 3, 0, 39, 5, 31, 70);
  181.  
  182.     // Militant classes (team 1)
  183.     AddPlayerClass(157, -2371.5, -1918.0, 0.0, 0.0, 6, 0, 22, 50, 28, 200);
  184.     AddPlayerClass(161, -2371.5, -1918.0, 0.0, 0.0, 7, 0, 22, 50, 29, 200);
  185.     AddPlayerClass(198, -2371.5, -1918.0, 0.0, 0.0, 5, 0, 22, 30, 33, 20);
  186.     AddPlayerClass(201, -2371.5, -1918.0, 0.0, 0.0, 2, 0, 24, 20, 25, 25);
  187.     AddPlayerClass(202, -2371.5, -1918.0, 0.0, 0.0, 42, 0, 39, 5, 30, 70);
  188.  
  189.     // Hydra
  190.     AddStaticVehicle(520, -2318.0, -1627.0, 483.0, 0.0, -1, -1);
  191.  
  192.     // Vehicles
  193.     AddStaticVehicle(539, -2355.0, -2850.0, 1.0, 3.0, -1, -1);
  194.     AddStaticVehicle(422, -1926.0, -2738.0, 14.0, -240.0, -1, -1);
  195.     AddStaticVehicle(483, -2544.0, -2173.0, 30.0, -6.0, -1, -1);
  196.     AddStaticVehicle(468, -2414.0, -2194.0, 33.0, -97.0, -1, -1);
  197.     AddStaticVehicle(525, -2219.0, -2147.0, 44.0, -235.0, -1, -1);
  198.     AddStaticVehicle(499, -2113.0, -2241.0, 30.0, -44.0, -1, -1);
  199.     AddStaticVehicle(507, -2089.0, -2241.0, 31.0, -226.0, -1, -1);
  200.     AddStaticVehicle(515, -1968.0, -2434.0, 30.0, -222.0, -1, -1);
  201.     AddStaticVehicle(500, -2096.0, -2542.0, 30.0, -47.0, 0, 0); // Black Mesa (Half Life :p)
  202.     AddStaticVehicle(466, -2125.0, -2503.0, 30.0, -126.0, -1, -1);
  203.     AddStaticVehicle(458, -2234.0, -2571.0, 31.0, 67.0, -1, -1);
  204.     AddStaticVehicle(522, -2208.0, -2508.0, 30.0, -40.0, -1, -1);
  205.     AddStaticVehicle(517, -2151.7, -2441.0, 30.0, -216.0, -1, -1);
  206.     AddStaticVehicle(481, -2550.0, -2674.0, 8.0, 48.0, -1, -1);
  207.     AddStaticVehicle(588, -2222.0, -2767.0, 36.0, -260.0, -1, -1);
  208.     AddStaticVehicle(573, -1735.0, -1916.0, 98.0, 89.0, -1, -1);
  209.     AddStaticVehicle(470, -1912.0, -1671.0, 23.0, -90.0, -1, -1);
  210.     AddStaticVehicle(486, -1852.0, -1614.0, 21.0, -209.0, -1, -1);
  211.     AddStaticVehicle(478, -2206.0, -2254.0, 30.0, -129.0, -1, -1);
  212.     AddStaticVehicle(510, -2381.0, -2204.0, 33.0, -24.0, -1, -1);
  213.     AddStaticVehicle(510, -2383.0, -2211.0, 33.0, -32.0, -1, -1);
  214.     AddStaticVehicle(495, -1996.0, -1560.0, 85.0, -188.0, -1, -1);
  215.     AddStaticVehicle(468, -2215.0, -1918.0, 237.0, -85.0, -1, -1);
  216.     AddStaticVehicle(471, -2686.0, -1726.0, 253.0, 26.0, -1, -1);
  217.     AddStaticVehicle(422, -2816.0, -1536.0, 139.0, -85.0, -1, -1);
  218.     AddStaticVehicle(426, -2784.0, -1525.0, 139.0, -177.0, -1, -1);
  219.     AddStaticVehicle(404, -2522.0, -1125.0, 178.0, -208.0, -1, -1);
  220.     AddStaticVehicle(471, -2330.0, -1091.0, 94.0, 217.0, -1, -1);
  221.     AddStaticVehicle(468, -2667.0, -1548.0, 305.0, 45.0, -1, -1);
  222.     AddStaticVehicle(510, -2528.0, -1704.0, 401.0, -161.0, -1, -1);
  223.     AddStaticVehicle(489, -2353.0, -1468.0, 391.0, -268.0, -1, -1);
  224.     AddStaticVehicle(587, -2345.0, -1823.0, 433.0, -89.0, -1, -1);
  225.     AddStaticVehicle(580, -2252.0, -1712.0, 480.0, 40.0, -1, -1);
  226.     AddStaticVehicle(413, -2334.0, -1579.0, 483.0, -128.0, -1, -1);
  227.     AddStaticVehicle(531, -2849.0, -1548.0, 139.0, -54.0, -1, -1);
  228.     AddStaticVehicle(414, -2615.0, -2156.0, 68.0, 69.0, -1, -1);
  229.  
  230.     /*if (fexist("coords.txt"))
  231.     {
  232.         fremove("coords.txt");
  233.     }*/
  234.     //hFile = fopen("coords.txt", io_readwrite);
  235.  
  236.     //gGameTimer = SetTimer("TimeUp", gPrefs[0], 0);
  237.     //gGameStart = GetTickCount();
  238.     ReadPrefs();
  239.     new mintime;
  240.     if (gPrefs[0] > 300)
  241.     {
  242.         mintime = (gPrefs[0] - ((gPrefs[0] / 300) * 300)) * 1000;
  243.     }
  244.     else // Assume they have a round longer than 1 min.
  245.     {
  246.         mintime = (gPrefs[0] - ((gPrefs[0] / 60) * 60)) * 1000;
  247.     }
  248.     if (mintime == 0)
  249.     {
  250.         mintime = 60000; // If they have an exact time, set it to the 1 min default.
  251.     }
  252.     gGameTimer = SetTimer("TimeGone", mintime, 0); // Start checking
  253.     //TimeGone();
  254.     return 1;
  255. }
  256.  
  257. public ReadPrefs()
  258. {
  259.     new prefnm[3][8] =
  260.     {
  261.         "rndtime",
  262.         "captime",
  263.         "strtpnt"
  264.         //"svtm"
  265.     };
  266.     new tmpval;
  267.     for (new i = 0; i < 3; i++)
  268.     {
  269.         tmpval = GetStatsValue(prefnm[i], "milhdset.txt");
  270.         //tmpval = strval("1");
  271.         if (tmpval != -1)
  272.         {
  273.             gPrefs[i] = tmpval;
  274.         }
  275.         //printf("gPrefs[%d] = %d", i, gPrefs[i]);
  276.         //new tmpstr[256];
  277.         //format(tmpstr, 256, "%s = %d", prefnm[i], gPrefs[i]);
  278.     }
  279.     if (gPrefs[2] > 3)
  280.     {
  281.         gPrefs[2] = 0;
  282.         //print("gPrefs[2] now = 0");
  283.     }
  284. }
  285.  
  286. public GetStatsValue(const paramname[], const statname[])
  287. {
  288.     if (fexist(statname))
  289.     {
  290.         new File:file = fopen(statname, io_read);
  291.         new tmpbuf[256];
  292.         new splitbuf[4][256];
  293.         while (fread(file, tmpbuf, sizeof (tmpbuf)))
  294.         {
  295.             split(tmpbuf, splitbuf, ' ');
  296.             if (!strcmp(paramname, splitbuf[0]))
  297.             {
  298.                 fclose(file);
  299.                 if (splitbuf[1][0] == '=')
  300.                 {
  301.                     if (splitbuf[2][0])
  302.                     {
  303.                         return strval(splitbuf[2]);
  304.                     }
  305.                     else
  306.                     {
  307.                         return -1;
  308.                     }
  309.                 }
  310.                 else
  311.                 {
  312.                     if (splitbuf[1][0])
  313.                     {
  314.                         return strval(splitbuf[1]);
  315.                     }
  316.                     else
  317.                     {
  318.                         return -1;
  319.                     }
  320.                 }
  321.             }
  322.         }
  323.         fclose(file);
  324.     }
  325.     return -1;
  326. }
  327.  
  328. public split(const strsrc[], strdest[][], delimiter)
  329. {
  330.     new i, li;
  331.     new aNum;
  332.     new len;
  333.     while (i <= strlen(strsrc))
  334.     {
  335.         if ((strsrc[i] == delimiter) || (i == strlen(strsrc)))
  336.         {
  337.             len = strmid(strdest[aNum], strsrc, li, i, 128);
  338.             strdest[aNum][len] = 0;
  339.             li = i + 1;
  340.             aNum++;
  341.         }
  342.         i++;
  343.     }
  344.     return 1;
  345. }
  346.  
  347. public TimeGone()
  348. {
  349.     //KillTimer(gGameTimer);
  350.     if (gObjectiveReached == 0)
  351.     {
  352.         //new timestr2[256];
  353.         //format(timestr2, 256, "gPrefs[0]: %d", gPrefs[0]);
  354.         //SendClientMessageToAll(TEAM_SWAT_COLOR, timestr2);
  355.         new timestr[256];
  356.         if (gPrefs[0] > 300)
  357.         {
  358.             gPrefs[0] -= 60;
  359.             gMinsGone++;
  360.             if (gMinsGone == 5)
  361.             {
  362.                 format(timestr, 256, "~w~%d minutes remaining.", (gPrefs[0] / 60));
  363.                 GameTextForAll(timestr, 5000, 3);
  364.                 gMinsGone = 0;
  365.             }
  366.             gGameTimer = SetTimer("TimeGone", 60000, 0);
  367.         }
  368.         else if (gPrefs[0] > 120)
  369.         {
  370.             gPrefs[0] -= 60;
  371.             format(timestr, 256, "~w~%d minutes remaining.", (gPrefs[0] / 60));
  372.             GameTextForAll(timestr, 5000, 3);
  373.             gGameTimer = SetTimer("TimeGone", 60000, 0);
  374.         }
  375.         else if (gPrefs[0] == 120)
  376.         {
  377.             gPrefs[0] -= 60;
  378.             GameTextForAll("~w~1 minute remaining.", 5000, 3);
  379.             gGameTimer = SetTimer("TimeGone", 10000, 0);
  380.         }
  381.         else if (gPrefs[0] > 20)
  382.         {
  383.             gPrefs[0] -= 10;
  384.             gGameTimer = SetTimer("TimeGone", 10000, 0);
  385.         }
  386.         else if (gPrefs[0] == 20)
  387.         {
  388.             gPrefs[0] -= 10;
  389.             GameTextForAll("~w~10", 1200, 3);
  390.             gGameTimer = SetTimer("TimeGone", 1000, 0);
  391.         }
  392.         else if (gPrefs[0] > 1)
  393.         {
  394.             gPrefs[0] -= 1;
  395.             format(timestr, 256, "~w~%d", gPrefs[0]);
  396.             GameTextForAll(timestr, 1200, 3);
  397.             gGameTimer = SetTimer("TimeGone", 1000, 0);
  398.         }
  399.         else
  400.         {
  401.             TimeUp();
  402.         }
  403.     }
  404. }
  405.  
  406. public TimeUp()
  407. {
  408.     for (new i = 0; i < MAX_PLAYERS; i++)
  409.     {
  410.         if (gTeam[i] == TEAM_SWAT)
  411.         {
  412.             GameTextForPlayer(i, "~g~You failed to retrieve the Equipment, you have lost.", 5000, 3);
  413.         }
  414.         else if (gTeam[i] == TEAM_MILL)
  415.         {
  416.             GameTextForPlayer(i, "~b~You successfully defended the plane, you have won.", 5000, 3);
  417.         }
  418.     }
  419.     SetTimer("ExitTheGameMode", 5000, 0);
  420.     ResetTimer();
  421.     KillCheck();
  422. }
  423.  
  424. public SetPlayerTeamFromClass(playerid, classid)
  425. {
  426.     // Set their team number based on the class they selected.
  427.     //if (gTeam[playerid] == 0)
  428.     //{
  429.     if (classid < 5)
  430.     {
  431.         gTeam[playerid] = TEAM_SWAT;
  432.     }
  433.     else
  434.     {
  435.         gTeam[playerid] = TEAM_MILL;
  436.     }
  437.     /*}
  438.     else
  439.     // Keep the teams (don't know if this will work).
  440.     {
  441.         if ((classid == 0) && (gTeam[playerid] != TEAM_SWAT))
  442.         {
  443.             classid = 1;
  444.         }
  445.         else if ((classid == 1) && (gTeam[playerid] != TEAM_MILL))
  446.         {
  447.             classid = 0;
  448.         }
  449.     }*/
  450. }
  451.  
  452. public SetPlayerToTeamColor(playerid)
  453. {
  454.     if (gTeam[playerid] == TEAM_SWAT)
  455.     {
  456.         SetPlayerColor(playerid, TEAM_SWAT_COLOR);
  457.     }
  458.     else if (gTeam[playerid] == TEAM_MILL)
  459.     {
  460.         SetPlayerColor(playerid, TEAM_MILL_COLOR);
  461.     }
  462.     //printf(" SetPlayerToTeamColor(%d, %d)", playerid, GetPlayerColor(playerid));
  463. }
  464.  
  465. public OnPlayerRequestClass(playerid, classid)
  466. {
  467.     SetPlayerTeamFromClass(playerid, classid);
  468.     SetupPlayerForClassSelection(playerid);
  469.     gPlayerClass[playerid] = classid;
  470.     if (classid < 5)
  471.     {
  472.         GameTextForPlayer(playerid, "~w~Military Hardware~n~~g~Attack", 500000, 6);
  473.     }
  474.     else
  475.     {
  476.         GameTextForPlayer(playerid, "~w~Military Hardware~n~~b~Defend", 500000, 6);
  477.     }
  478.     return 1;
  479. }
  480.  
  481. public SetupPlayerForClassSelection(playerid)
  482. {
  483.     SetPlayerInterior(playerid, 6);
  484.     SetPlayerPos(playerid, 2336.0, -1066.0, 1049.0);
  485.     SetPlayerFacingAngle(playerid, 43);
  486.     SetPlayerCameraPos(playerid, 2333.0, -1063.0, 1050.0);
  487.     SetPlayerCameraLookAt(playerid, 2336.0, -1066.0, 1049.0);
  488. }
  489.  
  490. public ExitTheGameMode()
  491. {
  492.     GameModeExit();
  493. }
  494.  
  495. public OnGameModeExit()
  496. {
  497.     KillCheck();
  498.     return 1;
  499. }
  500.  
  501. public KillCheck()
  502. {
  503.     for (new i = 0; i < MAX_PLAYERS; i++)
  504.     {
  505.         DisablePlayerCheckpoint(i);
  506.     }
  507.     gObjectiveReached = 1;
  508.     KillTimer(gGameTimer);
  509. }
  510.  
  511. public OnPlayerStateChange(playerid, newstate, oldstate)
  512. {
  513.     if (gObjectiveReached)
  514.     {
  515.         return 1;
  516.     }
  517.     else
  518.     {
  519.         if (newstate > 1)
  520.         {
  521.             if (playerid == gPlayerCheck)
  522.             {
  523.                 ResetTimer();
  524.             }
  525.             return 1;
  526.         }
  527.         else if ((gPlayerCheck == -1) && (IsPlayerInCheckpoint(playerid)))
  528.         {
  529.             gPlayerCheck = playerid;
  530.             gTimer = SetTimer("CheckCheckpoint", 1000, gPrefs[1]);
  531.             FormatTimeText(gPrefs[1]);
  532.         }
  533.     }
  534.     return 1;
  535. }
  536.  
  537. public OnPlayerConnect(playerid)
  538. {
  539.     //printf("OnPlayerConnect(%d)", playerid);
  540.     GameTextForPlayer(playerid, "Military Hardware", 2500, 5);
  541.     return 1;
  542. }
  543.  
  544. public OnPlayerDisconnect(playerid)
  545. {
  546.     if (playerid == gPlayerCheck)
  547.     {
  548.         ResetTimer();
  549.     }
  550.     gTeam[playerid] = 0;
  551.     return 1;
  552. }
  553.  
  554. public OnPlayerSpawn(playerid)
  555. {
  556.     //printf("OnPlayerSpawn(%d)", playerid);
  557.     SetPlayerInterior(playerid,0);
  558.     SetPlayerToTeamColor(playerid);
  559.     SetPlayerRandomSpawn(playerid);
  560.     NewCheckpointText(playerid);
  561.     GivePlayerMoney(playerid, 1000);
  562.     SetPlayerWorldBounds(playerid, -1694.0, -3049.0, -887.0, -2949.0);
  563.     SetVehicleParamsForPlayer(1, playerid, 0, 1);
  564.     DisablePlayerCheckpoint(playerid);
  565.     if (gTeam[playerid] == TEAM_SWAT)
  566.     {
  567.         SetPlayerCheckpoint(playerid, gTargets[gPrefs[2]][0], gTargets[gPrefs[2]][1], gTargets[gPrefs[2]][2], 5.0); // -2394.0, -2205.0, 33.0, 5.0);
  568.     }
  569.     //GetPlayerPos()
  570.     return 1;
  571. }
  572.  
  573. public ResetTimer()
  574. {
  575.     KillTimer(gTimer);
  576.     gPlayerCheck = -1;
  577.     gTimerLoops = 0;
  578. }
  579.  
  580. public ChangeCheckpoint()
  581. {
  582.     if (gTimer)
  583.     {
  584.         ResetTimer();
  585.     }
  586.     if (gPrefs[2] < 3)
  587.     {
  588.         gPrefs[2]++;
  589.         SetTimer("CheckpointText", 5000, 0);
  590.         for (new i = 0; i < MAX_PLAYERS; i++)
  591.         {
  592.             DisablePlayerCheckpoint(i);
  593.             if (gTeam[i] == TEAM_SWAT)
  594.             {
  595.                 //DisablePlayerCheckpoint(i);
  596.                 SetPlayerCheckpoint(i, gTargets[gPrefs[2]][0], gTargets[gPrefs[2]][1], gTargets[gPrefs[2]][2], 5.0);
  597.             }
  598.         }
  599.     }
  600.     else
  601.     {
  602.         for (new i = 0; i < MAX_PLAYERS; i++)
  603.         {
  604.             DisablePlayerCheckpoint(i);
  605.         }
  606.         SetTimer("ExitTheGameMode", 5000, 0);
  607.         //gObjectiveReached = 1;
  608.         KillCheck();
  609.         ResetTimer();
  610.     }
  611.     return 0;
  612. }
  613.  
  614. public SetPlayerRandomSpawn(playerid)
  615. {
  616.     //printf("SetPlayerRandomSpawn(%d)", playerid);
  617.     new pos = gTeam[playerid] + gPrefs[2] - 1;
  618.     new rand = random(10); // Choose a random number within the array of random spawns
  619.     SetPlayerPos(playerid, gAllSpawnPoints[pos][rand][0], gAllSpawnPoints[pos][rand][1], gAllSpawnPoints[pos][rand][2]); // Warp the player
  620.     return 1;
  621. }
  622.  
  623. public OnPlayerDeath(playerid, killerid, reason)
  624. {
  625.     if (playerid == gPlayerCheck)
  626.     {
  627.         ResetTimer();
  628.     }
  629.     new deathstr[256];
  630.     new whodiedname[MAX_PLAYER_NAME+1];
  631.     new whokilledname[MAX_PLAYER_NAME+1];
  632.     new deathreasonstr[256];
  633.     GetPlayerName(playerid, whodiedname, MAX_PLAYER_NAME);
  634.     GetWeaponName(reason, deathreasonstr, 255);
  635.     if (killerid == INVALID_PLAYER_ID)
  636.     {
  637.         if (strlen(deathreasonstr))
  638.         {
  639.             format(deathstr, 256, "%s died (%s)", whodiedname, deathreasonstr);
  640.         }
  641.         else
  642.         {
  643.             format(deathstr, 256, "%s died", whodiedname);
  644.         }
  645.         SendClientMessageToAll(OBJECTIVE_COLOR, deathstr);
  646.     }
  647.     else
  648.     {
  649.         GetPlayerName(killerid, whokilledname, MAX_PLAYER_NAME);
  650.         if (gTeam[killerid] != gTeam[playerid])
  651.         {
  652.             // Valid kill
  653.             if (strlen(deathreasonstr))
  654.             {
  655.                 format(deathstr, 256, "%s was killed by %s (%s)", whodiedname, whokilledname, deathreasonstr);
  656.             }
  657.             else
  658.             {
  659.                 format(deathstr, 256, "%s was killed by %s", whodiedname, whokilledname);
  660.             }
  661.             SendClientMessageToAll(OBJECTIVE_COLOR, deathstr);
  662.             SetPlayerScore(killerid, GetPlayerScore(killerid) + 1);
  663.         }
  664.         else
  665.         {
  666.             // Team kill
  667.             format(deathstr, 256, "%s killed team-mate %s (%s)", whokilledname, whodiedname, deathreasonstr);
  668.             SendClientMessageToAll(OBJECTIVE_COLOR, deathstr);
  669.         }
  670.     }
  671.     return 1;
  672. }
  673.  
  674. /*public OnPlayerCommandText(playerid, cmdtext[])
  675. {
  676.     if (IsPlayerAdmin(playerid))
  677.     {
  678.         if (strcmp(cmdtext, "/inctarget", true)==0)
  679.         {
  680.             print("Entered /inctarget");
  681.             ChangeCheckpoint();
  682.             CheckpointText();
  683.             return 1;
  684.         }
  685.     }
  686.         else if (strcmp(cmdtext, "/gc", true)==0)
  687.         {
  688.             print("Entered /gc");
  689.             new Float:x, Float:y, Float:z;
  690.             GetPlayerPos(playerid, x, y, z);
  691.             new coordsstring[256];
  692.             //new File:hFile = fopen("coords.txt", io_readwrite);
  693.             //new readstr[flength(hFile)];
  694.             //fread(hFile, readstr, flength(hFile), false);
  695.             format(coordsstring, 256, "\nAddStaticVehicle(0, %.1f, %.1f, %.1f, 93.0, -1, -1);\n", x, y, z);
  696.             //fwrite(hFile, coordsstring);
  697.             for (new i = 0; i < 256; i++)
  698.             {
  699.                 fputchar(hFile, coordsstring[i], true);
  700.             }
  701.             //fclose(hFile);
  702.             //fwrite(hFile, "hi");
  703.             return 1;
  704.         }
  705.         else if (strcmp(cmdtext, "/kill", true)==0)
  706.         {
  707.             SetPlayerHealth(playerid, 0.0);
  708.         }
  709.     //}
  710.     //else
  711.     //{
  712.         //printf ("Player %d entered: %s.", playerid, cmdtext);
  713.     //}
  714.     return 0;
  715. }*/
  716.  
  717. public OnPlayerEnterCheckpoint(playerid)
  718. {
  719.     if (gObjectiveReached)
  720.     {
  721.         return 1;
  722.     }
  723.     if ((gPlayerCheck == -1) && (!IsPlayerInAnyVehicle(playerid)))
  724.     {
  725.         gPlayerCheck = playerid;
  726.         gTimer = SetTimer("CheckCheckpoint", 1000, gPrefs[1]);
  727.         FormatTimeText(gPrefs[1]);
  728.     }
  729.     return 1;
  730. }
  731.  
  732. public CheckCheckpoint()
  733. {
  734.     if (IsPlayerInCheckpoint(gPlayerCheck) && !IsPlayerInAnyVehicle(gPlayerCheck))
  735.     {
  736.    
  737.         gTimerLoops++;
  738.         if (gTimerLoops == gPrefs[1])
  739.         {
  740.             CaptureText();
  741.             ChangeCheckpoint();
  742.         }
  743.         else
  744.         {
  745.             new timeremain = gPrefs[1] - gTimerLoops;
  746.             FormatTimeText(timeremain);
  747.         }
  748.     }
  749.     else
  750.     {
  751.         ResetTimer();
  752.     }
  753. }
  754.  
  755. public CheckpointText()
  756. {
  757.     for (new i = 0; i < MAX_PLAYERS; i++)
  758.     {
  759.         NewCheckpointText(i);
  760.     }
  761. }
  762.  
  763. public NewCheckpointText(n)
  764. {
  765.     if (gTeam[n] == TEAM_SWAT)
  766.     {
  767.         switch (gPrefs[2])
  768.         {
  769.             case 0:
  770.             {
  771.                 GameTextForPlayer(n, "~g~Capture the ~r~Logging Works ~g~being used as a headquaters.", 5000, 3);
  772.             }
  773.             case 1:
  774.             {
  775.                 GameTextForPlayer(n, "~g~Gain a foothold at the ~r~base of the mountain.", 5000, 3);
  776.             }
  777.             case 2:
  778.             {
  779.                 GameTextForPlayer(n, "~g~Capture the ~r~log cabin ~g~being used as a staging post.", 5000, 3);
  780.             }
  781.             case 3:
  782.             {
  783.                 GameTextForPlayer(n, "~g~Retake the piece of ~r~Military Hardware.", 5000, 3);
  784.             }
  785.         }
  786.     }
  787.     else if (gTeam[n] == TEAM_MILL)
  788.     {
  789.         switch (gPrefs[2])
  790.         {
  791.             case 0:
  792.             {
  793.                 GameTextForPlayer(n, "~b~Defend the Headquaters in the Logging Works.", 5000, 3);
  794.             }
  795.             case 1:
  796.             {
  797.                 GameTextForPlayer(n, "~b~Stop the SWAT gaining foothold at the base of the mountain.", 5000, 3);
  798.             }
  799.             case 2:
  800.             {
  801.                 GameTextForPlayer(n, "~b~Defend the log cabin staging post.", 5000, 3);
  802.             }
  803.             case 3:
  804.             {
  805.                 GameTextForPlayer(n, "~b~Defend the plane at ALL costs.", 5000, 3);
  806.             }
  807.         }
  808.     }
  809. }
  810.  
  811. public CaptureText()
  812. {
  813.     for (new i = 0; i < MAX_PLAYERS; i++)
  814.     {
  815.         if (i == gPlayerCheck)
  816.         {
  817.             switch (gPrefs[2])
  818.             {
  819.                 case 0:
  820.                 {
  821.                     GameTextForPlayer(i, "~g~You captured the Logging Works HQ.", 5000, 3);
  822.                 }
  823.                 case 1:
  824.                 {
  825.                     GameTextForPlayer(i, "~g~You secured the base of the mountain.", 5000, 3);
  826.                 }
  827.                 case 2:
  828.                 {
  829.                     GameTextForPlayer(i, "~g~You captured the staging post.", 5000, 3);
  830.                 }
  831.                 case 3:
  832.                 {
  833.                     GameTextForPlayer(i, "~g~Congratulations!  You retrieved the plane.~n~You have won.", 5000, 3);
  834.                 }
  835.             }
  836.             SetPlayerScore(i, GetPlayerScore(i) + 10);
  837.         }
  838.         else if (gTeam[i] == TEAM_SWAT)
  839.         {
  840.             switch (gPrefs[2])
  841.             {
  842.                 case 0:
  843.                 {
  844.                     GameTextForPlayer(i, "~g~Logging Works captured.", 5000, 3);
  845.                 }
  846.                 case 1:
  847.                 {
  848.                     GameTextForPlayer(i, "~g~Foothold established.", 5000, 3);
  849.                 }
  850.                 case 2:
  851.                 {
  852.                     GameTextForPlayer(i, "~g~Staging post secured.", 5000, 3);
  853.                 }
  854.                 case 3:
  855.                 {
  856.                     GameTextForPlayer(i, "~g~Hydra retrieved.~n~You have won.", 5000, 3);
  857.                 }
  858.             }
  859.         }
  860.         else if (gTeam[i] == TEAM_MILL)
  861.         {
  862.             switch (gPrefs[2])
  863.             {
  864.                 case 0:
  865.                 {
  866.                     GameTextForPlayer(i, "~b~Our headquaters have been captured.", 5000, 3);
  867.                 }
  868.                 case 1:
  869.                 {
  870.                     GameTextForPlayer(i, "~b~They're coming up the mountain.", 5000, 3);
  871.                 }
  872.                 case 2:
  873.                 {
  874.                     GameTextForPlayer(i, "~b~The cabin is lost.", 5000, 3);
  875.                 }
  876.                 case 3:
  877.                 {
  878.                     GameTextForPlayer(i, "~b~Hydra retrieved.~n~You have lost.", 5000, 3);
  879.                 }
  880.             }
  881.         }
  882.     }
  883. }
  884.  
  885. public FormatTimeText(n)
  886. {
  887.     new numstring[3][256];
  888.     format(numstring[1], 256, "~g~Protect the capture!~n~Time Remaining: %d", n);
  889.     format(numstring[2], 256, "~b~Stop the capture!~n~Time Remaining: %d", n);
  890.     format(numstring[0], 256, "~g~You are in the capture zone!~n~Time Remaining: %d", n);
  891.     for (new i = 0; i < MAX_PLAYERS; i++)
  892.     {
  893.         if (i == gPlayerCheck)
  894.         {
  895.             GameTextForPlayer(i, numstring[0], 1200, 3);
  896.         }
  897.         else if (gTeam[i])
  898.         {
  899.             GameTextForPlayer(i, numstring[gTeam[i]], 1200, 3);
  900.         }
  901.     }
  902. }
  903.  
  904. public OnPlayerLeaveCheckpoint(playerid)
  905. {
  906.     if (playerid == gPlayerCheck)
  907.     {
  908.         ResetTimer();
  909.     }
  910.     return 1;
  911. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement