Advertisement
Guest User

ZNPC: Zombified Non-Player Characters [v1.0] by Weponz

a guest
Aug 9th, 2015
2,600
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 6.84 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[2][3] =//REQUIRED: Change [2] to the amount of spawn locations.
  29. {
  30.     {0.0, 0.0, 0.0},//REQUIRED: Add zombie spawn locations here.
  31.     {0.0, 0.0, 0.0}//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.         SetPlayerPos(playerid, ZombieSpawns[spawn][0], ZombieSpawns[spawn][1], ZombieSpawns[spawn][2]);
  78.        
  79.         SetRNPCHealth(playerid, ZOMBIE_HEALTH);
  80.         SetPlayerSkin(playerid, ZOMBIE_SKIN);
  81.         SetPlayerColor(playerid, ZOMBIE_COLOR);
  82.        
  83.         RNPC_SetShootable(playerid, 1);
  84.         RNPC_ToggleVehicleCollisionCheck(playerid, 1);
  85.        
  86.         GetZombieVictimID[playerid] = INVALID_PLAYER_ID;
  87.         return 1;
  88.     }
  89.     else
  90.     {
  91.         GetVictimDetectRange[playerid] = ZOMBIE_DETECT;
  92.         GetVictimTimerStatus[playerid] = 0;
  93.     }
  94.     return 1;
  95. }
  96.  
  97. public OnPlayerDeath(playerid, killerid, reason)
  98. {
  99.     if(IsPlayerNPC(killerid))
  100.     {
  101.         ApplyAnimation(killerid, "BOMBER", "BOM_Plant", 4.1, 0, 1, 1, 1, 0, 1);
  102.         SetRNPCHealth(killerid, ZOMBIE_HEALTH);
  103.         return SendDeathMessage(killerid, GetZombieVictimID[killerid], reason);
  104.     }
  105.     return 1;
  106. }
  107.  
  108. public OnRNPCDeath(npcid, killerid, reason)
  109. {
  110.     SendDeathMessage(killerid, npcid, reason);
  111.     ApplyAnimation(npcid, "PED", "BIKE_fall_off", 4.1, 0, 1, 1, 1, 0, 1);
  112.     RespawnRNPC(npcid);
  113.     return 1;
  114. }
  115.  
  116. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  117. {
  118.     if(!IsPlayerNPC(playerid))
  119.     {
  120.         if(newkeys & KEY_FIRE)
  121.         {
  122.             if(GetPlayerWeapon(playerid) >= 22 && GetPlayerWeapon(playerid) <= 38)
  123.             {
  124.                 GetVictimDetectRange[playerid] = (ZOMBIE_DETECT * 4);
  125.                 if(GetVictimTimerStatus[playerid] == 1) { KillTimer(GetVictimResetTimer[playerid]); }
  126.                 GetVictimTimerStatus[playerid] = 1;
  127.                 GetVictimResetTimer[playerid] = SetTimerEx("ResetDetectRange", 5000, false, "i", playerid);
  128.             }
  129.         }
  130.         else if(newkeys & KEY_SPRINT && GetVictimTimerStatus[playerid] == 0)
  131.         {
  132.             GetVictimDetectRange[playerid] = (ZOMBIE_DETECT * 2);
  133.             GetVictimTimerStatus[playerid] = 1;
  134.             GetVictimResetTimer[playerid] = SetTimerEx("ResetDetectRange", 5000, false, "i", playerid);
  135.         }
  136.     }
  137.     return 1;
  138. }
  139.  
  140. public OnPlayerUpdate(playerid)
  141. {
  142.     if(!IsPlayerNPC(playerid))
  143.     {
  144.         if(GetPlayerSpecialAction(playerid) == SPECIAL_ACTION_DUCK && GetVictimTimerStatus[playerid] == 0)
  145.         {
  146.             GetVictimDetectRange[playerid] = (ZOMBIE_DETECT / 4);
  147.             GetVictimTimerStatus[playerid] = 1;
  148.             GetVictimResetTimer[playerid] = SetTimerEx("ResetDetectRange", 5000, false, "i", playerid);
  149.         }
  150.     }
  151.     return 1;
  152. }
  153.  
  154. public OnZombieAttack()
  155. {
  156.     for(new npcid = 0; npcid < MAX_ZOMBIES; npcid++)
  157.     {
  158.         if(IsPlayerNPC(npcid))
  159.         {
  160.             if(GetRNPCHealth(npcid) > 0)
  161.             {
  162.                 new victim = GetZombieVictim(npcid), Float:x, Float:y, Float:z, Float:health;
  163.                 GetPlayerPos(npcid, x, y, z);
  164.                 if(victim != INVALID_PLAYER_ID)
  165.                 {
  166.                     if(IsPlayerInRangeOfPoint(victim, GetVictimDetectRange[victim], x, y, z))
  167.                     {
  168.                         GetZombieVictimID[npcid] = victim;
  169.                        
  170.                         if(IsPlayerInRangeOfPoint(victim, 1, x, y, z))
  171.                         {
  172.                             RNPC_CreateBuild(npcid, PLAYER_RECORDING_TYPE_ONFOOT);
  173.                             RNPC_AddPause(100);
  174.                             RNPC_SetKeys(KEY_FIRE);
  175.                             RNPC_AddPause(100);
  176.                             RNPC_SetKeys(0);
  177.                             RNPC_FinishBuild();
  178.                             RNPC_StartBuildPlayback(npcid);
  179.                            
  180.                             GetPlayerHealth(victim, health);
  181.                             SetPlayerHealth(victim, health - ZOMBIE_DAMAGE);
  182.                             continue;
  183.                         }
  184.                         GetPlayerPos(victim, x, y, z);
  185.                    
  186.                         MoveRNPC(npcid, x, y, z, RNPC_SPEED_RUN, 1);
  187.                     }
  188.                 }
  189.             }
  190.         }
  191.     }
  192.     return 1;
  193. }
  194.  
  195. public OnZombieRoam()
  196. {
  197.     for(new npcid = 0; npcid < MAX_ZOMBIES; npcid++)
  198.     {
  199.         if(IsPlayerNPC(npcid))
  200.         {
  201.             if(GetRNPCHealth(npcid) > 0)
  202.             {
  203.                 new victim = GetZombieVictim(npcid), Float:x, Float:y, Float:z;
  204.                 GetPlayerPos(npcid, x, y, z);
  205.                 if(victim == INVALID_PLAYER_ID)
  206.                 {
  207.                     new pos = random(4);
  208.                     if(pos == 0) { x = x + 100.0; }
  209.                     else if(pos == 1) { x = x - 100.0; }
  210.                     else if(pos == 2) { y = y + 100.0; }
  211.                     else if(pos == 3) { y = y - 100.0; }
  212.  
  213.                     GetZombieVictimID[npcid] = INVALID_PLAYER_ID;
  214.                    
  215.                     RNPC_SetKeys(0);
  216.                    
  217.                     MoveRNPC(npcid, x, y, z, RNPC_SPEED_WALK, 1);
  218.                 }
  219.             }
  220.         }
  221.     }
  222.     return 1;
  223. }
  224.  
  225. public ResetDetectRange(playerid)
  226. {
  227.     if(GetPlayerSpecialAction(playerid) == SPECIAL_ACTION_DUCK)
  228.     {
  229.         GetVictimDetectRange[playerid] = (ZOMBIE_DETECT / 4);
  230.         GetVictimTimerStatus[playerid] = 1;
  231.         GetVictimResetTimer[playerid] = SetTimerEx("ResetDetectRange", 5000, false, "i", playerid);
  232.         return 1;
  233.     }
  234.        
  235.     GetVictimTimerStatus[playerid] = 0;
  236.     GetVictimDetectRange[playerid] = ZOMBIE_DETECT;
  237.     return 1;
  238. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement