03.03.2017, 14:40
how to make ping TextDraw?
new Text:textid; public OnGameModeInit() { textid = TextDrawCreate(545.0, 27.5, ""); TextDrawColor(textid, 0xAFAFAFAA); return 1; } public OnPlayerUpdate (playerid) { new ping; new string[128]; ping = GetPlayerPing (playerid); format (string, sizeof(string), "PING: %d", ping); TextDrawSetString(textid, string); TextDrawShowForPlayer(playerid, textid); return 1; }
Here, this should display the PING above the armour bar:
Код:
new Text:textid; public OnGameModeInit() { TextDrawColor(textid, 0xAFAFAFAA); textid = TextDrawCreate(545.0, 27.5, ""); return 1; } public OnPlayerUpdate (playerid) { new ping; new string[128]; ping = GetPlayerPing (playerid); format (string, sizeof(string), "PING: %d", ping); TextDrawSetString(textid, string); TextDrawShowForPlayer(playerid, textid); return 1; } |
Use a timer with an interval of 1 second to update the ping textdraw, that should be enough.
Most online-games don't even display your ping all the time. They display the ping when you use a /ping command and it displays only the ping for that moment. Ping isn't that important to update it up to 30 times per second (OnPlayerUpdate may run over 30 times per second and more as well). When it's being updated that fast, you can't even read the value because ping isn't the same all the time and the entire textdraw becomes useless. |
new Text:textid; new pingUpdate[MAX_PLAYERS]; forward UpdatePlayerPing(playerid); public OnGameModeInit() { textid = TextDrawCreate(545.0, 27.5, ""); TextDrawColor(textid, 0xAFAFAFAA); return 1; } public OnPlayerConnect(playerid) { pingUpdate[playerid] = SetTimerEx("UpdatePlayerPing", 1000, true, "i", playerid); return 1; } public OnPlayerDisconnect(playerid) { KillTimer(pingUpdate[playerid]); return 1; } public UpdatePlayerPing (playerid) { new ping; new string[128]; ping = GetPlayerPing (playerid); format (string, sizeof(string), "PING: %d", ping); TextDrawSetString(textid, string); TextDrawShowForPlayer(playerid, textid); return 1; }