Skip to content

Commit

Permalink
Release 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dronelektron committed Sep 25, 2022
2 parents 2a56ed2 + 43bb222 commit f460fe5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,11 @@ Allows you to inflict damage to the allies

* Download latest [release](https://github.com/dronelektron/melee-friendly-fire/releases) (compiled for SourceMod 1.11)
* Extract "plugins" folder to "addons/sourcemod" folder of your server

### Console Variables

* sm_melee_friendly_fire - Enable (1) or disable (0) melee friendly fire [default: "1"]

### Notes

Enable ```mp_friendlyfire```, otherwise the plugin will not work
30 changes: 30 additions & 0 deletions scripting/melee-friendly-fire.sp
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>

#define WEAPON_SLOT_MELEE 2

public Plugin myinfo = {
name = "Melee friendly fire",
Expand All @@ -7,3 +11,29 @@ public Plugin myinfo = {
version = "0.1.0",
url = "https://github.com/dronelektron/melee-friendly-fire"
};

static ConVar g_pluginEnabled = null;

public void OnPluginStart() {
g_pluginEnabled = CreateConVar("sm_melee_friendly_fire", "1", "Enable (1) or disable (0) melee friendly fire");
}

public void OnClientPutInServer(int client) {
SDKHook(client, SDKHook_TraceAttackPost, Hook_TraceAttackPost);
}

public void Hook_TraceAttackPost(int victim, int attacker, int inflictor, float damage, int damageType, int ammoType, int hitbox, int hitGroup) {
if (IsMeleeAttack(damageType) && IsPluginEnalbed()) {
int weapon = GetPlayerWeaponSlot(attacker, WEAPON_SLOT_MELEE);

SDKHooks_TakeDamage(victim, inflictor, attacker, damage, damageType, weapon);
}
}

bool IsMeleeAttack(int damageType) {
return damageType & DMG_CLUB == DMG_CLUB;
}

bool IsPluginEnalbed() {
return g_pluginEnabled.IntValue == 1;
}

0 comments on commit f460fe5

Please sign in to comment.