AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   blocking a user from switching teams (https://forums.alliedmods.net/showthread.php?t=189196)

HLM 07-04-2012 10:11

blocking a user from switching teams
 
my code works... but its not working as well as it should, I think I messed up with my variables or my math operations..


PHP Code:

if(g_teamlock[id] > 0.0)
    {
        new 
Float:clock = ( get_gametime() - g_teamlock[id] )
        
client_print(0print_chat"[DEBUG] clock: %f"clock)
        
//new timer = floatround( g_teamlock[id] + get_pcvar_float(sn_server_teamlock_time))
        
        //if ( get_cvar_num("sn_debug") )
        
client_print(0print_chat"[SKYNET] checking locks: set time: %f time add: %f game time: %f clock: %f"g_teamlock[id], get_pcvar_float(sn_server_teamlock_time), get_gametime(), clock )
        
        if( ( 
clock get_pcvar_float(sn_server_teamlock_time) ) ) 
        {
            
client_print(0,print_chat"clock check")
            
client_print(idprint_chat"[SKYNET] Team LOCKED for %f more seconds.", (get_pcvar_float(sn_server_teamlock_time) - clock))
            return 
PLUGIN_HANDLED
        
}
        else if( ( 
clock >= get_pcvar_float(sn_server_teamlock_time) ) )
        {
            
client_print(0print_chat"clock is dead.")
            
g_teamlock[id] = 0.0
            
return PLUGIN_CONTINUE
        
}
    } 

and here is the code that is executed to cause this to work (some bugs are caused with the player who has to switch)

PHP Code:

{
                        new 
iPlayers[32], iNumteamt1t2t1L[16], t2L[16], pos1pos2
                        get_players
(iPlayersiNum)
                        for(new 
0iNumi++)
                        {
                            if(!
is_user_bot(iPlayers[i]))
                            {
                                
team fm_get_user_team(iPlayers[i])
                                if(
team == 1)
                                {
                                    
t1L[pos1] = iPlayers[i]
                                    
t1++
                                    
pos1++
                                }                    
                                else if(
team == 2)
                                {
                                    
t2L[pos2] = iPlayers[i]
                                    
t2++
                                    
pos2++
                                }
                            }
                        }
                        new 
variant = (t2 t1)
                        if(-
variant 2)
                        {
                            
client_print(id,print_chat,"[SKYNET] Teams are fine you whiny bitch.")
                            return 
PLUGIN_HANDLED
                        
}
                        
//else if(t1 > t2)
                        //else if( variant < 0)
                        
while( variant )
                        {
                            new 
playerid t1L[random(pos1)]
                            if(!
is_user_admin(playerid))
                            {
                                
//HARD DEBUG
                                
client_print(0print_chat"[DEBUG] T1L, setting teamlock for %d"playerid)
                                
g_teamlock[playerid] = get_gametime()
                            }
                            new 
name[33]
                            
get_user_name(playeridname32)
                            if(
g_balanced[playerid] <= get_gametime())
                            {
                                
client_cmd(playerid"jointeam 2")
                                
client_print(0print_chat,"[SKYNET] %s randomly selected to switch teams."namet1)
                                
g_globalbalance = (get_gametime() + get_pcvar_float(sn_server_balance_cooldown))
                                
g_usedbalance[id] = (get_gametime() + get_pcvar_float(sn_user_balance_delay))
                                
g_balanced[playerid] = (get_gametime() + get_pcvar_float(sn_user_balance_cooldown))
                                
variant++
                            }
                            else
                            {
                                
client_print(0print_chat"[SKYNET] Selected player %s has been balanced too recently, user can be re-balanced in %d seconds "namefloatround(g_balanced[playerid] - get_gametime()))
                                return 
PLUGIN_HANDLED
                            
}
                        }
                        
//else if(t2 > t1)
                        //else if ( variant >= 2)
                        
while( variant >= )
                        {
                            new 
playerid t2L[random(pos2)]
                            if(!
is_user_admin(playerid))
                            {
                                
//HARD DEBUG
                                
client_print(0print_chat"[DEBUG] T2L, setting teamlock for %d"playerid)
                                
g_teamlock[playerid] = get_gametime()
                            }
                            new 
name[33]
                            
get_user_name(playeridname32)
                            if(
g_balanced[playerid] <= get_gametime())
                            {
                                
client_cmd(playerid"jointeam 1")
                                
client_print(0print_chat"[SKYNET] %s randomly selected to switch teams."namet2)
                                
g_globalbalance = (get_gametime() + get_pcvar_float(sn_server_balance_cooldown))
                                
g_usedbalance[id] = (get_gametime() + get_pcvar_float(sn_user_balance_delay))
                                
g_balanced[playerid] = (get_gametime() + get_pcvar_float(sn_user_balance_cooldown))
                                
variant--
                            }
                            else
                            {
                                
client_print(0print_chat"[SKYNET] Selected player %s has been balanced too recently, user can be re-balanced in %d seconds"namefloatround(g_balanced[playerid] - get_gametime()))
                                return 
PLUGIN_CONTINUE
                            
}
                        }
                        
                        
//new sum = HumanCount[1] + HumanCount[2] + HumanCount[3] + HumanCount[4]
                    



global variables
PHP Code:

new Float:g_teamlock[33];
new 
Float:g_usedbalance[33];
new 
Float:g_balanced[33];
new 
Float:g_globalbalance



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

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