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

[CS:GO] Auto assign plugin + other features


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Obyboby
Veteran Member
Join Date: Sep 2013
Old 07-05-2018 , 08:23   [CS:GO] Auto assign plugin + other features
Reply With Quote #1

Hello,

I would like to have a standalone plugin that allows me to achieve the following results:

- Players can only auto assign upon joining
- If a player is moved to spect by another even (afk manager, admin action, etc), they can only join the team they were in before they got moved
- The plugin should keep track of half time etc, so if I'm a terrorist, and I go afk, and then I want to join back, but in the meantime the teams have been switched, the plugin should assign me to counter terrorists instead
- If a player reconnects, they should be assigned to their previous team

To put it simple, there must be NO WAY to choose a team, a player must be randomly assigned to a team when they join and the plugin must ensure that they cannot bypass this limit. Some people are currently bypassing my plugins by retrying, or some of them cannot join back if they are moved to spect... it's a bit of a mess. A single plugin to take care of everything would be AWESOME.
Thanks!

Btw I already tried Team Change Unlimited but I'm having a couple issues with it (people sometimes cannot join teams, etc)

__________________
Obyboby is offline
LenHard
Senior Member
Join Date: Jan 2016
Old 07-07-2018 , 19:59   Re: [CS:GO] Auto assign plugin + other features
Reply With Quote #2

PHP Code:
#include <sourcemod>
#include <clientprefs>

#pragma semicolon 1
#pragma newdecls required

bool gB_Switch;

int gI_Team[MAXPLAYERS 1];
int gI_Game;

Handle gH_TeamsCookie;

public 
void OnPluginStart()
{
    
gH_TeamsCookie RegClientCookie("team_index""Saves the team index"CookieAccess_Private);
    
    
HookEvent("announce_phase_end"Event_SwitchTeamsEventHookMode_Post);
    
HookEvent("player_activate"Event_PlayerActiviateEventHookMode_Post);
    
    
AddCommandListener(CL_JoinTeam"jointeam");
}

public 
void OnMapStart() 
{
    if (
gI_Game 100)
        
gI_Game 0;
    else
        ++
gI_Game;    
    
gB_Switch false;
}

public 
void OnClientConnected(int client)
{
    if (!
IsFakeClient(client))
        
gI_Team[client] = 0;
}

public 
void OnClientCookiesCached(int client)
{
    if (
IsFakeClient(client))
        return;
    
    
char[] sValue = new char[10];
    
GetClientCookie(clientgH_TeamsCookiesValue10);
    
    if (
sValue[0] != '\0')
    {
        
char[][] sBuffer = new char[3][10];
        
ExplodeString(sValue";"sBuffer310);
        
        if (
StringToInt(sBuffer[1]) != gI_Game)
            return;
        
        if (
StringToInt(sBuffer[2]) != view_as<int>(gB_Switch))
            
gI_Team[client] = StringToInt(sBuffer[0]) == 23:2;
        else
            
gI_Team[client] = StringToInt(sBuffer[0]);
    }
}

public 
void OnClientDisconnect(int client)
{
    if (!
IsFakeClient(client))
    {
        
char[] sValue = new char[10];
        
FormatEx(sValue10"%i;%i;%i"gI_Team[client], gI_Gameview_as<int>(gB_Switch));
        
SetClientCookie(clientgH_TeamsCookiesValue);
    }
}

public 
void Event_SwitchTeams(Event hEvent, const char[] sEventNamebool bDontBroadcast)
{
    
gB_Switch = !gB_Switch;
    
    for (
int i 1<= MaxClients; ++i)
        if (
IsClientInGame(i))
            
gI_Team[i] = gI_Team[i] == 32:3;
}

public 
void Event_PlayerActiviate(Event hEvent, const char[] sEventNamebool bDontBroadcast)
{
    
CreateTimer(0.3Timer_ActivatehEvent.GetInt("userid"), TIMER_REPEAT);
}

public 
Action Timer_Activate(Handle hTimerany iUserid)
{
    
int client GetClientOfUserId(iUserid);
    
    if (
client <= MaxClients && IsClientInGame(client)) 
    {
        if (
AreClientCookiesCached(client))
        {
            if (
gI_Team[client] < 2)
                
gI_Team[client] = GetRandomInt(23);
            
ChangeClientTeam(clientgI_Team[client]);
            return 
Plugin_Stop;
        }
        else return 
Plugin_Continue;
    }
    else return 
Plugin_Stop;
}

