Raised This Month: $51 Target: $400
 12% 

Help Randomize Plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
WhiteFang1319
Senior Member
Join Date: Jan 2017
Old 05-27-2017 , 02:29   Help Randomize Plugin
Reply With Quote #1

Here's some code I have from Amx Match Deluxe Plugin. The function randomizes teams. But it doesn't take spectators into account. How do I make it work so that both people in teams and spectators are randomized.. ?
Would it work if I change if(is_user_connected(player) && (cs_get_user_team(player) != CS_TEAM_SPECTATOR )) ->
if(is_user_connected(player) && (cs_get_user_team(player) == CS_TEAM_SPECTATOR ))

Code:
public randomize_teams(id, level)
{
	// Declare variables	
	new num
	new players[32]
	
	new playersT_pos
	new playersCT_pos
	
	new playersT[32]
	new playersCT[32]
	
	new random_team
	
	new difference
	
	new player
	
	
	if (!access(id,level))
	{
		console_print(id,"* [AMX MATCH] %L", id, "COMMAND_NO_AUTH")
		console_print(id,"* %L", id, "COMMAND_NO_AUTH")
		
		return PLUGIN_HANDLED
	}

	ColorChat(0,TEAM_COLOR,"^4 [AMX MATCH] ^3 %L", LANG_PLAYER, "RANDOMIZING_TEAMS")

	// Set the arrays
	get_players(players, num)
	for(new i = 0; i < num; i++)
	{
		player = players[i]
		
		if(is_user_connected(player) && (cs_get_user_team(player) != CS_TEAM_SPECTATOR ))
		{
			random_team = random_num(1,2)
			
			if(random_team == 1) 
			{
				playersT[playersT_pos++] = player
			}
			else 
			{
				playersCT[playersCT_pos++] = player
			}
		}
	}
	
	difference = abs(playersCT_pos - playersT_pos)
	
	if(difference > 1)
	{
		if(playersCT_pos > playersT_pos)
		{
			for(new i = playersCT_pos; (i >= 0) && (playersCT_pos > playersT_pos); i--)
			{
				playersT[playersT_pos++] = playersCT[--playersCT_pos]
			}
		}
		else
		{
			for(new i = playersT_pos; (i >= 0) && (playersT_pos > playersCT_pos); i--)
			{
				playersCT[playersCT_pos++] = playersT[--playersT_pos]
			}
		}
	}
	
	
	// Set T team
	for(new i = 0; i < playersT_pos; i++)
	{
		cs_set_user_team(playersT[i], CS_TEAM_T)
		
		ColorChat(playersT[i],TEAM_COLOR,"^4 [AMX MATCH] ^3 %L", playersT[i], "NOW_ON_T")
	}	

	
	// Set CT team
	for(new i = 0; i < playersCT_pos; i++)
	{	
		cs_set_user_team(playersCT[i], CS_TEAM_CT)
		
		ColorChat(playersCT[i],TEAM_COLOR,"^4 [AMX MATCH] ^3 %L", playersCT[i], "NOW_ON_CT")
	}
	
	
	misc_restart_round("2")
	
	
	return PLUGIN_CONTINUE
}

Last edited by WhiteFang1319; 05-27-2017 at 02:33.
WhiteFang1319 is offline
DjSoftero
Veteran Member
Join Date: Nov 2014
Location: Lithuania
Old 05-27-2017 , 04:19   Re: Help Randomize Plugin
Reply With Quote #2

you have to entirely remove CS_TEAM_SPECTATOR check.
PHP Code:
//this
if(is_user_connected(player) && (cs_get_user_team(player) != CS_TEAM_SPECTATOR )
//into this
if(is_user_connected(player)) 
if you would have done:
PHP Code:
if(is_user_connected(player) && (cs_get_user_team(player) == CS_TEAM_SPECTATOR 
it would have only taken spectator players and randomized them

Last edited by DjSoftero; 05-27-2017 at 04:20. Reason: additional info
DjSoftero is offline
WhiteFang1319
Senior Member
Join Date: Jan 2017
Old 05-27-2017 , 05:32   Re: Help Randomize Plugin
Reply With Quote #3

Quote:
Originally Posted by DjSoftero View Post
you have to entirely remove CS_TEAM_SPECTATOR check.
PHP Code:
//this
if(is_user_connected(player) && (cs_get_user_team(player) != CS_TEAM_SPECTATOR )
//into this
if(is_user_connected(player)) 
if you would have done:
PHP Code:
if(is_user_connected(player) && (cs_get_user_team(player) == CS_TEAM_SPECTATOR 
it would have only taken spectator players and randomized them
Thanks
WhiteFang1319 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 09:25.


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