View Single Post
Author Message
trzmielu
Member
Join Date: Aug 2016
Old 12-21-2022 , 19:44   [CS:GO] VIP Queue
Reply With Quote #1

Hi, how can I improve the code, to make everything work well?
I want to create VIP Queue plugin, that will check at the round_end event if there's an VIP in spectators, then moves the player with an A flag from spectators to replace a random player from playing teams (randomly pick from T or CT) and then move the random player to spectators and letting him know that the VIP replaced him.

(the feature itself is a inspo from acekill.pl's 5vs5 server^)

This is the code that I have:
Code:
#include <sourcemod>
#include <cstrike>
#include <sdktools>

int playerToSwitch[MAXPLAYERS+1];
int PlayersList;

public void OnPluginStart()
{
	HookEvent("round_end", round_end);
	LoadTranslations("VIP_Queue.phrases");
}

public Action round_end(Event event, const char[] name, bool dontBroadcast) {
	int client = GetClientOfUserId(GetEventInt(event, "userid"));

	//Reset the players list
	PlayersList = 0;
	
	//If there are full teams start checking
	if(GetTeamClientCount(2) + GetTeamClientCount(3) == 10) {
		if(GetClientTeam(client) == 1 && IsPlayerVip(client)) {
			for (int i = 1; i <= MaxClients; i++)
			{
				if(IsValidClient(i)) {
					if (GetClientTeam(i) == 2 || GetClientTeam(i) == 3) {
						//Check if we are not kicking VIP
						if(!IsPlayerVip(i)) {
							playerToSwitch[i] = i;
							PlayersList = PlayersList+i;
						}
					}
				}
			}
		
			int RandomPlayer = GetRandomInt(1, PlayersList);
			int RandomPlayersTeam = GetClientTeam(RandomPlayer);
		
			ChangeClientTeam(playerToSwitch[RandomPlayer], 1);
			ChangeClientTeam(client, RandomPlayersTeam);
			PrintToChat(playerToSwitch[RandomPlayer], " \x10[VIP Queue]\x01 %t", "VIP Took Place");
		}
	}
	
	return Plugin_Handled;
}


stock bool IsPlayerVip(int client) {
	if (CheckCommandAccess(client, "check_vip", ADMFLAG_RESERVATION, false)) return true;
	return false;
}

stock bool IsValidClient(int client) 
{
	if ( !( 1 <= client <= MaxClients ) || !IsClientInGame(client) ) 
		return false; 

	return true; 
}
Thanks for every response!

Last edited by trzmielu; 12-21-2022 at 21:22.
trzmielu is offline