AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Kick a random bot. (https://forums.alliedmods.net/showthread.php?t=206129)

althor 01-18-2013 20:32

Kick a random bot.
 
Hello everyone. I am trying to kick a bot The first one it finds is fine. It does work how ever. It kicks the bot and If a player try's to connect to the server it wants to kick them no matter how many times they try to connect. Any help would be appreciated.

Here is the code I am using
Code:

public kickrandombot(id)
{
    //bots
    new Players[32]
    new playerCount, userid
    get_players(Players, playerCount, "d")
   
    for (new i=0; i<playerCount; i++)
    {   
        userid = get_user_userid(Players[i])
       
        server_cmd("kick #%d", userid)
        break;
    }
}


fysiks 01-19-2013 01:49

Re: Kick a random bot.
 
I'm not exactly sure about what you are saying but everything looks fine to me. Though, your for loop doesn't really do anything. It's just acting as an if statement:

PHP Code:

if( playerCount )
{
    
server_cmd("kick #%d"get_user_userid(players[0]))



AngeIII 01-19-2013 09:59

Re: Kick a random bot.
 
PHP Code:

if( playerCount )
{
    
server_cmd("kick #%d"get_user_userid(players[random_num(0,playerCount)]))



fysiks 01-19-2013 11:20

Re: Kick a random bot.
 
Quote:

Originally Posted by AngeIII (Post 1876219)
PHP Code:

if( playerCount )
{
    
server_cmd("kick #%d"get_user_userid(players[random_num(0,playerCount)]))



That is not correct. You are allowing for the possibility of players[playerCount] which is not a valid player returned by get_players(). You should use random(playerCount) which is better than random_num(0, playerCount-1).

althor 01-20-2013 10:33

Re: Kick a random bot.
 
Thanks guys for the comments.
I have tried almost everything I could think of.
It always done the same thing.
It "works" but when a player tried to connect. Right after kicking the first bot.
It would kick the "first" connecting player. Some players could get in. Some couldn't.

I was going by the wiki here.
http://www.amxmodx.org/doc/index.htm...et_players.htm

As fysiks pointed out. It should of worked and "did".
I even added a side by side loop to make sure it wasn't a actual player being kicked.
Added is_user_connecting and is_user_connected.

From the loop. Like it was counting the player connecting for a bot. Extremely weird.
Finally I had enough, So I made this in foxbot's source.

PHP Code:

kickrandombot()
{
    
server_cmd("bot kickrandombot")


Here is an alternative I tried.
PHP Code:

public kickrandombot(id)
{
    new 
Players[32]
    new 
playerCountiplayer
    get_players
(PlayersplayerCount"d")
    
    for (
i=0i<playerCounti++)
    {
        
player Players[i]
        if(
is_user_bot(player) && !is_user_connecting(player) && is_user_connected(player)) 
        {
            
server_cmd("kick #%d"player)
            break;
        }
    }


And another,
PHP Code:

public kickrandombot(id)
{
    new 
Players[32]
    new 
playerCount
    get_players
(PlayersplayerCount"d")

    if(
playerCount 0)
        
server_cmd("kick #%d"get_user_userid(players[random_num(1,playerCount)]))


Thank you everyone for your suggestions.
Althor

AngeIII 01-20-2013 10:52

Re: Kick a random bot.
 
get_user_userid(players[random_num(1,playerCount)]))
use fysiks method
get_user_userid(players[random(playerCount)]))

fysiks 01-20-2013 13:41

Re: Kick a random bot.
 
Attach the full plugin because what you are describing cannot be happening based on the code that you have shown.


All times are GMT -4. The time now is 13:31.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.