Raised This Month: $23 Target: $400
 5% 

REQ/HELP L4D1 No starting bots


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
axelnieves2012
Senior Member
Join Date: Oct 2014
Location: Argentina
Old 06-20-2020 , 19:40   REQ/HELP L4D1 No starting bots
Reply With Quote #1

After I tried this a trillon times, I give up.
I cannot make this work.

I need a plugin that kick all bots but allows AFK players' bots.
I need a human only game, but I want to keep AFK people bots, for coop.

director_no_survivor_bots keeps kicking any bot at any time, so people can't become AFK because their bots are kicked.

I tried so hard hooking player_spawn, player_first_spawn, player_team, but all I got is the same than "director_no_survivor_bots 1".

I stored people bots on a global var (g_iBots[MAXPLAYERS+1]) but it seems they are kicked before they are stored.

I even tried creating a timer, and nothing worked.
Attached Files
File Type: sp Get Plugin or Get Source (l4d1_human_game.sp - 21 views - 5.8 KB)

Last edited by axelnieves2012; 06-20-2020 at 20:15.
axelnieves2012 is offline
axelnieves2012
Senior Member
Join Date: Oct 2014
Location: Argentina
Old 06-20-2020 , 20:07   Re: REQ L4D1 No starting bots
Reply With Quote #2

PHP Code:
#include <sourcemod>
#pragma semicolon 1
#pragma newdecls required

#define PLUGIN_VERSION "1.0"
public Plugin myinfo =
{
    
name "L4D1 Human Game",
    
author "Axel Juan Nieves",
    
description "L4D1 Only Humans",
    
version PLUGIN_VERSION,
    
url ""
};

#define TEAM_SPEC        1
#define TEAM_SURVIVOR    2
#define TEAM_INFECTED    3

#define FLAGS_SURVIVOR    1
#define FLAGS_INFECTED    2
#define FLAGS_ALIVE        4
#define FLAGS_DEAD        8
#define FLAGS_BOT        16
#define FLAGS_HUMAN        32
#define FLAGS_OBSERVER    64
#define FLAGS_SPEC        128

g_iBots[MAXPLAYERS+1];

public 
void OnPluginStart()
{
    
CreateConVar("l4d1_human_game_version"PLUGIN_VERSION""FCVAR_DONTRECORD|FCVAR_NOTIFY);
    
    
AutoExecConfig(true"l4d1_human_game");
    
//LoadTranslations("l4d1_human_game.phrases");
    
    
HookEvent("player_spawn"event_player_spawnEventHookMode_PostNoCopy);
    
HookEvent("player_team"event_player_teamEventHookMode_PostNoCopy);
    
HookEvent("player_bot_replace"event_player_bot_replaceEventHookMode_Post); //bot replaced a player
    
HookEvent("bot_player_replace"event_bot_player_replaceEventHookMode_Post); //bot replaced a player
    //HookEvent ("weapon_fire", event_weapon_fire)
    //HookEvent("player_spawn", event_player_spawn_pre, EventHookMode_Pre);
}


