SA-MP Forums Archive
Ingame world time - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Ingame world time (/showthread.php?tid=611113)



Ingame world time - fuckingcruse - 02.07.2016

Hi, i tried toggling the world time. But it's something like, if i go esc the time pause, and then when i come from esc back in-game, it starts. I want the same time going for all. And 1 second = 2 rl seconds. I tried it, it didn't worked.


Re: Ingame world time - Nero_3D - 02.07.2016

Quote:
Originally Posted by wiki.sa-mp.com/wiki/TogglePlayerClock
Time is not synced with other players! Time can be synced using SetPlayerTime
Basically you create a timer, increment a variable and update the clock

Also show us what you tried


Re: Ingame world time - fuckingcruse - 02.07.2016

Ye sure, see this.
Код:
//OnGameModeInit
SetWorldTime(03); // As i want 03:00 as the world time when the game mode starts.

//OnRequestClass
TogglePlayerClock(playerid, 1);
That's it. I tried a textdraw to make it myself, but couldn't. So, help me here pls. And even can you tell me how to read the time? Like we do GetPlayerPos to get pos, then how can i get the ingame time.


Re: Ingame world time - Dayrion - 02.07.2016

Don't use TogglePlayerClock.
Код:
Time is not synced with other players! Time can be synced using SetPlayerTime.
Код:
//OnGameModeInit...
new hour, min, sec;
gettime(hour, min, sec);
SetWorldTime(hour);
SetTimer("TimeUp", 1000, true);
PHP код:
public TimeUp()
{
    new 
hourminsec;
    
gettime(hourminsec);;
    if(
min== && sec== 0)
    {
        
SetWorldTime(hour);
    }
    return 
1;




Re: Ingame world time - Nero_3D - 02.07.2016

I see no problem with TogglePlayerClock, its just unfortunate that there isn't a function to set the clock for all players
Using a textdraw instead would be a bit more effective (no need for the while loop)

PHP код:
// OnGameModeInit
SetTimerEx("Clock"750true"i"gettime() - 60 2); // start at 3 o'clock
// OnPlayerSpawn ?
TogglePlayerClock(playeridtrue);
//
forward Clock(start);
public 
Clock(start) {
    const 
sec 2;
    new
        
diff = ((gettime() - start) / sec) % (60 24),
        
GetPlayerPoolSize(),
        
minute diff 60,
        
hour diff 60
    
;
    while(
>= 0) {
        
SetPlayerTime(i--, hourminute);
    }

The problem is the update rate because we can't replicate 1 second exact, therefore I use a faster rate