View Single Post
Author Message
wendigo
Senior Member
Join Date: Nov 2012
Location: Denmark
Old 01-03-2023 , 15:49   Cleanup l4d2 plugin
Reply With Quote #1

My l4d2 server randomly crashes. And I suspect it might have something to do with this plugin someone was kind enough to make for me o nthe fly, a very very long time ago. Untested by anybody except only uploaded on my server.
The plugin reflects any teamdamage, back to the shooter. But not for admin. For admin, he can teamkill anybody.
Could anybody help me clean or see if any changes are needed?
This is the plugin that was made.

PHP Code:
#pragma semicolon 1
#include <sourcemod>
#include <sdkhooks>

bool bSmoked[MAXPLAYERS+1];

public 
void OnPluginStart()
{
    
HookEvent("round_start"OnRoundStart);
    
    
HookEvent("tongue_grab"OnTongueGrab);
    
HookEvent("tongue_release"OnTongueRelease);
}

public 
void OnPluginEnd()
{
    
UnhookEvent("round_start"OnRoundStart);
    
    
UnhookEvent("tongue_grab"OnTongueGrab);
    
UnhookEvent("tongue_release"OnTongueRelease);
    
    for (
int i 1<= MaxClientsi++)
    {
        if (
IsClientInGame(i))
        {
            
SDKUnhook(iSDKHook_OnTakeDamageOnTakeDamage);
        }
    }
}

public 
void OnClientPutInServer(int client)
{
    
SDKHook(clientSDKHook_OnTakeDamageOnTakeDamage);
}

public 
Action OnTakeDamage(int victimint &attackerint &inflictorfloat &damageint &damagetypeint &weaponfloat damageForce[3], float damagePosition[3])
{
    if (!
IsSurvivor(victim) || IsDominated(victim) || IsGettingUp(victim) || !IsSurvivor(attacker) || !IsPlayerAlive(attacker) || attacker == victim)
    {
        return 
Plugin_Continue;
    }
    
    if (
CheckCommandAccess(attacker"sm_admin"ADMFLAG_GENERIC) || IsPhysicsProp(inflictor) || IsGrenade(inflictor))
    {
        return 
Plugin_Continue;
    }
    
    
SDKHooks_TakeDamage(attackerinflictorattackerdamagedamagetypeweapondamageForcedamagePosition);
    
    
damage 0.0;
    return 
Plugin_Changed;
}

public 
void OnClientDisconnect(int client)
{
    
SDKUnhook(clientSDKHook_OnTakeDamageOnTakeDamage);
}

public 
void OnMapStart()
{
    for (
int i 1<= MaxClientsi++)
    {
        if (
IsClientInGame(i))
        {
            
bSmoked[i] = false;
        }
    }
}

public 
void OnRoundStart(Event event, const char[] namebool dontBroadcast)
{
    for (
int i 1<= MaxClientsi++)
    {
        if (
IsClientInGame(i))
        {
            
bSmoked[i] = false;
        }
    }
}

public 
void OnTongueGrab(Event event, const char[] namebool dontBroadcast)
{
    
int grabbed GetClientOfUserId(event.GetInt("victim"));
    if (!
IsSurvivor(grabbed) || bSmoked[grabbed])
    {
        return;
    }
    
    
bSmoked[grabbed] = true;
}

public 
void OnTongueRelease(Event event, const char[] namebool dontBroadcast)
{
    
int released GetClientOfUserId(event.GetInt("victim"));
    if (!
IsSurvivor(released) || !bSmoked[released])
    {
        return;
    }
    
    
bSmoked[released] = false;
}

bool IsDominated(int client)
{
    return (
GetEntProp(clientProp_Send"m_isIncapacitated"1) || bSmoked[client] || GetEntPropEnt(clientProp_Send"m_pounceAttacker") > || 
        
GetEntPropEnt(clientProp_Send"m_jockeyAttacker") > || GetEntPropEnt(clientProp_Send"m_carryAttacker") > || GetEntPropEnt(clientProp_Send"m_pummelAttacker") > 0);
}

bool IsGettingUp(int client)
{
    
int iSequence GetEntProp(clientProp_Send"m_nSequence");
    
    
char sModel[128];
    
GetEntPropString(clientProp_Data"m_ModelName"sModelsizeof(sModel));
    if (
StrEqual(sModel"models/survivors/survivor_gambler.mdl"false))
    {
        if (
iSequence == 620 || iSequence == 629 || iSequence == 667 || iSequence == 671 || iSequence == 672)
        {
            return 
true;
        }
    }
    else if (
StrEqual(sModel"models/survivors/survivor_producer"false) || StrEqual(sModel"models/survivors/survivor_adawong.mdl"false))
    {
        if (
iSequence == 629 || iSequence == 637 || iSequence == 674 || iSequence == 678 || iSequence == 679)
        {
            return 
true;
        }
    }
    else if (
StrEqual(sModel"models/survivors/survivor_coach.mdl"false))
    {
        if (
iSequence == 621 || iSequence == 629 || iSequence == 656 || iSequence == 660 || iSequence == 661)
        {
            return 
true;
        }
    }
    else if (
StrEqual(sModel"models/survivors/survivor_mechanic.mdl"false))
    {
        if (
iSequence == 625 || iSequence == 634 || iSequence == 671 || iSequence == 675 || iSequence == 676)
        {
            return 
true;
        }
    }
    else if (
StrEqual(sModel"models/survivors/survivor_namvet.mdl"false) || StrEqual(sModel"models/survivors/survivor_manager.mdl"false))
    {
        if (
iSequence == 528 || iSequence == 537 || iSequence == 759 || iSequence == 763 || iSequence == 764)
        {
            return 
true;
        }
    }
    else if (
StrEqual(sModel"models/survivors/survivor_teenangst.mdl"false))
    {
        if (
iSequence == 537 || iSequence == 546 || iSequence == 819 || iSequence == 823 || iSequence == 824)
        {
            return 
true;
        }
    }
    else if (
StrEqual(sModel"models/survivors/survivor_biker.mdl"false))
    {
        if (
iSequence == 531 || iSequence == 540 || iSequence == 762 || iSequence == 766 || iSequence == 767)
        {
            return 
true;
        }
    }
    
    return 
false;
}

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

stock bool IsPhysicsProp(int entity)
{
    if (
entity && IsValidEntity(entity) && IsValidEdict(entity))
    {
        
char sEntityClass[64];
        
GetEdictClassname(entitysEntityClasssizeof(sEntityClass));
        return 
StrEqual(sEntityClass"prop_physics");
    }
    
    return 
false;
}

stock bool IsGrenade(int entity)
{
    if (
entity && IsValidEntity(entity) && IsValidEdict(entity))
    {
        
char sEntityClass[64];
        
GetEdictClassname(entitysEntityClasssizeof(sEntityClass));
        return (
StrEqual(sEntityClass"inferno") || StrEqual(sEntityClass"pipe_bomb_projectile"));
    }
    
    return 
false;


Last edited by wendigo; 01-03-2023 at 15:49.
wendigo is offline