Thread: SpecBot 2021
View Single Post
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 12-25-2021 , 06:46   Re: SpecBot 2021
Reply With Quote #8

That plugin may be from 2016 but this one looks like it was coded in the early 2000s.

Apart from you using this as an obvious advertisement, the code can use tons of improvements.

The main problem is using repetitive code everywhere. All of this can be handled with a simple loop. I'd give this plugin max 30 lines of actual code, excluding the plugin registration stuff.

You're limiting the entire plugin for AMXX 1.9+ because of one line of code that can easily be made compatbile with older versions.

You're also limiting your plugin to exactly 3 bots when you can do this the non-hardcoded way and allow for full flexibility.

You have a non-functioning cvar "bs_enable" because you're getting its value in plugin_init(). Cvars are read in plugin_cfg() which is executed after plugin_init().

Apart from that, there are many minor things that can be worked on:

Code:
new bool:bot_on, bot_on2, bot_on3;

Why is just the first variable a boolean?
Why do you even have a separate variable for each bot?

Code:
// Sets bot connection confirmations off on each map change bot_on = false; bot_on2 = false; bot_on3 = false;

Since when do variables get saved on map change?

Code:
// Checks and connects bots every 60s if requirements are met     if(get_pcvar_num(g_pEnable)) {         set_task(60.0, "AddBots", 0, _, _, "b");     }

Why 60 seconds and not when a player joins/leaves?

Code:
new szBotName[35]

The maximum name length is 32.
Also, why the separate variables when you can just override the first one?

Code:
server_cmd("kick ^"%s^"", szBotName);

Why would you use kick with the name instead of the bot's id?
What happens if a player decides to use one of the bots' names?

Code:
if(get_playersnum(1) < get_pcvar_num(g_pMaxPlayers) && !bot_on)

"bot_on" should be checked first. There's no reason to call any natives if the variable didn't pass the logical test.

Code:
// Adds up to 3 bots if they're not connected and there's less players than the threshold public AddBots() {     if(get_playersnum(1) < get_pcvar_num(g_pMaxPlayers) && !bot_on) {         AddBot();         if(get_playersnum(1) < get_pcvar_num(g_pMaxPlayers) && !bot_on2) {             AddBot2();             if(get_playersnum(1) < get_pcvar_num(g_pMaxPlayers) && !bot_on3) {                 AddBot3();             }         }     } }

Why the need to keep calling the same function over and over again? You already got the number the first time, just add +1 and reuse it.

Code:
new szMsg[128]; dllfunc(DLLFunc_ClientConnect, id, szBotName, "127.0.0.1", szMsg);

You're not using the message, why get it in the first place?

And last, but not least, what happened to the author's name? If you're going to use someone else's code you should give credits for it.
__________________

Last edited by OciXCrom; 12-25-2021 at 06:49.
OciXCrom is offline
Send a message via Skype™ to OciXCrom