Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma semicolon 1
- #pragma newdecls required
- #include <sdktools>
- #include <sdkhooks>
- #define MAX_LIST 18
- Handle sdkSetAttack;
- static const char gWeapons[MAX_LIST][] =
- {
- "weapon_autoshotgun",
- "weapon_hunting_rifle",
- "weapon_pistol",
- "weapon_pistol_magnum",
- "weapon_pumpshotgun",
- "weapon_rifle",
- "weapon_rifle_ak47",
- "weapon_rifle_desert",
- "weapon_rifle_m60",
- "weapon_rifle_sg552",
- "weapon_shotgun_chrome",
- "weapon_shotgun_spas",
- "weapon_smg",
- "weapon_smg_mp5",
- "weapon_smg_silenced",
- "weapon_sniper_awp",
- "weapon_sniper_military",
- "weapon_sniper_scout"
- };
- static const float gDistance[MAX_LIST] =
- {
- 1650.0,
- 1100.0,
- 880.0,
- 1980.0,
- 1650.0,
- 1100.0,
- 1100.0,
- 1100.0,
- 1320.0,
- 1100.0,
- 1540.0,
- 1540.0,
- 880.0,
- 880.0,
- 880.0,
- 1870.0,
- 1320.0,
- 1320.0
- };
- public void OnPluginStart()
- {
- HookEvent("weapon_fire", EventFire);
- Handle hGameConf = LoadGameConfigFile("added_sound-attracts-zombies");
- StartPrepSDKCall(SDKCall_Entity);
- if( PrepSDKCall_SetFromConf(hGameConf, SDKConf_Signature, "SetAttackToSurvivors") == false )
- SetFailState("Could not load the \"SetAttackToSurvivors\" gamedata signature.");
- sdkSetAttack = EndPrepSDKCall();
- delete hGameConf;
- }
- public Action EventFire(Handle event, const char[] name, bool dontbroadcast)
- {
- int client = GetClientOfUserId(GetEventInt(event, "userid"));
- if(bIsSurvivor(client))
- {
- int weapon = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
- if(IsValidEntity(weapon))
- {
- char weaponname[36];
- GetEntityClassname(weapon, weaponname, sizeof(weaponname));
- float vPos[3], vTargetPos[3];
- GetClientEyePosition(client, vPos);
- for( int i = 0; i < MAX_LIST; i++ )
- {
- if(strcmp(weaponname, gWeapons[i]) == 0)
- {
- int entity = -1;
- while( (entity = FindEntityByClassname(entity, "infected")) != INVALID_ENT_REFERENCE )
- {
- GetEntPropVector(entity, Prop_Send, "m_vecOrigin", vTargetPos);
- float fTargetDistance = GetVectorDistance(vPos, vTargetPos);
- if(IsVisibleTo(vPos, vTargetPos))
- {
- if(fTargetDistance < gDistance[i])
- {
- SDKCall(sdkSetAttack, entity);
- }
- }
- else
- {
- float iOne = gDistance[i] / 3;
- int vForward = RoundToCeil(gDistance[i] / iOne);
- int vTotal = 50 / (vForward * vForward * vForward);
- if(GetRandomInt(0, 100) <= vTotal)
- {
- if(fTargetDistance < iOne)
- {
- SDKCall(sdkSetAttack, entity);
- }
- }
- }
- }
- break;
- }
- }
- }
- }
- }
- 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);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement