Raised This Month: $ Target: $400
 0% 

Cleanup l4d2 plugin


Post New Thread Reply   
 
Thread Tools Display Modes
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
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 01-03-2023 , 17:25   Re: Cleanup l4d2 plugin
Reply With Quote #2

Remove the plugin and test if it crashes without it, this is the first trial you should do.

Also, this "Unkook" stuff isn't necessary cause SM already does that for you on client disconnect and plugin end.

Probably someone else will ask for you to install Accelerator crash dump (if you don't have it) and share the dump.
__________________

Last edited by Marttt; 01-03-2023 at 17:29.
Marttt is offline
Grey83
Veteran Member
Join Date: Dec 2014
Location: Ukraine
Old 01-06-2023 , 12:48   Re: Cleanup l4d2 plugin
Reply With Quote #3

Quote:
Originally Posted by wendigo View Post
Could anybody help me clean or see if any changes are needed?
PHP Code:
#pragma semicolon 1
#pragma newdecls required

#include <sdkhooks>

bool
    bSmoked
[MAXPLAYERS+1];
char
    sBuffer
[44];

public 
void OnPluginStart()
{
    
HookEvent("round_start"OnRoundStart);

    
HookEvent("tongue_grab"OnTongueAction);
    
HookEvent("tongue_release"OnTongueAction);

    for(
int i 1<= MaxClientsi++) if(IsClientInGame(i)) SDKHook(iSDKHook_OnTakeDamageOnTakeDamage);
}

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

public 
void OnRoundStart(Event event, const char[] namebool dontBroadcast)
{
    
OnMapStart();
}

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

public 
void OnClientDisconnect(int client)
{
    
bSmoked[client] = false;
}

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

    
SDKHooks_TakeDamage(attackerinflictorattackerdamagedamagetypeweapondamageForcedamagePosition);

    
damage 0.0;
    return 
Plugin_Changed;
}

public 
void OnTongueAction(Event event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(event.GetInt("victim"));
    if(
IsSurvivor(client)) bSmoked[client] = name[7] == 'g';
}

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

bool IsGettingUp(int client)
{
    
GetEntPropString(clientProp_Data"m_ModelName"sBuffersizeof(sBuffer));
    if(
strncmp(sBuffer"models/survivors/survivor_"26false))
        return 
false;

    
int iSequence GetEntProp(clientProp_Send"m_nSequence");

    if(!
strcmp(sBuffer[26], "gambler.mdl"false))
        return 
iSequence == 620 || iSequence == 629 || iSequence == 667 || iSequence == 671 || iSequence == 672;
    else if(!
strcmp(sBuffer[26], "producer.mdl"false) || !strcmp(sBuffer[26], "adawong.mdl"false))
        return 
iSequence == 629 || iSequence == 637 || iSequence == 674 || iSequence == 678 || iSequence == 679;
    else if(!
strcmp(sBuffer[26], "coach.mdl"false))
        return 
iSequence == 621 || iSequence == 629 || iSequence == 656 || iSequence == 660 || iSequence == 661;
    else if(!
strcmp(sBuffer[26], "mechanic.mdl"false))
        return 
iSequence == 625 || iSequence == 634 || iSequence == 671 || iSequence == 675 || iSequence == 676;
    else if(!
strcmp(sBuffer[26], "manager.mdl"false) || !strcmp(sBuffer[26], "namvet.mdl"false))
        return 
iSequence == 528 || iSequence == 537 || iSequence == 759 || iSequence == 763 || iSequence == 764;
    else if(!
strcmp(sBuffer[26], "teenangst.mdl"false))
        return 
iSequence == 537 || iSequence == 546 || iSequence == 819 || iSequence == 823 || iSequence == 824;
    else if(!
strcmp(sBuffer[26], "biker.mdl"false))
        return 
iSequence == 531 || iSequence == 540 || iSequence == 762 || iSequence == 766 || iSequence == 767;

    return 
false;
}

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

stock bool IsPhysicsProp(int entity)
{
    return 
MaxClients entity && IsValidEntity(entity) && IsValidEdict(entity)
        && 
GetEdictClassname(entitysBuffersizeof(sBuffer)) && !strcmp(sBuffer"prop_physics");
}

stock bool IsGrenade(int entity)
{
    return 
MaxClients entity && IsValidEntity(entity) && IsValidEdict(entity)
        && 
GetEdictClassname(entitysBuffersizeof(sBuffer))
        && (!
strcmp(sBuffer"inferno") || !strcmp(sBuffer"pipe_bomb_projectile"));

__________________
Grey83 is offline
wendigo
Senior Member
Join Date: Nov 2012
Location: Denmark
Old 01-08-2023 , 12:51   Re: Cleanup l4d2 plugin
Reply With Quote #4

Thanks, I dont know what has been changed or added. But I will upload and test it
wendigo is offline
wendigo
Senior Member
Join Date: Nov 2012
Location: Denmark
Old 01-09-2023 , 08:42   Re: Cleanup l4d2 plugin
Reply With Quote #5

Unfortunately my server still crashes. As soon I remove plugin, it doesn't crash anymore.

Is it possible to make a more simple version of this plugin here?
Like it only works for admin, and nobody else?
wendigo is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 01-09-2023 , 08:54   Re: Cleanup l4d2 plugin
Reply With Quote #6

what could crash is a bad parameter in SDKHooks_TakeDamage, I would comment this line and try the plugin without it for a while, if no crashes probably is there.

saying this because already had crash issues with TakeDamage sdkhooks functions.

Also check if you have dissolve infected plugin installed.
__________________
Marttt is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 01-09-2023 , 10:08   Re: Cleanup l4d2 plugin
Reply With Quote #7

You could try replacing "SDKHook_OnTakeDamage" with "SDKHook_OnTakeDamageAlive" I found sometimes the former crashed while the latter worked better.
__________________
Silvers is offline
wendigo
Senior Member
Join Date: Nov 2012
Location: Denmark
Old 01-09-2023 , 11:09   Re: Cleanup l4d2 plugin
Reply With Quote #8

I really appreciate info and feedback guys.

I have below average when it comes to plugins. And you both pinpoint to SDKHook_OnTakeDamage could be the cursed one.

I will take Grey83's updated code, remove SDKHook_OnTakeDamage and paste it with add SDKHook_OnTakeDamageAlive.

Last edited by wendigo; 01-09-2023 at 11:10.
wendigo 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 04:53.


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