T1 cap timer HELP

Mr. Hated
07-19-2003, 11:56 PM
iv been working on a script that calculates flag cap times and iv run into a problem cause i dunno how to make actual "huds"... all i need is a "FearGuiFormattedText" displaying "CalcTime" any help would be appreciated...... and i dont want BP cause it will conflict with another script i have

this is what i have


function MarkGrab() {

$FlagGrabTime = getsimtime();

}

function CalcTime() {

%time = getsimtime() - $FlagGrabTime;

%minutes = floor(%time / 60);
%seconds = %time % 60;
%tenths = floor(%time * 10) - (floor(%time) * 10) ;
%TimeString = %minutes @ ":";
if (%seconds < 10)
%TimeString = %TimeString @ "0";
if (%minutes < 1)
%TimeString = "";
//%prefix = "seconds";
//else if (%minutes > 1);
//%prefix = "minutes";
$FlagCapTime = %TimeString @ %seconds @ "." @ %tenths;

%capmsg = "Flag was capped in: " @ $FlagCapTime;
//%capmsg = "<jc><f2>You capped their flag in a time of: <f0>" @ $FlagCapTime @ "" @ %prefix;
remoteBP(2048, %capmsg, 8);

}
}
Event::Attach(eventFlagTa ken, MarkGrab);
Event::Attach(EventFlagCa ptured, CalcTime);

CapTime::Init();

Timalis_
07-20-2003, 12:04 AM
off the top of my head....

$captime::con = newobject("CapTime::Con", SimGui::control, X, Y, W, H);
$captime::text = newobject("CapTime_Text", FearGuiFormattedText, X, Y, W, H);

Now.. that's off the top of my head so may need some tweaking.. mainly adding feargui::feargui menu as an item to the container as a frame, of course which can be toggled not visible later...
then to change the value of it..

control::setvalue("CapTime_Text", $FlagCapTime)

Of course...
W being Width
H being Height

Evita
07-20-2003, 12:17 AM
Display the info on cap, then delete the hud after 'x' seconds.

Do what ^ he said to display the info.
control::setvalue($MyText , $captime);

Create:

$MyContainer = newObject("Container", SimGui::Control, x, y, x, y);
$MyText = newObject("Text", FearGuiFormattedText, x, y, x, y);
addToSet($MyContainer, $MyText);
addToSet(playGui, $MyContainer);


Destroy:

removeFromSet(playGui, $MyContainer);
deleteObject($MyContainer );

Timalis_
07-20-2003, 12:21 AM
Knew I was forgetting something.. the reason I have yet to release anything heh.

SuperSlug
07-20-2003, 12:24 AM
This is what I've been using for a few months.
function Taunt::FlagTaken(%flagId, %clientId)
{
if(%clientId == getManagerId())
{
$Flag::StartGrab = getSimTime();
}
}

// From AOCTFHud
// Used to make sure colors don't get screwed up if you have ">" or "<" in your name
function AOCTF::CleanName(%name)
{
if(%name == " ")
return "_";

%name = string::Replace(%name, "<", "_");
%name = string::Replace(%name, ">", "_");
return %name;
}

// Cowboy's FlagCapsHud stopwatch timer
// Changed around for popup stuff
function Timed::Cap(%time)
{
%player = Client::getName(getManage rID());
%minutes = floor(%time / 60);
%seconds = %time % 60;
%tenths = floor(%time * 10) - (floor(%time) * 10);
if(%time > 60)
{
if(%minutes == 1)
{
remoteBP(2048, "<jc><f2>" @ AOCTF::CleanName(%player) @ "<f1>, you capped in <f2>" @ %minutes @ "<f1> minute and <f2>" @ %seconds @ "." @ %tenths @ "<f1> seconds, and have <f2>" @ $CapsPerMap @ "<f1> caps on <f2>" @ $servermission @ "<f1>.", 5);
}
else
{
remoteBP(2048, "<jc><f2>" @ AOCTF::CleanName(%player) @ "<f1>, you capped in <f2>" @ %minutes @ "<f1> minutes and <f2>" @ %seconds @ "." @ %tenths @ "<f1> seconds, and have <f2>" @ $CapsPerMap @ "<f1> caps on <f2>" @ $servermission @ "<f1>.", 5);
}
}
else if(%time < 60)
{
remoteBP(2048, "<jc><f2>" @ AOCTF::CleanName(%player) @ "<f1>, you capped in <f2>" @ %seconds @ "." @ %tenths @ "<f1> seconds, and have <f2>" @ $CapsPerMap @ "<f1> caps on <f2>" @ $servermission @ "<f1>.", 5);
}
}

