View Single Post
DJEarthQuake
Veteran Member
Join Date: Jan 2014
Location: Astral planes
Old 12-06-2020 , 12:15   Re: Request "Reconnect in the same team"
Reply With Quote #2

Quote:
Originally Posted by BrainDead View Post
Hello, new here. Hope i'm writing in a right section.
I need plugin who save SteamIDs of teams and when any player reconnect to the server, he join in the same team he was.
To working for spectators too.
For how long and why? What if somebody joins a team they did not want by mistake?

PHP Code:
#include amxmodx

#define MAX_PLAYERS                32
#define MAX_AUTHID_LENGTH          64

new authid[MAX_AUTHID_LENGTH]
new 
team16 ], HashedTaskman[34], Taskmang_team[MAX_PLAYERS], g_timeframe;
new 
Float:timerg_debugging;

public 
plugin_init()

{
    
register_plugin("Reconnect to same team","A",".sρiηX҉.");
    
register_event("Money","CS_Event_handler","bf");
    
g_timeframe register_cvar("mp_teamtime","120");
    
g_debugging register_cvar("mp_teamtime_debug""0");
}

public 
client_putinserver(id)

if(
is_user_connected(id) && !is_user_bot(id))
{
    
get_user_authid(id,authid,charsmax(authid));
    
replace(authidcharsmax(authid), "STEAM_""");
    
replace_all(authidcharsmax(authid), ":""");

    
#if AMXX_VERSION_NUM == 182;
    
md5(authidHashedTaskman);
    
#else
    
hash_stringauthidHash_Md5HashedTaskmancharsmax(HashedTaskman) );
    
#endif

    
if(get_pcvar_num(g_debugging) > 1)
        
server_print("Md5 hash of %s is %s^n",authid,HashedTaskman);

    
#if AMXX_VERSION_NUM == 182;

    
Taskman str_to_num(HashedTaskman);

    
#else

    
Taskman strtol(HashedTaskman);

    
#endif
    
    
if (Taskman 1000)
        
Taskman str_to_num(authid);


    if(
get_pcvar_num(g_debugging))
        
server_print("String to number of hash %s is %i^n",HashedTaskman,Taskman);

    
    if(
task_exists(Taskman) && index_by_authid(authid) == id )

        {
           
server_print("We have a reconnection tasked.^n");
           if(
Taskman == 0)
               
remove_task(Taskman) && server_print("^n^nBad task. Deleted.^n^n")
           else
           {
               
change_task(Taskman0.1);
               
set_msg_blockget_user_msgid"MOTD" ), BLOCK_SET );
               
set_msg_blockget_user_msgid"ShowMenu" ), BLOCK_SET );
               
set_msg_blockget_user_msgid"VGUIMenu" ), BLOCK_SET );
               
set_task(0.2,"retain_team",id);
           }

        }

}

public 
retain_team(id)

{
    new 
name[MAX_PLAYERS];

    
get_user_name(id,name,charsmax(name));

    if (
id 0)
        
server_print("%s is back!"name);

    if(
is_user_connected(id) && !is_user_bot(id))

    {

        if(
get_pcvar_num(g_debugging))
            
client_print(0,print_chat"%s is back!"name);


        if(
containi(g_team"CT") )
            {
            
set_msg_blockget_user_msgid"MOTD" ), BLOCK_SET );
            
client_cmd(id"jointeam 1");
            
client_cmd(id"joinclass 6");
            
set_msg_blockget_user_msgid"ShowMenu" ), BLOCK_SET );
            
set_msg_blockget_user_msgid"VGUIMenu" ), BLOCK_ONCE );
            }

        if(
containi(g_team"TERRORIST") )
            {
            
set_msg_blockget_user_msgid"MOTD" ), BLOCK_SET );
            
client_cmd(id"jointeam 2");
            
client_cmd(id"joinclass 5")
            
set_msg_blockget_user_msgid"ShowMenu" ), BLOCK_SET );
            
set_msg_blockget_user_msgid"VGUIMenu" ), BLOCK_ONCE );
            }

        if(!
equal(g_team"TERRORIST") && !equal(g_team"CT") )
            {
            
set_msg_blockget_user_msgid"MOTD" ), BLOCK_SET );
            
set_msg_blockget_user_msgid"ShowMenu" ), BLOCK_SET );
            
set_msg_blockget_user_msgid"VGUIMenu" ), BLOCK_ONCE );
            
client_cmd(id"jointeam 6");

            }

      }

}

public 
CS_Event_handler(id)

if(
is_user_alive(id) && !is_user_bot(id))

{
    
timer get_pcvar_num(g_timeframe)*1.0;

    
get_user_team(idteamcharsmax(team));

    if(
get_pcvar_num(g_debugging))
        
server_print("%s",team);


    
get_user_authid(id,authid,charsmax(authid));
    
replace(authidcharsmax(authid), "STEAM_""");
    
replace_all(authidcharsmax(authid), ":""");

    
#if AMXX_VERSION_NUM == 182;
    
md5(authidHashedTaskman);
    
#else
    
hash_stringauthidHash_Md5HashedTaskmancharsmax(HashedTaskman) );
    
#endif

    #if AMXX_VERSION_NUM == 182;
    
Taskman str_to_num(authid)
    
#else
    
Taskman strtol(HashedTaskman)
    
#endif

    
if(!task_exists(Taskman) && !equal(team"UNASSIGNED") && Taskman != 0)

        {

        if(
containi(team"CT") )
            {
                
set_task(timer,"set_team"Taskmanteamcharsmax(team));
            }
        if(
containi(team"TERRORIST") )
            {
                
set_task(timer,"set_team"Taskmanteamcharsmax(team));
            }
        if(
containi(team"SPECTATOR") )
            {
                
set_task(timer,"set_team"Taskmanteamcharsmax(team));
            }


        }



}

public 
set_team(TaskID)
    
g_team team

stock index_by_authid
(authid[64])
{
    new 
players[MAX_PLAYERS], playercountscan[MAX_PLAYERS];
    
server_print("^nChecking index_by_authid...");
    
get_players(players,playercount"c");

    for (new 
indexauthid=0indexauthid<playercountindexauthid++)
    {
        
get_user_authid(players[indexauthid], scancharsmax(scan))
        
replace(scancharsmax(scan), "STEAM_""");
        
replace_all(scancharsmax(scan), ":""");


        if(
get_pcvar_num(g_debugging) > 2)
        {
            
server_print("^nAuth is %s.^n"authid);
            
server_print("Scan is %s.^n^n"scan);
        }
        if(
strcmp(scan,authid0) == 0)
            return 
players[indexauthid];
    }

    return 
0;

__________________

Last edited by DJEarthQuake; 12-21-2020 at 17:24. Reason: Bugfix. Str_to_num on Amxx182 is consistently inconsistent.
DJEarthQuake is offline