Skip to content

Commit

Permalink
Add cvar + proper readme
Browse files Browse the repository at this point in the history
  • Loading branch information
kir68k committed Dec 17, 2023
1 parent c01e78e commit c90f900
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
plugins/
plugins/headshots.smx
15 changes: 15 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ISC License

Copyright (c) 2023, Kirixetamine <revelation@krxt.dev>

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
### No ConVars and Commands
# Description
This plugin allows for critical hits whenever you hit the head hitbox of an enemy.

# Which weapons work?
All hitscan weapons. Projectiles DO NOT work due to how `SDKHooks_TraceAttack` works.

# ConVars
- `tf_critheadshots_enable`
- To enable set to 1, to disable set to 0 or any other value.

# You forked a repo just for a ConVar?
Not explicitly. If I figure out how to get minicrits to work, I will implement that as well with a cvar to switch between normal and minicrits.
Binary file removed plugins/headshots.smx
Binary file not shown.
46 changes: 27 additions & 19 deletions scripting/headshots.sp
Original file line number Diff line number Diff line change
@@ -1,39 +1,47 @@
#include <sdkhooks>

bool
g_bHeadshot[MAXPLAYERS+1] = false;
g_bHeadshot[MAXPLAYERS + 1];
public Plugin myinfo =
{
name = "Titan.TF - Headshots",
author = "myst",
version = "1.0",
url = "https://titan.tf"
name = "Titan.TF - Headshots",
author = "myst",
version = "1.0",
url = "https://titan.tf"
}

ConVar g_ConVarEnableCritHeadshots;

public void OnPluginStart() {
g_ConVarEnableCritHeadshots = CreateConVar("tf_critheadshots_enable", "1", "Enables or disable crit headshots.\n 1 = Enable\n 0 = Disable")
}

public void OnPluginEnd()
{
for (int iClient = 1; iClient <= MaxClients; iClient++)
{
if (IsClientInGame(iClient))
g_bHeadshot[iClient] = false;
}
for (int iClient = 1; iClient <= MaxClients; iClient++)
{
if (IsClientInGame(iClient))
g_bHeadshot[iClient] = false;
}
}

public void OnClientPutInServer(int iClient) {
SDKHook(iClient, SDKHook_TraceAttack, TraceAttack);
if (g_ConVarEnableCritHeadshots.IntValue == 1) {
SDKHook(iClient, SDKHook_TraceAttack, TraceAttack);
}
}

public void OnClientDisconnect(int iClient) {
g_bHeadshot[iClient] = false;
g_bHeadshot[iClient] = false;
}

public Action TraceAttack(int iVictim, int &iAttacker, int &iInflictor, float &flDamage, int &iDamageType, int &iAmmoType, int iHitBox, int iHitgroup)
{
if (iHitgroup == 1)
{
iDamageType |= DMG_CRIT;
return Plugin_Changed;
public Action TraceAttack(int iVictim, int &iAttacker, int &iInflictor, float &flDamage, int &iDamageType, int &iAmmoType, int iHitBox, int iHitgroup) {
if (g_ConVarEnableCritHeadshots.IntValue == 1) {
if (iHitgroup == 1) {
iDamageType |= DMG_CRIT;
return Plugin_Changed;
}
}

return Plugin_Continue;
Expand Down

0 comments on commit c90f900

Please sign in to comment.