1.) Ping does not determine packet consistency (health) of a connection so this is a misleading conception of a players connection status. Maybe you should look at multiple factors and characteristics to sum up a better image of connection status.
2.) You are already aware of the textdraw type issue but there is also something else to look at. Why bother doing any updates if the players ping is still in the range of the last check? You are always updating regardless if the result was the same as last time.
Consider the following it needs to be finished/implemented some more that is your job
Code:
// Define different ping level states
#define PING_LEVEL_UPDATE -1
#define PING_LEVEL_1 0
#define PING_LEVEL_2 1
#define PING_LEVEL_3 3
#define PING_LEVEL_4 4
#define PING_LEVEL_5 5
// Keep track of the players current level
static PingLevel[MAX_PLAYERS] = { -1, ...};
// Ping level color table (finish updating this)
static PingLevelColors[][5] = {
{ 0x3692EDFF, 0x3692EDFF, 0x3692EDFF, 0x3692EDFF, 0x3692EDFF },
{ 0x3692EDFF, 0x3692EDFF, 0x3692EDFF, 0x3692EDFF, 0x3692EDFF },
{ 0x3692EDFF, 0x3692EDFF, 0x3692EDFF, 0x3692EDFF, 0x3692EDFF },
{ 0x3692EDFF, 0x3692EDFF, 0x3692EDFF, 0x3692EDFF, 0x3692EDFF },
{ 0x3692EDFF, 0x3692EDFF, 0x3692EDFF, 0x3692EDFF, 0x3692EDFF }
};
// Set the last update to an arbitrary update value forcing an auto-update
// no matter what
public OnPlayerDisconnect(playerid)
{
PingLevel[playerid] = PING_LEVEL_UPDATE;
return 1;
}
public WifiCheck()
{
for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
{
if(!IsPlayerConnected(i) || IsPlayerNPC(i)) continue;
// Only update IF the pings were different
if(GetPlayerPing(i) >= 0 && GetPlayerPing(i) < 201 && PingLevel[i] != PING_LEVEL_1)
{
PingLevel[i] = PING_LEVEL_1;
// No need to repeat code over and over when all we need is one versile function!
UpdateConnectionStatus(i, PING_LEVEL_1);
}
else if(GetPlayerPing(i) >= 201 && GetPlayerPing(i) < 401 && PingLevel[i] != PING_LEVEL_2)
{
PingLevel[i] = PING_LEVEL_2;
UpdateConnectionStatus(i, PING_LEVEL_2);
}
else if(GetPlayerPing(i) >= 401 && GetPlayerPing(i) < 551 && PingLevel[i] != PING_LEVEL_3)
{
PingLevel[i] = PING_LEVEL_3;
UpdateConnectionStatus(i, PING_LEVEL_3);
}
else if(GetPlayerPing(i) >= 551 && GetPlayerPing(i) < 701 && PingLevel[i] != PING_LEVEL_4)
{
PingLevel[i] = PING_LEVEL_4;
UpdateConnectionStatus(i, PING_LEVEL_4);
}
// Dont need to check if it is greater than 701 since WE KNOW IT IS!
else if(PingLevel[i] != PING_LEVEL_5)
{
PingLevel[i] = PING_LEVEL_5;
UpdateConnectionStatus(i, PING_LEVEL_5);
}
}
return 1;
}
static UpdateConnectionStatus(playerid, level)
{
PlayerTextDrawHide(playerid, Bar1[playerid]);
PlayerTextDrawHide(playerid, Bar2[playerid]);
PlayerTextDrawHide(playerid, Bar3[playerid]);
PlayerTextDrawHide(playerid, Bar4[playerid]);
PlayerTextDrawHide(playerid, Bar5[playerid]);
// Reference color array again no repeat code!
PlayerTextDrawBoxColor(playerid, Bar1[playerid], PingLevelColors[level][0]);
PlayerTextDrawBoxColor(playerid, Bar2[playerid], PingLevelColors[level][1]);
PlayerTextDrawBoxColor(playerid, Bar3[playerid], PingLevelColors[level][2]);
PlayerTextDrawBoxColor(playerid, Bar4[playerid], PingLevelColors[level][3]);
PlayerTextDrawBoxColor(playerid, Bar5[playerid], PingLevelColors[level][4]);
PlayerTextDrawShow(playerid, Bar1[playerid]);
PlayerTextDrawShow(playerid, Bar2[playerid]);
PlayerTextDrawShow(playerid, Bar3[playerid]);
PlayerTextDrawShow(playerid, Bar4[playerid]);
PlayerTextDrawShow(playerid, Bar5[playerid]);
return 1;
}