Advertisement
FlacoBey

Untitled

Jul 3rd, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.14 KB | None | 0 0
  1. #pragma semicolon 1
  2. #pragma newdecls required
  3.  
  4. #include <sdktools>
  5. #include <sdkhooks>
  6.  
  7. #define MAX_LIST 18
  8.  
  9. Handle sdkSetAttack;
  10.  
  11. static const char gMelee[MAX_LIST - 6][] =
  12. {
  13.     "baseball_bat",
  14.     "cricket_bat",
  15.     "crowbar",
  16.     "electric_guitar",
  17.     "fireaxe",
  18.     "frying_pan",
  19.     "golfclub",
  20.     "katana",
  21.     "machete",
  22.     "tonfa",
  23.     "knife",
  24.     "chainsaw"
  25. };
  26.  
  27. static const float gDamageCharger[12] =
  28. {
  29.     0.0,
  30.     0.0,
  31.     2.0,
  32.     0.0,
  33.     4.0,
  34.     0.0,
  35.     0.0,
  36.     4.0,
  37.     3.0,
  38.     0.0,
  39.     1.0,
  40.     0.0
  41. };
  42.  
  43.  static const float gDamageTank[12] =
  44. {
  45.     0.0,
  46.     0.0,
  47.     2.0,
  48.     0.0,
  49.     4.0,
  50.     0.0,
  51.     0.0,
  52.     4.0,
  53.     3.0,
  54.     0.0,
  55.     1.0,
  56.     0.0
  57. };
  58.  
  59. static const float gDamage[12] =
  60. {
  61.     1.0,
  62.     1.0,
  63.     4.0,
  64.     1.0,
  65.     7.0,
  66.     1.0,
  67.     1.0,
  68.     7.0,
  69.     6.0,
  70.     1.0,
  71.     2.0,
  72.     0.0
  73. };
  74.  
  75. static const char gWeapons[MAX_LIST][] =
  76. {
  77.     "weapon_autoshotgun",
  78.     "weapon_hunting_rifle",
  79.     "weapon_pistol",
  80.     "weapon_pistol_magnum",
  81.     "weapon_pumpshotgun",
  82.     "weapon_rifle",
  83.     "weapon_rifle_ak47",
  84.     "weapon_rifle_desert",
  85.     "weapon_rifle_m60",
  86.     "weapon_rifle_sg552",
  87.     "weapon_shotgun_chrome",
  88.     "weapon_shotgun_spas",
  89.     "weapon_smg",
  90.     "weapon_smg_mp5",
  91.     "weapon_smg_silenced",
  92.     "weapon_sniper_awp",
  93.     "weapon_sniper_military",
  94.     "weapon_sniper_scout"
  95. };
  96.  
  97. static const float gDistance[MAX_LIST] =
  98. {
  99.     1870.0,
  100.     1650.0,
  101.     1210.0,
  102.     1980.0,
  103.     1870.0,
  104.     1650.0,
  105.     1650.0,
  106.     1760.0,
  107.     1760.0,
  108.     1650.0,
  109.     1760.0,
  110.     1760.0,
  111.     1430.0,
  112.     1320.0,
  113.     660.0,
  114.     1980.0,
  115.     1760.0,
  116.     1760.0
  117. };
  118.  
  119. public void OnPluginStart()
  120. {
  121.     HookEvent("weapon_fire", EventFire);
  122.  
  123.     Handle hGameConf = LoadGameConfigFile("added_sound-attracts-zombies");
  124.     StartPrepSDKCall(SDKCall_Entity);
  125.     if( PrepSDKCall_SetFromConf(hGameConf, SDKConf_Signature, "SetAttackToSurvivors") == false )
  126.         SetFailState("Could not load the \"SetAttackToSurvivors\" gamedata signature.");
  127.     sdkSetAttack = EndPrepSDKCall();
  128.     delete hGameConf;
  129. }
  130.  
  131. public void OnClientPutInServer(int client)
  132. {
  133.     SDKHook(client, SDKHook_TraceAttack, OnTakeDamage);
  134. }
  135.  
  136. public Action OnTakeDamage(int victim, int &attacker, int &inflictor, float &damage, int &damagetype, int &ammotype, int hitbox, int hitgroup)
  137. {
  138.     if (!(damagetype & DMG_BURN || damagetype & DMG_BLAST))
  139.     {
  140.         if (attacker > 0 && attacker <= MaxClients && IsClientInGame(attacker) && GetClientTeam(attacker) == 2 && IsPlayerAlive(attacker))
  141.         {
  142.             if(victim > 0 && victim <= MaxClients && IsClientInGame(victim) && GetClientTeam(victim) == 3 && IsPlayerAlive(victim))
  143.             {
  144.  
  145.                 char classname[64];
  146.                 GetClientWeapon(attacker, classname, sizeof(classname));
  147.                 if(StrEqual(classname, "weapon_melee"))
  148.                 {
  149.                     GetEntPropString(GetPlayerWeaponSlot(attacker, 1), Prop_Data, "m_strMapSetScriptName", classname, sizeof(classname));
  150.                 }
  151.                 else return Plugin_Continue;
  152.                 int vClass = GetEntProp(victim, Prop_Send, "m_zombieClass");
  153.                 switch(vClass)
  154.                 {
  155.                     case 6:
  156.                     {
  157.                         for( int i = 0; i < 12; i++ )
  158.                         {
  159.                             if(strcmp(classname, gMelee[i]) == 0)
  160.                             {
  161.                                 damage = gDamageCharger[i];
  162.                                 if(hitgroup == 1) damage = gDamageCharger[i] * 15.0;
  163.                                 break;
  164.                             }
  165.                         }
  166.                     }
  167.                     case 8:
  168.                     {
  169.                         for( int i = 0; i < 12; i++ )
  170.                         {
  171.                             if(strcmp(classname, gMelee[i]) == 0)
  172.                             {
  173.                                 damage = gDamageTank[i];
  174.                                 if(hitgroup == 1) damage = gDamageTank[i] * 45.0;
  175.                                 break;
  176.                             }
  177.                         }
  178.                     }
  179.                     case 1, 2, 3, 4, 5:
  180.                     {
  181.                         for( int i = 0; i < 12; i++ )
  182.                         {
  183.                             if(strcmp(classname, gMelee[i]) == 0)
  184.                             {
  185.                                 damage = gDamage[i];
  186.                                 if(hitgroup == 1) damage = gDamage[i] * 5.0;
  187.                                 break;
  188.                             }
  189.                         }
  190.                     }
  191.                 }
  192.                 return Plugin_Changed;
  193.             }
  194.         }
  195.     }
  196.     return Plugin_Continue;
  197. }
  198.  
  199. public Action EventFire(Handle event, const char[] name, bool dontbroadcast)
  200. {
  201.     int client = GetClientOfUserId(GetEventInt(event, "userid"));
  202.     if(bIsSurvivor(client))
  203.     {
  204.         int weapon = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
  205.         if(IsValidEntity(weapon))
  206.         {
  207.             char weaponname[36];
  208.             GetEntityClassname(weapon, weaponname, sizeof(weaponname));
  209.  
  210.             float vPos[3], vTargetPos[3];
  211.             GetClientEyePosition(client, vPos);
  212.  
  213.             for( int i = 0; i < MAX_LIST; i++ )
  214.             {
  215.                 if(strcmp(weaponname, gWeapons[i]) == 0)
  216.                 {
  217.                     int entity = -1;
  218.                     while( (entity = FindEntityByClassname(entity, "infected")) != INVALID_ENT_REFERENCE )
  219.                     {
  220.                         GetEntPropVector(entity, Prop_Send, "m_vecOrigin", vTargetPos);
  221.                         vTargetPos[2] += 54;
  222.                         float fTargetDistance = GetVectorDistance(vPos, vTargetPos);
  223.                         if(IsVisibleTo(vPos, vTargetPos))
  224.                         {
  225.                             float iOne = gDistance[i] - fTargetDistance;
  226.                             float vTransit = gDistance[i] / iOne;
  227.                             float vTotal = 100 / (vTransit * vTransit * vTransit);
  228.                             if(GetRandomInt(0, 100) <= RoundToCeil(vTotal))
  229.                             {
  230.                                 SDKCall(sdkSetAttack, entity);
  231.                             }
  232.                         }
  233.                         else
  234.                         {
  235.                             float iOne = (gDistance[i] / 3) - fTargetDistance;
  236.                             float vTransit = gDistance[i] / iOne;
  237.                             float vTotal = 33 / (vTransit * vTransit * vTransit);
  238.                             if(GetRandomInt(0, 100) <= RoundToCeil(vTotal))
  239.                             {
  240.                                 if(fTargetDistance < iOne)
  241.                                 {
  242.                                     SDKCall(sdkSetAttack, entity);
  243.                                 }
  244.                             }
  245.                         }
  246.                     }
  247.                     break;
  248.                 }
  249.             }
  250.         }
  251.     }
  252. }  
  253.  
  254. static bool IsVisibleTo(float position[3], float targetposition[3])
  255. {
  256.     float vAngles[3], vLookAt[3];
  257.    
  258.     MakeVectorFromPoints(position, targetposition, vLookAt);
  259.     GetVectorAngles(vLookAt, vAngles);
  260.  
  261.     Handle trace = TR_TraceRayFilterEx(position, vAngles, MASK_SHOT, RayType_Infinite, _TraceFilter);
  262.    
  263.     bool isVisible = false;
  264.     if (TR_DidHit(trace))
  265.     {
  266.         float vStart[3];
  267.         TR_GetEndPosition(vStart, trace);
  268.        
  269.         if ((GetVectorDistance(position, vStart, false) + 25.0) >= GetVectorDistance(position, targetposition))
  270.         {
  271.             isVisible = true;
  272.         }
  273.     }
  274.  
  275.     delete trace;
  276.     return isVisible;
  277. }
  278.  
  279. public bool _TraceFilter(int entity, int contentsMask)
  280. {
  281.     if (IsValidEntity(entity))
  282.     {
  283.         return false;
  284.     }
  285.     return true;
  286. }
  287.  
  288. stock bool bIsSurvivor(int client)
  289. {
  290.     return client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 2 && !IsClientInKickQueue(client) && IsPlayerAlive(client);
  291. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement