Advertisement
FlacoBey

Untitled

Aug 3rd, 2019
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.76 KB | None | 0 0
  1. #pragma semicolon 1
  2. #pragma newdecls required
  3.  
  4. #include <sourcemod>
  5. #include <sdktools>
  6. #include <sdkhooks>
  7.  
  8. #define MAXPROJECTILES 64
  9.  
  10. ConVar cDamage, cRange, cDistance, cSpeed, cCount, cColor, cDistanceLight;
  11. float g_iDamage, g_iRange, g_iDistance, g_iSpeed;
  12. Handle g_hSpitVelocity;
  13. int g_iVelocity, g_iCount, g_iEntities[MAXPLAYERS + 1][MAXPROJECTILES], g_iOwner[2048 + 1];
  14.  
  15. public Plugin myinfo =
  16. {
  17.     name = "[L4D2] Spitter",
  18.     author = "BHaType",
  19.     description = "spitter",
  20.     version = "0.0.1",
  21.     url = "N/A"
  22. }
  23.  
  24. public void OnPluginStart()
  25. {
  26.     cDamage  = CreateConVar("magic_spitter_damage"     , "5.0" , "Number of damage"     , FCVAR_NONE);
  27.     cRange    = CreateConVar("magic_spitter_range"      , "60.0"    , "Range of hit"            , FCVAR_NONE);
  28.     cDistance   = CreateConVar("magic_spitter_distance" , "950.0"   , "Distance of detect"    , FCVAR_NONE);
  29.     cSpeed    = CreateConVar("magic_spitter_speed"      , "5.5" , "Speed of magic items"    , FCVAR_NONE);
  30.     cCount    = CreateConVar("magic_spitter_count"      , "12" , "Count of magic items" , FCVAR_NONE);
  31.     cColor    = CreateConVar("magic_spitter_color"      , "25 255 25" , "Color of magic items"  , FCVAR_NONE);
  32.     cDistanceLight    = CreateConVar("magic_spitter_color"      , "250" , "Distance of light magic items"   , FCVAR_NONE);
  33.  
  34.     g_iDamage   = cDamage.FloatValue;
  35.     g_iRange    = cRange.FloatValue;
  36.     g_iDistance = cDistance.FloatValue;
  37.     g_iSpeed    = cSpeed.FloatValue;
  38.     g_iCount    = cCount.IntValue;
  39.    
  40.     cDamage.AddChangeHook(IntsCvar);
  41.     cRange.AddChangeHook(IntsCvar);
  42.     cDistance.AddChangeHook(IntsCvar);
  43.     cSpeed.AddChangeHook(IntsCvar);
  44.     cCount.AddChangeHook(IntsCvar);
  45.    
  46.     g_iVelocity = FindSendPropInfo("CBasePlayer", "m_vecVelocity[0]");
  47.    
  48.     HookEvent("player_death", eDeath);
  49.     HookEvent("ability_use", eAbility);
  50.    
  51.     g_hSpitVelocity = FindConVar("z_spit_velocity");
  52.    
  53.     AutoExecConfig(true, "spitter_aimbot");
  54. }
  55.  
  56. public void IntsCvar(ConVar convar, const char[] oldValue, const char[] newValue)
  57. {
  58.     g_iDamage   = cDamage.FloatValue;
  59.     g_iRange    = cRange.FloatValue;
  60.     g_iDistance = cDistance.FloatValue;
  61.     g_iSpeed = cSpeed.FloatValue;
  62.     g_iCount    = cCount.IntValue;
  63. }
  64.  
  65. public void eAbility(Event event, const char[] name, bool dontBroadcast)
  66. {
  67.     int client;
  68.    
  69.     client = GetClientOfUserId(event.GetInt("userid"));
  70.     if (!client || !IsClientInGame(client)) return;
  71.    
  72.     if(GetEntProp(client, Prop_Send, "m_zombieClass") == 4)
  73.     {
  74.         float vPos[3], vAng[3];
  75.         char sColor[16];
  76.        
  77.         GetClientEyeAngles(client, vAng);
  78.         GetClientEyePosition(client, vPos);
  79.         GetAngleVectors(vAng, vAng, NULL_VECTOR, NULL_VECTOR);
  80.         NormalizeVector(vAng, vAng);
  81.         ScaleVector(vAng, GetConVarFloat(g_hSpitVelocity) * 0.45);
  82.        
  83.         cColor.GetString(sColor, sizeof sColor);
  84.        
  85.         for(int l; l < g_iCount; l++)
  86.         {
  87.             int weapon = CreateEntityByName("spitter_projectile");
  88.             if(IsValidEntity(weapon))
  89.             {
  90.                
  91.                 vAng[0] += GetRandomFloat(-60.0, 60.0);
  92.                 vAng[1] += GetRandomFloat(-60.0, 60.0);
  93.                 vAng[2] += GetRandomFloat(-60.0, 60.0);
  94.                 vPos[0] += GetRandomFloat(-20.0, 20.0);
  95.                 vPos[1] += GetRandomFloat(-20.0, 20.0);
  96.                 vPos[2] += GetRandomFloat(-20.0, 20.0);
  97.                
  98.                 DispatchSpawn(weapon);
  99.                 SetEntityGravity(weapon, 0.01);
  100.                
  101.                 MakeLightDynamic(vPos, vAng, sColor, GetConVarInt(cDistanceLight), weapon);
  102.                
  103.                 SetEntProp(weapon, Prop_Send, "m_nSolidType", 0);
  104.                 g_iOwner[weapon] = client;
  105.                
  106.                 for(int i; i < MAXPROJECTILES; i++)
  107.                 {
  108.                     if(EntRefToEntIndex(g_iEntities[client][i]) == INVALID_ENT_REFERENCE || EntRefToEntIndex(g_iEntities[client][i]) == 0)
  109.                     {
  110.                         g_iEntities[client][i] = EntIndexToEntRef(weapon);
  111.                         break;
  112.                     }
  113.                 }
  114.                
  115.                 CreateTimer(0.1, PreThink, EntIndexToEntRef(weapon), TIMER_REPEAT);
  116.                 TeleportEntity(weapon, vPos, NULL_VECTOR, vAng);
  117.             }
  118.             else
  119.                 AcceptEntityInput(weapon, "kill");
  120.         }
  121.     }
  122. }
  123.  
  124. public void eDeath (Event event, const char[] name, bool dontbroadcast)
  125. {
  126.     int client = GetClientOfUserId(event.GetInt("userid"));
  127.     if(client > 0 && client <= MaxClients)
  128.     {
  129.         if(GetEntProp(client, Prop_Send, "m_zombieClass") == 4)
  130.         {
  131.             int entity;
  132.             for(int i; i < MAXPROJECTILES; i++)
  133.             {
  134.                 if((entity = EntRefToEntIndex(g_iEntities[client][i])) != INVALID_ENT_REFERENCE && IsValidEntity(entity) && entity > MaxClients)
  135.                     AcceptEntityInput(entity, "kill");
  136.             }
  137.         }
  138.     }
  139. }
  140.  
  141. public Action PreThink (Handle timer, int index)
  142. {
  143.     index = EntRefToEntIndex(index);
  144.     if(index != INVALID_ENT_REFERENCE && IsValidEntity(index))
  145.         Tracering(index, g_iOwner[index]);
  146.     else
  147.         return Plugin_Stop;
  148.     return Plugin_Continue;
  149. }
  150.  
  151. void Tracering(int iEnt, int index)
  152. {
  153.     float vPos[3], vVel[3], flDistance;
  154.    
  155.     GetEntPropVector(iEnt, Prop_Send, "m_vecOrigin", vPos);
  156.     GetEntDataVector(iEnt, g_iVelocity, vVel);
  157.    
  158.     float vLenght = GetVectorLength(vVel);
  159.  
  160.     NormalizeVector(vVel, vVel);
  161.    
  162.     int client = lucker(iEnt);
  163.     if(client == -1)
  164.         client = index;
  165.        
  166.     if(client > 0 && IsValidEntity(client))
  167.     {
  168.         float vEnemy[3], vVelEnemy[3], vDir[3], doubleVel[3];
  169.  
  170.         GetClientEyePosition(client, vEnemy);
  171.         GetEntDataVector(client, g_iVelocity, vVelEnemy);
  172.        
  173.         flDistance = GetVectorDistance(vPos, vEnemy);
  174.         if(flDistance <= g_iRange && client != index)
  175.         {
  176.             SDKHooks_TakeDamage(client, iEnt, iEnt, g_iDamage, 1);
  177.             AcceptEntityInput(iEnt, "kill");
  178.         }
  179.        
  180.         SubtractVectors(vEnemy, vPos, vDir);
  181.         NormalizeVector(vDir, vDir);
  182.         ScaleVector(vDir, 0.5);
  183.         AddVectors(vVel, vDir, doubleVel);
  184.         NormalizeVector(doubleVel, doubleVel);
  185.         ScaleVector(doubleVel, vLenght + g_iSpeed);
  186.         TeleportEntity(iEnt, NULL_VECTOR, NULL_VECTOR, doubleVel);
  187.        
  188.     }
  189. }
  190.  
  191. int MakeLightDynamic(const float vOrigin[3], const float vAngles[3], const char[] sColor, int iDist, int parent)
  192. {
  193.     int entity = CreateEntityByName("light_dynamic");
  194.     char sTemp[16];
  195.     Format(sTemp, sizeof(sTemp), "6");
  196.     DispatchKeyValue(entity, "style", sTemp);
  197.     Format(sTemp, sizeof(sTemp), "%s 255", sColor);
  198.     DispatchKeyValue(entity, "_light", sTemp);
  199.     DispatchKeyValue(entity, "brightness", "1");
  200.     DispatchKeyValueFloat(entity, "spotlight_radius", 32.0);
  201.     DispatchKeyValueFloat(entity, "distance", float(iDist));
  202.     TeleportEntity(entity, vOrigin, vAngles, NULL_VECTOR);
  203.     DispatchSpawn(entity);
  204.     AcceptEntityInput(entity, "TurnOn");
  205.    
  206.     SetVariantString("!activator");
  207.     AcceptEntityInput(entity, "SetParent", parent);
  208.    
  209.     TeleportEntity(entity, view_as<float>({0, 0, 0}), NULL_VECTOR, NULL_VECTOR);
  210.    
  211.     return entity;
  212. }
  213.  
  214. int lucker(int index)
  215. {
  216.     float vPos[3], vPosEntity[3], vDistance = 100000.0, flDistance;
  217.     int count = -1;
  218.     GetEntPropVector(index, Prop_Send, "m_vecOrigin", vPos);
  219.     for(int i = 1; i <= MaxClients; i++)
  220.     {
  221.         if(IsClientInGame(i) && GetClientTeam(i) == 2 && IsPlayerAlive(i) && IsVisibleTo(i, index))
  222.         {
  223.             GetEntPropVector(i, Prop_Send, "m_vecOrigin", vPosEntity);
  224.             flDistance = GetVectorDistance(vPosEntity, vPos);
  225.             if(flDistance < vDistance && flDistance <= g_iDistance)
  226.             {
  227.                 vDistance = flDistance;
  228.                 count = i;
  229.             }
  230.         }
  231.     }
  232.    
  233.     return count;
  234. }
  235.  
  236. static bool IsVisibleTo(int client, int entity)
  237. {
  238.     float vAngles[3], vOrigin[3], vEnt[3], vLookAt[3];
  239.    
  240.     GetClientEyePosition(client, vOrigin);
  241.     GetEntPropVector(entity, Prop_Send, "m_vecOrigin", vEnt);
  242.     vEnt[2] += 64.0;
  243.    
  244.     MakeVectorFromPoints(vOrigin, vEnt, vLookAt);
  245.    
  246.     GetVectorAngles(vLookAt, vAngles);
  247.    
  248.     Handle trace = TR_TraceRayFilterEx(vOrigin, vAngles, MASK_SHOT, RayType_Infinite, TraceFilter, entity);
  249.    
  250.     bool isVisible = false;
  251.     if (TR_DidHit(trace))
  252.     {
  253.         float vStart[3];
  254.         TR_GetEndPosition(vStart, trace);
  255.        
  256.         if ((GetVectorDistance(vOrigin, vStart, false) + 25.0) >= GetVectorDistance(vOrigin, vEnt))
  257.         {
  258.             isVisible = true;
  259.         }
  260.     }
  261.     delete trace;
  262.     return isVisible;
  263. }
  264.  
  265. public bool TraceFilter(int entity, int mask, any data)
  266. {
  267.     if(entity == data)
  268.         return false;
  269.     return true;
  270. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement