Advertisement
FlacoBey

Untitled

Jun 16th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.86 KB | None | 0 0
  1. #pragma semicolon 1
  2. #pragma newdecls required
  3.  
  4. #include <sdktools>
  5. #include <sdkhooks>
  6.  
  7. #define MAX_LIST 20
  8.  
  9. Handle sdkSetAttack;
  10.  
  11. const char gWeapons[MAX_LIST] =
  12. {
  13.     "weapon_autoshotgun",
  14.     "weapon_hunting_rifle",
  15.     "weapon_pistol",
  16.     "weapon_pistol_magnum",
  17.     "weapon_pumpshotgun",
  18.     "weapon_rifle",
  19.     "weapon_rifle_ak47",
  20.     "weapon_rifle_desert",
  21.     "weapon_rifle_m60",
  22.     "weapon_rifle_sg552",
  23.     "weapon_shotgun_chrome",
  24.     "weapon_shotgun_spas",
  25.     "weapon_smg",
  26.     "weapon_smg_mp5",
  27.     "weapon_smg_silenced",
  28.     "weapon_sniper_awp",
  29.     "weapon_sniper_military",
  30.     "weapon_sniper_scout",
  31.     "weapon_grenade_launcher",
  32.     "weapon_pipe_bomb"
  33. }
  34.  
  35. const float gDistance[MAX_LIST] =
  36. {
  37.     1650.0,
  38.     660.0,
  39.     880.0,
  40.     1980.0,
  41.     1650.0,
  42.     1100.0,
  43.     1100.0,
  44.     1100.0,
  45.     1320.0,
  46.     1100.0,
  47.     1540.0,
  48.     1540.0,
  49.     880.0,
  50.     880.0,
  51.     880.0,
  52.     1870.0,
  53.     1320.0,
  54.     1320.0,
  55.     2200.0,
  56.     2200.0
  57. }
  58.  
  59. int iChance = 2;
  60.  
  61. public void OnPluginStart()
  62. {
  63.     HookEvent("weapon_fire", EventFire);
  64.  
  65.     Handle hGameConf = LoadGameConfigFile("SetAttackSurvivorCommons");
  66.     StartPrepSDKCall(SDKCall_Entity);
  67.     if( PrepSDKCall_SetFromConf(hGameConf, SDKConf_Signature, "SetAttackToSurvivors") == false )
  68.         SetFailState("Could not load the \"SetAttackToSurvivors\" gamedata signature.");
  69.     sdkSetAttack = EndPrepSDKCall();
  70.     delete hGameConf;
  71. }
  72.  
  73. public Action EventFire(Handle event, const char[] name, bool dontbroadcast)
  74. {
  75.     int client = GetClientOfUserId(GetEventInt(event, "userid"));
  76.     if(bIsSurvivor(client))
  77.     {
  78.         int weapon = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
  79.         if(IsValidEntity(weapon))
  80.         {
  81.             char weaponname[36];
  82.             GetEntityClassname(weapon, weaponname, sizeof(weaponname));
  83.  
  84.             float vPos[3], vTargetPos[3];
  85.             GetClientEyePosition(client, vPos);
  86.  
  87.             for( int i = 0; i < MAX_LIST; i++ )
  88.             {
  89.                 if(strcmp(weaponname, gWeapons[i]) == 0)
  90.                 {
  91.                     int entity = -1;
  92.                     while( (entity = FindEntityByClassname(entity, "infected")) != INVALID_ENT_REFERENCE )
  93.                     {
  94.                         GetEntPropVector(i, Prop_Send, "m_vecOrigin", vTargetPos);
  95.                         float fTargetDistance = GetVectorDistance(vPos, vTargetPos);
  96.  
  97.                         if(IsVisibleTo(vPos, vTargetPos))
  98.                         {
  99.                             if(fTargetDistance < gDistance[i])
  100.                             {
  101.                                 SDKCall(sdkSetAttack, i);
  102.                             }
  103.                         }
  104.                         else
  105.                         {
  106.                             if(GetRandomInt(0, 100) <= iChance)
  107.                             {
  108.                                 if(fTargetDistance < gDistance[i])
  109.                                 {
  110.                                     SDKCall(sdkSetAttack, i);
  111.                                 }
  112.                             }
  113.                         }
  114.                     }
  115.  
  116.                     break;
  117.                 }
  118.             }
  119.         }
  120.     }
  121.     return Plugin_Continue; // tehcnically don't need this since not returning anything else in this function
  122. }
  123.  
  124. public void OnEntityDestroyed(int entity)
  125. {
  126.     if(IsValidEntity(entity) && IsValidEdict(entity))
  127.     {
  128.         char sTypeEx[36];
  129.         GetEntityClassname(entity, sTypeEx, sizeof(sTypeEx));
  130.         if(strcmp(sTypeEx, "grenade_launcher_projectile") == 0)
  131.         {
  132.             float vPos[3], vTargetPos[3];
  133.             GetEntPropVector(entity, Prop_Send, "m_vecOrigin", vPos);
  134.             int common = -1;
  135.             while( (common = FindEntityByClassname(common, "infected")) != INVALID_ENT_REFERENCE )
  136.             {
  137.                 GetEntPropVector(common, Prop_Send, "m_vecOrigin", vTargetPos);
  138.                 float fTargetDistance = GetVectorDistance(vPos, vTargetPos);
  139.                 if(fTargetDistance <= gDistance[MAX_LIST - 2])
  140.                 {
  141.                     SDKCall(sdkSetAttack, common);
  142.                 }
  143.             }
  144.         }
  145.         else if(strcmp(sTypeEx, "pipe_bomb_projectile") == 0)
  146.         {
  147.             float vPos[3], vTargetPos[3];
  148.             GetEntPropVector(entity, Prop_Send, "m_vecOrigin", vPos);
  149.             int common = -1;
  150.             while( (common = FindEntityByClassname(entity, "infected")) != INVALID_ENT_REFERENCE )
  151.             {
  152.                 GetEntPropVector(common, Prop_Send, "m_vecOrigin", vTargetPos);
  153.                 float fTargetDistance = GetVectorDistance(vPos, vTargetPos);
  154.                 if(fTargetDistance <= gDistance[MAX_LIST - 1])
  155.                 {
  156.                     SDKCall(sdkSetAttack, common);
  157.                 }
  158.             }
  159.         }
  160.     }
  161. }
  162.  
  163. static bool IsVisibleTo(float position[3], float targetposition[3])
  164. {
  165.     float vAngles[3], vLookAt[3];
  166.    
  167.     MakeVectorFromPoints(position, targetposition, vLookAt);
  168.     GetVectorAngles(vLookAt, vAngles);
  169.  
  170.     Handle trace = TR_TraceRayFilterEx(position, vAngles, MASK_SHOT, RayType_Infinite, _TraceFilter);
  171.    
  172.     bool isVisible = false;
  173.     if (TR_DidHit(trace))
  174.     {
  175.         float vStart[3];
  176.         TR_GetEndPosition(vStart, trace);
  177.        
  178.         if ((GetVectorDistance(position, vStart, false) + 25.0) >= GetVectorDistance(position, targetposition))
  179.         {
  180.             isVisible = true;
  181.         }
  182.     }
  183.  
  184.     delete trace;
  185.     return isVisible;
  186. }
  187.  
  188. public bool _TraceFilter(int entity, int contentsMask)
  189. {
  190.     if (IsValidEntity(entity))
  191.     {
  192.         return false;
  193.     }
  194.     return true;
  195. }
  196.  
  197. stock bool bIsSurvivor(int client)
  198. {
  199.     return client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 2 && !IsClientInKickQueue(client) && IsPlayerAlive(client);
  200. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement