View Single Post
Ark_Procession
Senior Member
Join Date: Jun 2020
Location: Argentina
Old 02-20-2022 , 11:25   Re: Bot Names Plugin
Reply With Quote #7

Quote:
Originally Posted by OciXCrom View Post
Previous code was just an example. Here's a full version with a file and duplicates prevention.

The file is configs/BotNames.ini.
Bear in mind that if it runs out of names, it will stop renaming them rather than create duplicates.

PHP Code:
#include <amxmodx>
#include <amxmisc>

#if !defined MAX_NAME_LENGTH
const MAX_NAME_LENGTH 32
#endif

new Array:g_aBotNamesg_iTotalNames

public plugin_init()
{
    
register_plugin("Random Bot Names""1.0""OciXCrom")
    
g_aBotNames ArrayCreate(MAX_NAME_LENGTH)
    
ReadFile()
}

public 
plugin_end()
{
    
ArrayDestroy(g_aBotNames)
}

ReadFile()
{
    new 
szFilename[256]
    
get_configsdir(szFilenamecharsmax(szFilename))
    
add(szFilenamecharsmax(szFilename), "/BotNames.ini")
    new 
iFilePointer fopen(szFilename"rt")

    if(
iFilePointer)
    {
        new 
szData[MAX_NAME_LENGTH]

        while(!
feof(iFilePointer))
        {
            
fgets(iFilePointerszDatacharsmax(szData))
            
trim(szData)

            switch(
szData[0])
            {
                case 
EOS'#'';': continue
                default:
                {
                    
g_iTotalNames++
                    
ArrayPushString(g_aBotNamesszData)
                }
            }
        }

        
fclose(iFilePointer)
    }
}

public 
client_putinserver(id)
{
    if(!
is_user_bot(id))
    {
            return
    }

    if(
g_iTotalNames--)
    {
        new 
szName[MAX_NAME_LENGTH], random(g_iTotalNames)
        
ArrayGetString(g_aBotNamesiszNamecharsmax(szName))
        
ArrayDeleteItem(g_aBotNamesi)

        static const 
szNameField[] = "name"
        
set_user_info(idszNameFieldszName)
    }

@DJEarthQuake - nonsense logic as always. That has the potential of making redundant loops and working in a non-efficient way. Why kick the bot if you already know it's a duplicate instead of simply renaming it?!
Amazing! works flawlessly

i had to create the botnames.ini manually since it wasnt created automatically


Thank you
Ark_Procession is offline