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

player SwitchTeam


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
XHeadHunterX
Member
Join Date: Aug 2013
Old 08-17-2013 , 22:36   player SwitchTeam
Reply With Quote #1

Why is this not working? Is it because the round end does not apply to specific players thus making the GetClientOfUserId impossible?

PHP Code:
public Action:OnRoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
client GetClientOfUserId(GetEventInt(event"userid"));    

    if(
GetClientTeam(client) == CS_TEAM_T && IsFakeClient(client) == false)
    
CS_SwitchTeam(client3)

XHeadHunterX is offline
Chrisber
AlliedModders Donor
Join Date: Jul 2007
Location: localhost
Old 08-18-2013 , 05:01   Re: player SwitchTeam
Reply With Quote #2

round_event is a general event which only fires once per round, not per player.
You have to make a loop trough all players.
Chrisber is offline
Eden.Campo
Member
Join Date: Mar 2013
Old 08-20-2013 , 01:47   Re: player SwitchTeam
Reply With Quote #3

Code:
#include <sourcemod>
#include <sdktools>

public OnPluginStart()
{
        // Hook the Event, make it a PRE event, to not cause any probs on round start
	HookEvent("round_end", OnRoundEnd, EventHookMode_Pre);
}

public Action:OnRoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
{
        // Loop all the clients in server
	for(new i = 1; i <= MaxClients; i++)
	{
                // Skip invalid clients
		if(!IsClientInGame(i) || IsFakeClient(i))
		continue;
		
                // Change client's team if T 
		if(GetClientTeam(i) == CS_TEAM_T)
		ChangeClientTeam(i, 3);
	}
}

Last edited by Eden.Campo; 08-20-2013 at 01:49.
Eden.Campo is offline
XHeadHunterX
Member
Join Date: Aug 2013
Old 08-23-2013 , 13:04   Re: player SwitchTeam
Reply With Quote #4

Thanks!

Last edited by XHeadHunterX; 08-23-2013 at 15:06.
XHeadHunterX is offline
XHeadHunterX
Member
Join Date: Aug 2013
Old 08-23-2013 , 14:20   Re: player SwitchTeam
Reply With Quote #5

snip

Last edited by XHeadHunterX; 08-23-2013 at 15:03.
XHeadHunterX is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 08-23-2013 , 15:08   Re: player SwitchTeam
Reply With Quote #6

I don't think so, at least from what bail has previously said.

Also change i < MaxClients to i <= MaxClients.
__________________
11530 is offline
XHeadHunterX
Member
Join Date: Aug 2013
Old 08-23-2013 , 15:48   Re: player SwitchTeam
Reply With Quote #7

Is there a way to switch the player right before the round starts? If I switch the player on the round start event (prehooked), it works but the player still spawns at the last team location.
XHeadHunterX is offline
TnTSCS
AlliedModders Donor
Join Date: Oct 2010
Location: Undisclosed...
Old 08-23-2013 , 15:51   Re: player SwitchTeam
Reply With Quote #8

after you switch the players team, do a respawn. CS_RespawnPlayer
__________________
View my Plugins | Donate
TnTSCS is offline
XHeadHunterX
Member
Join Date: Aug 2013
Old 08-23-2013 , 16:10   Re: player SwitchTeam
Reply With Quote #9

Quote:
Originally Posted by TnTSCS View Post
after you switch the players team, do a respawn. CS_RespawnPlayer
Yea I tried it and it works but it's kind of weird because you hear the sound "hey what are you doing" since it counts as a suicide and it also removes a kill point on the scoreboard, I'm not sure if there is another way to avoid that

Last edited by XHeadHunterX; 08-23-2013 at 16:13.
XHeadHunterX is offline
htcarnage
Senior Member
Join Date: Oct 2009
Old 08-23-2013 , 17:52   Re: player SwitchTeam
Reply With Quote #10

Create a timer to switch the team at the end of the round + whatever the round restart delay is.

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

new Handle:Restart_Delay;

public 
OnPluginStart()
{
    
HookEvent("round_end"Event_Round);
    
Restart_Delay FindConVar("mp_round_restart_delay");
}

public 
Action:Event_Round(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
Float:delay GetConVarFloat(Restart_Delay) - 0.1
    
for(new 1<= MaxClientsi++)
    {
        
CreateTimer(delayChangeTeamsGetClientUserId(i));
    }
}

public 
Action:ChangeTeams(Handle:timerany:userid)
{
    new 
client GetClientOfUserId(userid);
    if(
client 0)
    {
        if(
GetClientTeam(client) == 2)
            
CS_SwitchTeam(client3);
        else if(
GetClientTeam(client == 3)
            
CS_SwitchTeam(client2)
    }

Now that code would switch every client's team every round, so you would have to figure some way to single out the clients whose team you would want to switch..
__________________

Last edited by htcarnage; 08-23-2013 at 17:53.
htcarnage 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 03:43.


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