Results 1 to 8 of 8

Thread: [Tutorial] Time Left Script

  1. #1
    Sergeant EvoloZz's Avatar
    Join Date
    Sep 2012
    Location
    Helsinki, Finland
    Posts
    360
    Thanks
    314
    Thanked 167 Times in 120 Posts

    [Tutorial] Time Left Script

    Hey lads, this is my tutorial about time left showing in the server's name, its super easy, but many people need it on their servers
    Lets start by calling the thread, call only on start of gametype.
    So go and find Callback_StartGameType() and add new line
    Code:
    thread maps\mp\gametypes\_time::TimeLeft();
    Then make new .gsc file, and add something like this:
    Code:
    TimeLeft()
    {
        level.timeleft = 30; // change this to how long is one map, for example scr_tdm_timelimit "30", its really important
    
        setCvar("sv_hostname", "My Server Time Left: " + level.timeleft + " minutes");
    
        while(1)
        {
    
             wait 60;
             level.timeleft = level.timeleft - 1; // probably easier just level.timeleft--;
             setCvar("sv_hostname", "My Server Time Left " + level.timeleft + " minutes");
        }
    }
    Explanation:
    level.timeleft = 30 / defines that counter starts from 30
    setCvar / changes the stuff in your config
    while(1) / infinite loop, so it never breaks, can also use for(;;)
    wait 60 / waits 1 minute (in seconds)
    level.timeleft--; / just -1 every minute :>

    Thats it for my first tut :P

  2. The Following User Says Thank You to EvoloZz For This Useful Post:

    kung foo man (22nd January 2013)

  3. #2
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    Code:
    while(1)
    {
    	servername = "IzNoGoD's awesome scripted server ";
    	timeleft = level.timelimit - int((gettime() - level.starttime) / 60000 + 0.5);
    	setcvar("sv_hostname", servername + " Time left: " + timeleft + " mins");
    	wait 10;
    }
    Use built-in functions so it also works when you change scr_tdm_timelimit etc.

  4. The Following 2 Users Say Thank You to IzNoGoD For This Useful Post:

    EvoloZz (23rd January 2013),kung foo man (22nd January 2013)

  5. #3
    Private First Class Earliboy's Avatar
    Join Date
    Nov 2012
    Location
    Germany
    Posts
    130
    Thanks
    5
    Thanked 88 Times in 61 Posts
    Code:
    TimeLeft()
    {
        servername = getCvar("sv_hostname");
    
        while(1)
        {
    	timeleft = level.timelimit - int((gettime() - level.starttime) / 60000 + 0.5);
    	setcvar("sv_hostname", servername + " || Time left: " + timeleft + " mins");
    	wait 10;
        }
    }
    This would be a littlebit easier, cause you can still set the servername via cfg file.
    No ... No ... this is not possible .......

  6. The Following 2 Users Say Thank You to Earliboy For This Useful Post:

    EvoloZz (23rd January 2013),kung foo man (22nd January 2013)

  7. #4
    Corporal STAUFFi's Avatar
    Join Date
    Aug 2012
    Location
    Germany
    Posts
    269
    Thanks
    106
    Thanked 128 Times in 83 Posts

    xD STAUFFii likedEvolozz's Tutorial
    Last edited by STAUFFi; 23rd January 2013 at 04:30.

  8. #5
    Sergeant EvoloZz's Avatar
    Join Date
    Sep 2012
    Location
    Helsinki, Finland
    Posts
    360
    Thanks
    314
    Thanked 167 Times in 120 Posts
    "Thank you-button" has been implented

  9. #6
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    Quote Originally Posted by Earliboy View Post
    Code:
    TimeLeft()
    {
        servername = getCvar("sv_hostname");
    
        while(1)
        {
    	timeleft = level.timelimit - int((gettime() - level.starttime) / 60000 + 0.5);
    	setcvar("sv_hostname", servername + " || Time left: " + timeleft + " mins");
    	wait 10;
        }
    }
    This would be a littlebit easier, cause you can still set the servername via cfg file.
    Would not. Would fuck up the name at map_rotate, as it would say "IzNoGoD's awesome server Time left: 0 mins Time left: 30 mins", as you get the new sv_hostname from the var you just wrote the time_left to.

    Use a second cvar to store the original name plox.

  10. The Following User Says Thank You to IzNoGoD For This Useful Post:

    kung foo man (23rd January 2013)

  11. #7
    Private First Class Earliboy's Avatar
    Join Date
    Nov 2012
    Location
    Germany
    Posts
    130
    Thanks
    5
    Thanked 88 Times in 61 Posts
    Ah ye, i remember to that That was the prob i had
    Code:
    TimeLeft()
    {
        servername = getCvar("sv_hostname");
        level.oldHostname = servername;
    
        while(1)
        {
    	timeleft = level.timelimit - int((gettime() - level.starttime) / 60000 + 0.5);
    	setcvar("sv_hostname", servername + " || Time left: " + timeleft + " mins");
    	wait 10;
        }
    }
    Just add at GT.gsc (gametype) at the thread endmap()
    Code:
    if(isDefined(level.oldHostname))
         setCvar("sv_hostname",level.oldHostname);
    No ... No ... this is not possible .......

  12. The Following User Says Thank You to Earliboy For This Useful Post:

    kung foo man (23rd January 2013)

  13. #8
    Global Mossaderator Mitch's Avatar
    Join Date
    Nov 2012
    Posts
    654
    Thanks
    204
    Thanked 450 Times in 305 Posts
    Quote Originally Posted by Earliboy View Post
    Ah ye, i remember to that That was the prob i had
    Code:
    TimeLeft()
    {
        servername = getCvar("sv_hostname");
        level.oldHostname = servername;
    
        while(1)
        {
    	timeleft = level.timelimit - int((gettime() - level.starttime) / 60000 + 0.5);
    	setcvar("sv_hostname", servername + " || Time left: " + timeleft + " mins");
    	wait 10;
        }
    }
    Just add at GT.gsc (gametype) at the thread endmap()
    Code:
    if(isDefined(level.oldHostname))
         setCvar("sv_hostname",level.oldHostname);
    or set your default hostname in a new cvar and load this one at start of the map or each loop.

    And btw use this for endMap to make a script global (this will be after map vote)
    Code:
    onEndMap()
    {
    	level waittill("intermission");
    	iprintlnbold("The map has ended");
    }
    Last edited by Mitch; 24th January 2013 at 07:47.

  14. The Following User Says Thank You to Mitch For This Useful Post:

    kung foo man (24th January 2013)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •