Raised This Month: $ Target: $400
 0% 

Get a random player in each team.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
danonix
Senior Member
Join Date: Dec 2012
Old 01-07-2014 , 13:26   Get a random player in each team.
Reply With Quote #1

Hello guys,

I would like to ask you for help, because I don't know how to get a random player in each team.
I have got this code
Code:
public Losuj_Kapitanow(id){
new players[32],numCT, numTT
if(!Kapitan_CTbool){
    get_players(players, numCT, "che", "CT")
    Kapitan_CT[id]=players[random(numCT)]
}
if(!Kapitan_TTbool){
    get_players(players, numTT, "che", "TERRORIST")
    Kapitan_TT[id]=players[random(numTT)]
}
CountDown()
if(Czas_Odliczania == 0){
    if(is_user_connected(id) && get_user_team(id) == 1 && !Kapitan_TTbool){
        set_hudmessage(255, 0, 0, -1.0, 0.01)
        show_hudmessage(id, "Wybrano Kapitanow!^nKapitan TT: %s", Kapitan_TT[id])
        Kapitan_TTbool=true;
    }
    if(is_user_connected(id) && get_user_team(id) == 2 && !Kapitan_CTbool){
        set_hudmessage(0, 255, 0, -1.0, 0.01)
        show_hudmessage(id, "Wybrano Kapitanow!^nKapitan CT: %s", Kapitan_CT[id])
        Kapitan_CTbool=true;
    }
}
}
And it doesn't work and gives me an error.
Code:
L 01/07/2014 - 19:24:24: Start of error session.
L 01/07/2014 - 19:24:24: Info (map "de_dust2") (file "addons/amxmodx/logs/error_20140107.log")
L 01/07/2014 - 19:24:24: [AMXX] Displaying debug trace (plugin "kapitanowie.amxx")
L 01/07/2014 - 19:24:24: [AMXX] Run time error 4: index out of bounds 
L 01/07/2014 - 19:24:24: [AMXX]    [0] kapitanowie.sma::Losuj_Kapitanow (line 52)
It doesn't get a random player.
52 line is a "Kapitan_CT[id]=players[random(numCT)]"

Thanks for any help.
danonix is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 01-07-2014 , 16:08   Re: Get a random player in each team.
Reply With Quote #2

how is this Losuj_Kapitanow() called?
jimaway is offline
danonix
Senior Member
Join Date: Dec 2012
Old 01-08-2014 , 08:32   Re: Get a random player in each team.
Reply With Quote #3

Quote:
Originally Posted by jimaway View Post
how is this Losuj_Kapitanow() called?
It is called by a hltv event.

@11922911
Thanks, done

Code:
public Losuj_Kapitanow(id){
    if(playersInTeam(CS_TEAM_CT) >= 1 && playersInTeam(CS_TEAM_T) >= 1){
        new players[32],numCT, numTT
        if(!Kapitan_CTbool){
            get_players(players, numCT, "che", "CT")
            Kapitan_CT[id]=players[random(numCT)]
        }
        if(!Kapitan_TTbool){
            get_players(players, numTT, "che", "TERRORIST")
            Kapitan_TT[id]=players[random(numTT)]
        }
        CountDown()
        if(Czas_Odliczania == 0){
            if(is_user_connected(id) && get_user_team(id) == 1 && !Kapitan_TTbool){
                set_hudmessage(255, 0, 0, -1.0, 0.01)
                show_hudmessage(id, "Wybrano Kapitanow!^nKapitan TT: %s", Kapitan_TT[id])
                Kapitan_TTbool=true;
            }
            if(is_user_connected(id) && get_user_team(id) == 2 && !Kapitan_CTbool){
                set_hudmessage(0, 255, 0, -1.0, 0.01)
                show_hudmessage(id, "Wybrano Kapitanow!^nKapitan CT: %s", Kapitan_CT[id])
                Kapitan_CTbool=true;
            }
        }
    }
}




stock playersInTeam(CsTeams:team){
    new iIle = 0, i;
    for( i = 1 ; i <= get_maxplayers() ; i++ ){ // musi być <=
        if( !is_user_connected( i ) )
            continue;
        
        if(cs_get_user_team(i) == team)
            iIle++;
    }
    return iIle;
}

Last edited by danonix; 01-08-2014 at 08:39.
danonix is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 01-08-2014 , 11:46   Re: Get a random player in each team.
Reply With Quote #4

Quote:
Originally Posted by danonix View Post
It is called by a hltv event.

@11922911
Thanks, done

