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

This is EFFING stupid!


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
chinagreenelvis
Senior Member
Join Date: Dec 2009
Old 11-16-2010 , 20:24   This is EFFING stupid!
Reply With Quote #1

PHP Code:

#include <sourcemod>
#include <sdktools>

#define PLUGIN_VERSION "2.0"

public Plugin:myinfo 
{
    
name "L4D/L4D2 Less Than 4 Dead (v2)",
    
author "chinagreenelvis",
    
description "Removes survivor bots from multiplayer games",
    
version PLUGIN_VERSION,
    
url "http://www.chinagreenelvis.com"
}

new 
bool:ClientHasABot[MAXPLAYERS+1];

public 
OnPluginStart() 
{
    
SetConVarInt(FindConVar("director_no_survivor_bots"), 1);
    
SetConVarInt(FindConVar("survivor_limit"), 1);
    
    
HookEvent("player_team"Event_PlayerTeam);
    
HookEvent("bot_player_replace"Event_PlayerBotReplace);
    
HookEvent("player_bot_replace"Event_PlayerBotReplace);
}

public 
OnClientConnected(client)
{
    if (!
IsFakeClient(client))
    {
        
ServerCommand("sb_add");
        
ClientHasABot[client] = true;
    }
}

public 
OnClientDisconnect(client)
{
    if (
ClientHasABot[client] == true)
    {
        
KickBot(client);
    }
}

public 
Event_PlayerTeam(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
client GetClientOfUserId(GetEventInt(event,"userid"));
    if (
IsClientConnected(client) && IsClientInGame(client) && !IsFakeClient(client))
    {
        if (
GetEventInt(event"team") == 2)
        {
            if (
ClientHasABot[client] == true)
            {
                
ClientHasABot[client] = false;
            }
            new 
survivorlimit GetConVarInt(FindConVar("survivor_limit"));
            if (
survivorlimit 4)
            {
                
SetConVarInt(FindConVar("survivor_limit"), survivorlimit 1);
            }
        }
    }
    if (
GetEventInt(event"team") == 3)
    {
        if (
ClientHasABot[client] == true)
        {
            
KickBot(client);
        }
    }
}

public 
Event_BotPlayerReplace(Handle:event, const String:name[], bool:dontBroadcast)
{
    
}

public 
Event_PlayerBotReplace(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
bot GetClientOfUserId(GetEventInt(event,"bot"));
    if(
GetClientTeam(bot) == && GetEntProp(botProp_Send"m_humanSpectatorUserID") == 0)
    {
        if (
IsPlayerAlive(bot))
        {
            
ForcePlayerSuicide(bot);
        }
        
KickClient(bot);
    }
}

