Raised This Month: $74 Target: $400
 18% 

CSGO - Move all players to spec


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Tibaus
Junior Member
Join Date: Apr 2020
Old 05-31-2020 , 22:05   CSGO - Move all players to spec
Reply With Quote #1

Hi,
I'm writing a menu on sourcepawn which one of the options is moving all players to spectate. How can I do this?
I've been seeing same examples but I can't find one which I can move all players to spectate, only moving one player.


Thanks
Tibaus is offline
mrtn
Junior Member
Join Date: May 2020
Old 06-01-2020 , 05:13   Re: CSGO - Move all players to spec
Reply With Quote #2

To move all players to spectator is as simple as iterating client Ids, checking if they are in the game and not spectating, and moving to spectator with ChangeClientTeam() (CS_SwitchTeam() can only switch a client to CT or T):

PHP Code:
for (int clientId 1clientId <= MaxClientsclientId++) {
    if (
IsClientInGame(clientId) && !IsClientObserver(clientId)) {
        
ChangeClientTeam(clientIdCS_TEAM_SPECTATOR);
    }

mrtn is offline
Tibaus
Junior Member
Join Date: Apr 2020
Old 06-01-2020 , 23:30   Re: CSGO - Move all players to spec
Reply With Quote #3

Quote:
Originally Posted by mrtn View Post
To move all players to spectator is as simple as iterating client Ids, checking if they are in the game and not spectating, and moving to spectator with ChangeClientTeam() (CS_SwitchTeam() can only switch a client to CT or T):

PHP Code:
for (int clientId 1clientId <= MaxClientsclientId++) {
    if (
IsClientInGame(clientId) && !IsClientObserver(clientId)) {
        
ChangeClientTeam(clientIdCS_TEAM_SPECTATOR);
    }


mrtn, Thanks! That Works


Now I need to move a specific player, how can I do that? First I need to show each player in the menu and when one player is selected, move to CT or TR.

Thanks!
Tibaus is offline
Reply


Thread Tools
Display Modes

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 19:34.


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