Please or Register to create posts and topics.

In-Game Timer

PreviousPage 2 of 3Next

Tested it out in my own map, works out great Chicken. Thanks :thumbup:

My Hammer Maps
[Released] Power Interference
[Released] Rust and Dust (Spotlight Map!)
[Released] Multiportal

BAM - winning. I'll edit this later so you can just spawn the entities through press of key.

?????????????????????????????TWP Releases | My Workshop

Ha ha! I posted first!

At the beginning:

Code: Select all
function init(){
   text <- Entities.CreateByClassname("game_text");
   EntFireByHandle(text,"addoutput","targetname @DisplayText",0,null,null);
   EntFireByHandle(text,"addoutput","spawnflags 1",0,null,null);
   EntFireByHandle(text,"addoutput","fadein 0.01",0,null,null);
   EntFireByHandle(text,"addoutput","fadeout 0.01",0,null,null);
   EntFireByHandle(text,"addoutput","holdtime 1.0",0,null,null);
}

At the end, replace SetPos(){ ... } with this:

Code: Select all
function Startup(){
   printl("Starting Timer...");

   init();

   EntFire( "@DisplayText", "SetTextColor", "210 210 210 128", 0.0 );
   EntFire( "@DisplayText", "SetTextColor2", "50 90 116 128", 0.0 );
   EntFire( "@DisplayText", "SetPosY", "0.85", 0.0 );
   EntFire( "@DisplayText", "SetPosX", "0.1", 0.0 );
   EntFire( "@DisplayText", "SetText", "00:00:00", 0.0 );

   DisplayText();
}

Startup();

At the beginning, replace EntFire( "@DisplayText_Relay", "Trigger", "", 1.0 ) with

Code: Select all
EntFireByHandle(!self,"RunScriptCode","DisplayText();",1.0,null,null);

And you should have a working timer! Use ent_fire worldspawn RunScriptFile (whatever you called the file).nut to start the timer!

Alter the values to your liking.

Falsi sumus crusto!
FelixGriffin wrote:
Ha ha! I posted first!

Hrmm so you did...

Quote:
<ChickenMobile> hey wstrika
<ChickenMobile> did you want me to edit the script so then you can turn cheats on and then have the timer appear?
<ChickenMobile> by binding a button for example
<wstrika> god damn the fucking water monster in half life
<wstrika> NOPE NOPE NOPE NOPE
<ChickenMobile> Nope?
<ChickenMobile> wstrika,
<ChickenMobile> wrathofmobius,
<ChickenMobile> I mean wstrika
<ChickenMobile> wstrika,
<ChickenMobile> wstrika,
<wrathofmobius> wstrika
<wrathofmobius> wstrika
<ChickenMobile> wstrika,
<ChickenMobile> wstrika,
<ChickenMobile> FINE THEN I WONT

back on topic:
perhaps the script can go in the misc downloads section so then it can be shared? (some people are idiots and wont know how to change code or create .nut files to save their life)

?????????????????????????????TWP Releases | My Workshop

Good idea. I'll upload it later today then.

Falsi sumus crusto!
ChickenMobile wrote:
FelixGriffin wrote:
Ha ha! I posted first!

Hrmm so you did...

Quote:
<ChickenMobile> hey wstrika
<ChickenMobile> did you want me to edit the script so then you can turn cheats on and then have the timer appear?
<ChickenMobile> by binding a button for example
<wstrika> god damn the fucking water monster in half life
<wstrika> NOPE NOPE NOPE NOPE
<ChickenMobile> Nope?
<ChickenMobile> wstrika,
<ChickenMobile> wrathofmobius,
<ChickenMobile> I mean wstrika
<ChickenMobile> wstrika,
<ChickenMobile> wstrika,
<wrathofmobius> wstrika
<wrathofmobius> wstrika
<ChickenMobile> wstrika,
<ChickenMobile> wstrika,
<ChickenMobile> FINE THEN I WONT

back on topic:
perhaps the script can go in the misc downloads section so then it can be shared? (some people are idiots and wont know how to change code or create .nut files to save their life)

It would have to be something that started on mapload, maybe. Like a bind to a key that restarts the map, and loads it with the timer overlay.

Maybe. I'm not sure if that's possible...

Maybe if it were in a preload script, but that kind of defeats the purpose.

Falsi sumus crusto!

You could always edit your mapspawn.nut located scripts/vscripts and put in all the relevant commands needed on startup. Therefore you will always have the timer going as soon as you start the level (your computer only).

Code: Select all
//********************************************************************************************
//MAPSPAWN.nut is called on newgame or transitions
//********************************************************************************************
printl("==== calling mapspawn.nut")

function init(){
   text <- Entities.CreateByClassname("game_text");
   EntFireByHandle(text,"addoutput","targetname @DisplayText",0,null,null);
   EntFireByHandle(text,"addoutput","spawnflags 1",0,null,null);
   EntFireByHandle(text,"addoutput","fadein 0.01",0,null,null);
   EntFireByHandle(text,"addoutput","fadeout 0.01",0,null,null);
   EntFireByHandle(text,"addoutput","holdtime 1.0",0,null,null);
}

