View Single Post
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 07-29-2020 , 15:48   Re: [CS:GO] Molotov Friendly Fire
Reply With Quote #14

Try this:
PHP Code:

#include <sourcemod>
#include <sdkhooks>
#pragma newdecls required

public Plugin myinfo =
{
    
name "Molotov Friendly Fire",
    
author "Ilusion9",
    
description "Enable only molotov damage for teammates and block everything else.",
    
version "1.0",
    
url "https://github.com/Ilusion9/"
};

bool g_IsPluginLoadedLate;

public 
APLRes AskPluginLoad2(Handle myselfbool latechar[] errorint err_max)
{
    
g_IsPluginLoadedLate late;
}

public 
void OnPluginStart()
{
    if (
g_IsPluginLoadedLate)
    {
        for (
int i 1<= MaxClientsi++)
        {
            if (
IsClientInGame(i))
            {
                
OnClientPutInServer(i);
            }
        }
    }
}

public 
void OnClientPutInServer(int client)
{
    
SDKHook(clientSDKHook_OnTakeDamageSDK_OnTakeDamage);
    
SDKHook(clientSDKHook_TraceAttackSDK_OnTraceAttack);
}

public 
Action SDK_OnTakeDamage(int victimint &attackerint &inflictorfloat &damageint &damagetypeint &weaponfloat damageForce[3], float damagePosition[3])
{
    
// inflictor is not a grenade, world damage or enemy team
    
if (inflictor <= MaxClients || !IsValidClient(attacker) || GetClientTeam(attacker) != GetClientTeam(victim))
    {
        return 
Plugin_Continue;
    }
    
    
damage 0.0;
    
damagetype |= DMG_PREVENT_PHYSICS_FORCE;
    
    return 
Plugin_Changed;
}

public 
Action SDK_OnTraceAttack(int victimint &attackerint &inflictorfloat &damageint &damagetypeint &ammotypeint hitboxint hitgroup)
{
    
// world damage or enemy team
    
if (!IsValidClient(attacker) || GetClientTeam(attacker) != GetClientTeam(victim))
    {
        return 
Plugin_Continue;
    }
    
    return 
Plugin_Handled;
}

bool IsValidClient(int client)
{
    if (
client || client MaxClients || !IsClientInGame(client))
    {
        return 
false;
    }
    
    return 
true;

You can set the ff_ convars as you wish, but make sure the friendly fire is working
__________________

Last edited by Ilusion9; 07-29-2020 at 15:56.
Ilusion9 is offline