PHP Code:
#pragma semicolon 1
#include <sourcemod>
#include <sdkhooks>
#define PLUGIN_VERSION "1.0"
ConVar cv_Enabled;
bool bEnabled;
public Plugin myinfo =
{
name = "Disable Weapon Damage",
author = "Sgt. Gremulock",
description = "Look at the title.",
version = PLUGIN_VERSION,
url = "sourcemod.net"
};
public void OnPluginStart()
{
CreateConVar("sm_nowepdamage_version", PLUGIN_VERSION, "Plugin's version.", FCVAR_REPLICATED|FCVAR_NOTIFY);
cv_Enabled = CreateConVar("sm_nowepdamage_enabled", "1", "Enable/disable the plugin.", _, true, 0.0, true, 1.0);
bEnabled = cv_Enabled.BoolValue;
HookConVarChange(cv_Enabled, CvarUpdate);
AutoExecConfig(true);
}
public void CvarUpdate(ConVar cvar, const char[] oldValue, const char[] newValue)
{
bEnabled = cv_Enabled.BoolValue;
}
public void OnClientPostAdminCheck(int client)
{
if (bEnabled)
{
SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage);
}
}
public Action OnTakeDamage(int victim, int &attacker, int &inflictor, float &damage, int &damagetype)
{
if (bEnabled)
{
if (IsValidClient(victim) && IsValidClient(attacker))
{
char name[MAX_NAME_LENGTH];
new weapon = GetEntProp(attacker, Prop_Send, "m_hActiveWeapon");
GetEntityClassname(weapon, name, sizeof(name));
if (StrContains(name, "weapon"))
{
damage = 0.0;
return Plugin_Changed;
}
}
}
return Plugin_Continue;
}
bool IsValidClient(int client, bool nobots = true)
{
if (client <= 0 || client > MaxClients || !IsClientConnected(client) || (nobots && IsFakeClient(client)))
{
return false;
}
return IsClientInGame(client);
}