#pragma semicolon 1
#include <sourcemod>
#include <sdkhooks>
#include <sdktools>
#define VERSION "1.4"
#define teg "\x073EFF3E[HS]"
public Plugin:myinfo=
{
name="Only Headshot",
author="Spir",
description="Plugin that allows only headshots. Also, ability to allow HE and knife killings and to disable world damages !",
version=VERSION,
url="http://www.dowteam.com/"
};
new String:language[4];
new String:languagecode[4];
new bool:p_enabled;
new bool:p_allowknife;
new bool:p_allowhe;
new Handle:p_Cvarenabled = INVALID_HANDLE;
new Handle:p_Cvarallowknife = INVALID_HANDLE;
new Handle:p_Cvarallowhe = INVALID_HANDLE;
new g_iHealth, g_Armor;
public OnPluginStart()
{
LoadTranslations("onlyheadshot.phrases");
GetLanguageInfo(GetServerLanguage(), languagecode, sizeof(languagecode), language, sizeof(language));
CreateConVar("sm_onlyhs_version", VERSION, "Only Headshot", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY|FCVAR_DONTRECORD);
p_Cvarenabled = CreateConVar("sm_onlyhs_enable", "1", "Enable this plugin. 0 = Disabled.");
p_Cvarallowknife = CreateConVar("sm_onlyhs_knife", "1", "Enable Knifings. 0 = Disabled.");
p_Cvarallowhe = CreateConVar("sm_onlyhs_he", "1", "Enable HE Killing. 0 = Disabled.");
HookEvent("player_hurt", EventPlayerHurt, EventHookMode_Pre);
HookConVarChange(p_Cvarenabled, OnSettingChanged);
HookConVarChange(p_Cvarallowknife, OnSettingChanged);
HookConVarChange(p_Cvarallowhe, OnSettingChanged);
AutoExecConfig(true, "onlyhs");
g_iHealth = FindSendPropOffs("CCSPlayer", "m_iHealth");
if (g_iHealth == -1)
{
SetFailState("[Only Headshot] Error - Unable to get offset for CSSPlayer::m_iHealth");
}
g_Armor = FindSendPropOffs("CCSPlayer", "m_ArmorValue");
if (g_Armor == -1)
{
SetFailState("[Only Headshot] Error - Unable to get offset for CSSPlayer::m_ArmorValue");
}
}
public OnConfigsExecuted()
{
p_enabled = GetConVarBool(p_Cvarenabled);
p_allowknife = GetConVarBool(p_Cvarallowknife);
p_allowhe = GetConVarBool(p_Cvarallowhe);
}
public OnSettingChanged(Handle:convar, const String:oldValue[], const String:newValue[])
{
if (convar == p_Cvarenabled)
{
if (newValue[0] == '1')
{
p_enabled = true;
PrintToChatAll("%s \x07CCCCCC%t \x073EFF3E%t", teg, "Headshot", "enabled");
}
else
{
p_enabled = false;
PrintToChatAll("%s \x07CCCCCC%t \x07FF4040%t", teg, "Headshot", "disabled");
}
}
if (convar == p_Cvarallowknife)
{
if (newValue[0] == '1')
{
p_allowknife = true;
PrintToChatAll("%s \x07CCCCCC%t \x073EFF3E%t", teg, "Knifing", "enabled");
}
else
{
p_allowknife = false;
PrintToChatAll("%s \x07CCCCCC%t \x07FF4040%t", teg, "Knifing", "disabled");
}
}
if (convar == p_Cvarallowhe)
{
if (newValue[0] == '1')
{
p_allowhe = true;
PrintToChatAll("%s \x07CCCCCC%t \x073EFF3E%t", teg, "HE Killing", "enabled");
}
else
{
p_allowhe = false;
PrintToChatAll("%s \x07CCCCCC%t \x07FF4040%t", teg, "HE Killing", "disabled");
}
}
}
public OnClientPutInServer(client)
{
SDKHook(client, SDKHook_TraceAttack, OnTraceAttack);
}
public Action:OnTraceAttack(victim, &attacker, &inflictor, &Float:damage, &damagetype, &ammotype, hitbox, hitgroup)
{
if (p_enabled)
{
decl String:weapon[32];
decl String:grenade[32];
GetEdictClassname(inflictor, grenade, sizeof(grenade));
GetClientWeapon(attacker, weapon, sizeof(weapon));
if (hitgroup == 1)
{
return Plugin_Continue;
}
else if (p_allowknife && StrEqual(weapon, "weapon_knife"))
{
return Plugin_Continue;
}
else if (p_allowhe && StrEqual(grenade, "hegrenade_projectile"))
{
return Plugin_Continue;
}
else
{
return Plugin_Handled;
}
}
return Plugin_Continue;
}
public Action:EventPlayerHurt(Handle:event, const String:name[],bool:dontBroadcast)
{
if (p_enabled)
{
if (!p_allowhe)
{
new victim = GetClientOfUserId(GetEventInt(event, "userid"));
new attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
new dhealth = GetEventInt(event, "dmg_health");
new darmor = GetEventInt(event, "dmg_armor");
new health = GetEventInt(event, "health");
new armor = GetEventInt(event, "armor");
decl String:weapon[32];
GetEventString(event, "weapon", weapon, sizeof(weapon));
if(StrEqual(weapon, "hegrenade", false))
{
if (attacker != victim && victim != 0)
{
if (dhealth > 0)
{
SetEntData(victim, g_iHealth, (health + dhealth), 4, true);
}
if (darmor > 0)
{
SetEntData(victim, g_Armor, (armor + darmor), 4, true);
}
}
}
}
if (!p_allowknife)
{
new victim = GetClientOfUserId(GetEventInt(event, "userid"));
new attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
new dhealth = GetEventInt(event, "dmg_health");
new darmor = GetEventInt(event, "dmg_armor");
new health = GetEventInt(event, "health");
new armor = GetEventInt(event, "armor");
decl String:weapon[32];
GetEventString(event, "weapon", weapon, sizeof(weapon));
if(StrEqual(weapon, "weapon_knife", false))
{
if (attacker != victim && victim != 0)
{
if (dhealth > 0)
{
SetEntData(victim, g_iHealth, (health + dhealth), 4, true);
}
if (darmor > 0)
{
SetEntData(victim, g_Armor, (armor + darmor), 4, true);
}
}
}
}
}
return Plugin_Continue;
}