Guest User

Zombie

a guest
Jan 7th, 2019
1,965
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 15.25 KB | None | 0 0
  1. #include <a_samp>
  2. #include <fcnpc>
  3. #include <YSI\y_timers>
  4. #include <colandreas>
  5.  
  6. #define MAX_ZOMBIES     200
  7. #define ZOMBIE_RANGE    50.0
  8. #define ZOMBIE_SKIN     162
  9. #define ZOMBIE_HEALTH   100
  10. #define ZOMBIE_COLOR    (0xFF0000FF)
  11.  
  12. forward CreateZombies(newkeys);
  13. forward OnPlayerKillZombie(playerid, zombieid);
  14. forward ResetDetectRange(playerid);
  15. forward ZombieHealthLabel(npcid);
  16.  
  17. new SpawnedZombies = 0,
  18.     CreationTimer,
  19.     IsAZombie[MAX_PLAYERS],
  20.     Text3D:ZombieLabel[MAX_PLAYERS],
  21.     Timer:ZombieTimer[MAX_PLAYERS],
  22.     HumanFound[MAX_PLAYERS];
  23.  
  24. new Float:ZombieSpawns[][4] =
  25. {
  26.     //LS
  27.     {1751.1097,-2106.4529,13.5469,183.1979}, // El-Corona - Outside random house
  28.     {2652.6418,-1989.9175,13.9988,182.7107}, // Random house in willowfield - near playa de seville and stadium
  29.     {2489.5225,-1957.9258,13.5881,2.3440}, // Hotel in willowfield - near cluckin bell
  30.     {2689.5203,-1695.9354,10.0517,39.5312}, // Outside stadium - lots of cars
  31.     {2770.5393,-1628.3069,12.1775,4.9637}, // South in east beach - north of stadium - carparks nearby
  32.     {2807.9282,-1176.8883,25.3805,173.6018}, // North in east beach - near apartments
  33.     {2552.5417,-958.0850,82.6345,280.2542}, // Random house north of Las Colinas
  34.     {2232.1309,-1159.5679,25.8906,103.2939}, // Jefferson motel
  35.     {2388.1003,-1279.8933,25.1291,94.3321}, // House south of pig pen
  36.     {2481.1885,-1536.7186,24.1467,273.4944}, // East LS - near clucking bell and car wash
  37.     {2495.0720,-1687.5278,13.5150,359.6696}, // Outside CJ's house - lots of cars nearby
  38.     {2306.8252,-1675.4340,13.9221,2.6271}, // House in ganton - lots of cars nearby
  39.     {2191.8403,-1455.8251,25.5391,267.9925}, // House in south jefferson - lots of cars nearby
  40.     {1830.1359,-1092.1849,23.8656,94.0113}, // Mulholland intersection carpark
  41.     {2015.3630,-1717.2535,13.5547,93.3655}, // Idlewood house
  42.     {1654.7091,-1656.8516,22.5156,177.9729}, // Right next to PD
  43.     {1127.6726,-2037.4873,69.8059,271.5750}, // Conference Center
  44.     {1508.6849,-1059.0846,25.0625,1.8058}, // Across the street of BANK - lots of cars in intersection carpark
  45.     {1421.0819,-885.3383,50.6531,3.6516}, // Outside house in vinewood
  46.     {1133.8237,-1272.1558,13.5469,192.4113}, // Near hospital
  47.     {1235.2196,-1608.6111,13.5469,181.2655}, // Backalley west of mainstreet
  48.     {590.4648,-1252.2269,18.2116,25.0473}, // Outside "BAnk of San Andreas"
  49.     {842.5260,-1007.7679,28.4185,213.9953}, // North of Graveyard
  50.     {911.9332,-1232.6490,16.9766,5.2999}, // LS Film Studio
  51.     {477.6021,-1496.6207,20.4345,266.9252}, // Rodeo Place
  52.     {255.4621,-1366.3256,53.1094,312.0852}, // Outside propery in richman
  53.     {281.5446,-1261.4562,73.9319,305.0017}, // Another richman property
  54.     {790.1918,-839.8533,60.6328,191.9514}, // Mulholland house
  55.     {1299.1859,-801.4249,84.1406,269.5274}, // Maddoggs
  56.     {1240.3170,-2036.6886,59.9575,276.4659}, // Verdant Bluffs
  57.     {2215.5181,-2627.8174,13.5469,273.7786}, // Ocean docks 1
  58.     {2509.4346,-2637.6543,13.6453,358.3565}, // Ocean Docks spawn 2
  59.    
  60.     //LV
  61.     {1435.8024,2662.3647,11.3926,1.1650}, //  Northern train station
  62.     {1457.4762,2773.4868,10.8203,272.2754}, //  Northern golf club
  63.     {1739.6390,2803.0569,14.2735,285.3929}, //  Northern housing estate 1
  64.     {1870.3096,2785.2471,14.2734,42.3102}, //  Northern housing estate 2
  65.     {1959.7142,2754.6863,10.8203,181.4731}, //  Northern house 1
  66.     {2314.2556,2759.4504,10.8203,93.2711}, //  Northern industrial estate 1
  67.     {2216.5674,2715.0334,10.8130,267.6540}, //  Northern industrial estate 2
  68.     {2101.4192,2678.7874,10.8130,92.0607}, //  Northern near railway line
  69.     {1951.1090,2660.3877,10.8203,180.8461}, //  Northern house 2
  70.     {1666.6949,2604.9861,10.8203,179.8495}, //  Northern house 3
  71.     {2808.3367,2421.5107,11.0625,136.2060}, //  Northern shopping centre
  72.     {2633.3203,2349.7061,10.6719,178.7175}, //  V-Rock
  73.     {2606.6348,2161.7490,10.8203,88.7508}, //  South V-Rock
  74.     {2616.5286,2100.6226,10.8158,177.7834}, //  North Ammunation 1
  75.     {2491.8816,2397.9370,10.8203,266.6003}, //  North carpark 1
  76.     {2531.7891,2530.3223,21.8750,91.6686}, //  North carpark 2
  77.     {2340.6677,2530.4324,10.8203,177.8630}, //  North Pizza Stack
  78.     {2097.6855,2491.3313,14.8390,181.8117}, //  Emerald Isle
  79.     {1893.1000,2423.2412,11.1782,269.4385}, //  Souvenir shop
  80.     {1698.9330,2241.8320,10.8203,357.8584}, //  Northern casino
  81.     {1479.4559,2249.0769,11.0234,306.3790}, //  Baseball stadium 1
  82.     {1298.1548,2083.4016,10.8127,256.7034}, //  Baseball stadium 2
  83.     {1117.8785,2304.1514,10.8203,81.5490}, //  North carparks
  84.     {1108.9878,1705.8639,10.8203,0.6785}, //  Dirtring racing 1
  85.     {1423.9780,1034.4188,10.8203,90.9590}, //  Sumo
  86.     {1537.4377,752.0641,11.0234,271.6893}, //  Church
  87.     {1917.9590,702.6984,11.1328,359.2682}, //  Southern housing estate
  88.     {2089.4785,658.0414,11.2707,357.3572}, //  Southern house 1
  89.     {2489.8286,928.3251,10.8280,67.2245}, //  Wedding chapel
  90.     {2697.4717,856.4916,9.8360,267.0983}, //  Southern construction site
  91.     {2845.6104,1288.1444,11.3906,3.6506}, //  Southern train station
  92.     {2437.9370,1293.1442,10.8203,86.3830}, //  Wedding chapel (near Pyramid)
  93.     {2299.5430,1451.4177,10.8203,269.1287}, //  Carpark (near Pyramid)
  94.     {2214.3008,2041.9165,10.8203,268.7626}, //  Central parking lot
  95.     {2005.9174,2152.0835,10.8203,270.1372}, //  Central motel
  96.     {2222.1042,1837.4220,10.8203,88.6461}, //  Clowns Pocket
  97.     {2025.6753,1916.4363,12.3382,272.5852}, //  The Visage
  98.     {2087.9902,1516.5336,10.8203,48.9300}, //  Royal Casino
  99.     {2172.1624,1398.7496,11.0625,91.3783}, //  Auto Bahn
  100.     {2139.1841,987.7975,10.8203,0.2315}, //  Come-a-lot
  101.     {1860.9672,1030.2910,10.8203,271.6988}, //  Behind 4 Dragons
  102.     {1673.2345,1316.1067,10.8203,177.7294}, //  Airport carpark
  103.     {1412.6187,2000.0596,14.7396,271.3568}, //  South baseball stadium houses
  104.    
  105.     //SF
  106.     {-2723.4639,-314.8138,7.1839,43.5562},  // golf course spawn
  107.     {-2694.5344,64.5550,4.3359,95.0190},  // in front of a house
  108.     {-2458.2000,134.5419,35.1719,303.9446},  // hotel
  109.     {-2796.6589,219.5733,7.1875,88.8288},  // house
  110.     {-2706.5261,397.7129,4.3672,179.8611},  // park
  111.     {-2866.7683,691.9363,23.4989,286.3060},  // house
  112.     {-2764.9543,785.6434,52.7813,357.6817},  // donut shop
  113.     {-2660.9402,883.2115,79.7738,357.4440},  // house
  114.     {-2861.0796,1047.7109,33.6068,188.2750}, //  parking lot
  115.     {-2629.2009,1383.1367,7.1833,179.7006},  // parking lot at the bridge
  116.     {-2079.6802,1430.0189,7.1016,177.6486},  // pier
  117.     {-1660.2294,1382.6698,9.8047,136.2952}, //  pier 69
  118.     {-1674.1964,430.3246,7.1797,226.1357},  // gas station]
  119.     {-1954.9982,141.8080,27.1747,277.7342},  // train station
  120.     {-1956.1447,287.1091,35.4688,90.4465},  // car shop
  121.     {-1888.1117,615.7245,35.1719,128.4498},  // random
  122.     {-1922.5566,886.8939,35.3359,272.1293},  // random
  123.     {-1983.3458,1117.0645,53.1243,271.2390},  // church
  124.     {-2417.6458,970.1491,45.2969,269.3676},  // gas station
  125.     {-2108.0171,902.8030,76.5792,5.7139},  // house
  126.     {-2097.5664,658.0771,52.3672,270.4487},  // random
  127.     {-2263.6650,393.7423,34.7708,136.4152},  // random
  128.     {-2287.5027,149.1875,35.3125,266.3989},  // baseball parking lot
  129.     {-2039.3571,-97.7205,35.1641,7.4744},  // driving school
  130.     {-1867.5022,-141.9203,11.8984,22.4499},  // factory
  131.     {-1537.8992,116.0441,17.3226,120.8537},  // docks ship
  132.     {-1708.4763,7.0187,3.5489,319.3260},  // docks hangar
  133.     {-1427.0858,-288.9430,14.1484,137.0812},  // airport
  134.     {-2173.0654,-392.7444,35.3359,237.0159},  // stadium
  135.     {-2320.5286,-180.3870,35.3135,179.6980},  // burger shot
  136.     {-2930.0049,487.2518,4.9141,3.8258}  // harbor
  137. };
  138.  
  139. public OnFilterScriptInit()
  140. {
  141.     CA_Init();
  142.     CreationTimer = SetTimer("CreateZombies", 50, true);
  143.     return 1;
  144. }
  145.  
  146. public CreateZombies(newkeys)
  147. {
  148.     new string[50], zombie, SpawnRandom = random(sizeof(ZombieSpawns));
  149.     if(SpawnedZombies < MAX_ZOMBIES)
  150.     {
  151.         format(string,sizeof(string),"Zombie(%d)",MAX_PLAYERS-(SpawnedZombies));
  152.         zombie = FCNPC_Create(string);
  153.  
  154.         ZombieLabel[zombie] = Create3DTextLabel("Zombie\n{991643}[|||||||||||]", -1, 30.0, 40.0, 50.0, 60.0, -1, 0);
  155.         Attach3DTextLabelToPlayer(ZombieLabel[zombie], zombie, 0.0, 0.0, 0.4);
  156.  
  157.         FCNPC_Spawn(zombie,ZOMBIE_SKIN,ZombieSpawns[SpawnRandom][0],ZombieSpawns[SpawnRandom][1],ZombieSpawns[SpawnRandom][2]);
  158.        
  159.         new Rand = random(9);
  160.         switch(Rand)
  161.         {
  162.             case 0: FCNPC_SetWeapon(zombie, 1);
  163.             case 1: FCNPC_SetWeapon(zombie, 2);
  164.             case 2: FCNPC_SetWeapon(zombie, 3);
  165.             case 3: FCNPC_SetWeapon(zombie, 4);
  166.             case 4: FCNPC_SetWeapon(zombie, 5);
  167.             case 5: FCNPC_SetWeapon(zombie, 6);
  168.             case 6: FCNPC_SetWeapon(zombie, 7);
  169.             case 7: FCNPC_SetWeapon(zombie, 8);
  170.             case 8: FCNPC_SetWeapon(zombie, 15);
  171.         }
  172.         FCNPC_SetHealth(zombie, ZOMBIE_HEALTH);
  173.  
  174.         ZombieTimer[zombie] = repeat MoveZombie(zombie, newkeys);
  175.         SetPlayerColor(zombie,ZOMBIE_COLOR);
  176.         IsAZombie[zombie] = 1;
  177.         SpawnedZombies++;
  178.     }
  179.     else
  180.     {
  181.         KillTimer(CreationTimer);
  182.         printf("Zombies creation done!");
  183.     }
  184.     return 1;
  185. }
  186.  
  187. public OnPlayerDeath(playerid, killerid, reason)
  188. {
  189.     SendDeathMessage(killerid, playerid, reason);
  190.     return 1;
  191. }
  192.  
  193. public FCNPC_OnDeath(npcid, killerid, reason)
  194. {
  195.     HumanFound[npcid] = 0;
  196.     SendDeathMessage(killerid, npcid, reason);
  197.     ApplyAnimation(npcid, "PED", "BIKE_fall_off", 4.1, 0, 1, 1, 1, 0, 1);
  198.     CallLocalFunction("OnPlayerKillZombie","ii", killerid, npcid);
  199.     return 1;
  200. }
  201.  
  202. public FCNPC_OnTakeDamage(npcid, issuerid, Float:amount, weaponid, bodypart)
  203. {
  204.     if(weaponid == 24) FCNPC_SetHealth(npcid, FCNPC_GetHealth(npcid)-50);//DesertEagle
  205.     if(weaponid == 22) FCNPC_SetHealth(npcid, FCNPC_GetHealth(npcid)-50);//Colt45
  206.     if(weaponid == 32) FCNPC_SetHealth(npcid, FCNPC_GetHealth(npcid)-10);//Tec9
  207.     if(weaponid == 28) FCNPC_SetHealth(npcid, FCNPC_GetHealth(npcid)-10);//Uzi
  208.     if(weaponid == 23) FCNPC_SetHealth(npcid, FCNPC_GetHealth(npcid)-50);//SilencedColt
  209.     if(weaponid == 31) FCNPC_SetHealth(npcid, FCNPC_GetHealth(npcid)-35);//M4
  210.     if(weaponid == 30) FCNPC_SetHealth(npcid, FCNPC_GetHealth(npcid)-40);//AK
  211.     if(weaponid == 29) FCNPC_SetHealth(npcid, FCNPC_GetHealth(npcid)-18);//MP5
  212.     if(weaponid == 34) FCNPC_SetHealth(npcid, FCNPC_GetHealth(npcid)-300);//SniperRifle
  213.     if(weaponid == 33) FCNPC_SetHealth(npcid, FCNPC_GetHealth(npcid)-35);//CuntGun
  214.     if(weaponid == 25) FCNPC_SetHealth(npcid, FCNPC_GetHealth(npcid)-100);//PumpShotgun
  215.     if(weaponid == 27) FCNPC_SetHealth(npcid, FCNPC_GetHealth(npcid)-70);//Spaz12
  216.  
  217.     if(!IsPlayerConnected(npcid)) return 0;
  218.     if(!IsPlayerConnected(issuerid)) return 0;
  219.     if(issuerid != INVALID_PLAYER_ID && weaponid >= 22 && weaponid <= 38 && bodypart == 9)
  220.     {
  221.         FCNPC_SetHealth(npcid, 0);
  222.         GameTextForPlayer(issuerid, "~r~HEADSHOT",3000,4);
  223.     }
  224.     if(issuerid != INVALID_PLAYER_ID && weaponid == 38 && !IsPlayerAdmin(issuerid))
  225.     {
  226.         Ban(issuerid);
  227.     }
  228.     ZombieHealthLabel(npcid);
  229.     return 1;
  230. }
  231.  
  232.  
  233. public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
  234. {
  235.     new Float:HP;
  236.     GetPlayerHealth(playerid, HP);
  237.     if(weaponid == 0) SetPlayerHealth(playerid, HP-1);
  238.     if(weaponid == 1) SetPlayerHealth(playerid, HP-7);
  239.     if(weaponid == 2) SetPlayerHealth(playerid, HP-9);
  240.     if(weaponid == 3) SetPlayerHealth(playerid, HP-8);
  241.     if(weaponid == 4) SetPlayerHealth(playerid, HP-10);
  242.     if(weaponid == 5) SetPlayerHealth(playerid, HP-8);
  243.     if(weaponid == 6) SetPlayerHealth(playerid, HP-9);
  244.     if(weaponid == 7) SetPlayerHealth(playerid, HP-7);
  245.     if(weaponid == 8) SetPlayerHealth(playerid, HP-10);
  246.     if(weaponid == 15) SetPlayerHealth(playerid, HP-5);
  247.     return 1;
  248. }
  249.  
  250. timer MoveZombie[100](zombieid, newkeys)
  251. {
  252.     new Float:xa, Float:ya, Float:za, Float:health;
  253.     if(FCNPC_IsDead(zombieid)) return 1;
  254.     foreach(new i : Player)
  255.     {
  256.         GetPlayerPos(i, xa, ya, za);
  257.         if(IsPlayerInRangeOfPoint(zombieid, 1, xa, ya, za))
  258.         {
  259.             HumanFound[zombieid] = 2;
  260.             FCNPC_MeleeAttack(zombieid,500);
  261.             GetPlayerHealth(i, health);
  262.             break;
  263.         }
  264.         else if(IsPlayerInRangeOfPoint(zombieid,ZOMBIE_RANGE / 4, xa, ya, za))
  265.         {
  266.             if(GetPlayerSpecialAction(zombieid) == SPECIAL_ACTION_DUCK)
  267.             {
  268.                 if(HumanFound[zombieid] == 2)
  269.                 {
  270.                     FCNPC_StopAttack(zombieid);
  271.                 }
  272.                 HumanFound[zombieid] = 1;
  273.                 FCNPC_GoTo(zombieid, xa, ya, za, FCNPC_MOVE_TYPE_RUN);
  274.                 SetTimer("ResetDetectRange", 5000, false);
  275.             }
  276.             break;
  277.         }
  278.         else if(IsPlayerInRangeOfPoint(zombieid, ZOMBIE_RANGE / 2, xa, ya, za))
  279.         {
  280.             if(HumanFound[zombieid] == 2)
  281.             {
  282.                 FCNPC_StopAttack(zombieid);
  283.             }
  284.             HumanFound[zombieid] = 1;
  285.             FCNPC_GoTo(zombieid, xa, ya, za, FCNPC_MOVE_TYPE_RUN);
  286.             SetTimer("ResetDetectRange", 5000, false);
  287.             break;
  288.         }
  289.         else if(IsPlayerInRangeOfPoint(zombieid, ZOMBIE_RANGE, xa, ya, za))
  290.         {
  291.             if(HumanFound[zombieid] == 2)
  292.             {
  293.                 FCNPC_StopAttack(zombieid);
  294.             }
  295.             HumanFound[zombieid] = 1;
  296.             FCNPC_GoToPlayerEx(zombieid, i, 5, 5, FCNPC_MOVE_TYPE_RUN);
  297.             SetTimer("ResetDetectRange", 5000, false);
  298.             break;
  299.         }
  300.         else if(IsPlayerInRangeOfPoint(zombieid, ZOMBIE_RANGE * 2 , xa, ya, za))
  301.         {
  302.             if(newkeys & KEY_SPRINT)
  303.             {
  304.                 GetPlayerPos(zombieid, xa, ya, za);
  305.                 if(HumanFound[zombieid] == 2)
  306.                 {
  307.                     FCNPC_StopAttack(zombieid);
  308.                 }
  309.                 HumanFound[zombieid] = 1;
  310.                 FCNPC_GoToPlayerEx(zombieid, i, 5, 5, FCNPC_MOVE_TYPE_RUN);
  311.                 SetTimer("ResetDetectRange", 5000, false);
  312.                 break;
  313.             }
  314.         }
  315.         else if(IsPlayerInRangeOfPoint(zombieid,ZOMBIE_RANGE * 5, xa, ya, za))
  316.         {
  317.             if(GetPlayerWeapon(i) == 22 && GetPlayerWeapon(i) >= 23 && GetPlayerWeapon(i) <= 38)
  318.             {
  319.                 GetPlayerPos(zombieid, xa, ya, za);
  320.                 if(HumanFound[zombieid] == 2)
  321.                 {
  322.                     FCNPC_StopAttack(zombieid);
  323.                 }
  324.                 HumanFound[zombieid] = 1;
  325.                 FCNPC_GoToPlayerEx(zombieid, i, 5, 5, FCNPC_MOVE_TYPE_RUN);
  326.                 SetTimer("ResetDetectRange", 5000, false);
  327.                 break;
  328.             }
  329.         }
  330.         else
  331.         {
  332.             HumanFound[zombieid] = 0;
  333.             new Float:x, Float:y, Float:z;
  334.             GetPlayerPos(zombieid, x, y, z);
  335.             FCNPC_StopAttack(zombieid);
  336.             if(HumanFound[zombieid] == 0)
  337.             {
  338.                 new pos = random(4);
  339.                 if(pos == 0) { x = x + 100.0; }
  340.                 else if(pos == 1) { x = x - 100.0; }
  341.                 else if(pos == 2) { y = y + 100.0; }
  342.                 else if(pos == 3) { y = y - 100.0; }
  343.  
  344.                 FCNPC_SetKeys(zombieid, 0, 0, 0);
  345.                 FCNPC_GoTo(zombieid, x, y, z, FCNPC_MOVE_TYPE_WALK);
  346.             }
  347.         }
  348.     }
  349.     return 1;
  350. }
  351.  
  352. public ZombieHealthLabel(npcid)
  353. {
  354.     new Float:h = FCNPC_GetHealth(npcid),str[80];
  355.     if(h < 25) str = "Zombie\n{991643}[|            ]";
  356.     else if(h < 50) str = "Zombie\n{991643}[|||        ]";
  357.     else if(h < 75) str = "Zombie\n{991643}[||||||    ]";
  358.     else if(h < 95) str = "Zombie\n{991643}[||||||||    ]";
  359.     else str = "Zombie\n{991643}[|||||||||||]";
  360.     Update3DTextLabelText(ZombieLabel[npcid], ZOMBIE_COLOR, str);
  361.     printf("Health (%.02f) Called",h);
  362.     return 1;
  363. }
  364.  
  365. public ResetDetectRange(playerid)
  366. {
  367.     HumanFound[playerid] = 0;
  368.     return 1;
  369. }
  370.  
  371. public OnPlayerKillZombie(playerid,zombieid)
  372. {
  373.     FCNPC_Respawn(zombieid);
  374.     return 1;
  375. }
  376.  
  377. public FCNPC_OnRespawn(npcid)
  378. {
  379.     new spawn = random(sizeof(ZombieSpawns));
  380.     FCNPC_SetWeapon(npcid,1);
  381.     FCNPC_SetAmmo(npcid,1);
  382.     FCNPC_SetPosition(npcid,ZombieSpawns[spawn][0],ZombieSpawns[spawn][1],ZombieSpawns[spawn][2]);
  383.     return 1;
  384. }
  385.  
  386. stock FCNPC_GoToPlayerEx(npcid, playerid, Float:dist, Float:rangle, movetype = FCNPC_MOVE_TYPE_RUN)
  387. {
  388.     new Float:xa, Float:ya, Float:za, Float:fa;
  389.     GetPlayerPos(playerid, xa, ya, za);
  390.     GetPlayerFacingAngle(playerid, fa);
  391.     rangle += fa;
  392.     xa = (xa + dist * floatsin(-rangle,degrees));
  393.     ya = (ya + dist * floatcos(-rangle,degrees));
  394.     FCNPC_GoTo(npcid, xa, ya, za,movetype, 0.4, true);
  395.     return 1;
  396. }
Add Comment
Please, Sign In to add comment