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(eventLoadPl ayGui, PingHUD::Create);
Event::Attach(eventGuiOpe n, PingHUD::playGuiOpen);
Event::Attach(eventGuiClo se, 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::GetPosit ion("ChatHudBG_Container" ), 0);
%yp = getWord(Control::GetPosit ion("ChatHudBG_Container" ), 1);
%xs = getWord(Control::GetExten t("ChatHudBG_Container" ), 0);
%ys = getWord(Control::GetExten t("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("PingHU D_FPS", FearGuiFormattedText, 0, 0, 16, 16);
%hudPing=newObject("PingH UD_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::Fram eRate);
if(%fps < 15)
Control::setValue("PingHU D_FPS", "<F2>FPS: <F0><JR>" @ %fps);
else if(%fps < 30)
Control::setValue("PingHU D_FPS", "<F2>FPS: <F2><JR>" @ %fps);
else
Control::setValue("PingHU D_FPS", "<F2>FPS: <F1><JR>" @ %fps);
remoteEval(2048, eval, PingResponse, getsimtime());
Schedule::Add("PingHUD::U pdate();", 1, "PingHUD");
}
function remotePingResponse(%clien t, %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("PingHU D_Ping", "<F2>Ping: <F1><JR>" @ %ping);
else if(%ping < 100)
Control::setValue("PingHU D_Ping", "<F2>Ping: <F2><JR>" @ %ping);
else
Control::setValue("PingHU D_Ping", "<F2>Ping: <F0><JR>" @ %ping);
$PingHud::Count = 0;
$PingHud::Ping = 0;
}
}
function PingHUD::playGuiOpen(%gui )
{
if(%gui == "playGui")
PingHUD::Update();
}
function PingHUD::playGuiClose(%gu i)
{
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(eventUpdat eTime, Time::GetMinutes((%time + 1) * -1), Time::GetSeconds((%time + 1) * -1));
}
fits onto chathud above the clockhud
|