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

Solved Swapmeroundend


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Zyten
Senior Member
Join Date: Jan 2018
Old 06-20-2018 , 14:34   Swapmeroundend
Reply With Quote #1

Looking for plugin to swap from ct to t after round end by command !swapmeroundend

Last edited by Zyten; 06-21-2018 at 09:41.
Zyten is offline
mug1wara
AlliedModders Donor
Join Date: Jun 2018
Old 06-20-2018 , 15:32   Re: Swapmeroundend
Reply With Quote #2

If I got this right. When someone types !swapmeroundend, the swap function is enabled. When the round ends and the swap function is enabled, it will switch the player to the opposit team. If the swap function is disabled, it won't switch on round end?
PHP Code:
#include <sourcemod> 

#pragma semicolon 1 

bool g_bAllowed[MAXPLAYERS 1]; 

public 
void OnPluginStart() 

    
HookEvent("round_end"Event_End); 
     
    
RegConsoleCmd("sm_swapmeroundend"Cmd_Swap); 


public 
void OnClientDisconnect(int iClient)
{
    
g_bAllowed[iClient] = false;
}

public 
Action Event_End(Event hEvent, const char[] sNamebool bDontBroadcast

    for (
int i 1<= MaxClientsi++)
    {
        if (
IsClientInGame(i))
        {
            if (
g_bAllowed[i])
            {
                if (
GetClientTeam(i) == 3)
                {
                    
ChangeClientTeam(i2);
                }
                
                
g_bAllowed[i] = false;
            }
        }
    }


public 
Action Cmd_Swap(int iClientint iArgs

    if (
g_bAllowed[iClient]) 
        
g_bAllowed[iClient] = false
         
    else 
        
g_bAllowed[iClient] = true

    return 
Plugin_Handled


Last edited by mug1wara; 06-21-2018 at 10:02.
mug1wara is offline
Rohanlogs
Senior Member
Join Date: Nov 2015
Old 06-20-2018 , 15:52   Re: Swapmeroundend
Reply With Quote #3

Quote:
Originally Posted by mug1wara View Post
If I got this right. When someone types !swapmeroundend, the swap function is enabled.
Eh, no I'm pretty sure he wants this command to be available in a public server, which means you're going to need to make that bool indexed.
Because that will not work in a mass of people.

Edit: Also because of that, its probably going to swap the whole server.

Edit2: I'm also pretty sure round end fires only once and there is no index passed. You need to make a loop.
__________________

Last edited by Rohanlogs; 06-20-2018 at 15:57.
Rohanlogs is offline
mug1wara
AlliedModders Donor
Join Date: Jun 2018
Old 06-20-2018 , 16:02   Re: Swapmeroundend
Reply With Quote #4

PHP Code:
#include <sourcemod> 

#pragma semicolon 1 

bool g_bAllowed[MAXPLAYERS 1]; 

public 
void OnPluginStart() 

    
HookEvent("round_end"Event_End); 
     
    
RegConsoleCmd("sm_swapmeroundend"Cmd_Swap); 


public 
void OnClientDisconnect(int iClient)
{
    
g_bAllowed[iClient] = false;
}

public 
Action Event_End(Event hEvent, const char[] sNamebool bDontBroadcast

    for (
int i 1<= MaxClientsi++)
        if (
IsClientInGame(i))
            if (
g_bAllowed[i])
                if (
GetClientTeam(i) == 3
                    
ChangeClientTeam(i2);


public 
Action Cmd_Swap(int iClientint iArgs

    if (
g_bAllowed[iClient]) 
        
g_bAllowed[iClient] = false
         
    else 
        
g_bAllowed[iClient] = true

    return 
Plugin_Handled


Last edited by mug1wara; 06-21-2018 at 05:51.
mug1wara is offline
Rohanlogs
Senior Member
Join Date: Nov 2015
Old 06-20-2018 , 16:11   Re: Swapmeroundend
Reply With Quote #5

Quote:
Originally Posted by mug1wara View Post
oh yea, forgot to index the bool xD also looped through clients with the active bool ty
Now when players disconnect and new players connect, some random people will have g_bAllowed true. You need to make sure when they connect/disconnect that its set to false. When you loop through clients and execute functions on them, you need to make sure the client is valid. After that take another look at the posters request.
__________________
Rohanlogs is offline
Rohanlogs
Senior Member
Join Date: Nov 2015
Old 06-20-2018 , 16:37   Re: Swapmeroundend
Reply With Quote #6

Something more like this:

Spoiler
Note that the team index is mod-specific.
This will work for CS:GO which is what the poster is running.
For CS:GO CT is 3 and T = 2.
__________________
Rohanlogs is offline
KlausLaw
AlliedModders Donor
Join Date: Feb 2018
Location: Israel
Old 06-20-2018 , 16:37   Re: Swapmeroundend
Reply With Quote #7

Code:
bool g_getSwapped[MAXPLAYERS + 1];

public void OnPluginStart()
{
	RegConsoleCmd("sm_swapmeroundend", SM_Swapme);
	HookEvent("round_end", Event_Round_End);
}

public OnClientDisconnect(int client)
{
	g_getSwapped[client] = false;
}

public Action SM_Swapme(int client, int args)
{
	if (GetClientTeam(client) == CS_TEAM_T)
	{
		PrintToChat(client, "You can only use this command in the \x04CT\x01 team.");
		return Plugin_Handled;
	}
	g_getSwapped[client] = !g_getSwapped[client];
	PrintToChat(client, "You will now be \x04%s\x01 to team \x04t\x01.", g_getSwapped[client] ? "swapped" : "unswapped");
	return Plugin_Handled;
}

public Action Event_Round_End(Event event, const char[] name, bool dontBroadcast)
{
	for (int i = 1; i <= MaxClients; i++)
	{
		if (!IsClientInGame(i) || !g_getSwapped[i])continue;
		g_getSwapped[i] = false;
		if (GetClientTeam(i) == CS_TEAM_T)continue;
		ChangeClientTeam(i, CS_TEAM_T);		
	}
}
__________________
Taking private requests


Last edited by KlausLaw; 06-20-2018 at 16:48.
KlausLaw is offline
mug1wara
AlliedModders Donor
Join Date: Jun 2018
Old 06-20-2018 , 17:33   Re: Swapmeroundend
Reply With Quote #8

Better using OnClientAuthorized, rather than OnClientPostAdminCheck.

Also @Klaus "g_getSwapped[client] = !g_getSwapped[client];"
Better to check the value of the bool than make it equal to false. Because it will never remain true. If so, why even have a boolean?

This is how I would do it, tested and working well.
PHP Code:
#include <sourcemod> 

#pragma semicolon 1 

bool g_bAllowed[MAXPLAYERS 1]; 

public 
void OnPluginStart() 

    
HookEvent("round_end"Event_End); 
     
    
RegConsoleCmd("sm_swapmeroundend"Cmd_Swap); 


public 
void OnClientDisconnect(int iClient)
{
    
g_bAllowed[iClient] = false;
}

public 
Action Event_End(Event hEvent, const char[] sNamebool bDontBroadcast

    for (
int i 1<= MaxClientsi++)
    {
        if (
IsClientInGame(i))
        {
            if (
g_bAllowed[i])
            {
                if (
GetClientTeam(i) == 3)
                {
                    
ChangeClientTeam(i2);
                }
                
                
g_bAllowed[i] = false;
            }
        }
    }


public 
Action Cmd_Swap(int iClientint iArgs

    if (
g_bAllowed[iClient]) 
        
g_bAllowed[iClient] = false
         
    else 
        
g_bAllowed[iClient] = true

    return 
Plugin_Handled


Last edited by mug1wara; 06-21-2018 at 10:02.
mug1wara is offline
KlausLaw
AlliedModders Donor
Join Date: Feb 2018
Location: Israel
Old 06-20-2018 , 17:54   Re: Swapmeroundend
Reply With Quote #9

Quote:
Originally Posted by mug1wara View Post

Also @Klaus "g_getSwapped[client] = !g_getSwapped[client];"
Better to check the value of the bool than make it equal to false. Because it will never remain true. If so, why even have a boolean?
g_getSwapped[client] = !g_getSwapped[client];
Doesn't change the value to false, it changes the value to the opposite value.
__________________
Taking private requests


Last edited by KlausLaw; 06-20-2018 at 17:57.
KlausLaw is offline
mug1wara
AlliedModders Donor
Join Date: Jun 2018
Old 06-20-2018 , 19:38   Re: Swapmeroundend
Reply With Quote #10

It doesn't really work like that Klaus. Let me explain for you.

PHP Code:
g_bSomething = !g_bSomething/* g_bSomething WILL equal to FALSE if set to true */

if (!g_bSomething){} /* IF the value is FALSE */ 
https://wiki.alliedmods.net/Tags_(Scripting)#Boolean
mug1wara 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:32.


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