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

L4D/2 SDK call crashes the server sometimes... [SOLVED]


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Visual77
Veteran Member
Join Date: Jan 2009
Old 06-17-2011 , 08:24   L4D/2 SDK call crashes the server sometimes... [SOLVED]
Reply With Quote #1

In L4D1/2 you need to use SDK call as ChangeClientTeam(client, 2) dosn't put you in control of a survivor bot. FakeClientCommand(client, "jointeam 2" is another attempt that works but the problem with this command is that it won't let you take over a survivor bot if the survivor is dead or incapaciated.

I've been using this code and recently found out that it crashes the server sometimes. The only weird part here is that it sometimes works without crashing the server. I tried this all alone on one of my servers sp I know the issue is related to this team-switching code.

My question now, how can I make this code different and get it working without server crashes? If there are alive survivor bots available, I want the client to take over those, and if there are no alive bots, I want the survivor to take over one of the dead ones.

#define L4D_MAXCLIENTS_PLUS1 (MaxClients+1)
#define L4D_TEAM_SURVIVORS 2
PHP Code:
if (team == 2)
{
    new 
Bot GetAliveSurvivors();
    if(
GetAliveSurvivors() > 0)
    {
            
ChangeClientTeam(target1); 
            
SDKCall(fSHSBottarget); 
            
SDKCall(fTOBtargettrue); 
    }
    else
    {
            new 
dBot GetDeadSurvivors();
            if (
GetDeadSurvivors() > 0)
            {
                    
ChangeClientTeam(target1); 
                    
SDKCall(fSHSdBottarget); 
                    
SDKCall(fTOBtargettrue); 
            }
    }
}

stock GetAliveSurvivors()
{
    new 
alive 0;

    new 
i;
    for(
1L4D_MAXCLIENTS_PLUS1i++)
    {
        if(
IsClientInGame(i) && IsPlayerAlive(i) && GetClientTeam(i) == L4D_TEAM_SURVIVORS)
        {
            
alive++;
        }
    }
    
    return 
alive;
}

stock GetDeadSurvivors()
{
    new 
dead 0;

    new 
i;
    for(
1L4D_MAXCLIENTS_PLUS1i++)
    {
        if(
IsClientInGame(i) && !IsPlayerAlive(i) && GetClientTeam(i) == L4D_TEAM_SURVIVORS)
        {
            
dead++;
        }
    }
    
    return 
dead;

gamedata:
Code:
"Games"
{
    "left4dead2"
    {
        "Signatures"
                {
                    "TakeOverBot"
                    {
                        "library" "server"
                        "linux" "@_ZN13CTerrorPlayer11TakeOverBotEb"
                        "windows" "\x81*****\x53\x55\x56\x8D***\x57\x8B\xF1\x33\xDB"
                        }
                        "SetHumanSpec"
                        {
                        "library" "server"
                           "linux" "@_ZN11SurvivorBot17SetHumanSpectatorEP13CTerrorPlayer"
                        "windows" "\x53\x56\x8B\xF1\x33\xDB\x39*******\x5E\x32\xC0\x5B"
                        }
                }
    }

}

Last edited by Visual77; 06-20-2011 at 04:23.
Visual77 is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 06-17-2011 , 11:51   Re: L4D/2 SDK call crashes the server sometimes when client is joining the survivor t
Reply With Quote #2

Code:
#define L4D_MAXCLIENTS_PLUS1 (MaxClients+1)
MaxClients doesn't work this way... essentially you're trying to define a compile-time definition using a runtime variable.

Incidentally, this is always why global arrays have to be defined in terms of MAXPLAYERS instead of MaxClients.

I would heavily suggest just using MaxClients+1 wherever you current use this define.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 06-17-2011 at 11:53.
Powerlord is offline
Visual77
Veteran Member
Join Date: Jan 2009
Old 06-17-2011 , 12:20   Re: L4D/2 SDK call crashes the server sometimes when client is joining the survivor t
Reply With Quote #3

I've removed that and changed it to for (new i = 1; i <= MaxClients; i++)
The defined line was initially in the plugin that my change team mod is based on (L4D Switch Players I belive)

However, this still dosn't fix the random server crash that happens when I switch back and fourth between the survivor team (team 2), the infected (team 3) and the spectator team(team 1). The server crash always happens at the very same instant I change to the survivor team, but the weird part is that I can change to the survivor team a couple of times before it finally crashes. Therefor something else must be wrong in the code.
Visual77 is offline
AtomicStryker
Veteran Member
Join Date: Apr 2009
Location: Teutonia!!
Old 06-18-2011 , 08:12   Re: L4D/2 SDK call crashes the server sometimes when client is joining the survivor t
Reply With Quote #4

There's 3 or 4 plugins that do working teamswapping. Why don't you copy a working one (well you tried obviously so i dont know what you broke).


Take DebugPrintToAll from the same plugin youre copying and stick it infront of every SDKCall. Then check the logs on which call in what situation crashed.
AtomicStryker is offline
Visual77
Veteran Member
Join Date: Jan 2009
Old 06-18-2011 , 08:37   Re: L4D/2 SDK call crashes the server sometimes when client is joining the survivor t
Reply With Quote #5

Atomic, there is a bug with the already existing plugins and this is why I'm changing them. Take L4D Switch Players mod for example: slay yourself using the admin menu, then switch to the infected side and switch back to the survivor side with the sdk call.
You will take over the very same bot that you just slayed. Hence I'm adding checks for alive/dead.

I will try the debug in the sdk call. I'll post back if I find anything.
Visual77 is offline
Visual77
Veteran Member
Join Date: Jan 2009
Old 06-19-2011 , 07:56   Re: L4D/2 SDK call crashes the server sometimes when client is joining the survivor t
Reply With Quote #6

changed the code method of counting alive/dead bots and got no crashes anymore.
Solved!

Last edited by Visual77; 06-20-2011 at 04:24.
Visual77 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 17:39.


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