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

Solved [L4D & L4D2] No Friendly Fire Issue


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 10-07-2017 , 19:58   [L4D & L4D2] No Friendly Fire Issue
Reply With Quote #1

I need help with this:

PHP Code:
#pragma semicolon 1
#include <sourcemod>
#include <sdkhooks>
#define PLUGIN_VERSION "1.0"

public Plugin:myinfo =
{
    
name "[L4D & L4D2] No Friendly Fire",
    
author "Psykotik",
    
description "Disables friendly fire.",
    
version PLUGIN_VERSION,
    
url "www.sourcemod.net"
}

new 
Handle:pFF;
new 
Handle:pFFF;

public 
OnPluginStart()
{
    
CreateConVar("l4d_friendlyfire_version"PLUGIN_VERSION"Plugin version");
    
pFF CreateConVar("l4d_friendlyfire""0""Enable friendly fire? 0 = Off, 1 = On");
    
pFFF CreateConVar("l4d_friendlyfire_from_fire""0""Enable friendly fire from fire sources? 0 = Off, 1 = On");
    
AutoExecConfig(true"l4d_nofriendlyfire");
}

public 
OnClientPostAdminCheck(client)
{
    
SDKHook(clientSDKHook_OnTakeDamageOnTakeDamage);
}

public 
OnClientDisconnect(client)
{
    if (
client && IsClientInGame(client)) SDKUnhook(clientSDKHook_OnTakeDamageOnTakeDamage);
}

