Checking For Bots


	if string.sub(string.lower(text), 1, 9) == "!kickbots" then
		for _, bot in pairs(player.GetAll()) do
			if bot:IsBot() then
				bot:Kick("Bot Kicked")
			end
		end
		SAMsg({Color(50,150,255), ply:Nick(), color_white, " kicked all bots"})
	return ""
	end

This command works fine but there is one issue, It doesn’t check if any of the players on the server are bots and runs the code anyway, how would I do this?

I don’t understand. If the code works fine what is the problem? What do you mean “it doesn’t check if any of the players on the server are bots and runs the code anyway.”

Is it kicking everyone on the server? That doesn’t sound like the code is running fine. What do you want it to do, and what is it doing instead?

[lua]if #player.GetBots() > 0 then

for _, bot in pairs( player.GetBots() ) do
	bot:Kick( "Bot" )
end

-- send message

else

-- error message?

end[/lua]

It a security mesaure type thing. I need something that contains the code in the if statement which checks if there is a single bot on the server before running the code, if not it returns an error.

[editline]17th November 2014[/editline]

Thank you, wasn’t aware of this function.

Wouldn’t
[lua]ply:SteamID() == “BOT”[/lua]
Solve that issue as an extra if IsBot isn’t working?