View Single Post
Den_Marko
Junior Member
Join Date: Jul 2013
Old 10-28-2014 , 21:56   Re: [L4D1/2] bebop - additional coop players (20+ players possible)
Reply With Quote #190

Quote:
Originally Posted by St00ne View Post
Are you serious Den_Marko? >< You just posted my e3 version in which I fixed the timers syntax and game_mode detection!

Nevermind, I also used your simplified version to make it, so... yeah nvm it's open source.

++
I'm sorry but I just deleted some extra time, you can check out and test their

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

#define TEAM_SPECTATORS    1
#define TEAM_SURVIVORS    2
#define BEBOP_VERSION    "0.3e beta"

new newMapActivatedPlayers;
new 
bool:g_GameMode true;
new 
Handle:gamemodes;
new 
Handle:hGameConf INVALID_HANDLE;
new 
Handle:hSpec INVALID_HANDLE;
new 
Handle:hSwitch INVALID_HANDLE;

public 
Plugin:MyInfo 
{
    
name "bebop",
    
author "frool, Den Marko, St00ne",
    
description "allows \"unlimited\" additional players in coop mode",
    
version BEBOP_VERSION,
    
url "http://forums.alliedmods.net/showthread.php?t=110210"
};

public 
OnPluginStart()
{
    
hGameConf LoadGameConfigFile("bebop");

    
StartPrepSDKCall(SDKCall_Player);
    
PrepSDKCall_SetFromConf(hGameConfSDKConf_Signature"SetHumanSpec");
    
PrepSDKCall_AddParameter(SDKType_CBasePlayerSDKPass_Pointer);
    
hSpec EndPrepSDKCall();

    
StartPrepSDKCall(SDKCall_Player);
    
PrepSDKCall_SetFromConf(hGameConfSDKConf_Signature"TakeOverBot");
    
PrepSDKCall_AddParameter(SDKType_BoolSDKPass_Plain);
    
hSwitch EndPrepSDKCall();

    
//GameMode();
    
gamemodes FindConVar("mp_gamemode");
    
HookConVarChange(gamemodes,  Event_GameModeChanges);
    
HookEvent("player_activate"Event_PlayerActivateEventHookMode_Pre);
}

public 
Event_GameModeChanges(Handle:convar, const String:oldValue[], const String:newValue[])
{
    if (
strcmp(oldValuenewValue) != 0)
    {
        
GameMode();
    }
}

GameMode()
{
    
decl String:GameName[64];
    
GetConVarString(gamemodesGameNamesizeof(GameName));
    if((
StrEqual(GameName"coop") == true)
    || (
StrEqual(GameName"realism") == true)
    || (
StrEqual(GameName"survival") == true))
    {
        
g_GameMode true;
    }
    else if((
StrEqual(GameName"versus") == true)
    || (
StrEqual(GameName"teamversus") == true)
    || (
StrEqual(GameName"scavenge") == true)
    || (
StrEqual(GameName"teamscavenge") == true))
    {
        
g_GameMode false;
    }
}

public 
OnMapEnd()
{    
    
newMapActivatedPlayers 0;
}

public 
OnClientDisconnect(client)
{    
    if(
g_GameMode)
    {
        if(
newMapActivatedPlayers 4)
        {
            if (!
IsFakeClient(client))
            {
                new 
count GetHumanInGamePlayerCount() - 1;
                if(
count >= 4)
                {
                    
CreateTimer(1.0Timer_KickNoMoreNeededBot0TIMER_REPEAT);
                }
            }
        }
    }
}

public 
Event_PlayerActivate(Handleevent, const String:name[], bool:dontBroadcast)
{    
    if(
g_GameMode)
    {
        new 
client GetClientOfUserId(GetEventInt(event"userid"));
        if (!
IsFakeClient(client))
        {
            
newMapActivatedPlayers++;
            new 
count GetHumanInGamePlayerCount();
            if (
count && newMapActivatedPlayers && (GetClientTeam(client) != TEAM_SURVIVORS || GetClientTeam(client) == TEAM_SPECTATORS))
            {
                
SpawnFakeClient();
                
CreateTimer(10.0Timer_PutClientToSurvivorTeamGetClientSerial(client), TIMER_REPEAT);
            }
        }
    }
}

public 
Action:Timer_PutClientToSurvivorTeam(Handle:timerany:serial)
{
    new 
client GetClientFromSerial(serial);
    if (
client && IsClientInGame(client) && !IsFakeClient(client))
    {
        if (
GetClientTeam(client) == TEAM_SPECTATORS)
        {
            new 
bot GetABot();
            if(
bot)
            {
                
SDKCall(hSpecbotclient);
                
SDKCall(hSwitchclienttrue);
            }
        }
    }
    return 
Plugin_Stop;
}

GetABot()
{
    new 
r=0;
    new 
bots=0;
    for(new 
i=1i<MaxClientsi++)
    {
        if (
IsClientInGame(i) && GetClientTeam(i) == TEAM_SURVIVORS
        {
            if( 
IsFakeClient(i) ) r=i;
            
bots++;
        }
    }
    return 
r;
}

public 
Action:Timer_KickNoMoreNeededBot(Handle:timerany:data)
{
    new 
String:    clientname[256];
    for (new 
1<= MaxClientsi++)
    {
        if (
IsClientConnected(i))
        {
            if (
IsFakeClient(i) && (GetClientTeam(i) == TEAM_SURVIVORS))
            {
                if(
HasIdlePlayer(i))
                {
                    
GetClientName(iclientnamesizeof(clientname));
                    if (
StrEqual(clientname"NewBot"true))
                    {
                        continue;
                    }
                    
KickClient(i"client_is_NewBot");
                    break;
                }
            }
        }
    }
    return 
Plugin_Stop;
}

public 
Action:Timer_KickFakeClient(Handle:timerany:serial)
{
    new 
client GetClientFromSerial(serial);
    if (
IsClientConnected(client))
    {
        
KickClient(client"client_is_NewBot");
    }
    return 
Plugin_Stop;
}

GetHumanInGamePlayerCount()
{
    new 
count 0;
    for (new 
1<= MaxClientsi++)
    {
        if (
IsClientConnected(i))
        {
            if (!
IsFakeClient(i))
            {
                if (
IsClientInGame(i))
                {
                    
count++;
                }
            }
        }
    }
    return 
count;
}

bool:SpawnFakeClient()
{
    new 
bool:ret false;
    new 
client 0;
    
client CreateFakeClient("NewBot");
    if (
client != 0)
    {
        
ChangeClientTeam(client2);
        if (
DispatchKeyValue(client"classname""survivorbot") == true)
        {
            if (
DispatchSpawn(client) == true)
            {
                
CreateTimer(1.0Timer_KickFakeClientGetClientSerial(client), TIMER_REPEAT);
                
ret true;
            }
        }
        if (
ret == false)
        {
            
KickClient(client"");
        }
    }
    return 
ret;
}

stock bool:HasIdlePlayer(bot)
{
    if(
IsValidEntity(bot))
    {
        
decl String:sNetClass[12];
        
GetEntityNetClass(botsNetClasssizeof(sNetClass));
        if(
strcmp(sNetClass"SurvivorBot") == 0)
        {
            if(
GetEntProp(botProp_Send"m_humanSpectatorUserID") == 0)
            {
                return 
true;
            }
            else return 
false;        
        }
        else return 
false
    
}
    return 
false;
}

//***END***/// 
__________________

Last edited by Den_Marko; 10-28-2014 at 21:58.
Den_Marko is offline