[T1 request] Ping HUD for VP

ping/fps added on by runar
thank mav for sending to me after I annoyed him in irc for a day



////////////////////////////////////////////////////////////
// File: PingHUD.cs
// Version: 3.3
// Author: Runar
// Credits:
// Info: Neato little Ping
//
////////////////////////////////////////////////////////////

$PingHUD::Exist = "False";

Event::Attach(eventLoadPlayGui, PingHUD::Create);
Event::Attach(eventGuiOpen, PingHUD::playGuiOpen);
Event::Attach(eventGuiClose, PingHUD::playGuiClose);
Event::Attach(eventExit, PingHUD::Destroy);

////////////////////////////////////////////////////////////

// Create HUD, if exists Update
function PingHUD::Create()
{
if($PingHUD::Exist)
{
return;
}

// Just to make sure we delete any stale objects
PingHUD::Destroy();

// Calculate the position with the chathud
%xp = getWord(Control::GetPosition("ChatHudBG_Container"), 0);
%yp = getWord(Control::GetPosition("ChatHudBG_Container"), 1);
%xs = getWord(Control::GetExtent("ChatHudBG_Container"), 0);
%ys = getWord(Control::GetExtent("ChatHudBG_Container"), 1);
%x = %xp + %xs - 45;
%y = %yp;

// Make sure we don't double it!
$PingHUD::Exist = "True";

// Here's the container
%hudContainer=newObject("PingHUD_Container", SimGui::Control, %x, %y, 35, 34);

// Here's text object
%hudFPS=newObject("PingHUD_FPS", FearGuiFormattedText, 0, 0, 16, 16);
%hudPing=newObject("PingHUD_Ping", FearGuiFormattedText, 0, 10, 16, 16);

// Add text to container
addToSet(%hudContainer, %hudFPS);
addToSet(%hudContainer, %hudPing);

// Add the container to PlayGui
addToSet(PlayGui, %hudContainer);

PingHUD::Update();
}

function PingHUD::Update()
{
%fps = floor($ConsoleWorld::FrameRate);

if(%fps < 15)
Control::setValue("PingHUD_FPS", "<F2>FPS: <F0><JR>" @ %fps);
else if(%fps < 30)
Control::setValue("PingHUD_FPS", "<F2>FPS: <F2><JR>" @ %fps);
else
Control::setValue("PingHUD_FPS", "<F2>FPS: <F1><JR>" @ %fps);

remoteEval(2048, eval, PingResponse, getsimtime());
Schedule::Add("PingHUD::Update();", 1, "PingHUD");
}

function remotePingResponse(%client, %time)
{
%ping = floor((getsimtime() - %time) * 500);

$PingHud::ping = $PingHud::ping + %ping;
$PingHud::Count++;

if($PingHud::Count == 5)
{
%ping = floor($PingHud::ping / 5);

if(%ping < 75)
Control::setValue("PingHUD_Ping", "<F2>Ping: <F1><JR>" @ %ping);
else if(%ping < 100)
Control::setValue("PingHUD_Ping", "<F2>Ping: <F2><JR>" @ %ping);
else
Control::setValue("PingHUD_Ping", "<F2>Ping: <F0><JR>" @ %ping);

$PingHud::Count = 0;
$PingHud::ping = 0;
}
}

function PingHUD::playGuiOpen(%gui)
{
if(%gui == "playGui")
PingHUD::Update();

}

function PingHUD::playGuiClose(%gui)
{
if(%gui == "playGui")
Schedule::Cancel("PingHUD");

}

function PingHUD::Destroy()
{
HUD::Destroy("PingHUD_");
HUD::Destroy("PingHUD_");
$PingHUD::Exist = "False";
}

// Tribes function override
function remoteSetTime(%serverId, %time)
{
if(%serverId != 2048)
return;

setHudTimer(%time);

Event::Trigger(eventUpdateTime, Time::GetMinutes((%time + 1) * -1), Time::GetSeconds((%time + 1) * -1));
}


fits onto chathud above the clockhud
 
Back
Top