function Startup(){
   printl("Starting Timer...");

   init();

   EntFire( "@DisplayText", "SetTextColor", "210 210 210 128", 0.0 );
   EntFire( "@DisplayText", "SetTextColor2", "50 90 116 128", 0.0 );
   EntFire( "@DisplayText", "SetPosY", "0.85", 0.0 );
   EntFire( "@DisplayText", "SetPosX", "0.1", 0.0 );
   EntFire( "@DisplayText", "SetText", "00:00:00", 0.0 );

   DisplayText();
}

Startup();

//Global counter
counter <- 0

//Display time
function DisplayText()
{
   EntFire( "@DisplayText", "setText", ConvertToFormat(), 0 )
   EntFire( "@DisplayText", "Display", "", 0.01 )

   //Trigger the relay for each second
   counter++
   //The relay here should just call the DisplayText() function
   EntFireByHandle(!self,"RunScriptCode","DisplayText();",1.0,null,null);
}

function ConvertToFormat()
{
   //using modulus logic we can figure out hours mins and left over seconds from counter
   local modMinuteSeconds = counter % 3600
   local hours = (counter - modMinuteSeconds) / 3600
   local modSecs = modMinuteSeconds % 60
   local mins = (modMinuteSeconds - modSecs) / 60
   local secs = modSecs

   local Smins = ""
   local Ssecs = ""

   if(mins < 10)
   {
      Smins = "0" + mins.tostring()
   }
   else {
      Smins = mins.tostring()
   }
   if(secs < 10)
   {
      Ssecs = "0" + secs.tostring()
   }
   else {
      Ssecs = secs.tostring()
   }

   //Insert time conversion here from seconds from counter to relevant format 00:00:00

   local displayTime = hours  + ":" + Smins  + ":" + Ssecs
   return displayTime
}

EDIT: turns out this doesn't work and doesn't want to recognise any Source specific code. Wonder if I can reference the script file though.

EDIT2: YES YES YES YES! I got it to work. Also there is a slight problem in your code Felix: it should be self and not !self.

Add this into your mapspawn.nut

Code: Select all
EntFire( "bignet", "RunScriptFile", "chicken_scripts/counter", 1.5 );

And then copy this code and put it in a .nut file located scripts/vscripts/chicken_scripts/ named counter.nut

Code: Select all

//Global counter
counter <- 0

//Display time
function DisplayText()
{
   EntFire( "@DisplayText", "setText", ConvertToFormat(), 0 )
   EntFire( "@DisplayText", "Display", "", 0.01 )

   //Trigger the relay for each second
   counter++
   //The relay here should just call the DisplayText() function
   EntFireByHandle(self,"RunScriptCode","DisplayText()",1.0,null,null);
}

function ConvertToFormat()
{
   //using modulus logic we can figure out hours mins and left over seconds from counter
   local modMinuteSeconds = counter % 3600
   local hours = (counter - modMinuteSeconds) / 3600
   local modSecs = modMinuteSeconds % 60
   local mins = (modMinuteSeconds - modSecs) / 60
   local secs = modSecs

   local Smins = ""
   local Ssecs = ""

   if(mins < 10)
   {
      Smins = "0" + mins.tostring()
   }
   else {
      Smins = mins.tostring()
   }
   if(secs < 10)
   {
      Ssecs = "0" + secs.tostring()
   }
   else {
      Ssecs = secs.tostring()
   }

   //Insert time conversion here from seconds from counter to relevant format 00:00:00

   local displayTime = hours  + ":" + Smins  + ":" + Ssecs
   return displayTime
}

function init(){
   text <- Entities.CreateByClassname("game_text");
   EntFireByHandle(text,"addoutput","targetname @DisplayText",0,null,null);
   EntFireByHandle(text,"addoutput","spawnflags 1",0,null,null);
   EntFireByHandle(text,"addoutput","fadein 0",0,null,null);
   EntFireByHandle(text,"addoutput","fadeout 0",0,null,null);
   EntFireByHandle(text,"addoutput","holdtime 1.0",0,null,null);

   SendToConsole("sv_cheats 1")
}

function Startup(){
   printl("Starting Timer...");

   init();

   EntFire( "@DisplayText", "SetTextColor", "210 210 210 128", 0.0 );
   EntFire( "@DisplayText", "SetTextColor2", "50 90 116 128", 0.0 );
   EntFire( "@DisplayText", "SetPosY", "0.85", 0.0 );
   EntFire( "@DisplayText", "SetPosX", "0.1", 0.0 );
   EntFire( "@DisplayText", "SetText", "00:00:00", 0.0 );

   SendToConsole("sv_cheats 0")

   DisplayText();
}

Startup();

?????????????????????????????TWP Releases | My Workshop

Works like a charm, good work, Chicken. I suppose milliseconds are out of the question?

Not necessarily, but IDK how long it takes for each tick. It might get a bit off.

Also, why do you need cheats? Can't a script entfire whenever it wants to?

EDIT: I uploaded it to the Download Database, I hope you don't mind. http://forums.thinking.withportals.com/downloads.php?view=detail&df_id=2331

Falsi sumus crusto!
PreviousPage 2 of 3Next