The online racing simulator
need help with another peice of code (happyhour))
hi guys i just need your help again im up to coding happyhour now its all working counts down proper and every thing what im stuck on is

getting it to show the countdown to happyhour due to its automatic

bassicly what i want is when someone types the command !happyhour i want it to show "HappyHour Starts in : (TIME)" and i cant get it to work

any ideas?

thanks chris
It just refers to one hour each day right? Like happy hour is 7pm every day, right?
Quote from Dygear :It just refers to one hour each day right? Like happy hour is 7pm every day, right?

no every 6 hours

so on insim start up it counts down from 6hours once it reaches 0 happyhour starts automatticly then it resets back to 6 hours happyhour runs for 1 hour
then starts again once the timer hits 0
So what exactly is the problem? You seem to have figured it out already. I take it you store the time remaining to happy hour in seconds, are you having problems converting it to HH:MM:SS?
So you already know the time (in seconds) when the next happy hour starts and you know how to get the current time in seconds. What you must do then is take away the happy hour time from the current time. The remainder will be the amount of time in seconds until the next happy hour.
set a System.DateNow Perhaps?
Pretty sure this is from Allied Modders, I think AMX Mod X, I just converted it to PHP a long time ago. Returns seconds into a string that is nice and readable.

<?php 
class Time {
    const 
SECONDS_IN_MINUTE =     60;
    const 
SECONDS_IN_HOUR   =   3600;
    const 
SECONDS_IN_DAY    =  86400;
    const 
SECONDS_IN_WEEK   604800;
    public static function 
getTimeLen($s) {
        if (
$s 0) {
            
$w $d $h $m 0$element = array();

            
$w round($s self::SECONDS_IN_WEEK);
            if (
$w 0$element[] = sprintf('%d %s'$w, ($w == 1) ? 'week' 'weeks');
            
$s -= $w self::SECONDS_IN_WEEK;
            
$d round($s self::SECONDS_IN_DAY);
            if (
$d 0$element[] = sprintf('%d %s'$d, ($d == 1) ? 'day' 'days');
            
$s -= $d self::SECONDS_IN_DAY;
            
$h round($s self::SECONDS_IN_HOUR);
            if (
$h 0$element[] = sprintf('%d %s'$h, ($h == 1) ? 'hour' 'hours');
            
$s -= $h self::SECONDS_IN_HOUR;
            
$m round($s self::SECONDS_IN_MINUTE);
            if (
$m 0$element[] = sprintf('%d %s'$m, ($m == 1) ? 'minute' 'minutes');
            
$s -= $m self::SECONDS_IN_MINUTE;
            if (
$s 0$element[] = sprintf('%d %s'$s, ($s == 1) ? 'second' 'seconds');

            switch(
count($element)) {
                case 
1: return sprintf("%s"$element[0]);
                case 
2: return sprintf("%s & %s"$element[0], $element[1]);
                case 
3: return sprintf("%s, %s & %s"$element[0], $element[1], $element[2]);
                case 
4: return sprintf("%s, %s, %s & %s"$element[0], $element[1], $element[2], $element[3]);
                case 
5: return sprintf("%s, %s, %s, %s & %s"$element[0], $element[1], $element[2], $element[3], $element[4]);
            }
        }
    }
}
?>

my mate just told me that we are having trouble getting the timers value so everything else is workin fine just havin troble getting the timer value

hope that makes sense
In what language do you write your app? Possibly C#?
No, that was PHP.
#11 - PoVo
Quote from Dygear :No, that was PHP.

I think he meant it to the thread creator.

And yes it's C#
Yes, I was asking the thread's author, I of course can recognize PHP when I see it

I guess that using C# Timers is not the best idea in this case, because you cannot get any value from it. My C# experience is very limited, so I cannot offer you any better solution, but here is what I'd do if I had to use timers.


int secsToHappyHour = 21600; //6hrs = 21600 seconds

private void happyHourTimer_Tick(object sender, EventArgs e)
{
secsToHappyHour--;
if(secsToHappyHour < 1)
{
doSomething();
}
}

If you set interval of HappyHourTimer to 1000, it should decrement secsToHappyHour every second and once it reaches zero, it does something. If you want to display the time remaining to HH, just convert the secsToHappyHour to HH:MM:SS and display it.
It's C yeah
Not PHP

FGED GREDG RDFGDR GSFDG