public 
Action event_player_bot_replace(Handle event, const char[] namebool dontBroadcast//bot replaced a player
{
    
//Let's allow a human player become a bot while he is connected, but remember his ID. We will kick that bot when his client disconnects.
    
int client GetClientOfUserId(GetEventInt(event"player"));
    
int bot GetClientOfUserId(GetEventInt(event"bot"));
    
    
g_iBots[client] = bot;
    
    
//PrintToChatAll("%N is repalcing %N", GetClientOfUserId(GetEventInt(event, "bot")), GetClientOfUserId(GetEventInt(event, "player")));
    //PrintToServer("%N is repalcing %N", GetClientOfUserId(GetEventInt(event, "bot")), GetClientOfUserId(GetEventInt(event, "player")));
    
return Plugin_Continue;
}

public 
Action event_bot_player_replace(Handle event, const char[] namebool dontBroadcast//player replaced a bot
{
    
//Let's allow a human player become a bot while he is connected, but remember his ID. We will kick that bot when his client disconnects.
    
g_iBots[GetClientOfUserId(GetEventInt(event"player"))] = 0;
    
//g_iHumans[GetClientOfUserId(GetEventInt(event, "bot"))] = 0;
    //PrintToChatAll("%N is repalcing %N", GetClientOfUserId(GetEventInt(event, "bot")), GetClientOfUserId(GetEventInt(event, "player")));
    //PrintToServer("%N is repalcing %N", GetClientOfUserId(GetEventInt(event, "bot")), GetClientOfUserId(GetEventInt(event, "player")));
    
return Plugin_Continue;
}

public 
void event_player_spawn(Handle event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(GetEventInt(event"userid"));
    if ( !
IsFakeClient(client) )
        return;
    
    if ( 
GetPlayersCount(FLAGS_SURVIVOR|FLAGS_BOT) > GetPlayersCount(FLAGS_SURVIVOR|FLAGS_HUMAN|FLAGS_OBSERVER|FLAGS_SPEC) )
    {
        
PrintToChatAll("Humans afk:%i, bots:%i. Kicking %N"GetPlayersCount(FLAGS_SURVIVOR|FLAGS_HUMAN|FLAGS_OBSERVER|FLAGS_SPEC), GetPlayersCount(FLAGS_SURVIVOR|FLAGS_BOT), client);
        
KickClient(client);
    }
    else
    {
        
PrintToChatAll("Humans afk:%i, bots:%i. DO NOT KICK %N"GetPlayersCount(FLAGS_SURVIVOR|FLAGS_HUMAN|FLAGS_OBSERVER|FLAGS_SPEC), GetPlayersCount(FLAGS_SURVIVOR|FLAGS_BOT), client);
    }
}

//when a player leaves the server, this kicks its bot...
public void event_player_team(Handle event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(GetEventInt(event"userid"));
    
int bot g_iBots[client];
    if ( 
GetEventBool(event"disconnect") )
    {
        if ( 
IsValidClientInGame(bot) )
        {
            if ( 
IsFakeClient(bot) && !IsClientObserver(bot) )
            {
                
//PrintToChatAll("Kicking bot %N", bot);
                
PrintToServer("Kicking bot %N"bot);
                
KickClient(bot);
            }
        }
    }
    
    
PrintToServer(" - - - - - - -%N isbot(%i) disconnect(%i)"clientGetEventBool(event"isbot"), GetEventBool(event"disconnect"));
}

stock int GetPlayersCount(int flags=0)
{
    
int countsuccess;
    
//if both FLAGS_INFECTED and FLAGS_SURVIVOR are omited, both will be enabled.
    
if (flags & (FLAGS_INFECTED FLAGS_SURVIVOR) == 0)
        
flags |= (FLAGS_INFECTED FLAGS_SURVIVOR);
    
    if (
flags & (FLAGS_BOT FLAGS_HUMAN) == 0)
        
flags |= (FLAGS_BOT FLAGS_HUMAN);
    
    
//if both FLAGS_ALIVE and FLAGS_DEAD are omited, both will be enabled.
    
if (flags & (FLAGS_ALIVE FLAGS_DEAD) == 0)
        
flags |= (FLAGS_ALIVE FLAGS_DEAD);
    
    
//if both FLAGS_BOT and FLAGS_HUMAN are omited, both will be enabled.
    
if (flags & (FLAGS_BOT FLAGS_HUMAN) == 0)
        
flags |= (FLAGS_ALIVE FLAGS_DEAD);
    
    for (
int i=1i<=MAXPLAYERSi++)
    {
        
success 0;
        if (!
IsValidClientInGame(i))
            continue;
        
        
//check alive status...
        
if ( IsPlayerAlive(i) && flags&FLAGS_ALIVE)
            
success++;
        else if ( !
IsPlayerAlive(i) && flags&FLAGS_DEAD)
            
success++;
        
        
//check team...
        
if (GetClientTeam(i)==TEAM_INFECTED && flags&FLAGS_INFECTED)
            
success++;
        else if (
GetClientTeam(i)!=TEAM_INFECTED && flags&FLAGS_SURVIVOR)
            
success++;
        else if (
GetClientTeam(i)!=TEAM_SPEC && flags&FLAGS_SPEC)
            
success++;
        
        
//check bot...
        
if ( IsFakeClient(i) && flags&FLAGS_BOT )
            
success++;
        else if ( !
IsFakeClient(i) && flags&FLAGS_HUMAN )
        {
            
//check idle humans...
            
if ( IsClientObserver(i) && flags&FLAGS_OBSERVER )
            {
                
success++;
            }
            else if ( !
IsClientObserver(i) && (flags&FLAGS_OBSERVER==0) )
            {
                
success++;
            }
        }
        
        
//check above conditions...
        
if (success==3)
            
count++;
    }
    return 
count;
}

stock int IsValidClientInGame(int client)
{
    if (
IsValidClientIndex(client))
    {
        if (
IsClientInGame(client))
            return 
1;
    }
    return 
0;
}

stock int IsValidClientIndex(int index)
{
    if (
index>&& index<=MaxClients)
    {
        return 
1;
    }
    return 
0;

This is my code so far.
It seems to work but it fails.

1) The first time I startup the server, all bots are kicked (this is ok).
2) If I join the server, all survivor bots join the server but 3 of them are kicked, and 1 is keep (this is ok).
3) If I become AFK, my bot is kicked (FAIL).
4) If I manually add a survivor bot after this, he joins the server for 2 seconds and he is kicked again (FAIL).

