Raised This Month: $344 Target: $400
 86%   Almost there!

Randomize Teams


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ssproxima
Senior Member
Join Date: Jan 2015
Old 02-09-2021 , 23:27   Randomize Teams
Reply With Quote #1

Hello,

Can any body help me with a plugin in which if an admin types /random the players of both team gets randomly put in both teams and it can only be used one time per map.
ssproxima is offline
raizo11
Senior Member
Join Date: Dec 2013
Old 02-10-2021 , 05:35   Re: Randomize Teams
Reply With Quote #2

Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <cstrike>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "My Computer"

new One_Time = 1;

public plugin_init() {
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	register_clcmd( "say /random","Command_Random" );
}


public Command_Random(id)
{
    new flags = get_user_flags(id)
    
    if(!(flags & ADMIN_KICK))
    {
        client_print(id,print_chat,"You have no access to this command")
        return PLUGIN_HANDLED
    }
    
    if(One_Time == 1)
    {
	
        new num, players[32]
	
        get_players(players,num)
	
        for(new i=0;i<=num;i++)
        {
            if(cs_get_user_team(players[i])==CS_TEAM_SPECTATOR) 
	       continue
		
            new rannum = random_num(1,2)
	    
            if(rannum==1) 
            {
                cs_set_user_team(players[i],CS_TEAM_T)
            }
            else 
            {
                cs_set_user_team(players[i],CS_TEAM_CT)
            }
        }
        client_print(id,print_chat,"You have changed successfully the teams!")
    }
    else
    {
    	client_print(id,print_chat,"Only one time per map")
    }
    One_Time = 0
    
    return PLUGIN_HANDLED
}
__________________

Last edited by raizo11; 02-10-2021 at 20:02.
raizo11 is offline
Send a message via ICQ to raizo11 Send a message via AIM to raizo11 Send a message via MSN to raizo11 Send a message via Yahoo to raizo11 Send a message via Skype™ to raizo11
ssproxima
Senior Member
Join Date: Jan 2015
Old 02-10-2021 , 09:19   Re: Randomize Teams
Reply With Quote #3

Thanks will try it out and give feedback
ssproxima is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 02-10-2021 , 14:28   Re: Randomize Teams
Reply With Quote #4

raizo why're you creating a 33 sized array when 1 boolean variable will just do fine.

also

checking if user is connected is useless since get_players function is guaranteed to return connected players on the runtime.

an addition on creating variables inside a loop is highly not recommended + save your indexed array in an int variable rather than reindexing it everytime.

Code:
        for(new i=0;i<=num;i++)
        {
            if(!is_user_connected(players[i]))
                continue
		
            if(cs_get_user_team(players[i])==CS_TEAM_SPECTATOR) 
	       continue
		
            new rannum = random_num(1,2)
	    
            if(rannum==1) 
            {
                cs_set_user_team(players[i],CS_TEAM_T)
            }
            else 
            {
                cs_set_user_team(players[i],CS_TEAM_CT)
            }
        }
__________________
@Jailbreak Main Mod v2.6.6 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 02-10-2021 at 14:28.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
ssproxima
Senior Member
Join Date: Jan 2015
Old 02-10-2021 , 22:12   Re: Randomize Teams
Reply With Quote #5

The plugin works as expected but I was able to randomize many times in a round of course I tested it with bots and not real players on server. Would it affect?
ssproxima is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 02-11-2021 , 06:33   Re: Randomize Teams
Reply With Quote #6

try this, i didn't test it.

PHP Code:
/* Sublime AMXX Editor v2.2 */

#pragma semicolon 1

#include <amxmodx>
// #include <amxmisc>
#include <cstrike>
// #include <engine>
// #include <fakemeta>
// #include <hamsandwich>
// #include <fun>
// #include <xs>
// #include <sqlx>

#define PLUGIN  "Randomize Teams"
#define VERSION "1.0"
#define AUTHOR  "NapoleoN#"

#if !defined MAX_PLAYERS
    
const MAX_PLAYERS 32;
#endif

new bool:bUsed;

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR);

    
register_clcmd("say /random""randomizeTeams");
}

public 
randomizeTeams(id)
{
    if(
get_user_flags(id) & ADMIN_KICK)
    {
        if(!
bUsed)
        {
            new 
iPlayers[MAX_PLAYERS], iNum;
            
get_players(iPlayersiNum);

            for(new 
iiNumi++)
            {
                
cs_set_user_team(iPlayers[i], CS_TEAM_T);

                if(
iPlayers[1] <= iNum)
                {
                    
cs_set_user_team(iPlayers[1], CS_TEAM_CT);
                }
            }
            
bUsed true;
        }
    }

__________________

Last edited by Napoleon_be; 02-11-2021 at 08:18.
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Natsheh
Veteran Member
Join Date: Sep 2012
Old 02-11-2021 , 07:33   Re: Randomize Teams
Reply With Quote #7

He asked for the command to be used once per map not to be used for each player just once.

Also Napoleon if(iPlayers[i++] the I is post increment so it will return the old value.
__________________
@Jailbreak Main Mod v2.6.6 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 02-11-2021 at 07:35.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 02-11-2021 , 08:14   Re: Randomize Teams
Reply With Quote #8

You're totaly right, updated my code. Should all be fine now.
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Natsheh
Veteran Member
Join Date: Sep 2012
Old 02-11-2021 , 11:24   Re: Randomize Teams
Reply With Quote #9

your method of randomizing is kind incorrect and confusing.

here a simple way.

PHP Code:
public randomizeTeams(id)
{
    if(
get_user_flags(id) & ADMIN_KICK)
    {
        if(!
bUsed)
        {
            new 
iPlayers[MAX_PLAYERS], iNum;
            
get_players(iPlayersiNum);
            if(
iNum <= 1)
            {
                        
client_print(idprint_chat"There must be atleast 2 players to randomize!");
                        return;
            }

            new 
iHalf iNum 2

            
for(new ijplayeriHalfi++)
            {
                    
player iPlayers[(j=random(iNum))];
                    
cs_set_user_team(playerCS_TEAM_CT);
                    
iPlayers[j] = iPlayers[--iNum];
            }

            for(new 
ijplayeriHalfi++)
            {
                    
player iPlayers[(j=random(iNum))];
                    
cs_set_user_team(playerCS_TEAM_T);
                    
iPlayers[j] = iPlayers[--iNum];
            }

            
bUsed true;
        }
    }

__________________
@Jailbreak Main Mod v2.6.6 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 02-11-2021 at 11:26.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 02-12-2021 , 15:57   Re: Randomize Teams
Reply With Quote #10

Was thinking of doing it that way too first, but couldn't really figure out how to and didn't really want to spend too much time testing it.
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Reply


Thread Tools
Display Modes

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 12:25.


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