Guest User

Untitled

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