All pastes #917866 Raw Edit

Untitled

public text v1 · immutable
#917866 ·published 2008-02-25 19:14 UTC
rendered paste body
#include <a_samp>
forward SyncVirtualTime();
 
public OnFilterScriptInit() {
    new h,m;
    CalculateVirtualTime(h,m);
    printf("\nVirtual Time: %02d:%02d\n", h,m);
    SetTimer("SyncVirtualTime",120000,1);
}
 
public OnPlayerSpawn(playerid) {
    // since OnPlayerDeath is setting the time also, let's set it back
    new h,m;
    TogglePlayerClock(playerid, 1);
    CalculateVirtualTime(h,m);
    SetPlayerTime(playerid, h, m);
}
 
public SyncVirtualTime() {
    // Even if there's no "big" differences, we remove them every 2 minutes
    // (see timer above)
    new h,m;
    CalculateVirtualTime(h,m);
    for(new i = 0; i < MAX_PLAYERS; i++) {
        if(IsPlayerConnected(i)) {
            SetPlayerTime(i,h,m);
        }
    }
}
 
CalculateVirtualTime(&hour,&minute) {
    // This is just for Creating "a" time that is based on the Server's time,
    // so it'll calculate all the time FINE for everyone, no matter when he
    // joins, it'll be the same
    new h,i,s;
    gettime(h,i,s);
    new time = (h * 24 * 60) + i * 60 + s;
    time = time % (24 * 60);
    minute = time % 60;
    hour = (time - minute) / 60;
}