public 
Action CL_JoinTeam(int client, const char[] sCmdint args)
{
    if (
client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 1
    {
        if (
gI_Team[client] < 2)
            
gI_Team[client] = GetRandomInt(23);
        
ChangeClientTeam(clientgI_Team[client]);
    }
    return 
Plugin_Handled;

Try this, tell me if I messed up somewhere (assuming it works) [Untested]
__________________

Last edited by LenHard; 07-07-2018 at 20:02.
LenHard is offline
Obyboby
Veteran Member
Join Date: Sep 2013
Old 07-08-2018 , 07:02   Re: [CS:GO] Auto assign plugin + other features
Reply With Quote #3

Quote:
Originally Posted by LenHard View Post
PHP Code:
#include <sourcemod>
#include <clientprefs>

#pragma semicolon 1
#pragma newdecls required

bool gB_Switch;

int gI_Team[MAXPLAYERS 1];
int gI_Game;

Handle gH_TeamsCookie;

public 
void OnPluginStart()
{
    
gH_TeamsCookie RegClientCookie("team_index""Saves the team index"CookieAccess_Private);
    
    
HookEvent("announce_phase_end"Event_SwitchTeamsEventHookMode_Post);
    
HookEvent("player_activate"Event_PlayerActiviateEventHookMode_Post);
    
    
AddCommandListener(CL_JoinTeam"jointeam");
}

public 
void OnMapStart() 
{
    if (
gI_Game 100)
        
gI_Game 0;
    else
        ++
gI_Game;    
    
gB_Switch false;
}

public 
void OnClientConnected(int client)
{
    if (!
IsFakeClient(client))
        
gI_Team[client] = 0;
}

public 
void OnClientCookiesCached(int client)
{
    if (
IsFakeClient(client))
        return;
    
    
char[] sValue = new char[10];
    
GetClientCookie(clientgH_TeamsCookiesValue10);
    
    if (
sValue[0] != '\0')
    {
        
char[][] sBuffer = new char[3][10];
        
ExplodeString(sValue";"sBuffer310);
        
        if (
StringToInt(sBuffer[1]) != gI_Game)
            return;
        
        if (
StringToInt(sBuffer[2]) != view_as<int>(gB_Switch))
            
gI_Team[client] = StringToInt(sBuffer[0]) == 23:2;
        else
            
gI_Team[client] = StringToInt(sBuffer[0]);
    }
}

public 
void OnClientDisconnect(int client)
{
    if (!
IsFakeClient(client))
    {
        
char[] sValue = new char[10];
        
FormatEx(sValue10"%i;%i;%i"gI_Team[client], gI_Gameview_as<int>(gB_Switch));
        
SetClientCookie(clientgH_TeamsCookiesValue);
    }
}

public 
void Event_SwitchTeams(Event hEvent, const char[] sEventNamebool bDontBroadcast)
{
    
gB_Switch = !gB_Switch;
    
    for (
int i 1<= MaxClients; ++i)
        if (
IsClientInGame(i))
            
gI_Team[i] = gI_Team[i] == 32:3;
}

public 
void Event_PlayerActiviate(Event hEvent, const char[] sEventNamebool bDontBroadcast)
{
    
CreateTimer(0.3Timer_ActivatehEvent.GetInt("userid"), TIMER_REPEAT);
}

public 
Action Timer_Activate(Handle hTimerany iUserid)
{
    
int client GetClientOfUserId(iUserid);
    
    if (
client <= MaxClients && IsClientInGame(client)) 
    {
        if (
AreClientCookiesCached(client))
        {
            if (
gI_Team[client] < 2)
                
gI_Team[client] = GetRandomInt(23);
            
ChangeClientTeam(clientgI_Team[client]);
            return 
Plugin_Stop;
        }
        else return 
Plugin_Continue;
    }
    else return 
Plugin_Stop;
}

public 
Action CL_JoinTeam(int client, const char[] sCmdint args)
{
    if (
client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 1
    {
        if (
gI_Team[client] < 2)
            
gI_Team[client] = GetRandomInt(23);
        
ChangeClientTeam(clientgI_Team[client]);
    }
    return 
Plugin_Handled;

Try this, tell me if I messed up somewhere (assuming it works) [Untested]
Seems like players are spawning on top of each other, even CTs are spawning in terrorists spawn etc xD
__________________
Obyboby 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:08.


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