Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma semicolon 1
- #pragma newdecls required
- #include <sdktools>
- #include <sdkhooks>
- Handle sdkSetAttack;
- float weapon_autoshotgun = 1650.0;
- float weapon_hunting_rifle = 660.0;
- float weapon_pistol = 880.0;
- float weapon_pistol_magnum = 1980.0;
- float weapon_pumpshotgun = 1650.0;
- float weapon_rifle = 1100.0;
- float weapon_rifle_ak47 = 1100.0;
- float weapon_rifle_desert = 1100.0;
- float weapon_rifle_m60 = 1320.0;
- float weapon_rifle_sg552 = 1100.0;
- float weapon_shotgun_chrome = 1540.0;
- float weapon_shotgun_spas = 1540.0;
- float weapon_smg = 880.0;
- float weapon_smg_mp5 = 880.0;
- float weapon_smg_silenced = 880.0;
- float weapon_sniper_awp = 1870.0;
- float weapon_sniper_military = 1320.0;
- float weapon_sniper_scout = 1320.0;
- float weapon_grenade_launcher = 2200.0;
- float weapon_pipe_bomb = 2200.0;
- int iChance = 2;
- public void OnPluginStart()
- {
- Handle hGameConf = LoadGameConfigFile("SetAttackSurvivorCommons");
- StartPrepSDKCall(SDKCall_Entity);
- if( PrepSDKCall_SetFromConf(hGameConf, SDKConf_Signature, "SetAttackToSurvivors") == false )
- SetFailState("Could not load the \"SetAttackToSurvivors\" gamedata signature.");
- sdkSetAttack = EndPrepSDKCall();
- HookEvent("weapon_fire", EventFire);
- }
- public Action EventFire(Handle event, const char[] name, bool dontbroadcast)
- {
- int client = GetClientOfUserId(GetEventInt(event, "userid"));
- int weapon = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
- if(IsValidEntity(weapon))
- {
- char weaponname[36];
- GetEntityClassname(weapon, weaponname, sizeof(weaponname));
- if(bIsSurvivor(client))
- {
- float vPos[3], vTargetPos[3];
- GetClientEyePosition(client, vPos);
- if(strcmp(weaponname, "weapon_autoshotgun") == 0)
- {
- for(int i = 33; i <= 2048; i++)
- {
- if(IsCommonInfected(i))
- {
- GetEntPropVector(i, Prop_Send, "m_vecOrigin", vTargetPos);
- float fTargetDistance = GetVectorDistance(vPos, vTargetPos);
- if(IsVisibleTo(vPos, vTargetPos))
- {
- if(fTargetDistance < weapon_autoshotgun)
- {
- SDKCall(sdkSetAttack, i);
- }
- }
- else
- {
- if(GetRandomInt(0, 100) <= iChance)
- {
- if(fTargetDistance < weapon_autoshotgun)
- {
- SDKCall(sdkSetAttack, i);
- }
- }
- }
- }
- }
- }
- else if(strcmp(weaponname, "weapon_hunting_rifle") == 0)
- {
- for(int i = 33; i <= 2048; i++)
- {
- if(IsCommonInfected(i))
- {
- GetEntPropVector(i, Prop_Send, "m_vecOrigin", vTargetPos);
- float fTargetDistance = GetVectorDistance(vPos, vTargetPos);
- if(IsVisibleTo(vPos, vTargetPos))
- {
- if(fTargetDistance < weapon_hunting_rifle)
- {
- SDKCall(sdkSetAttack, i);
- }
- }
- else
- {
- if(GetRandomInt(0, 100) <= iChance)
- {
- if(fTargetDistance < weapon_hunting_rifle)
- {
- SDKCall(sdkSetAttack, i);
- }
- }
- }
- }
- }
- }
- else if(strcmp(weaponname, "weapon_pistol") == 0)
- {
- for(int i = 33; i <= 2048; i++)
- {
- if(IsCommonInfected(i))
- {
- GetEntPropVector(i, Prop_Send, "m_vecOrigin", vTargetPos);
- float fTargetDistance = GetVectorDistance(vPos, vTargetPos);
- if(IsVisibleTo(vPos, vTargetPos))
- {
- if(fTargetDistance < weapon_pistol)
- {
- SDKCall(sdkSetAttack, i);
- }
- }
- else
- {
- if(GetRandomInt(0, 100) <= iChance)
- {
- if(fTargetDistance < weapon_pistol)
- {
- SDKCall(sdkSetAttack, i);
- }
- }
- }
- }
- }
- }
- else if(strcmp(weaponname, "weapon_pistol_magnum") == 0)
- {
- for(int i = 33; i <= 2048; i++)
- {
- if(IsCommonInfected(i))
- {
- GetEntPropVector(i, Prop_Send, "m_vecOrigin", vTargetPos);
- float fTargetDistance = GetVectorDistance(vPos, vTargetPos);
- if(IsVisibleTo(vPos, vTargetPos))
- {
- if(fTargetDistance < weapon_pistol_magnum)
- {
- SDKCall(sdkSetAttack, i);
- }
- }
- else
- {
- if(GetRandomInt(0, 100) <= iChance)
- {
- if(fTargetDistance < weapon_pistol_magnum)
- {
- SDKCall(sdkSetAttack, i);
- }
- }
- }
- }
- }
- }
- else if(strcmp(weaponname, "weapon_pumpshotgun") == 0)
- {
- for(int i = 33; i <= 2048; i++)
- {
- if(IsCommonInfected(i))
- {
- GetEntPropVector(i, Prop_Send, "m_vecOrigin", vTargetPos);
- float fTargetDistance = GetVectorDistance(vPos, vTargetPos);
- if(IsVisibleTo(vPos, vTargetPos))
- {
- if(fTargetDistance < weapon_pumpshotgun)
- {
- SDKCall(sdkSetAttack, i);
- }
- }
- else
- {
- if(GetRandomInt(0, 100) <= iChance)
- {
- if(fTargetDistance < weapon_pumpshotgun)
- {
- SDKCall(sdkSetAttack, i);
- }
- }
- }
- }
- }
- }
- else if(strcmp(weaponname, "weapon_rifle") == 0)
- {
- for(int i = 33; i <= 2048; i++)
- {
- if(IsCommonInfected(i))
- {
- GetEntPropVector(i, Prop_Send, "m_vecOrigin", vTargetPos);
- float fTargetDistance = GetVectorDistance(vPos, vTargetPos);
- if(IsVisibleTo(vPos, vTargetPos))
- {
- if(fTargetDistance < weapon_rifle)
- {
- SDKCall(sdkSetAttack, i);
- }
- }
- else
- {
- if(GetRandomInt(0, 100) <= iChance)
- {
- if(fTargetDistance < weapon_rifle)
- {
- SDKCall(sdkSetAttack, i);
- }
- }
- }
- }
- }
- }
- else if(strcmp(weaponname, "weapon_rifle_ak47") == 0)
- {
- for(int i = 33; i <= 2048; i++)
- {
- if(IsCommonInfected(i))
- {
- GetEntPropVector(i, Prop_Send, "m_vecOrigin", vTargetPos);
- float fTargetDistance = GetVectorDistance(vPos, vTargetPos);
- if(IsVisibleTo(vPos, vTargetPos))
- {
- if(fTargetDistance < weapon_rifle_ak47)
- {
- SDKCall(sdkSetAttack, i);
- }
- }
- else
- {
- if(GetRandomInt(0, 100) <= iChance)
- {
- if(fTargetDistance < weapon_rifle_ak47)
- {
- SDKCall(sdkSetAttack, i);
- }
- }
- }
- }
- }
- }
- else if(strcmp(weaponname, "weapon_rifle_desert") == 0)
- {
- for(int i = 33; i <= 2048; i++)
- {
- if(IsCommonInfected(i))
- {
- GetEntPropVector(i, Prop_Send, "m_vecOrigin", vTargetPos);
- float fTargetDistance = GetVectorDistance(vPos, vTargetPos);
- if(IsVisibleTo(vPos, vTargetPos))
- {
- if(fTargetDistance < weapon_rifle_desert)
- {
- SDKCall(sdkSetAttack, i);
- }
- }
- else
- {
- if(GetRandomInt(0, 100) <= iChance)
- {
- if(fTargetDistance < weapon_rifle_desert)
- {
- SDKCall(sdkSetAttack, i);
- }
- }
- }
- }
- }
- }
- else if(strcmp(weaponname, "weapon_rifle_m60") == 0)
- {
- for(int i = 33; i <= 2048; i++)
- {
- if(IsCommonInfected(i))
- {
- GetEntPropVector(i, Prop_Send, "m_vecOrigin", vTargetPos);
- float fTargetDistance = GetVectorDistance(vPos, vTargetPos);
- if(IsVisibleTo(vPos, vTargetPos))
- {
- if(fTargetDistance < weapon_rifle_m60)
- {
- SDKCall(sdkSetAttack, i);
- }
- }
- else
- {
- if(GetRandomInt(0, 100) <= iChance)
- {
- if(fTargetDistance < weapon_rifle_m60)
- {
- SDKCall(sdkSetAttack, i);
- }
- }
- }
- }
- }
- }
- else if(strcmp(weaponname, "weapon_rifle_sg552") == 0)
- {
- for(int i = 33; i <= 2048; i++)
- {
- if(IsCommonInfected(i))
- {
- GetEntPropVector(i, Prop_Send, "m_vecOrigin", vTargetPos);
- float fTargetDistance = GetVectorDistance(vPos, vTargetPos);
- if(IsVisibleTo(vPos, vTargetPos))
- {
- if(fTargetDistance < weapon_rifle_sg552)
- {
- SDKCall(sdkSetAttack, i);
- }
- }
- else
- {
- if(GetRandomInt(0, 100) <= iChance)
- {
- if(fTargetDistance < weapon_rifle_sg552)
- {
- SDKCall(sdkSetAttack, i);
- }
- }
- }
- }
- }
- }
- else if(strcmp(weaponname, "weapon_shotgun_chrome") == 0)
- {
- for(int i = 33; i <= 2048; i++)
- {
- if(IsCommonInfected(i))
- {
- GetEntPropVector(i, Prop_Send, "m_vecOrigin", vTargetPos);
- float fTargetDistance = GetVectorDistance(vPos, vTargetPos);
- if(IsVisibleTo(vPos, vTargetPos))
- {
- if(fTargetDistance < weapon_shotgun_chrome)
- {
- SDKCall(sdkSetAttack, i);
- }
- }
- else
- {
- if(GetRandomInt(0, 100) <= iChance)
- {
- if(fTargetDistance < weapon_shotgun_chrome)
- {
- SDKCall(sdkSetAttack, i);
- }
- }
- }
- }
- }
- }
- else if(strcmp(weaponname, "weapon_shotgun_spas") == 0)
- {
- for(int i = 33; i <= 2048; i++)
- {
- if(IsCommonInfected(i))
- {
- GetEntPropVector(i, Prop_Send, "m_vecOrigin", vTargetPos);
- float fTargetDistance = GetVectorDistance(vPos, vTargetPos);
- if(IsVisibleTo(vPos, vTargetPos))
- {
- if(fTargetDistance < weapon_shotgun_spas)
- {
- SDKCall(sdkSetAttack, i);
- }
- }
- else
- {
- if(GetRandomInt(0, 100) <= iChance)
- {
- if(fTargetDistance < weapon_shotgun_spas)
- {
- SDKCall(sdkSetAttack, i);
- }
- }
- }
- }
- }
- }
- else if(strcmp(weaponname, "weapon_smg") == 0)
- {
- for(int i = 33; i <= 2048; i++)
- {
- if(IsCommonInfected(i))
- {
- GetEntPropVector(i, Prop_Send, "m_vecOrigin", vTargetPos);
- float fTargetDistance = GetVectorDistance(vPos, vTargetPos);
- if(IsVisibleTo(vPos, vTargetPos))
- {
- if(fTargetDistance < weapon_smg)
- {
- SDKCall(sdkSetAttack, i);
- }
- }
- else
- {
- if(GetRandomInt(0, 100) <= iChance)
- {
- if(fTargetDistance < weapon_smg)
- {
- SDKCall(sdkSetAttack, i);
- }
- }
- }
- }
- }
- }
- else if(strcmp(weaponname, "weapon_smg_mp5") == 0)
- {
- for(int i = 33; i <= 2048; i++)
- {
- if(IsCommonInfected(i))
- {
- GetEntPropVector(i, Prop_Send, "m_vecOrigin", vTargetPos);
- float fTargetDistance = GetVectorDistance(vPos, vTargetPos);
- if(IsVisibleTo(vPos, vTargetPos))
- {
- if(fTargetDistance < weapon_smg_mp5)
- {
- SDKCall(sdkSetAttack, i);
- }
- }
- else
- {
- if(GetRandomInt(0, 100) <= iChance)
- {
- if(fTargetDistance < weapon_smg_mp5)
- {
- SDKCall(sdkSetAttack, i);
- }
- }
- }
- }
- }
- }
- else if(strcmp(weaponname, "weapon_smg_silenced") == 0)
- {
- for(int i = 33; i <= 2048; i++)
- {
- if(IsCommonInfected(i))
- {
- GetEntPropVector(i, Prop_Send, "m_vecOrigin", vTargetPos);
- float fTargetDistance = GetVectorDistance(vPos, vTargetPos);
- if(IsVisibleTo(vPos, vTargetPos))
- {
- if(fTargetDistance < weapon_smg_silenced)
- {
- SDKCall(sdkSetAttack, i);
- }
- }
- else
- {
- if(GetRandomInt(0, 100) <= iChance)
- {
- if(fTargetDistance < weapon_smg_silenced)
- {
- SDKCall(sdkSetAttack, i);
- }
- }
- }
- }
- }
- }
- else if(strcmp(weaponname, "weapon_sniper_awp") == 0)
- {
- for(int i = 33; i <= 2048; i++)
- {
- if(IsCommonInfected(i))
- {
- GetEntPropVector(i, Prop_Send, "m_vecOrigin", vTargetPos);
- float fTargetDistance = GetVectorDistance(vPos, vTargetPos);
- if(IsVisibleTo(vPos, vTargetPos))
- {
- if(fTargetDistance < weapon_sniper_awp)
- {
- SDKCall(sdkSetAttack, i);
- }
- }
- else
- {
- if(GetRandomInt(0, 100) <= iChance)
- {
- if(fTargetDistance < weapon_sniper_awp)
- {
- SDKCall(sdkSetAttack, i);
- }
- }
- }
- }
- }
- }
- else if(strcmp(weaponname, "weapon_sniper_military") == 0)
- {
- for(int i = 33; i <= 2048; i++)
- {
- if(IsCommonInfected(i))
- {
- GetEntPropVector(i, Prop_Send, "m_vecOrigin", vTargetPos);
- float fTargetDistance = GetVectorDistance(vPos, vTargetPos);
- if(IsVisibleTo(vPos, vTargetPos))
- {
- if(fTargetDistance < weapon_sniper_military)
- {
- SDKCall(sdkSetAttack, i);
- }
- }
- else
- {
- if(GetRandomInt(0, 100) <= iChance)
- {
- if(fTargetDistance < weapon_sniper_military)
- {
- SDKCall(sdkSetAttack, i);
- }
- }
- }
- }
- }
- }
- else if(strcmp(weaponname, "weapon_sniper_scout") == 0)
- {
- for(int i = 33; i <= 2048; i++)
- {
- if(IsCommonInfected(i))
- {
- GetEntPropVector(i, Prop_Send, "m_vecOrigin", vTargetPos);
- float fTargetDistance = GetVectorDistance(vPos, vTargetPos);
- if(IsVisibleTo(vPos, vTargetPos))
- {
- if(fTargetDistance < weapon_sniper_scout)
- {
- SDKCall(sdkSetAttack, i);
- }
- }
- else
- {
- if(GetRandomInt(0, 100) <= iChance)
- {
- if(fTargetDistance < weapon_sniper_scout)
- {
- SDKCall(sdkSetAttack, i);
- }
- }
- }
- }
- }
- }
- }
- }
- return Plugin_Continue;
- }
- public void OnEntityDestroyed(int entity)
- {
- if(IsValidEntity(entity) && IsValidEdict(entity))
- {
- char sTypeEx[36];
- GetEntityClassname(entity, sTypeEx, sizeof(sTypeEx));
- if(strcmp(sTypeEx, "grenade_launcher_projectile") == 0)
- {
- float vPos[3], vTargetPos[3];
- GetEntPropVector(entity, Prop_Send, "m_vecOrigin", vPos);
- for(int i = 33; i <= 2048; i++)
- {
- if(IsCommonInfected(i))
- {
- GetEntPropVector(i, Prop_Send, "m_vecOrigin", vTargetPos);
- float fTargetDistance = GetVectorDistance(vPos, vTargetPos);
- if(fTargetDistance <= weapon_grenade_launcher)
- {
- SDKCall(sdkSetAttack, i);
- }
- }
- }
- }
- else if(strcmp(sTypeEx, "pipe_bomb_projectile") == 0)
- {
- float vPos[3], vTargetPos[3];
- GetEntPropVector(entity, Prop_Send, "m_vecOrigin", vPos);
- for(int i = 33; i <= 2048; i++)
- {
- if(IsCommonInfected(i))
- {
- GetEntPropVector(i, Prop_Send, "m_vecOrigin", vTargetPos);
- float fTargetDistance = GetVectorDistance(vPos, vTargetPos);
- if(fTargetDistance <= weapon_pipe_bomb)
- {
- SDKCall(sdkSetAttack, i);
- }
- }
- }
- }
- }
- }
- static bool IsVisibleTo(float position[3], float targetposition[3])
- {
- float vAngles[3], vLookAt[3];
- MakeVectorFromPoints(position, targetposition, vLookAt);
- GetVectorAngles(vLookAt, vAngles);
- Handle trace = TR_TraceRayFilterEx(position, vAngles, MASK_SHOT, RayType_Infinite, _TraceFilter);
- bool isVisible = false;
- if (TR_DidHit(trace))
- {
- float vStart[3];
- TR_GetEndPosition(vStart, trace);
- if ((GetVectorDistance(position, vStart, false) + 25.0) >= GetVectorDistance(position, targetposition))
- {
- isVisible = true;
- }
- }
- delete trace;
- return isVisible;
- }
- public bool _TraceFilter(int entity, int contentsMask)
- {
- if (IsValidEntity(entity))
- {
- return false;
- }
- return true;
- }
- stock bool bIsSurvivor(int client)
- {
- return client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 2 && !IsClientInKickQueue(client) && IsPlayerAlive(client);
- }
- stock bool IsCommonInfected(int entity)
- {
- if (entity > 33 && IsValidEntity(entity) && IsValidEdict(entity))
- {
- char entType[64];
- GetEdictClassname(entity, entType, sizeof(entType));
- return StrEqual(entType, "infected");
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement