From fac0494c0ccd5775bffde2ca3c753431dac31ab1 Mon Sep 17 00:00:00 2001 From: neon Date: Fri, 3 Apr 2020 18:05:46 +0200 Subject: [PATCH] Update: PushNades --- _PushNades/scripting/PushNades.sp | 129 ++++++++++++++++++++++++++---- 1 file changed, 115 insertions(+), 14 deletions(-) diff --git a/_PushNades/scripting/PushNades.sp b/_PushNades/scripting/PushNades.sp index a75a6490..0f4aedf8 100644 --- a/_PushNades/scripting/PushNades.sp +++ b/_PushNades/scripting/PushNades.sp @@ -6,33 +6,99 @@ #pragma semicolon 1 #pragma newdecls required -Handle g_hCVar_PushNadesEnabled = INVALID_HANDLE; -Handle g_hCVar_PushRange = INVALID_HANDLE; -Handle g_hCVar_PushStrength = INVALID_HANDLE; -Handle g_hCVar_PushScale = INVALID_HANDLE; +ConVar g_hCVar_PushNadesEnabled; +ConVar g_hCVar_PushStrength; +ConVar g_hCVar_PushScale; +int g_iToolsActiveWeapon; +int g_iToolsVelocity; +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- public Plugin myinfo = { name = "PushNades", author = "Neon", description = "Push Zombies away from the Human that threw the HE-Grenade", - version = "1.0", + version = "2.0", url = "https://steamcommunity.com/id/n3ontm" } +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- public void OnPluginStart() { g_hCVar_PushNadesEnabled = CreateConVar("sm_hegrenade_push_enabled", "0", "Enable PushBack for HE-Grenades", 0, true, 0.0, true, 1.0); g_hCVar_PushScale = CreateConVar("sm_hegrenade_push_scale", "0", "Make the push scale with the distance to the explosion", 0, true, 0.0, true, 1.0); - g_hCVar_PushRange = CreateConVar("sm_hegrenade_push_range", "500", "Range arround Explosion in which Zombies are affected by the push."); - g_hCVar_PushStrength = CreateConVar("sm_hegrenade_push_strength", "2500", "How strong the HE-Grenade pushes back"); + g_hCVar_PushStrength = CreateConVar("sm_hegrenade_push_strength", "500", "How strong the HE-Grenade pushes back"); - AutoExecConfig(true, "plugin.PushNades"); + g_iToolsActiveWeapon = FindSendPropInfo("CBasePlayer", "m_hActiveWeapon"); + g_iToolsVelocity = FindDataMapInfo(0, "m_vecAbsVelocity"); - HookEvent("hegrenade_detonate", OnHEDetonate); + AutoExecConfig(); } +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void OnClientPutInServer(int client) +{ + SDKHook(client, SDKHook_OnTakeDamageAlivePost, DamageOnTakeDamageAlivePost); +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void DamageOnTakeDamageAlivePost(int victim, int attacker, int inflictor, float damage, int damagetype, int weapon, const float damageForce[3], const float damagePosition[3], int damagecustom) +{ + char sWeapon[64]; + if (inflictor == attacker) + { + weapon = WeaponsGetActiveWeaponIndex(attacker); + if (weapon > 0) + GetEdictClassname(weapon, sWeapon, sizeof(sWeapon)); + } + else + GetEdictClassname(inflictor, sWeapon, sizeof(sWeapon)); + + if (!StrEqual(sWeapon, "hegrenade_projectile")) + return; + + if (!g_hCVar_PushNadesEnabled.BoolValue) + return; + + if (!IsValidClient(attacker, false) || !IsValidClient(victim, false)) + return; + + if (!IsPlayerAlive(attacker) || !ZR_IsClientHuman(attacker)) + return; + + if (!IsPlayerAlive(victim) || !ZR_IsClientZombie(victim)) + return; + + float fVictimLoc[3]; + float fAttackerLoc[3]; + + GetClientAbsOrigin(victim, fVictimLoc); + GetClientAbsOrigin(attacker, fAttackerLoc); + + float fPushVector[3]; + MakeVectorFromPoints(fAttackerLoc, fVictimLoc, fPushVector); + NormalizeVector(fPushVector, fPushVector); + ScaleVector(fPushVector, g_hCVar_PushStrength.FloatValue); + + float fVelocity[3]; + GetEntDataVector(victim, g_iToolsVelocity, fVelocity); + AddVectors(fPushVector, fVelocity, fVelocity); + + SetEntDataVector(victim, g_iToolsVelocity, fVelocity); +} +/* +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- public Action OnHEDetonate(Event hEvent, const char[] sEvent, bool bDontBroadcast) { if (!GetConVarBool(g_hCVar_PushNadesEnabled)) @@ -94,17 +160,52 @@ public Action OnHEDetonate(Event hEvent, const char[] sEvent, bool bDontBroadcas } } } - } return Plugin_Continue; } - -bool IsValidClient(int client, bool nobots = true) +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public int KnockbackFindExplodingGrenade(float fLoc[3]) { - if (client <= 0 || client > MaxClients || !IsClientInGame(client) || (nobots && IsFakeClient(client))) + char sClassname[64]; + + int iMaxEntities = GetMaxEntities(); + for (int i = MaxClients; i <= iMaxEntities; i++) { - return false; + if (!IsValidEdict(i)) + continue; + + GetEdictClassname(i, sClassname, sizeof(sClassname)); + if (!StrEqual(sClassname, "hegrenade_projectile", false)) + continue; + + int iTakeDamage = GetEntProp(i, Prop_Data, "m_takedamage"); + if (iTakeDamage == 0) + { + GetEntPropVector(i, Prop_Send, "m_vecOrigin", fLoc); + return i; + } } + return -1; +} +*/ +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +stock int IsValidClient(int client, bool nobots = true) +{ + if (client <= 0 || client > MaxClients || !IsClientConnected(client) || (nobots && IsFakeClient(client))) + return false; + return IsClientInGame(client); } + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public int WeaponsGetActiveWeaponIndex(int client) +{ + return GetEntDataEnt2(client, g_iToolsActiveWeapon); +} \ No newline at end of file