Advertisement
FlacoBey

Untitled

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