Code:
public Losuj_Kapitanow(id){
    if(playersInTeam(CS_TEAM_CT) >= 1 && playersInTeam(CS_TEAM_T) >= 1){
        new players[32],numCT, numTT
        if(!Kapitan_CTbool){
            get_players(players, numCT, "che", "CT")
            Kapitan_CT[id]=players[random(numCT)]
        }
        if(!Kapitan_TTbool){
            get_players(players, numTT, "che", "TERRORIST")
            Kapitan_TT[id]=players[random(numTT)]
        }
        CountDown()
        if(Czas_Odliczania == 0){
            if(is_user_connected(id) && get_user_team(id) == 1 && !Kapitan_TTbool){
                set_hudmessage(255, 0, 0, -1.0, 0.01)
                show_hudmessage(id, "Wybrano Kapitanow!^nKapitan TT: %s", Kapitan_TT[id])
                Kapitan_TTbool=true;
            }
            if(is_user_connected(id) && get_user_team(id) == 2 && !Kapitan_CTbool){
                set_hudmessage(0, 255, 0, -1.0, 0.01)
                show_hudmessage(id, "Wybrano Kapitanow!^nKapitan CT: %s", Kapitan_CT[id])
                Kapitan_CTbool=true;
            }
        }
    }
}




stock playersInTeam(CsTeams:team){
    new iIle = 0, i;
    for( i = 1 ; i <= get_maxplayers() ; i++ ){ // musi być <=
        if( !is_user_connected( i ) )
            continue;
        
        if(cs_get_user_team(i) == team)
            iIle++;
    }
    return iIle;
}
well there's your problem, hltv event doesen't pass any variable to the function
jimaway is offline
11922911
Senior Member
Join Date: Dec 2011
Location: Yuen Long Country
Old 01-07-2014 , 20:30   Re: Get a random player in each team.
Reply With Quote #5

You also have to check if there is no player in each team.
__________________
youtube:
@holla16
11922911 is offline
danonix
Senior Member
Join Date: Dec 2012
Old 01-08-2014 , 11:48   Re: Get a random player in each team.
Reply With Quote #6

I didn't know about that, thanks! So I should use this event, right?
Code:
register_logevent("Poczatek_Rundy", 2, "1=Round_Start")
danonix is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 01-08-2014 , 11:49   Re: Get a random player in each team.
Reply With Quote #7

that doesn't pass anything neither
jimaway is offline
danonix
Senior Member
Join Date: Dec 2012
Old 01-08-2014 , 12:00   Re: Get a random player in each team.
Reply With Quote #8

So Jimaway, could you tell me please, how I could do it? I was sitting in chair for ten minutes, but I have 0 ideas about that.

Last edited by danonix; 01-08-2014 at 12:06.
danonix is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 01-08-2014 , 12:04   Re: Get a random player in each team.
Reply With Quote #9

Code:
new Kapitan_CT, Kapitan_TT;
public Losuj_Kapitanow()
{
    new players[32],numCT, numTT
    if(!Kapitan_CTbool)
    {
        get_players(players, numCT, "che", "CT")
        Kapitan_CT=players[random(numCT)]
    }
    if(!Kapitan_TTbool)
    {
        get_players(players, numTT, "che", "TERRORIST")
        Kapitan_TT=players[random(numTT)]
    }
    CountDown()
    if(Czas_Odliczania == 0)
    {
        if(is_user_connected(Kapitan_TT) && get_user_team(Kapitan_TT) == 1 && !Kapitan_TTbool)
        {
            set_hudmessage(255, 0, 0, -1.0, 0.01)
            show_hudmessage(Kapitan_TT, "Wybrano Kapitanow!^nKapitan TT: %s", Kapitan_TT)
            Kapitan_TTbool=true;
        }
        if(is_user_connected(Kapitan_CT) && get_user_team(Kapitan_CT) == 2 && !Kapitan_CTbool)
        {
            set_hudmessage(0, 255, 0, -1.0, 0.01)
            show_hudmessage(Kapitan_CT, "Wybrano Kapitanow!^nKapitan CT: %s", Kapitan_CT)
            Kapitan_CTbool=true;
        }
    }
}
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).

Last edited by YamiKaitou; 01-08-2014 at 12:04.
YamiKaitou is offline
danonix
Senior Member
Join Date: Dec 2012
Old 01-08-2014 , 12:08   Re: Get a random player in each team.
Reply With Quote #10

Alright, now I know how I will do it to print only for teammates.

Thank you Guys, you are great

@Btw

Arrays Kapitan_TT and Kapitan_CT doesnt have to be indexed?

Last edited by danonix; 01-08-2014 at 12:12.
danonix is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 10:05.


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