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

[CS:GO] VIP Queue


Post New Thread Reply   
 
Thread Tools Display Modes
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
databomb
Veteran Member
Join Date: Jun 2009
Location: california
Old 12-23-2022 , 23:20   Re: [CS:GO] VIP Queue
Reply With Quote #2

There's still a ways to go here. You may want to consider how you want someone to join the queue. Will it be automatic based on when the VIP joins the server? If it's not automatic then you'll want to consider adding in a command (RegConsoleCmd) so the VIP can join the queue and that's where you'll be doing your check for
Code:
IsPlayerVip(client) && GetClientTeam(client) == CS_TEAM_SPECTATOR
Within your round_end code you'd want to check the size of the queue to see if you want to pull the oldest entry to take some action with swapping players.
__________________

Last edited by databomb; 12-23-2022 at 23:20.
databomb 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 14:47.


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