sm-plugins/crithit_system.sp

135 lines
3.2 KiB
SourcePawn

/* Plugin Template generated by Pawn Studio */
#include <sourcemod>
#include <sdktools_functions>
new Handle:crit_e, Handle:crit_ao, Handle:crit_cc, Handle:crit_m;
new bool:crit_e_bool, bool:crit_ao_bool, Float:crit_cc_float, crit_m_int;
public Plugin:myinfo =
{
name = "CritHit System",
author = "Chefe",
description = "Allows to modify the Crit-Calculation.",
version = "1.1",
url = "www.sourcemod.net"
}
public OnPluginStart()
{
crit_e = CreateConVar("sm_crit_enabled", "1", "Enable or Disable the Plugin.");
HookConVarChange(crit_e, OnCritEnabledChange);
crit_ao = CreateConVar("sm_crit_only_admins", "1", "Enable or Disable only for Admins.");
HookConVarChange(crit_ao, OnCritAOChange);
crit_cc = CreateConVar("sm_crit_chance", "0.50", "Set the Critchance in Mode 1.", _, true, 0.0, true, 1.0);
HookConVarChange(crit_cc, OnCritCCChange);
crit_m = CreateConVar("sm_crit_mode", "2", "Set the crit Mode ( 1 = chance set in sm_crit_chance | 2 = crit only | 3 = Aim mode)");
HookConVarChange(crit_m, OnCritMChange);
CreateConVar("sm_crit_version", "1.1", "Version of the Critplugin", FCVAR_NOTIFY);
crit_e_bool = GetConVarBool(crit_e)
crit_ao_bool = GetConVarBool(crit_ao)
crit_cc_float = GetConVarFloat(crit_cc)
crit_m_int = GetConVarInt(crit_m)
AutoExecConfig(true);
}
public OnCritEnabledChange(Handle:cvar, const String:oldVal[], const String:newVal[])
{
crit_e_bool = !!StringToInt(newVal);
}
public OnCritAOChange(Handle:cvar, const String:oldVal[], const String:newVal[])
{
crit_ao_bool = !!StringToInt(newVal);
}
public OnCritCCChange(Handle:cvar, const String:oldVal[], const String:newVal[])
{
crit_cc_float = StringToFloat(newVal);
}
public OnCritMChange(Handle:cvar, const String:oldVal[], const String:newVal[])
{
crit_m_int = StringToInt(newVal);
}
public Action:TF2_CalcIsAttackCritical(client, weapon, String:weaponname[], &bool:result)
{
new AdminId:admin_id = GetUserAdmin(client);
new client_aim = GetClientAimTarget(client, true);
if (crit_e_bool)
{
if (crit_m_int == 1)
{
if (!crit_ao_bool && IsClientInGame(client))
{
if (crit_cc_float > GetRandomFloat(0.0, 1.0))
{
result = true;
return Plugin_Handled;
}
}
else if (crit_ao_bool && IsClientInGame(client) && admin_id != INVALID_ADMIN_ID)
{
if (crit_cc_float > GetRandomFloat(0.0, 1.0))
{
result = true;
return Plugin_Handled;
}
}
}
else if (crit_m_int == 2)
{
if (!crit_ao_bool && IsClientInGame(client))
{
result = true;
return Plugin_Handled;
}
else if (crit_ao_bool && IsClientInGame(client) && admin_id != INVALID_ADMIN_ID)
{
result = true;
return Plugin_Handled;
}
}
else if (crit_m_int == 3)
{
if (crit_ao_bool && admin_id != INVALID_ADMIN_ID && IsClientInGame(client))
{
if (client_aim != -1)
{
result = true;
return Plugin_Handled;
}
else if (client_aim == -1)
{
result = false;
return Plugin_Handled;
}
}
else if (!crit_ao_bool && IsClientInGame(client))
{
if (client_aim != -1)
{
result = true;
return Plugin_Handled;
}
else if (client_aim == -1)
{
result = false;
return Plugin_Handled;
}
}
}
}
else
{
return Plugin_Continue;
}
return Plugin_Continue;
}