IPB

Welcome Guest ( Log In | Register )

> All bots are named RCBot, How can I rename my bots?
phenrol
post Jan 28 2014, 03:18 AM
Post #1


Newbie
*

Group: Members
Posts: 8
Joined: 28-January 14
Member No.: 2,322



Hello,

I have RCbot2 working on my DOD:S linux server and I can spawn functioning bots, however, all of them are named "RCBot", which is rather annoying.

I have tried messing with the profiles, and the server reads them in just fine as indicated by the startup output when the plugin is loading, however, anything I do with these does not seem to change anything.

I can individually set their name using sm_rename, but that is a pain.

can anyone help me with this issue?

Thanks
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
 
Reply to this topicStart new topic
Replies
n0nnie
post Oct 29 2014, 06:54 AM
Post #2


Member
**

Group: Members
Posts: 35
Joined: 27-October 14
Member No.: 2,361



Sorry for Doublepost but I think, this deserves an extra Post =)

Profiles are not read still but with the help of ZadRoot it was possible to get this Sourcemodplugin to work. In fact he did the fixes in the code für dod and I was compiling it XD


CODE
#include <sourcemod>
#include <sdktools>

#pragma semicolon 1
#pragma unused cvarVersion

#define PLUGIN_VERSION "1.0"
#define PLUGIN_DESCRIPTION "Gives automatic names to bots on creation."
#define BOT_NAME_FILE "configs/botnames.txt"

// this array will store the names loaded
new Handle:bot_names;

// this array will have a list of indexes to
// bot_names, use these in order
new Handle:name_redirects;

// this is the next index to use into name_redirects
// update this each time you use a name
new next_index;

// various convars
new Handle:cvarVersion; // version cvar!
new Handle:cvarEnabled; // are we enabled?
new Handle:cvarPrefix; // bot name prefix
new Handle:cvarRandom; // use random-order names?
new Handle:cvarAnnounce; // announce new bots?
new Handle:cvarSuppress; // supress join/team/namechange messages?

public Plugin:myinfo =
{
    name = "Bot Names",
    author = "Rakeri",
    description = PLUGIN_DESCRIPTION,
    version = PLUGIN_VERSION,
    url = "https://forums.alliedmods.net/showthread.php?p=1054057"
}

// a function to generate name_redirects
GenerateRedirects()
{
    new loaded_names = GetArraySize(bot_names);

    if (name_redirects != INVALID_HANDLE)
    {
        ResizeArray(name_redirects, loaded_names);
    } else {
        name_redirects = CreateArray(1, loaded_names);
    }

    for (new i = 0; i < loaded_names; i++)
    {
        SetArrayCell(name_redirects, i, i);
        
        // nothing to do random-wise if i == 0
        if (i == 0)
        {
            continue;
        }

        // now to introduce some chaos
        if (GetConVarBool(cvarRandom))
        {
            SwapArrayItems(name_redirects, GetRandomInt(0, i - 1), i);
        }
    }
}

// a function to load data into bot_names
ReloadNames()
{
    next_index = 0;
    decl String:path[PLATFORM_MAX_PATH];
    BuildPath(Path_SM, path, sizeof(path), BOT_NAME_FILE);
    
    if (bot_names != INVALID_HANDLE)
    {
        ClearArray(bot_names);
    } else {
        bot_names = CreateArray(MAX_NAME_LENGTH);
    }
    
    new Handle:file = OpenFile(path, "r");
    if (file == INVALID_HANDLE)
    {
        //PrintToServer("bot name file unopened");
        return;
    }
    
    // this LENGTH*3 is sort of a hack
    // don't make long lines, people!
    decl String:newname[MAX_NAME_LENGTH*3];
    decl String:formedname[MAX_NAME_LENGTH];
    decl String:prefix[MAX_NAME_LENGTH];

    GetConVarString(cvarPrefix, prefix, MAX_NAME_LENGTH);

    while (IsEndOfFile(file) == false)
    {
        if (ReadFileLine(file, newname, sizeof(newname)) == false)
        {
            break;
        }
        
        // trim off comments starting with // or #
        new commentstart;
        commentstart = StrContains(newname, "//");
        if (commentstart != -1)
        {
            newname[commentstart] = 0;
        }
        commentstart = StrContains(newname, "#");
        if (commentstart != -1)
        {
            newname[commentstart] = 0;
        }
        
        new length = strlen(newname);
        if (length < 2)
        {
            // we loaded a bum name
            // (that is, blank line or 1 char == bad)
            //PrintToServer("bum name");
            continue;
        }

        // get rid of pesky whitespace
        TrimString(newname);
        
        Format(formedname, MAX_NAME_LENGTH, "%s%s", prefix, newname);
        PushArrayString(bot_names, formedname);
    }
    
    CloseHandle(file);
}

// called when the plugin loads
public OnPluginStart()
{
    // cvars!
    cvarVersion = CreateConVar("sm_botnames_version", PLUGIN_VERSION, PLUGIN_DESCRIPTION, FCVAR_NOTIFY | FCVAR_PLUGIN | FCVAR_DONTRECORD);
    cvarEnabled = CreateConVar("sm_botnames_enabled", "1", "sets whether bot naming is enabled", FCVAR_NOTIFY | FCVAR_PLUGIN);
    cvarPrefix = CreateConVar("sm_botnames_prefix", "", "sets a prefix for bot names (include a trailing space, if needed!)", FCVAR_NOTIFY | FCVAR_PLUGIN);
    cvarRandom = CreateConVar("sm_botnames_random", "1", "sets whether to randomize names used", FCVAR_NOTIFY | FCVAR_PLUGIN);
    cvarAnnounce = CreateConVar("sm_botnames_announce", "1", "sets whether to announce bots when added", FCVAR_NOTIFY | FCVAR_PLUGIN);
    cvarSuppress = CreateConVar("sm_botnames_suppress", "1", "sets whether to supress join/team change/name change bot messages", FCVAR_NOTIFY | FCVAR_PLUGIN);
    
    // hook team change, connect to supress messages
    HookEvent("player_connect", Event_PlayerConnect, EventHookMode_Pre);
    HookEvent("player_team", Event_PlayerTeam, EventHookMode_Pre);

    // trickier... name changes are user messages, so...
    HookUserMessage(GetUserMessageId("SayText"), UserMessage_SayText2, true);

    // register our commands
    RegServerCmd("sm_botnames_reload", Command_Reload);

    AutoExecConfig();
}

public OnMapStart()
{
    ReloadNames();
    GenerateRedirects();
}

// reload bot name, via console
public Action:Command_Reload(args)
{
    ReloadNames();
    GenerateRedirects();
    PrintToServer("[botnames] Loaded %i names.", GetArraySize(bot_names));
}

// handle client connection, to change the names...
public OnClientPostAdminCheck(client)
{
    new loaded_names = GetArraySize(bot_names);

    if (IsFakeClient(client) && loaded_names != 0)
    {
        // we got a bot, here, boss
        
        decl String:newname[MAX_NAME_LENGTH];
        GetArrayString(bot_names, GetArrayCell(name_redirects, next_index), newname, MAX_NAME_LENGTH);

        next_index++;
        if (next_index > loaded_names - 1)
        {
            next_index = 0;
        }
        
        SetClientInfo(client, "name", newname);
        if (GetConVarBool(cvarAnnounce))
        {
            PrintToChatAll("[botnames] Bot %s created.", newname);
            PrintToServer("[botnames] Bot %s created.", newname);
        }
    }
    
}

// handle "SayText2" usermessages, including name change notifies!
public Action:UserMessage_SayText2(UserMsg:msg_id, Handle:bf, const players[], playersNum, bool:reliable, bool:init)
{
    if (!(GetConVarBool(cvarEnabled) && GetConVarBool(cvarSuppress)))
    {
        return Plugin_Continue;
    }

    decl String:message[256];

    BfReadShort(bf); // team color

    BfReadString(bf, message, sizeof(message));
    // check for Name_Change, not #TF_Name_Change (compatibility?)
    if (StrContains(message, "Name_Change") != -1)
    {
        BfReadString(bf, message, sizeof(message)); // original
        BfReadString(bf, message, sizeof(message)); // new
        if (FindStringInArray(bot_names, message) != -1)
        {
            // 'tis a bot!
            return Plugin_Handled;
        }
    }

    return Plugin_Continue;
}

// handle player team change, to supress bot messages
public Action:Event_PlayerTeam(Handle:event, const String:name[], bool:dontBroadcast)
{
    if (!(GetConVarBool(cvarEnabled) && GetConVarBool(cvarSuppress)))
    {
        return Plugin_Continue;
    }

    new client = GetClientOfUserId(GetEventInt(event, "userid"));
    if (client == 0)
    {
        // weird error, ignore
        return Plugin_Continue;
    }
    if (IsFakeClient(client))
    {
        // fake client == bot
        SetEventBool(event, "silent", true);
        return Plugin_Changed;
    }

    return Plugin_Continue;
}

// handle player connect, to supress bot messages
public Action:Event_PlayerConnect(Handle:event, const String:name[], bool:dontBroadcast)
{
    if (!(GetConVarBool(cvarEnabled) && GetConVarBool(cvarSuppress)))
    {
        return Plugin_Continue;
    }

    decl String:networkID[32];
    GetEventString(event, "networkid", networkID, sizeof(networkID));

    if(!dontBroadcast && StrEqual(networkID, "BOT"))
    {
        // we got a bot connectin', resend event as no-broadcast
        decl String:clientName[MAX_NAME_LENGTH], String:address[32];
        GetEventString(event, "name", clientName, sizeof(clientName));
        GetEventString(event, "address", address, sizeof(address));

        new Handle:newEvent = CreateEvent("player_connect", true);
        SetEventString(newEvent, "name", clientName);
        SetEventInt(newEvent, "index", GetEventInt(event, "index"));
        SetEventInt(newEvent, "userid", GetEventInt(event, "userid"));
        SetEventString(newEvent, "networkid", networkID);
        SetEventString(newEvent, "address", address);

        FireEvent(newEvent, true);

        return Plugin_Handled;
    }

    return Plugin_Continue;
}
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
d3m0n
post Nov 15 2014, 06:06 AM
Post #3


Member
**

Group: Members
Posts: 25
Joined: 2-May 14
Member No.: 2,333



QUOTE(n0nnie @ Oct 29 2014, 01:54 PM) *

Sorry for Doublepost but I think, this deserves an extra Post =)

Profiles are not read still but with the help of ZadRoot it was possible to get this Sourcemodplugin to work. In fact he did the fixes in the code für dod and I was compiling it XD


I tried the plugin.

It changes the name from Bot01 to a name in the botnames.txt but then rcbot changes the name AGAIN to RCBot, which is what I get even without the plugin.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Posts in this topic
phenrol   All bots are named RCBot   Jan 28 2014, 03:18 AM
madmax2   Welcome to the RCbot forums... When I rename my p...   Jan 28 2014, 09:40 AM
genmac   probably a bug on the linux compile.   Jan 28 2014, 09:43 AM
phenrol   Thanks for the replies. The profiles do in fact...   Jan 29 2014, 05:28 AM
madmax2   Seems to me this was posted someplace before, so I...   Jan 29 2014, 10:19 PM
phenrol   I have indeed tried Ted's new .76 linux build ...   Jan 31 2014, 04:48 AM
Ted   I've updated the build with the fix for this i...   Feb 2 2014, 03:09 AM
madmax2   I'm trying this on winXP listen server, to see...   Jan 31 2014, 07:47 PM
phenrol   Ultimately, I would like custom names for the spaw...   Feb 1 2014, 12:41 AM
genmac   Looks like a bug and the bot01 are the default dum...   Feb 1 2014, 11:29 AM
phenrol   Do you believe it is a bug with the linux RCBot2 c...   Feb 1 2014, 05:35 PM
phenrol   FYI, I answered my own questions about the windows...   Feb 1 2014, 08:30 PM
genmac   Rcbot2 currently is more for client/listenserver u...   Feb 2 2014, 02:56 AM
madmax2   Ted to the rescue... That was fast... Thanks... :)...   Feb 2 2014, 06:31 AM
phenrol   Ted, thank you for taking a look at the code. I a...   Feb 2 2014, 03:56 PM
phenrol   Here is an update on this. I looked around for a ...   Feb 2 2014, 08:04 PM
genmac   glad you got the bot names taken cared of. as for ...   Feb 3 2014, 02:07 PM
n0nnie   I am aware, this is from February, but it is exact...   Oct 27 2014, 10:24 AM
n0nnie   Sorry for Doublepost but I think, this deserves an...   Oct 29 2014, 06:54 AM
d3m0n   Sorry for Doublepost but I think, this deserves a...   Nov 15 2014, 06:06 AM
n0nnie   I tried the plugin. It changes the name from Bot...   Nov 19 2014, 01:04 PM
d3m0n   That is strange oO Works very fine for me. I do n...   Nov 21 2014, 09:59 AM
n0nnie   Are you using the latest Linux release from Chees...   Nov 23 2014, 03:08 PM
n0nnie   Yes, this one: http://rcbot.bots-united.com/forum...   Dec 11 2014, 03:12 PM
d3m0n   Another Idea: Did you use the webcompiler of sour...   Dec 12 2014, 12:17 PM


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 14th July 2025 - 05:46 PM