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

[REQ] Hibernate and Allow bots


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
jgbc3d
Junior Member
Join Date: Apr 2011
Old 01-05-2017 , 17:33   [REQ] Hibernate and Allow bots
Reply With Quote #1

Hi, I dont know if there is something wrong with my server because with these cvars:
Code:
sm_cvar sb_all_bot_game
sm_cvar sv_hibernate_when_empty
placed in my server.cfg, I cant have both set to "1" the last cvars is set to "0" automatically. I ve tested one old plugin "All bot team" and is the same issue, I was wondering if someone can make a plugin or teach me how to make one that when human players joins, sets "sb_all_bot_game 1" and when all humans leave, sets "sv_hibernate_when_empty 1".
jgbc3d is offline
africanspacejesus
Senior Member
Join Date: Nov 2016
Location: Bay Area, CA
Old 01-08-2017 , 16:06   Re: [REQ] Hibernate and Allow bots
Reply With Quote #2

I can write this for you. I'm sure we can negotiate a fair price. My Steam
https://steamcommunity.com/id/swagattack835/
africanspacejesus is offline
jgbc3d
Junior Member
Join Date: Apr 2011
Old 01-10-2017 , 15:03   Re: [REQ] Hibernate and Allow bots
Reply With Quote #3

well First of all I dont know how to code a plugin so I tried to edit this one ALL BOT TEAM 1.2 and is working for me, I just only added a dumbness, see the new code, and compiled it on the online compiler, the one inside sourcemod files didnt work...STILL I want to learn how to code a plugin so I can make a better one and by myself

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

#define PLUGIN_VERSION "1.2"

static bool:b_HasRoundStarted; // Used to state if the round started or not
static bool:b_HasRoundEnded; // States if the round has ended or not
static bool:AfterInitialRound;
static bool:PlayerHasEnteredStart[MAXPLAYERS+1];
static bool:g_bIsL4D2;
static PlayersInServer;

public Plugin:myinfo = 
{
    name = "[L4D/L4D2] All Bot Teams",
    author = "MI 5",
    description = "This plugin allows survivor players to face all infected bot teams, or vice versa",
    version = PLUGIN_VERSION,
    url = "http://forums.alliedmods.net/showthread.php?t=140347"
}

public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max) 
{
    // Checks to see if the game is a L4D game. If it is, check if its the sequel.
    decl String:GameName[12];
    GetGameFolderName(GameName, sizeof(GameName));
    if (StrContains(GameName, "left4dead", false) == -1)
        return APLRes_Failure;
    if (StrEqual(GameName, "left4dead2", false))
        g_bIsL4D2 = true;
    
    return APLRes_Success;
}

public OnPluginStart()
{
    CreateConVar("l4d_abt_version", PLUGIN_VERSION, "Version of L4D All Bot Teams", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY|FCVAR_DONTRECORD);
    
    HookEvent("round_start", Event_RoundStart);
    HookEvent("player_bot_replace", Event_CheckForPlayers, EventHookMode_Post);
    HookEvent("player_first_spawn", Event_PlayerFirstSpawned);
    HookEvent("player_entered_start_area", Event_PlayerFirstSpawned);
    HookEvent("player_entered_checkpoint", Event_PlayerFirstSpawned);
    HookEvent("player_transitioned", Event_PlayerFirstSpawned);
    HookEvent("player_left_start_area", Event_PlayerFirstSpawned);
    HookEvent("player_left_checkpoint", Event_PlayerFirstSpawned);
    HookEvent("map_transition", Event_GameEnded);
}

public OnClientPutInServer(client)
{
    if (IsFakeClient(client))
        return;
    
    PlayersInServer++;
}

public Action:Event_RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
{
    // If round has started ...
    if (b_HasRoundStarted)
        return;
    
    b_HasRoundStarted = true;
    b_HasRoundEnded = false;
    
    // When the game starts, stop the bots till a player joins
    SetConVarInt(FindConVar("sb_stop"), 1);
    
    if (AfterInitialRound)
        SetConVarInt(FindConVar("sb_stop"), 0);
}

public Action:Event_CheckForPlayers(Handle:event, const String:name[], bool:dontBroadcast)
{
    if (!RealPlayersInServer())
    {
        if (g_bIsL4D2)
        {
            SetConVarInt(FindConVar("sb_all_bot_game"), 0);
            SetConVarInt(FindConVar("allow_all_bot_survivor_team"), 0);
            SetConVarInt(FindConVar("sv_hibernate_when_empty"), 1);
        }
        else
        SetConVarInt(FindConVar("sb_all_bot_team"), 0);
    }
}

