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(0, print_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(0, print_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(id, print_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(0, print_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], iNum, team, t1, t2, t1L[16], t2L[16], pos1, pos2
get_players(iPlayers, iNum)
for(new i = 0; i < iNum; i++)
{
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(-1 < 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 < 0 )
{
new playerid = t1L[random(pos1)]
if(!is_user_admin(playerid))
{
//HARD DEBUG
client_print(0, print_chat, "[DEBUG] T1L, setting teamlock for %d", playerid)
g_teamlock[playerid] = get_gametime()
}
new name[33]
get_user_name(playerid, name, 32)
if(g_balanced[playerid] <= get_gametime())
{
client_cmd(playerid, "jointeam 2")
client_print(0, print_chat,"[SKYNET] %s randomly selected to switch teams.", name, t1)
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(0, print_chat, "[SKYNET] Selected player %s has been balanced too recently, user can be re-balanced in %d seconds ", name, floatround(g_balanced[playerid] - get_gametime()))
return PLUGIN_HANDLED
}
}
//else if(t2 > t1)
//else if ( variant >= 2)
while( variant >= 2 )
{
new playerid = t2L[random(pos2)]
if(!is_user_admin(playerid))
{
//HARD DEBUG
client_print(0, print_chat, "[DEBUG] T2L, setting teamlock for %d", playerid)
g_teamlock[playerid] = get_gametime()
}
new name[33]
get_user_name(playerid, name, 32)
if(g_balanced[playerid] <= get_gametime())
{
client_cmd(playerid, "jointeam 1")
client_print(0, print_chat, "[SKYNET] %s randomly selected to switch teams.", name, t2)
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(0, print_chat, "[SKYNET] Selected player %s has been balanced too recently, user can be re-balanced in %d seconds", name, floatround(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;
__________________