Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.87 KB | None | 0 0
  1. /*
  2.     ZNPC: Zombified Non-Player Characters [v1.0] by Weponz
  3. */
  4. #define FILTERSCRIPT
  5. #include <a_samp>//Credits: SA:MP Team
  6. #include <rnpc>//Credits: Mauzen
  7.  
  8. #define MAX_ZOMBIES 50//OPTIONAL: Define the max amount of zombies to spawn here. (Default: 50)
  9.  
  10. #define ZOMBIE_NAME "Zombie[%i]"//OPTIONAL: Define the name of zombies here. (Default: Zombie[%i])
  11. #define ZOMBIE_HEALTH 50//OPTIONAL: Define the full amount of health for zombies here. (Default: 50%)
  12. #define ZOMBIE_SKIN 162//OPTIONAL: Define the skin id for zombies here. (Default: 162)
  13. #define ZOMBIE_COLOR 0xFF0000FF//OPTIONAL: Define the color of zombies here. (Default: Red)
  14. #define ZOMBIE_DETECT 25//OPTIONAL: Define the minimum detect range for zombies here. (Default: 25 Metres)
  15. #define ZOMBIE_DAMAGE 25//OPTIONAL: Define the damage amount for zombies here. (Default: 25%)
  16.  
  17. forward OnZombieAttack();
  18. forward OnZombieRoam();
  19.  
  20. forward ResetDetectRange(playerid);
  21.  
  22. new GetZombieVictimID[MAX_ZOMBIES];
  23.  
  24. new GetVictimDetectRange[MAX_PLAYERS];
  25. new GetVictimResetTimer[MAX_PLAYERS];
  26. new GetVictimTimerStatus[MAX_PLAYERS];
  27.  
  28. new Float:ZombieSpawns[3][4] = {
  29.     {1642.0972, -2332.3430, -2.6797, 1.7723},//REQUIRED: Add zombie spawn locations here.
  30.     {1685.3428, -2333.3137, 13.5469, 1.6459},//REQUIRED: Add zombie spawn locations here.
  31.     {1616.1416, -2276.0334, 13.5140, 358.7454}//REQUIRED: Add zombie spawn locations here.
  32. };
  33.  
  34. stock GetZombieVictim(npcid)
  35. {
  36.     for(new playerid = 0; playerid < MAX_PLAYERS; playerid++)
  37.     {
  38.         if(!IsPlayerNPC(playerid) && IsPlayerConnected(playerid))
  39.         {
  40.             new Float:x, Float:y, Float:z;
  41.             GetPlayerPos(npcid, x, y, z);
  42.             if(IsPlayerInRangeOfPoint(playerid, GetVictimDetectRange[playerid], x, y, z) && GetPlayerState(playerid) == PLAYER_STATE_ONFOOT && GetPlayerInterior(playerid) == 0 && GetPlayerVirtualWorld(playerid) == 0) return playerid;
  43.         }
  44.     }
  45.     return INVALID_PLAYER_ID;
  46. }
  47.  
  48. public OnFilterScriptInit()
  49. {
  50.     RNPC_SetUpdateRate(80);
  51.  
  52.     MapAndreas_Init(MAP_ANDREAS_MODE_NOBUFFER);
  53.  
  54.     new count = 0;
  55.     for(new npcid = 0; npcid < MAX_ZOMBIES; npcid++)
  56.     {
  57.         new name[24];
  58.         format(name, sizeof(name), ZOMBIE_NAME, npcid + 1);
  59.         ConnectRNPC(name);
  60.         count++;
  61.     }
  62.     printf("Number of zombies created: %i", count);
  63.  
  64.     SetTimer("OnZombieAttack", 1000, true);
  65.     SetTimer("OnZombieRoam", 10000, true);
  66.     return 1;
  67. }
  68.  
  69. public OnPlayerSpawn(playerid)
  70. {
  71.     ApplyAnimation(playerid, "BOMBER", "null", 0, 0, 0, 0, 0, 1);
  72.     ApplyAnimation(playerid, "PED", "null", 0, 0, 0, 0, 0, 1);
  73.  
  74.     if(IsPlayerNPC(playerid))
  75.     {
  76.         new spawn = random(sizeof(ZombieSpawns));
  77.         SetSpawnInfo(playerid, 0, ZOMBIE_SKIN, ZombieSpawns[spawn][0], ZombieSpawns[spawn][1], ZombieSpawns[spawn][2], 0, 0, 0, 0, 0, 0);
  78.  
  79.         SetRNPCHealth(playerid, ZOMBIE_HEALTH);
  80.         SetPlayerColor(playerid, ZOMBIE_COLOR);
  81.  
  82.         RNPC_SetShootable(playerid, 1);
  83.         RNPC_ToggleVehicleCollisionCheck(playerid, 1);
  84.  
  85.         GetZombieVictimID[playerid] = INVALID_PLAYER_ID;
  86.         return 1;
  87.     }
  88.     else
  89.     {
  90.         GetVictimDetectRange[playerid] = ZOMBIE_DETECT;
  91.         GetVictimTimerStatus[playerid] = 0;
  92.     }
  93.     return 1;
  94. }
  95.  
  96. public OnPlayerDeath(playerid, killerid, reason)
  97. {
  98.     if(IsPlayerNPC(killerid))
  99.     {
  100.         ApplyAnimation(killerid, "BOMBER", "BOM_Plant", 4.1, 0, 1, 1, 1, 0, 1);
  101.         SetRNPCHealth(killerid, ZOMBIE_HEALTH);
  102.         return SendDeathMessage(killerid, GetZombieVictimID[killerid], reason);
  103.     }
  104.     return 1;
  105. }
  106.  
  107. public OnRNPCDeath(npcid, killerid, reason)
  108. {
  109.     SendDeathMessage(killerid, npcid, reason);
  110.     ApplyAnimation(npcid, "PED", "BIKE_fall_off", 4.1, 0, 1, 1, 1, 0, 1);
  111.     RespawnRNPC(npcid);
  112.     return 1;
  113. }
  114.  
  115. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  116. {
  117.     if(!IsPlayerNPC(playerid))
  118.     {
  119.         if(newkeys & KEY_FIRE)
  120.         {
  121.             if(GetPlayerWeapon(playerid) >= 22 && GetPlayerWeapon(playerid) <= 38)
  122.             {
  123.                 GetVictimDetectRange[playerid] = (ZOMBIE_DETECT * 4);
  124.                 if(GetVictimTimerStatus[playerid] == 1) { KillTimer(GetVictimResetTimer[playerid]); }
  125.                 GetVictimTimerStatus[playerid] = 1;
  126.                 GetVictimResetTimer[playerid] = SetTimerEx("ResetDetectRange", 5000, false, "i", playerid);
  127.             }
  128.         }
  129.         else if(newkeys & KEY_SPRINT && GetVictimTimerStatus[playerid] == 0)
  130.         {
  131.             GetVictimDetectRange[playerid] = (ZOMBIE_DETECT * 2);
  132.             GetVictimTimerStatus[playerid] = 1;
  133.             GetVictimResetTimer[playerid] = SetTimerEx("ResetDetectRange", 5000, false, "i", playerid);
  134.         }
  135.     }
  136.     return 1;
  137. }
  138.  
  139. public OnPlayerUpdate(playerid)
  140. {
  141.     if(!IsPlayerNPC(playerid))
  142.     {
  143.         if(GetPlayerSpecialAction(playerid) == SPECIAL_ACTION_DUCK && GetVictimTimerStatus[playerid] == 0)
  144.         {
  145.             GetVictimDetectRange[playerid] = (ZOMBIE_DETECT / 4);
  146.             GetVictimTimerStatus[playerid] = 1;
  147.             GetVictimResetTimer[playerid] = SetTimerEx("ResetDetectRange", 5000, false, "i", playerid);
  148.         }
  149.     }
  150.     return 1;
  151. }
  152.  
  153. public OnZombieAttack()
  154. {
  155.     for(new npcid = 0; npcid < MAX_ZOMBIES; npcid++)
  156.     {
  157.         if(IsPlayerNPC(npcid))
  158.         {
  159.             if(GetRNPCHealth(npcid) > 0)
  160.             {
  161.                 new victim = GetZombieVictim(npcid), Float:x, Float:y, Float:z, Float:health;
  162.                 GetPlayerPos(npcid, x, y, z);
  163.                 if(victim != INVALID_PLAYER_ID)
  164.                 {
  165.                     if(IsPlayerInRangeOfPoint(victim, GetVictimDetectRange[victim], x, y, z))
  166.                     {
  167.                         GetZombieVictimID[npcid] = victim;
  168.  
  169.                         if(IsPlayerInRangeOfPoint(victim, 1, x, y, z))
  170.                         {
  171.                             RNPC_CreateBuild(npcid, PLAYER_RECORDING_TYPE_ONFOOT);
  172.                             RNPC_AddPause(100);
  173.                             RNPC_SetKeys(KEY_FIRE);
  174.                             RNPC_AddPause(100);
  175.                             RNPC_SetKeys(0);
  176.                             RNPC_FinishBuild();
  177.                             RNPC_StartBuildPlayback(npcid);
  178.  
  179.                             GetPlayerHealth(victim, health);
  180.                             SetPlayerHealth(victim, health - ZOMBIE_DAMAGE);
  181.                             continue;
  182.                         }
  183.                         GetPlayerPos(victim, x, y, z);
  184.  
  185.                         MoveRNPC(npcid, x, y, z, RNPC_SPEED_RUN, 1);
  186.                     }
  187.                 }
  188.             }
  189.         }
  190.     }
  191.     return 1;
  192. }
  193.  
  194. public OnZombieRoam()
  195. {
  196.     for(new npcid = 0; npcid < MAX_ZOMBIES; npcid++)
  197.     {
  198.         if(IsPlayerNPC(npcid))
  199.         {
  200.             if(GetRNPCHealth(npcid) > 0)
  201.             {
  202.                 new victim = GetZombieVictim(npcid), Float:x, Float:y, Float:z;
  203.                 GetPlayerPos(npcid, x, y, z);
  204.                 if(victim == INVALID_PLAYER_ID)
  205.                 {
  206.                     new pos = random(4);
  207.                     if(pos == 0) { x = x + 100.0; }
  208.                     else if(pos == 1) { x = x - 100.0; }
  209.                     else if(pos == 2) { y = y + 100.0; }
  210.                     else if(pos == 3) { y = y - 100.0; }
  211.  
  212.                     GetZombieVictimID[npcid] = INVALID_PLAYER_ID;
  213.  
  214.                     RNPC_SetKeys(0);
  215.  
  216.                     MoveRNPC(npcid, x, y, z, RNPC_SPEED_WALK, 1);
  217.                 }
  218.             }
  219.         }
  220.     }
  221.     return 1;
  222. }
  223.  
  224. public ResetDetectRange(playerid)
  225. {
  226.     if(GetPlayerSpecialAction(playerid) == SPECIAL_ACTION_DUCK)
  227.     {
  228.         GetVictimDetectRange[playerid] = (ZOMBIE_DETECT / 4);
  229.         GetVictimTimerStatus[playerid] = 1;
  230.         GetVictimResetTimer[playerid] = SetTimerEx("ResetDetectRange", 5000, false, "i", playerid);
  231.         return 1;
  232.     }
  233.  
  234.     GetVictimTimerStatus[playerid] = 0;
  235.     GetVictimDetectRange[playerid] = ZOMBIE_DETECT;
  236.     return 1;
  237. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement