This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

Preventing someone from joining CT if the ratio is not 3 terrorists to 1 ct


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Terminator1337
Junior Member
Join Date: Jan 2015
Old 02-23-2015 , 11:23   Preventing someone from joining CT if the ratio is not 3 terrorists to 1 ct
Reply With Quote #1

Hi there, I wrote this code:

Code:
HookEvent("player_team", Player_SwitchTeam, EventHookMode_Pre);

public Action:Player_SwitchTeam(Handle:event, const String:name[], bool:dontBroadcast)
{
	new newTeam = GetEventInt(event, "team");
	new oldTeam = GetEventInt(event, "oldteam");
	
	new client = GetClientOfUserId(GetEventInt(event, "userid"));
	
	if ((client < 1) || !IsClientInGame(client) || IsFakeClient(client))
		return Plugin_Handled;
		
	//Remove the warden if he switches back to T
	if (client == wardenIndex && newTeam == CS_TEAM_T)
		RemoveWarden();
		
	//Trying to switch to CT?
	if (newTeam == CS_TEAM_CT && oldTeam != CS_TEAM_CT)
	{
		new countTs = 0;
		new countCTs = 0;
		
		//Count players
		for (new i = 1; i <= MAXPLAYERS; i++)
		{
			if (IsClientInGame(i))
			{
				if (GetClientTeam(i) == CS_TEAM_T)
					countTs++;
				 
				else if (GetClientTeam(i) == CS_TEAM_CT)
					countCTs++;
			}      
		}
		
		new teamRatio = 3;
		
		//Is the ratio going to be unbalanced?
		if ((countCTs < (countTs / teamRatio)) || (countCTs <= 0))
			return Plugin_Continue;
			
		else
		{
			EmitSoundToClient(client, RELATIVE_SOUND_PATH_ERROR);
			
			CPrintToChat(client, "{green}[PG]{default} You cannot be a guard as the ratio is not 3:1!");
			
			return Plugin_Handled;
		}
	}
	
	return Plugin_Continue;
}
However, nothing happens unfortunately. If anyone could help it'd be great, thanks.
Terminator1337 is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 02-23-2015 , 18:17   Re: Preventing someone from joining CT if the ratio is not 3 terrorists to 1 ct
Reply With Quote #2

use AddCommandListener(Command_JoinTeam, "jointeam")
8guawong 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 23:55.


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