AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Last player replace (on disconnect) without round end? (https://forums.alliedmods.net/showthread.php?t=244802)

LNATIC 07-23-2014 21:01

Last player replace (on disconnect) without round end?
 
Hi all, as the title says.. how can I do this?

I have this code, but it does't work (the round ends anyway):
PHP Code:

public client_disconnect(id)  if(is_user_alive(id))     check_round(); // call check round function

check_round(){
    if(
g_bRoundEnd) return; // round ending bool (false on round start, true on round end)
    
static szName[32], randomplayerrandomplayer fnGetRandomPlayer();
    if(
fnGetTeamPlayers(1) == 1){
        
cs_set_user_team(randomplayerCS_TEAM_T); // change team
        
get_user_name(randomplayerszName31 ); // get the name
        
client_print(0,print_chat,"The last TT left, %s is the new TT",szName); // advertise which player
        
ExecuteHamB(Ham_CS_RoundRespawnrandomplayer); // respawn the new last player
    
}
}
fnGetTeamPlayers(team) {
    static 
iiPls;
    for (
0g_iMaxpli++){
        if (
is_user_connected(i)){
            switch(
team){
                case 
1:if (cs_get_user_team(i) == CS_TEAM_T)    iPls++;
                case 
2:if (cs_get_user_team(i) == CS_TEAM_CT)    iPls++;
            }
        }
    }
    return 
iPls;
}
fnGetRandomPlayer(){
    new 
iPlayers[32], iNum
    get_players
(iPlayersiNum"h")
    if( 
iNum <= )    return iPlayers[0]
    new 
iRandomNum random(iNum)
    new 
iRandomPlayer iPlayersiRandomNum ]
    if( 
iRandomPlayer == g_iLastChoosenPlayer ){
        
iPlayersiRandomNum ] = iPlayers[ --iNum ]
        
iRandomPlayer iPlayersrandom(iNum) ]
    }
    
g_iLastChoosenPlayer  iRandomPlayer
    
return iRandomPlayer



Eagle07 07-23-2014 22:59

Re: Last player replace (on disconnect) without round end?
 
Try
PHP Code:

public client_disconnect(id)

    if(!
g_bRoundEnd)
    static 
szName[32], randomplayer
    
new new_terr players[random(pnum)]
    if(
fnGetTeamPlayers(1) == 1){ 
        
cs_set_user_team(new_terrCS_TEAM_T);
        
get_user_name(new_terrszName31 ); // get the name 
        
client_print(0,print_chat,"The last TT left, %s is the new TT",szName); // advertise which player 
        
ExecuteHamB(Ham_CS_RoundRespawnnew_terr); // respawn the new last player 
    


fnGetTeamPlayers(team) { 
    static 
iiPls
    for (
0g_iMaxpli++){ 
        if (
is_user_connected(i)){ 
            switch(
team){ 
                case 
1:if (cs_get_user_team(i) == CS_TEAM_T)    iPls++; 
                case 
2:if (cs_get_user_team(i) == CS_TEAM_CT)    iPls++; 
            } 
        } 
    } 
    return 
iPls



claudiuhks 07-24-2014 04:01

Re: Last player replace (on disconnect) without round end?
 
Really?

PHP Code:

0is_user_connected(i)
32 /*maxplayers*/ // what about player #32 

Plus, iPls value is statically declared and will never reset.

LNATIC 07-24-2014 15:14

Re: Last player replace (on disconnect) without round end?
 
Quote:

Originally Posted by claudiuhks (Post 2172878)
Really?

PHP Code:

0is_user_connected(i)
32 /*maxplayers*/ // what about player #32 

Plus, iPls value is statically declared and will never reset.

Oops haha I missed it, thanks for your answer and sorry :stupid:

EDIT: Thank you too Eagle07, your code works :D


All times are GMT -4. The time now is 13:15.

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