[FilterScript] Connection bar
#1

CONNECTION BAR



INFO

Code:
This script gets player ping and display 5 bars which will show the connection status
Code:
5 Bars - ping (0-200) color (blue)
4 Bars - ping (201-400) color (green)
3 Bars - ping (401-550) color (yellow)
2 Bars - ping (551-700) color (red/pink)
1 Bar - ping (701+) color (red)
PICS



















DOWNLOAD






CREDITS

SA-MP TEAM for a_samp
ME for Connection bars
ADRI1 for His text draw editor
GAMMIX for Helping
POTTUS for Helping
Reply
#2

wow such a good job
Reply
#3

Looks good! Though, I would prefer something like going from green to red (with accent colours)
Reply
#4

Why create PlayerTextDraws? You know you can achieve this with global textdraws!
Whenever you change a property of any textdraw (global or player), property like color, fontsize etc. all expect string, the effect is shown when you reshow the textdraw to player.

So if you change color and reshow to one player, the property is only changed for that player only (according to wiki).
PHP Code:
// example
TextDrawColor(textdraw0xFF0000FF);
TextDrawShowForAll(textdraw); // red color is shown for all players


TextDrawColor(textdraw0x00FF00FF);
// above: only id 0 and 15 will have green color
TextDrawShowForPlayer(0textdraw);
TextDrawShowForPlayer(15textdraw); 
Reply
#5

Good job!
Reply
#6

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;
}
Reply
#7

I m p r e s s i v e. Btw pottus why to call a function over 90 times per a check while you can store it in a var and use that var?
new pping = GetPlayerPing(i);
And later... pping >= x...
Won't that make it a bit more optimized?
Reply
#8

repeating code is awful that is why pottus said that
Reply
#9

Thanks all

UPDATE:

CREDITS
GAMMIX for helping
POTTUS for helping

@pottus i changed

PHP Code:
// Dont need to check if it is greater than 701 since WE KNOW IT IS!
else if(PingLevel[i] != PING_LEVEL_5
to

PHP Code:
else if(GetPlayerPing(i) > 700 && PingLevel[i] != PING_LEVEL_5
it conflict!

it would show 5 bars and a sec later 1 bar over and over again

DOWNLOAD

max bars are in blue




@Matz

max bars are in green color as u asked

DOWNLOAD

Reply
#10

Okay all good I didn't test! But it's good you fixed it good training for you.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)