View Single Post
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 07-02-2022 , 17:35   Re: /spec and /back plugin
Reply With Quote #8

Quote:
Originally Posted by lexzor View Post
PHP Code:
#include <amxmodx>
#include <cstrike>

new CsTeams:csLastTeam[MAX_PLAYERS 1];

public 
plugin_init() {
    
register_clcmd("say /spec","spec_transfer");
    
register_clcmd("say_team /spec","spec_transfer");
    
register_clcmd("say /back","back_transfer");
    
register_clcmd("say_team /back","back_transfer");
}

public 
client_connect(id) { csLastTeam[id] = CS_TEAM_UNASSIGNED; }

public 
spec_transfer(id)
{
    if(
cs_get_user_team(id) != CS_TEAM_SPECTATOR)
    {
        
cs_set_user_team(idCS_TEAM_SPECTATOR);
        
        if(
is_user_alive(id))
            
user_silentkill(id1);
        
        
csLastTeam[id] = cs_get_user_team(id);
    }
    else
    {
        
client_print(id,print_chat,"You are already on spectator");
    }
}

public 
back_transfer(id)
{
    if(
cs_get_user_team(id) == CS_TEAM_SPECTATOR)
    {
        
cs_set_user_team(idcsLastTeam[id]);
    }
    else
    {
        
client_print(id,print_chat,"you are not in spectator");
    }

You should store the current team in csLastTeam[] before switching the player to spectator.
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be