public 
Action:OnTakeDamage(victim, &attacker, &inflictor, &Float:damage, &damagetype)
{
    if (
victim && attacker && GetClientTeam(attacker) == && GetClientTeam(victim) == 2)
    {
        if (
GetConVarInt(pFF) == || GetConVarInt(pFFF) == && (damagetype == || damagetype == 2056 || damagetype == 268435464))
        {
            
damage 0.0;
            return 
Plugin_Changed;
        }
    }

    return 
Plugin_Continue;

It functions as intended but I get these errors in my logs whenever I throw a molotov on the ground around the survivor bots:
Spoiler



I don't know if I would get the same errors if I throw a molotov at other human players though.
__________________

Last edited by Psyk0tik; 10-22-2017 at 11:23. Reason: Removed attachment and marked thread as [Solved].
Psyk0tik is offline
xerox8521
Senior Member
Join Date: Sep 2011
Old 10-08-2017 , 04:40   Re: [L4D & L4D2] No Friendly Fire Issue
Reply With Quote #2

You need to check if the attacker is valid. You can use this function:

PHP Code:
stock bool IsValidClient(int client)
{
    return (
<= client <= MaxClients && IsClientInGame(client));

xerox8521 is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 10-08-2017 , 04:47   Re: [L4D & L4D2] No Friendly Fire Issue
Reply With Quote #3

Quote:
Originally Posted by xerox8521 View Post
You need to check if the attacker is valid. You can use this function:

PHP Code:
stock bool IsValidClient(int client)
{
    return (
<= client <= MaxClients && IsClientInGame(client));

Thank you.

And would I need to add anything else to the code? You said to check if the attacker is valid, so would I need to add something else besides the function you provided?

EDIT: I tried this but I still get errors.

PHP Code:
#pragma semicolon 1 
#include <sourcemod> 
#include <sdkhooks> 
#define PLUGIN_VERSION "1.0" 

public Plugin:myinfo 

    
name "[L4D & L4D2] No Friendly Fire"
    
author "Psykotik"
    
description "Disables friendly fire."
    
version PLUGIN_VERSION
    
url "www.sourcemod.net" 


new 
Handle:pFF
new 
Handle:pFFF

public 
OnPluginStart() 

    
CreateConVar("l4d_friendlyfire_version"PLUGIN_VERSION"Plugin version"); 
    
pFF CreateConVar("l4d_friendlyfire""0""Enable friendly fire? 0 = Off, 1 = On"); 
    
pFFF CreateConVar("l4d_friendlyfire_from_fire""0""Enable friendly fire from fire sources? 0 = Off, 1 = On"); 
    
AutoExecConfig(true"l4d_nofriendlyfire"); 


public 
OnClientPostAdminCheck(client

    
SDKHook(clientSDKHook_OnTakeDamageOnTakeDamage); 


public 
OnClientDisconnect(client

    if (
client && IsClientInGame(client)) SDKUnhook(clientSDKHook_OnTakeDamageOnTakeDamage); 


stock bool IsValidClient(int client

    return (
<= client <= MaxClients && IsClientInGame(client)); 
}

public 
Action:OnTakeDamage(victim, &attacker, &inflictor, &Float:damage, &damagetype

    if (
IsValidClient(attacker) && IsValidClient(victim) && victim && attacker && GetClientTeam(attacker) == && GetClientTeam(victim) == 2
    { 
        if (
GetConVarInt(pFF) == || GetConVarInt(pFFF) == && (damagetype == || damagetype == 2056 || damagetype == 268435464)) 
        { 
            
damage 0.0
            return 
Plugin_Changed
        } 
    } 

    return 
Plugin_Continue

__________________

Last edited by Psyk0tik; 10-22-2017 at 11:23.
Psyk0tik is offline
cravenge
Veteran Member
Join Date: Nov 2015
Location: Chocolate Factory
Old 10-08-2017 , 08:14   Re: [L4D & L4D2] No Friendly Fire Issue
Reply With Quote #4

Edit: Fixed the lines producing the compilation errors.
PHP Code:
#pragma semicolon 1 
#include <sourcemod> 
#include <sdkhooks> 

#define PLUGIN_VERSION "1.0" 

public Plugin myinfo 

    
name "[L4D & L4D2] No Friendly Fire"
    
author "Psykotik"
    
description "Disables friendly fire."
    
version PLUGIN_VERSION
    
url "www.sourcemod.net" 
};

ConVar pFFpFFF;

public 
void OnPluginStart()
{
    
CreateConVar("l4d_friendlyfire_version"PLUGIN_VERSION"Version of the plugin.");
    
pFF CreateConVar("l4d_friendlyfire""0""Friendly Fire status: 0 = Disabled, 1 = Enabled");
    
pFFF CreateConVar("l4d_friendlyfire_from_fire""0""Friendly Fire status from fire sources: 0 = Disabled, 1 = Enabled");
    
    
AutoExecConfig(true"l4d_nofriendlyfire");
}

public 
void OnClientPostAdminCheck(int client

    
SDKHook(clientSDKHook_OnTakeDamageOnTakeDamage); 


public 
void OnClientDisconnect(int client

    
SDKUnhook(clientSDKHook_OnTakeDamageOnTakeDamage); 
}

public 
Action OnTakeDamage(int victimint &attackerint &inflictorfloat &damageint &damagetypeint &weaponfloat damageForce[3], float damagePosition[3]) 

    if (!
IsSurvivor(victim) || !IsSurvivor(attacker))
    {
        return 
Plugin_Continue;
    }
    
    if (!
pFF.BoolValue || (!pFFF.BoolValue && (damagetype == || damagetype == 2056 || damagetype == 268435464)))
    {
        
damage 0.0;
        return 
Plugin_Changed;
    }
    
    return 
Plugin_Continue;
}

stock bool IsSurvivor(int client)
{
    return (
client && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 2);


Last edited by cravenge; 10-08-2017 at 09:29.
cravenge is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 10-08-2017 , 08:51   Re: [L4D & L4D2] No Friendly Fire Issue
Reply With Quote #5

Quote:
Originally Posted by cravenge View Post
Okay, I've fixed it and applied the new syntax.
PHP Code:
#pragma semicolon 1 
#include <sourcemod> 
#include <sdkhooks> 

#define PLUGIN_VERSION "1.0" 

public Plugin myinfo 

    
name "[L4D & L4D2] No Friendly Fire"
    
author "Psykotik"
    
description "Disables friendly fire."
    
version PLUGIN_VERSION
    
url "www.sourcemod.net" 
};

ConVar pFFpFFF;

public 
void OnPluginStart()
{
    
CreateConVar("l4d_friendlyfire_version"PLUGIN_VERSION"Version of the plugin.");
    
pFF CreateConVar("l4d_friendlyfire""0""Friendly Fire status: 0 = Disabled, 1 = Enabled");
    
pFFF CreateConVar("l4d_friendlyfire_from_fire""0""Friendly Fire status from fire sources: 0 = Disabled, 1 = Enabled");
    
    
AutoExecConfig(true"l4d_nofriendlyfire");
}

public 
void OnClientPostAdminCheck(int client

    
SDKHook(clientSDKHook_OnTakeDamageOnTakeDamage); 


public 
void OnClientDisconnect(int client

    
SDKUnhook(clientSDKHook_OnTakeDamageOnTakeDamage); 
}

public 
Action OnTakeDamage(int victimint &attackerint &inflictorfloat &damageint &damagetypefloat damageForce[3], float damagePosition[3]) 

    if (!
IsSurvivor(victim) || !IsSurvivor(attacker))
    {
        return 
Plugin_Continue;
    }
    
    if (!
pFF.BoolValue || (!pFFF.BoolValue && (damagetype == || damagetype == 2056 || damagetype == 268435464)))
    {
        
damage 0.0;
        return 
Plugin_Changed;
    }
    
    return 
Plugin_Continue;
}

stock bool IsSurvivor(int client)
{
    return (
client && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 2);

I tried your fix and now it's failing to compile. The compiler is saying that there's an "error 100: function prototypes do not match" on lines 29 and 34.
__________________

Last edited by Psyk0tik; 10-22-2017 at 11:23.
Psyk0tik is offline
cravenge
Veteran Member
Join Date: Nov 2015
Location: Chocolate Factory
Old 10-08-2017 , 09:30   Re: [L4D & L4D2] No Friendly Fire Issue
Reply With Quote #6

No worries, check my post again. I've changed it.
cravenge is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 10-08-2017 , 10:05   Re: [L4D & L4D2] No Friendly Fire Issue
Reply With Quote #7

Quote:
Originally Posted by cravenge View Post
No worries, check my post again. I've changed it.
Thank you so much cravenge! No more errors whatsoever!

+
__________________

Last edited by Psyk0tik; 10-22-2017 at 11:23.
Psyk0tik 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 05:38.


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