View Single Post
lexzor
Veteran Member
Join Date: Nov 2020
Old 07-02-2022 , 18:49   Re: /spec and /back plugin
Reply With Quote #9

Quote:
Originally Posted by Napoleon_be View Post
You should store the current team in csLastTeam[] before switching the player to spectator.
you are right

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

#define ADMIN_FLAG "c"
#define CHAT_PREFIX "^4[^3TAG^4]^1"

new CsTeams:csLastTeam[MAX_PLAYERS 1];

public 
plugin_init()
{
    
register_plugin("Back""1.0""AM");

    
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(!
isok(id))
        return 
PLUGIN_HANDLED;

    new 
CsTeams:csTeam cs_get_user_team(id);

    if(
csTeam != CS_TEAM_SPECTATOR)
    {
        
csLastTeam[id] = csTeam;
        
cs_set_user_team(idCS_TEAM_SPECTATOR);
        
        if(
is_user_alive(id))
            
user_silentkill(id1);

        
client_print_color(idprint_team_default"%s You have been moved to^4 Spectator^1 team"CHAT_PREFIX);
    }
    else 
client_print_color(idprint_team_default"%s You are already in^4 Spectator^1 team!");

    return 
PLUGIN_HANDLED;
}

public 
back_transfer(id)
{
    if(!
isok(id))
        return 
PLUGIN_HANDLED;

    if(
cs_get_user_team(id) == CS_TEAM_SPECTATOR)
    {
        
cs_set_user_team(idcsLastTeam[id]);
        
client_print_color(idprint_team_default"%s You have been moved to^4 %s^1 team"CHAT_PREFIXcsLastTeam[id] == CS_TEAM_T "Terrorist" "Counter-Terrorist");
    }
    else 
client_print_color(idprint_team_default"%s You must be in^4 Spectator^1 team!");

    return 
PLUGIN_HANDLED;


stock bool:isok(id)
{
    if(!(
get_user_flags(id) & read_flags(ADMIN_FLAG)))
        return 
true;
    
    
client_print_color(idprint_team_default"%s You must be an^4 admin^1 to use this command!"CHAT_PREFIX);
    return 
false

/back command will move back into your last team before using /spec command. you can change admin acces and tag chat

Last edited by lexzor; 07-02-2022 at 18:50.
lexzor is offline