FlacoBey

Untitled

Feb 16th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.47 KB | None | 0 0
  1. #include <sourcemod>
  2. #include <sdktools>
  3. #include <sdkhooks>
  4.  
  5. new bool:IsAlreadyInflicted[2048+1] = false;
  6. #define Electric "electrical_arc_01_system"
  7.  
  8. public OnPluginStart()
  9. {
  10.     HookEvent("infected_hurt", HurtInfected);
  11. }
  12.  
  13. public HurtInfected(Handle:event, const String:name[], bool:dontBroadcast)
  14. {
  15.     int victim = GetEventInt(event, "entityid");
  16.     int damagetype = GetEventInt(event, "type");
  17.     float vicPos[3], target_distance[3];
  18.    
  19.     if (damagetype & DMG_BULLET)
  20.     {
  21.         GetEntPropVector(victim, Prop_Send, "m_vecOrigin", vicPos);
  22.         for (int target = 33; target < 2049; target++)
  23.         {
  24.             if (IsCommonInfected(target))
  25.             {
  26.                 if(!IsAlreadyInflicted[target])
  27.                 {
  28.                     GetEntPropVector(target, Prop_Send, "m_vecOrigin", target_distance);
  29.                     float fTargetDistance = GetVectorDistance(vicPos, target_distance);
  30.                     if (fTargetDistance > 200.0) continue;
  31.                     ForceDamageEntity(victim, 1000, target);
  32.                     CreateEffect(target);
  33.                     IsAlreadyInflicted[target] = true;
  34.                     FindNewTarget(target);
  35.                 }
  36.             }
  37.         }
  38.     }
  39. }
  40.  
  41. public OnEntityCreated(entity, const char[] classname)
  42. {
  43.     if(IsCommonInfected(entity))
  44.     {
  45.         IsAlreadyInflicted[entity] = false;
  46.     }
  47. }
  48.  
  49. void CreateEffect(index)
  50. {
  51.     float index_origin[3];
  52.     GetEntPropVector(index, Prop_Send, "m_vecOrigin", index_origin);
  53.     new iEnt = CreateEntityByName("info_particle_system");
  54.     DispatchKeyValue(iEnt, "start_active", "1");
  55.     DispatchKeyValue(iEnt, "effect_name", Electric);
  56.     TeleportEntity(iEnt, index_origin, NULL_VECTOR, NULL_VECTOR);
  57.     DispatchSpawn(iEnt);
  58.     ActivateEntity(iEnt);
  59.     SetVariantString("!activator");
  60.     AcceptEntityInput(iEnt, "SetParent", index, iEnt);
  61.     AcceptEntityInput(iEnt, "Start");
  62. }
  63.  
  64. stock bool IsCommonInfected(int entity)
  65. {
  66.     if (entity > 0 && IsValidEntity(entity) && IsValidEdict(entity))
  67.     {
  68.         char entType[64];
  69.         GetEdictClassname(entity, entType, sizeof(entType));
  70.         return StrEqual(entType, "infected");
  71.     }
  72.     return false;
  73. }
  74.  
  75. stock ForceDamageEntity(causer, damage, victim)
  76. {
  77.     float victim_origin[3];
  78.     new String:rupture[32];
  79.     new String:damage_victim[32];
  80.     IntToString(damage, rupture, sizeof(rupture));
  81.     Format(damage_victim, sizeof(damage_victim), "hurtme%d", victim);
  82.     GetEntPropVector(victim, Prop_Send, "m_vecOrigin", victim_origin);
  83.     new entity = CreateEntityByName("point_hurt");
  84.     DispatchKeyValue(victim, "targetname", damage_victim);
  85.     DispatchKeyValue(entity, "DamageTarget", damage_victim);
  86.     DispatchKeyValue(entity, "Damage", rupture);
  87.     DispatchSpawn(entity);
  88.     TeleportEntity(entity, victim_origin, NULL_VECTOR, NULL_VECTOR);
  89.     AcceptEntityInput(entity, "Hurt", (causer > 0 && causer <= MaxClients) ? causer : -1);
  90.     DispatchKeyValue(entity, "classname", "point_hurt");
  91.     DispatchKeyValue(victim, "targetname", "null");
  92.     AcceptEntityInput(entity, "Kill");
  93. }
  94.  
  95. stock FindNewTarget(zombie)
  96. {
  97.     new entity = -1;
  98.     while ((entity = FindEntityByClassname(entity, "infected")) != INVALID_ENT_REFERENCE)
  99.     {
  100.         if (entity != zombie && IsAlreadyInflicted[entity])
  101.         {
  102.             float victim_orig[3], index_origin[3]
  103.             GetEntPropVector(zombie, Prop_Send, "m_vecOrigin", index_origin);
  104.             GetEntPropVector(entity, Prop_Send, "m_vecOrigin", victim_orig);
  105.             float fTargetDistance = GetVectorDistance(victim_orig, index_origin);
  106.             if (fTargetDistance > 200.0) continue;
  107.             if (entity != zombie && !IsAlreadyInflicted[entity])
  108.             {
  109.                 IsAlreadyInflicted[entity]=true;FindNewTarget(entity);
  110.                 ForceDamageEntity(zombie, 1000, entity);
  111.                 CreateEffect(zombie);break;
  112.             }
  113.         }
  114.     }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment