|
Senior Member
Join Date: Jun 2020
Location: Argentina
|
02-20-2022
, 11:25
Re: Bot Names Plugin
|
#7
|
Quote:
Originally Posted by OciXCrom
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_aBotNames, g_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(szFilename, charsmax(szFilename))
add(szFilename, charsmax(szFilename), "/BotNames.ini")
new iFilePointer = fopen(szFilename, "rt")
if(iFilePointer)
{
new szData[MAX_NAME_LENGTH]
while(!feof(iFilePointer))
{
fgets(iFilePointer, szData, charsmax(szData))
trim(szData)
switch(szData[0])
{
case EOS, '#', ';': continue
default:
{
g_iTotalNames++
ArrayPushString(g_aBotNames, szData)
}
}
}
fclose(iFilePointer)
}
}
public client_putinserver(id)
{
if(!is_user_bot(id))
{
return
}
if(g_iTotalNames--)
{
new szName[MAX_NAME_LENGTH], i = random(g_iTotalNames)
ArrayGetString(g_aBotNames, i, szName, charsmax(szName))
ArrayDeleteItem(g_aBotNames, i)
static const szNameField[] = "name"
set_user_info(id, szNameField, szName)
}
}
@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
|
|
|
|