public OnClientDisconnect(client)
{
    // If is a bot, skip this function
    if (IsFakeClient(client))
        return;
    
    PlayerHasEnteredStart[client] = false;
    PlayersInServer--;
    
    if (PlayersInServer == 0)
    {
        if (g_bIsL4D2)
        {
            SetConVarInt(FindConVar("sb_all_bot_game"), 0);
            SetConVarInt(FindConVar("allow_all_bot_survivor_team"), 0);
            SetConVarInt(FindConVar("sv_hibernate_when_empty"), 1);
        }
        else
        SetConVarInt(FindConVar("sb_all_bot_team"), 0);
    }
}

public Action:Event_GameEnded(Handle:event, const String:name[], bool:dontBroadcast)
{
    // If round has not been reported as ended ..
    if (!b_HasRoundEnded)
    {
        // we mark the round as ended
        b_HasRoundEnded = true;
        b_HasRoundStarted = false;
        AfterInitialRound = true;
        
        for (new i = 1; i <= MaxClients; i++)
            PlayerHasEnteredStart[i] = false;
    }
}

public Action:Event_PlayerFirstSpawned(Handle:event, const String:name[], bool:dontBroadcast)
{
    if (b_HasRoundEnded)
        return;
    
    new client = GetClientOfUserId(GetEventInt(event, "userid"));
    
    if (!client)
        return;
    
    if (IsFakeClient(client))
        return;
    
    // If player has already entered the start area, don't go into this
    if (PlayerHasEnteredStart[client])
        return;
    
    PlayerHasEnteredStart[client] = true;
    
    SetConVarInt(FindConVar("sb_stop"), 0);
    
    if (g_bIsL4D2)
    {
        SetConVarInt(FindConVar("sv_hibernate_when_empty"), 0);
        SetConVarInt(FindConVar("sb_all_bot_game"), 1);
        SetConVarInt(FindConVar("allow_all_bot_survivor_team"), 1);
    }
    else
    SetConVarInt(FindConVar("sb_all_bot_team"), 1);
}

public OnMapEnd()
{
    b_HasRoundEnded = true;
    b_HasRoundStarted = false;
    AfterInitialRound = false;
    
    for (new i = 1; i <= MaxClients; i++)
        PlayerHasEnteredStart[i] = false;
}

bool:RealPlayersInServer ()
{
    for (new i=1;i<=MaxClients;i++)
    {
        if (IsClientInGame(i) && !IsFakeClient(i))
            return true;
    }
    return false;
}

public OnPluginEnd()
{
    if (g_bIsL4D2)
    {
        ResetConVar(FindConVar("sv_hibernate_when_empty"), true, true);
        ResetConVar(FindConVar("sb_all_bot_game"), true, true);
        ResetConVar(FindConVar("allow_all_bot_survivor_team"), true, true);
    }
    else
    ResetConVar(FindConVar("sb_all_bot_team"), true, true);
    
    ResetConVar(FindConVar("sb_stop"), true, true);
}


//////////////////////////
jgbc3d is offline
OSWO
Senior Member
Join Date: Jul 2015
Location: United Kingdom, London
Old 01-10-2017 , 16:37   Re: [REQ] Hibernate and Allow bots
Reply With Quote #4

Quote:
Originally Posted by africanspacejesus View Post
I can write this for you. I'm sure we can negotiate a fair price. My Steam
https://steamcommunity.com/id/swagattack835/
What a fantastic way to resolve a player's problem. "Pay". You're gonna go far kid.
__________________
SourceTimer | WeaponSkins++ | BasePlugins++ https://github.com/OSCAR-WOS

Last edited by OSWO; 01-10-2017 at 16:39.
OSWO is offline
jgbc3d
Junior Member
Join Date: Apr 2011
Old 01-10-2017 , 16:48   Re: [REQ] Hibernate and Allow bots
Reply With Quote #5

Quote:
Originally Posted by jgbc3d View Post
well First of all I dont know how to code a plugin so I tried to edit this one ALL BOT TEAM 1.2 and is working for me, I just only added a dumbness, see the new code, and compiled it on the online compiler, the one inside sourcemod files didnt work...STILL I want to learn how to code a plugin so I can make a better one and by myself

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

#define PLUGIN_VERSION "1.2"

static bool:b_HasRoundStarted; // Used to state if the round started or not
static bool:b_HasRoundEnded; // States if the round has ended or not
static bool:AfterInitialRound;
static bool:PlayerHasEnteredStart[MAXPLAYERS+1];
static bool:g_bIsL4D2;
static PlayersInServer;

public Plugin:myinfo = 
{
    name = "[L4D/L4D2] All Bot Teams",
    author = "MI 5",
    description = "This plugin allows survivor players to face all infected bot teams, or vice versa",
    version = PLUGIN_VERSION,
    url = "http://forums.alliedmods.net/showthread.php?t=140347"
}

public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max) 
{
    // Checks to see if the game is a L4D game. If it is, check if its the sequel.
    decl String:GameName[12];
    GetGameFolderName(GameName, sizeof(GameName));
    if (StrContains(GameName, "left4dead", false) == -1)
        return APLRes_Failure;
    if (StrEqual(GameName, "left4dead2", false))
        g_bIsL4D2 = true;
    
    return APLRes_Success;
}

public OnPluginStart()
{
    CreateConVar("l4d_abt_version", PLUGIN_VERSION, "Version of L4D All Bot Teams", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY|FCVAR_DONTRECORD);
    
    HookEvent("round_start", Event_RoundStart);
    HookEvent("player_bot_replace", Event_CheckForPlayers, EventHookMode_Post);
    HookEvent("player_first_spawn", Event_PlayerFirstSpawned);
    HookEvent("player_entered_start_area", Event_PlayerFirstSpawned);
    HookEvent("player_entered_checkpoint", Event_PlayerFirstSpawned);
    HookEvent("player_transitioned", Event_PlayerFirstSpawned);
    HookEvent("player_left_start_area", Event_PlayerFirstSpawned);
    HookEvent("player_left_checkpoint", Event_PlayerFirstSpawned);
    HookEvent("map_transition", Event_GameEnded);
}

public OnClientPutInServer(client)
{
    if (IsFakeClient(client))
        return;
    
    PlayersInServer++;
}

public Action:Event_RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
{
    // If round has started ...
    if (b_HasRoundStarted)
        return;
    
    b_HasRoundStarted = true;
    b_HasRoundEnded = false;
    
    // When the game starts, stop the bots till a player joins
    SetConVarInt(FindConVar("sb_stop"), 1);
    
    if (AfterInitialRound)
        SetConVarInt(FindConVar("sb_stop"), 0);
}

public Action:Event_CheckForPlayers(Handle:event, const String:name[], bool:dontBroadcast)
{
    if (!RealPlayersInServer())
    {
        if (g_bIsL4D2)
        {
            SetConVarInt(FindConVar("sb_all_bot_game"), 0);
            SetConVarInt(FindConVar("allow_all_bot_survivor_team"), 0);
            SetConVarInt(FindConVar("sv_hibernate_when_empty"), 1);
        }
        else
        SetConVarInt(FindConVar("sb_all_bot_team"), 0);
    }
}

public OnClientDisconnect(client)
{
    // If is a bot, skip this function
    if (IsFakeClient(client))
        return;
    
    PlayerHasEnteredStart[client] = false;
    PlayersInServer--;
    
    if (PlayersInServer == 0)
    {
        if (g_bIsL4D2)
        {
            SetConVarInt(FindConVar("sb_all_bot_game"), 0);
            SetConVarInt(FindConVar("allow_all_bot_survivor_team"), 0);
            SetConVarInt(FindConVar("sv_hibernate_when_empty"), 1);
        }
        else
        SetConVarInt(FindConVar("sb_all_bot_team"), 0);
    }
}

public Action:Event_GameEnded(Handle:event, const String:name[], bool:dontBroadcast)
{
    // If round has not been reported as ended ..
    if (!b_HasRoundEnded)
    {
        // we mark the round as ended
        b_HasRoundEnded = true;
        b_HasRoundStarted = false;
        AfterInitialRound = true;
        
        for (new i = 1; i <= MaxClients; i++)
            PlayerHasEnteredStart[i] = false;
    }
}

public Action:Event_PlayerFirstSpawned(Handle:event, const String:name[], bool:dontBroadcast)
{
    if (b_HasRoundEnded)
        return;
    
    new client = GetClientOfUserId(GetEventInt(event, "userid"));
    
    if (!client)
        return;
    
    if (IsFakeClient(client))
        return;
    
    // If player has already entered the start area, don't go into this
    if (PlayerHasEnteredStart[client])
        return;
    
    PlayerHasEnteredStart[client] = true;
    
    SetConVarInt(FindConVar("sb_stop"), 0);
    
    if (g_bIsL4D2)
    {
        SetConVarInt(FindConVar("sv_hibernate_when_empty"), 0);
        SetConVarInt(FindConVar("sb_all_bot_game"), 1);
        SetConVarInt(FindConVar("allow_all_bot_survivor_team"), 1);
    }
    else
    SetConVarInt(FindConVar("sb_all_bot_team"), 1);
}

public OnMapEnd()
{
    b_HasRoundEnded = true;
    b_HasRoundStarted = false;
    AfterInitialRound = false;
    
    for (new i = 1; i <= MaxClients; i++)
        PlayerHasEnteredStart[i] = false;
}

bool:RealPlayersInServer ()
{
    for (new i=1;i<=MaxClients;i++)
    {
        if (IsClientInGame(i) && !IsFakeClient(i))
            return true;
    }
    return false;
}

public OnPluginEnd()
{
    if (g_bIsL4D2)
    {
        ResetConVar(FindConVar("sv_hibernate_when_empty"), true, true);
        ResetConVar(FindConVar("sb_all_bot_game"), true, true);
        ResetConVar(FindConVar("allow_all_bot_survivor_team"), true, true);
    }
    else
    ResetConVar(FindConVar("sb_all_bot_team"), true, true);
    
    ResetConVar(FindConVar("sb_stop"), true, true);
}


//////////////////////////
nevermind...it works at the beginning, but after play for a few minutes, it does not go to hibernate
jgbc3d is offline
africanspacejesus
Senior Member
Join Date: Nov 2016
Location: Bay Area, CA
Old 01-10-2017 , 19:25   Re: [REQ] Hibernate and Allow bots
Reply With Quote #6

Quote:
Originally Posted by OSWO View Post
What a fantastic way to resolve a player's problem. "Pay". You're gonna go far kid.
I only saw the request tag in the title. I was looking for some paid plugin work to do.
__________________
Taking paid plugin requests
africanspacejesus is offline
jgbc3d
Junior Member
Join Date: Apr 2011
Old 01-10-2017 , 20:08   Re: [REQ] Hibernate and Allow bots
Reply With Quote #7

Quote:
Originally Posted by africanspacejesus View Post
I only saw the request tag in the title. I was looking for some paid plugin work to do.
OK guys, I have to be agree with something, If you cant get a job done pay someone to do it for you, however I believe this is a place to help each other and share information, also am not asking for a customized operative system, is just something that can call two EXISTING COMMANDS, as I said I dont know how to code but I think this one in particular cant be very difficult to code, I dont know...so lets please to not fill this thread with something that wont help me.
Look this is what I have so far, am still working on it because now I need it goes to hibernation when there are not HUMANs on the server

Code:
#include <sourcemod>

public Plugin myinfo =
{
    name = "TEST",
    author = "TEST",
    description = "TEST",
    version = "1.0",
    url = "TEST.TEST"
};

public OnClientPutInServer(client)
{
    SetConVarInt(FindConVar("sb_all_bot_game"), 1);
}

public OnClientDisconnect(client)
{
    if (IsFakeClient(client))
        return;
        
    {
        SetConVarInt(FindConVar("sb_all_bot_game"), 0);
        SetConVarInt(FindConVar("sv_hibernate_when_empty"), 1);
    }
}
jgbc3d is offline
africanspacejesus
Senior Member
Join Date: Nov 2016
Location: Bay Area, CA
Old 01-11-2017 , 00:44   Re: [REQ] Hibernate and Allow bots
Reply With Quote #8

When i get time ill make it or fix yours
__________________
Taking paid plugin requests
africanspacejesus is offline
jgbc3d
Junior Member
Join Date: Apr 2011
Old 01-11-2017 , 02:03   Re: [REQ] Hibernate and Allow bots
Reply With Quote #9

Quote:
Originally Posted by africanspacejesus View Post
When i get time ill make it or fix yours
thanks any help is Very appreciated , I will keep updated this thread with any change I made to my own code
jgbc3d is offline
jgbc3d
Junior Member
Join Date: Apr 2011
Old 01-11-2017 , 20:43   Re: [REQ] Hibernate and Allow bots
Reply With Quote #10

Looks like this one is working well, you will notice it is not well coded but is working for now. feel free to edit, but please tell me what you did

Code:
#include <sourcemod>

public Plugin myinfo =
{
    name = "TEST",
    author = "TEST",
    description = "TEST",
    version = "1.0",
    url = "TEST"
};

public OnPluginStart()
{
    HookEvent("player_disconnect", Event_PlayerDisconnect);
}

public OnClientPutInServer(client)
{
    SetConVarInt(FindConVar("sv_hibernate_when_empty"), 0);
    SetConVarInt(FindConVar("sb_all_bot_game"), 1);
}

public Action:Event_PlayerDisconnect(Handle:hEvent, const String:strName[], bool:bDontBroadcast)
{
    for (new i = 1; i <= MaxClients; i++)
    {
        if (IsClientInGame(i))
        {
            SetConVarInt(FindConVar("sb_all_bot_game"), 1);
            
        } else 
        {
            SetConVarInt(FindConVar("sv_hibernate_when_empty"), 1);

        }
    }
}
jgbc3d 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 21:28.


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