KickBot(client)
{
    new 
bool:ABotHasBeenKicked false;
    for (new 
1<= MaxClientsi++) 
    {
        if (
ABotHasBeenKicked == false)
        {
            if (
IsClientConnected(i) && IsClientInGame(i) && GetClientTeam(i) == 2
            { 
                if (
IsFakeClient(i) && GetEntProp(iProp_Send"m_humanSpectatorUserID") == 0
                {
                    if (
IsPlayerAlive(i))
                    {
                        
ForcePlayerSuicide(i);
                    }
                    
KickClient(i);
                    
ClientHasABot[client] = false;
                    
ABotHasBeenKicked true;
                }
            }
        }
    }

I connect to my server alone. I start off with me and a bot. This should not happen and defies all logic. I should be starting off by myself, and the "survivor_limit" cvar should be 2. Instead, the cvar is set to 2 and a bot is right there with me. And then I unload a clip into its face.

Event_PlayerTeam comes after OnClientConnected, right? Therefore sb_add should take place before the cvar is changed and not after. But if I remove the cvar change from the code, the bot is no longer spawned.

It just doesn't make sense to me. At all.
chinagreenelvis is offline
retsam
Veteran Member
Join Date: Aug 2008
Location: so-cal
Old 11-16-2010 , 21:36   Re: This is EFFING stupid!
Reply With Quote #2

I dont know, I only glanced at it for a second, and I dont code for L4D, so this could very well be wrong, but....if survival_limit is a game cvar and you want it set to 1, you most likely need to do it on mapstart, not on pluginstart. pluginstart happens before the map is started so, most likely its reading default value of the convar....which I guess is 2? You should be finding convar in plugin start, but not setting it there.....
__________________
retsam is offline
API
Veteran Member
Join Date: May 2006
Old 11-16-2010 , 22:15   Re: This is EFFING stupid!
Reply With Quote #3

Console commands aren't executed immediately. They are executed on the next frame, so even if you call the ServerCommand() first, it isn't guaranteed to fire before the next line of code on the stack.
__________________
API is offline
Send a message via AIM to API
chinagreenelvis
Senior Member
Join Date: Dec 2009
Old 11-17-2010 , 09:38   Re: This is EFFING stupid!
Reply With Quote #4

I figured out part of the problem, and that's sb_add seems to autofill future slots. Valve really jacked up the way this all works in L4D2.

The same thing happens if you leave survivor_limit at 4, kick all the bots and just add one. The other two instantly appear. So if you fill one slot then open up another one, a bot appears and fills it.
chinagreenelvis is offline
chinagreenelvis
Senior Member
Join Date: Dec 2009
Old 11-17-2010 , 18:54   Re: This is EFFING stupid!
Reply With Quote #5

Okay. So. The following code works great if I start a server by myself and someone new joins in. I start off alone, and when a new client joins a bot is created. When they join the game, they take the bot's place. When they leave, the bot goes bye-bye.

But if I start a game with two people in a lobby, "survivor_limit" is increased to four and we get two bots, aka a full team.

Can anyone figure out why?

PHP Code:
#include <sourcemod>
#include <sdktools>

#define PLUGIN_VERSION "2.0"

public Plugin:myinfo 
{
    
name "L4D/L4D2 Less Than 4 Dead (v2)",
    
author "chinagreenelvis",
    
description "Removes survivor bots from multiplayer games",
    
version PLUGIN_VERSION,
    
url "http://www.chinagreenelvis.com"
}

new 
potentialsurvivors 0;

public 
OnPluginStart() 
{
    
CreateConVar("l4d_2_lessthan4dead_v2_minsurvivors""1""Minimum number of survivors to allow"FCVAR_PLUGIN);
    
CreateConVar("l4d_2_lessthan4dead_v2_maxsurvivors""4""Maximum number of survivors to allow (additional plugins required for more than 4 players)"FCVAR_PLUGIN);
    
    
SetConVarInt(FindConVar("director_no_survivor_bots"), 1);
    
SetConVarInt(FindConVar("survivor_limit"), 1);
}

public 
OnClientConnected(client)
{
    if (!
IsFakeClient(client))
    {
        
PrintToChatAll("potentialsurvivors = %i"potentialsurvivors);
        new 
minsurvivors GetConVarInt(FindConVar("l4d_2_lessthan4dead_v2_minsurvivors"));
        new 
maxsurvivors GetConVarInt(FindConVar("l4d_2_lessthan4dead_v2_maxsurvivors"));
        new 
survivorlimit GetConVarInt(FindConVar("survivor_limit"));
        if (
potentialsurvivors == survivorlimit)
        {    
            if (
potentialsurvivors >= minsurvivors)
            {
                if (
survivorlimit maxsurvivors)
                {
                    
CreateTimer(1.0Timer_SurvivorLimitAdd);                
                }
            }
            else if (
potentialsurvivors minsurvivors)
            {
                
ServerCommand("sb_add");
            }
        }
        
potentialsurvivors++;
        
PrintToChatAll("potentialsurvivors = %i"potentialsurvivors);
    }    
}

public 
OnClientDisconnect(client)
{
    if (!
IsFakeClient(client))
    {    
        new 
minsurvivors GetConVarInt(FindConVar("l4d_2_lessthan4dead_v2_minsurvivors"));
        new 
survivorlimit GetConVarInt(FindConVar("survivor_limit"));
        
PrintToChatAll("potentialsurvivors = %i"potentialsurvivors);
        if (
potentialsurvivors minsurvivors)
        {
            if (
survivorlimit minsurvivors)
            {
                
CreateTimer(1.0Timer_SurvivorLimitSubtract);
            }
        }
        
potentialsurvivors--;
        
PrintToChatAll("potentialsurvivors = %i"potentialsurvivors);
    }
}

public 
Action:Timer_SurvivorLimitAdd(Handle:timer)
{
    new 
maxsurvivors GetConVarInt(FindConVar("l4d_2_lessthan4dead_v2_maxsurvivors"));
    new 
survivorlimit GetConVarInt(FindConVar("survivor_limit"));
    
    if (
survivorlimit maxsurvivors)
    {
        
SetConVarInt(FindConVar("survivor_limit"), survivorlimit 1falsefalse);
        
ServerCommand("sb_add");
    }
}

public 
Action:Timer_SurvivorLimitSubtract(Handle:timer)
{
    new 
minsurvivors GetConVarInt(FindConVar("l4d_2_lessthan4dead_v2_minsurvivors"));
    new 
survivorlimit GetConVarInt(FindConVar("survivor_limit"));
    
    if (
survivorlimit minsurvivors)
    {
        
SetConVarInt(FindConVar("survivor_limit"), survivorlimit 1falsefalse);
        
KickBot();
    }
}

KickBot()
{
    
PrintToChatAll("A bot should be about to be kicked.")
    new 
bool:ABotHasBeenKicked false;
    for (new 
1<= MaxClientsi++) 
    {
        if (
ABotHasBeenKicked == false)
        {
            if (
IsClientConnected(i) && IsClientInGame(i) && GetClientTeam(i) == 2
            { 
                
PrintToChatAll("A bot is very likely about to be kicked.")
                if (
IsFakeClient(i) && GetEntProp(iProp_Send"m_humanSpectatorUserID") == 0
                {
                    
PrintToChatAll("A bot is definitely about to be kicked.")
                    if (
IsPlayerAlive(i))
                    {
                        
ForcePlayerSuicide(i);
                    }
                    
KickClient(i);
                    
ABotHasBeenKicked true;
                }
            }
        }
    }

chinagreenelvis is offline
AtomicStryker
Veteran Member
Join Date: Apr 2009
Location: Teutonia!!
Old 11-18-2010 , 17:53   Re: This is EFFING stupid!
Reply With Quote #6

Because a Lobby connection enforces certain settings like that one.
It's basically a map change
AtomicStryker 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 16:55.


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