// get total time from flag grab to capture
function SuperSlug::CappedFlag(%te am, %client)
{
if(%client == getManagerID())
{
$CapsPerMap++;

$Flag::EndGrab = getSimTime() - $Flag::StartGrab;

Timed::Cap($Flag::EndGrab );
$Flag::StartGrab = 0;
}
}

function SuperSlug::Reset()
{
$CapsPerMap = 0;
$Flag::StartGrab = 0;
$Flag::EndGrab = 0;
}

Event::Attach(eventFlagTa ken, Taunt::FlagTaken);
Event::Attach(eventFlagCa ptured, SuperSlug::CappedFlag);
Event::Attach(eventConnec ted, SuperSlug::Reset);
Event::Attach(eventMatchS tarted, SuperSlug::Reset);

Mr. Hated
07-20-2003, 02:14 PM
okay now im getting an error "addtoset playgui doesnt exist" this is what i got now


$CapTimer::Xpos = "0";
$CapTimer:: = "326";

function FlagTimer::Init() {

$Captimer_cont = newObject("Container", SimGui::Control, $CapTimer::Xpos, $CapTimer::ypos, 200, 10);
$captime_text = newObject("Text", FearGuiFormattedText, $CapTimer::Xpos, $CapTimer::Ypos, 200, 10);
addToSet($captime_cont, $captime_text);
addToSet(playGui, $captimer_cont);

}

function MarkGrab() {

$FlagGrabTime = getsimtime();

}

function CapTimer::Destroy() {

//removeFromSet(playGui, $Captime_cont);
deleteObject($Captime_Con t);
}

function CalcTime() {

%time = getsimtime() - $FlagGrabTime;

%minutes = floor(%time / 60);
%seconds = %time % 60;
%tenths = floor(%time * 10) - (floor(%time) * 10) ;
%TimeString = %minutes @ ":";
if (%seconds < 10)
%TimeString = %TimeString @ "0";
if (%minutes < 1)
%TimeString = "";
//%prefix = "seconds";
//else if (%minutes > 1);
//%prefix = "minutes";
$FlagCapTime = %TimeString @ %seconds @ "." @ %tenths;

control::setvalue($CapTim e_Text, $FlagCapTime);

schedule("CapTimer::Destroy();", 5);
}

Event::Attach(eventFlagTa ken, MarkGrab);
Event::Attach(EventFlagCa ptured, CalcTime);

FlagTimer::Init();

SuperSlug
07-20-2003, 02:28 PM
$CapTimer::Xpos = "0";
$CapTimer::Ypos = "326";

function FlagTimer::Init()
{
$Captimer_cont = newObject("Container", SimGui::Control, $CapTimer::Xpos, $CapTimer::ypos, 200, 10);
$captime_text = newObject("Text", FearGuiFormattedText, $CapTimer::Xpos, $CapTimer::Ypos, 200, 10);
addToSet($captime_cont, $captime_text);
addToSet(playGui, $captimer_cont);
}

function MarkGrab(%team, %client)
{
if(%client == getManagerID())
$FlagGrabTime = getsimtime();
}

function CapTimer::Destroy()
{
removeFromSet(playGui, $Captime_cont);
deleteObject($Captime_Con t);
}

function CalcTime(%team, %client)
{
if(%client == getManagerID())
{
%time = getsimtime() - $FlagGrabTime;

%minutes = floor(%time / 60);
%seconds = %time % 60;
%tenths = floor(%time * 10) - (floor(%time) * 10) ;
%TimeString = %minutes @ ":";
if (%seconds < 10)
%TimeString = %TimeString @ "0";
if (%minutes < 1)
%TimeString = "";
//%prefix = "seconds";
//else if (%minutes > 1);
//%prefix = "minutes";
$FlagCapTime = %TimeString @ %seconds @ "." @ %tenths;

control::setvalue($CapTim e_Text, $FlagCapTime);

schedule("CapTimer::Destroy();", 5);
}
}

Event::Attach(eventFlagTa ken, MarkGrab);
Event::Attach(EventFlagCa ptured, CalcTime);

FlagTimer::Init();

Timalis_
07-20-2003, 02:28 PM
Ok.. this is what I found out with tinkering around... you need to put the addtoplayset(playgui, $container); line after the playgui has been opened. so a function like

event::attach(eventguiope n, captime::guiopen);
function captime::guiopen(%gui)
{
if (%gui == "playgui")
{
addtoset(playgui, $captimer_cont);
}

}

Something along those lines...

Or you can also have the addtoset function in another event, something like match started, or connected. Anything that is called after the playgui is loaded.