Last edited by axelnieves2012; 06-20-2020 at 20:08.
axelnieves2012 is offline
fbef0102
Senior Member
Join Date: Sep 2017
Location: TW
Old 07-22-2020 , 22:34   Re: REQ/HELP L4D1 No starting bots
Reply With Quote #3

just make a plugin to kick bot without using "director_no_survivor_bots"

you can look here for reference
Spoiler
__________________

Last edited by fbef0102; 07-23-2020 at 00:32.
fbef0102 is offline
axelnieves2012
Senior Member
Join Date: Oct 2014
Location: Argentina
Old 07-25-2020 , 23:21   Re: REQ/HELP L4D1 No starting bots
Reply With Quote #4

Quote:
Originally Posted by fbef0102 View Post
just make a plugin to kick bot without using "director_no_survivor_bots"

you can look here for reference
Spoiler
Hello, it's done but it has not worked. Starting bots wasn't kicked.
After that, I got AFK and two random bots were kicked, where 3 of them should have been kicked.
axelnieves2012 is offline
fbef0102
Senior Member
Join Date: Sep 2017
Location: TW
Old 07-25-2020 , 23:40   Re: REQ/HELP L4D1 No starting bots
Reply With Quote #5

Post your code.
__________________
fbef0102 is offline
axelnieves2012
Senior Member
Join Date: Oct 2014
Location: Argentina
Old 07-29-2020 , 23:46   Re: REQ/HELP L4D1 No starting bots
Reply With Quote #6

Quote:
Originally Posted by fbef0102 View Post
Post your code.
Here it is, brother. l4d1_human_game.sp

Starting bots are not kicked.
If I use "spectate" command on console, and then rejoin, bot are kicked randomly.
I am testing this on a SRCDS, alone (i am the one person connected to server).

Then, If I use "spectate" again, and "jointeam 2 (another unused bot here)", remaining bot is not kicked.
axelnieves2012 is offline
fbef0102
Senior Member
Join Date: Sep 2017
Location: TW
Old 07-30-2020 , 01:15   Re: REQ/HELP L4D1 No starting bots
Reply With Quote #7

Quote:
Originally Posted by axelnieves2012 View Post
Here it is, brother. Attachment 182876

Starting bots are not kicked.
If I use "spectate" command on console, and then rejoin, bot are kicked randomly.
I am testing this on a SRCDS, alone (i am the one person connected to server).

Then, If I use "spectate" again, and "jointeam 2 (another unused bot here)", remaining bot is not kicked.
1. Because I set a timer to wait 30s to kick bot if survivors are not out the start safe area yet.

2. I rewrite the code, using userid to pass is much safer, l4dmultislots.sp

3. My code is just for reference, it shows how to kick a non-afk bot.
Don't just copy and paste , learn what these functions do and write code by yourself
__________________

Last edited by fbef0102; 07-30-2020 at 01:19.
fbef0102 is offline
Reply


Thread Tools
Display Modes

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 11:25.


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