Raised This Month: $51 Target: $400
 12% 

Inflict damage to teammates without turning on global friendly fire


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ImACow
AlliedModders Donor
Join Date: Feb 2015
Old 08-19-2018 , 06:13   Inflict damage to teammates without turning on global friendly fire
Reply With Quote #1

Hi

I'm looking if there is a way to allow teammates to damage each other without flipping the friendly fire convars to 1


PHP Code:
mp_teammates_are_enemies 0
mp_friendlyfire 0 

I do see the damage appear in the OnTakeDamage hook, but no damage is applied.
Even when I call SDKHooks_TakeDamage on the player, 0 damage is applied.

PHP Code:

SDKHook
(clientSDKHook_OnTakeDamageOnTakeDamage);

public 
Action OnTakeDamage(int victimint &attackerint &inflictorfloat &damageint &damagetypeint &weaponfloat damageForce[3], float damagePosition[3], int damagecustom)
{
    
PrintToChat(victim"OnTakeDamage > %N attacked %N for %f damage"attackervictimdamage);
    
SDKHooks_TakeDamage(victimvictimvictimdamagedamagetypeweapondamageForcedamagePosition);

PHP Code:
OnTakeDamage ImACow attacked Brian for 39.999996 damage 

Anyone any experience with achieving something similar?

With regards,
Cow
__________________

Last edited by ImACow; 08-19-2018 at 06:32.
ImACow is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 08-19-2018 , 06:19   Re: Inflict damage to teammates without turning on global friendly fire
Reply With Quote #2

because float &damage is 0?

and don't call SDKHooks_TakeDamage in that function when you can modify float &damage.
Ilusion9 is offline
ImACow
AlliedModders Donor
Join Date: Feb 2015
Old 08-19-2018 , 06:31   Re: Inflict damage to teammates without turning on global friendly fire
Reply With Quote #3

I do see the damage, however non is applied
PHP Code:
OnTakeDamage ImACow attacked Brian for 39.999996 damage 
__________________
ImACow is offline
mug1wara
AlliedModders Donor
Join Date: Jun 2018
Old 08-19-2018 , 07:41   Re: Inflict damage to teammates without turning on global friendly fire
Reply With Quote #4

Hook weapon_fire (I doubt this will even work)
PHP Code:
#include <sourcemod>
#include <sdktools>

#pragma semicolon 1

public void OnPluginStart()
{
    
HookEvent("weapon_fire"Event_Fire);
}

public 
Action Event_Fire(Event hEvent, const char[] sNamebool bDontBroadcast)
{
    
int iClient hEvent.GetInt("userid");
    
    if (
IsValidClient(iClient))
    {
        
float fStart[3], fAngle[3];
        
        
GetClientEyePosition(iClientfStart);
        
GetClientEyeAngles(iClientfAngle);
        
        
Handle hTrace TR_TraceRayFilterEx(fStartfAngleMASK_SHOTRayType_InfiniteTR_FilterPlayer);
        
        if (
TR_DidHit(hTrace))
        {
            for (
int i 1<= MaxClientsi++)
            {
                if (
GetClientTeam(iClient) == GetClientTeam(i))
                {
                    
/* do stuff here */
                
}
            }
        }
        
        
CloseHandle(hTrace);
    }
}

public 
bool IsValidClient(int iClient)
{
    if (
iClient <= MaxClients && IsClientConnected(iClient) && IsClientInGame(iClient) && !IsFakeClient(iClient))
        return 
true;
    
    return 
false;
}

public 
bool TR_FilterPlayer(int iEntityint iMaskint iData
{
    return 
iEntity MaxClients;

mug1wara is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 08-19-2018 , 09:08   Re: Inflict damage to teammates without turning on global friendly fire
Reply With Quote #5

Quote:
Originally Posted by ImACow View Post
I do see the damage, however non is applied
PHP Code:
OnTakeDamage ImACow attacked Brian for 39.999996 damage 
the try to change the damagetype, the attacker and the inflictor
Ilusion9 is offline
MasterMind420
BANNED
Join Date: Nov 2010
Old 08-19-2018 , 13:38   Re: Inflict damage to teammates without turning on global friendly fire
Reply With Quote #6

Try using this instead...

Code:
SDKHook(client, SDKHook_OnTakeDamageAlive, OnTakeDamage);

public Action OnTakeDamage(int victim, int &attacker, int &inflictor, float &damage, int &damagetype, int &weapon, float damageForce[3], float damagePosition[3], int damagecustom)
{
    PrintToChat(victim, "OnTakeDamage > %N attacked %N for %f damage", attacker, victim, damage);
    SDKHooks_TakeDamage(victim, victim, victim, damage, damagetype, weapon, damageForce, damagePosition);
}
if that doesn't work try this...

Code:
SDKHook(client, SDKHook_OnTakeDamageAlive, OnTakeDamage);

public Action OnTakeDamage(int victim, int &attacker, int &inflictor, float &damage, int &damagetype, int &weapon, float damageForce[3], float damagePosition[3], int damagecustom)
{
    damage = 1.0;
    return Plugin_Changed;
}
or this...

Code:
SDKHook(client, SDKHook_OnTakeDamageAlive, OnTakeDamage);

public Action OnTakeDamage(int victim, int &attacker, int &inflictor, float &damage, int &damagetype, int &weapon, float damageForce[3], float damagePosition[3], int damagecustom)
{
    SDKHooks_TakeDamage(victim, victim, victim, damage, damagetype, weapon, damageForce, damagePosition);
    return Plugin_Changed;
}
I find OnTakeDamageAlive to be more reliable when applying damage.
MasterMind420 is offline
ImACow
AlliedModders Donor
Join Date: Feb 2015
Old 08-19-2018 , 18:10   Re: Inflict damage to teammates without turning on global friendly fire
Reply With Quote #7

SDKHooks_TakeDamage(victim, victim, victim) does indeed inflict damage.

But the killfeed is showing suicides, so now I'm going to see if I can change those messages
__________________
ImACow is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 08-19-2018 , 19:16   Re: Inflict damage to teammates without turning on global friendly fire
Reply With Quote #8

You might find code for the below useful.

https://forums.alliedmods.net/showthread.php?t=237011

Configuration

Configuration - Reverse killshot damage to attacker

Configuration - Disable all damage including fall damage (skill servers)

Configuration - Mirror damage back to attacker
__________________
Neuro Toxin is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 20:09.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode