View Single Post
`666
AlliedModders Donor
Join Date: Jan 2006
Old 04-08-2022 , 09:57   Re: Persistent Bot Named XYZ
Reply With Quote #3

Tested only in insurgency

PHP Code:
#pragma semicolon 1
#pragma newdecls required

#include <sourcemod>
#include <sdktools>

int        g_iNameSet 0;
char    g_sOriginalName[32];

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

public 
void OnPluginStart() {
    
HookEvent("player_team"Event_PlayerTeamEventHookMode_Post);

    for (
int i 1<= MaxClientsi++) {
        if (!
IsClientInGame(i) || !IsFakeClient(i)) {
            continue;
        }
        
SetName(i);
        break;
    }
}

public 
void OnClientDisconnect(int client) {
    if (
client == g_iNameSet && client 0) {
        
int iHumans 0,
            
iBot 0;
    
        for (
int i 1<= MaxClientsi++) {
            if (!
IsClientInGame(i) || == g_iNameSet) {
                continue;
            }
            if (!
IsFakeClient(i)) {
                
iHumans++;
                continue;
            }

            
iBot i;

            if (
iHumans) {
                break;
            }
        }

        if (
iHumans && iBot) {
            
SetName(iBot);
        } else {
            
g_iNameSet 0;
        }
    }
}

public 
Action Event_PlayerTeam(Event event, const char[] namebool dontBroadcast) {
    if (
g_iNameSet) {
        return 
Plugin_Continue;
    }

    
int client GetClientOfUserId(event.GetInt("userid"));
    if (
client && IsClientInGame(client) && IsFakeClient(client)) {
        
SetName(client);
    }

    return 
Plugin_Continue;
}

void SetName(int client) {
    
//Remember original name so we can restore on plugin unload
    
GetClientName(clientg_sOriginalNamesizeof(g_sOriginalName));
    
SetClientName(client"[Bot]-XYZ");
    
g_iNameSet client;
}

public 
void OnPluginEnd() {
    if (
g_iNameSet && IsClientInGame(g_iNameSet) && IsFakeClient(g_iNameSet)) {
        
SetClientName(g_iNameSetg_sOriginalName);
    }

`666 is offline