Ingame world time
#1

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.
Reply
#2

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
Reply
#3

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.
Reply
#4

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;

Reply
#5

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
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)