[Ajuda] Sitema de tempo muda derrepente
#1

Olб malta, uso o sitema de tempo que vem nos FS padrгo, sу que coloquei no meu GM VOu colocar aqui.


O que acontece й que de x em x tempo ele muda derrepente, assim de noite para dia e de dia para noite !
serб o SetTimer ?


pawn Код:
public OnGameModeInit()
{
new h,m;
CalculateVirtualTime(h,m);
printf("\nVirtual Time: %02d:%02d\n", h,m);
SetTimer("SyncVirtualTime",120000,1);
SetWorldTime(15);

No fim
pawn Код:
public OnPlayerSpawn(playerid)
{
new h,m;
TogglePlayerClock(playerid, 1);
CalculateVirtualTime(h,m);
SetPlayerTime(playerid, h, m);
pawn Код:
public SyncVirtualTime()
{
    new h,m;
    CalculateVirtualTime(h,m);
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            SetPlayerTime(i,h,m);
        }
    }
}

CalculateVirtualTime(&hour,&minute)
{
    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;
}
Reply
#2

Bom, isto se deve ao fato de que este sistema foi feito para tentar simular quando й dia ou noite na vida real em jogo.(pelo menos й o que eu acho.)
Reply
#3

Sim isso faz isso mesmo ! ou seja os minutos no jogo sao os segundos na realidade, e tem momentos que esta correto, escurece normalmente e assim mas acho que quando pega o settimer

SetTimer("SyncVirtualTime",120000,1);

que faz algo de errado e muda assim drasticamente de dia para noite e noite para dia
Reply
#4

Aqui estб funзгo correta, retirada do filterscript "gl_realtime".

pawn Код:
//
// Keeps the in game time synced to the server's time and
// draws the current time on the player's hud using a textdraw/
// (1 minute = 1 minute real world time)
//
//  © 2009-2012 SA-MP Team

#include <a_samp>
#pragma tabsize 0

//--------------------------------------------------

new Text:txtTimeDisp;
new hour, minute;
new timestr[32];

forward UpdateTimeAndWeather();

//--------------------------------------------------

new fine_weather_ids[] = {1,2,3,4,5,6,7,12,13,14,15,17,18,24,25,26,27,28,29,30,40};
new foggy_weather_ids[] = {9,19,20,31,32};
new wet_weather_ids[] = {8};

stock UpdateWorldWeather()
{
    new next_weather_prob = random(100);
    if(next_weather_prob < 70)      SetWeather(fine_weather_ids[random(sizeof(fine_weather_ids))]);
    else if(next_weather_prob < 95) SetWeather(foggy_weather_ids[random(sizeof(foggy_weather_ids))]);
    else                            SetWeather(wet_weather_ids[random(sizeof(wet_weather_ids))]);
}

//--------------------------------------------------

//new last_weather_update=0;

public UpdateTimeAndWeather()
{
    // Update time
    gettime(hour, minute);
    format(timestr,32,"%02d:%02d",hour,minute);
    TextDrawSetString(txtTimeDisp,timestr);
    SetWorldTime(hour);
   
    new x=0;
    while(x!=MAX_PLAYERS) {
        if(IsPlayerConnected(x) && GetPlayerState(x) != PLAYER_STATE_NONE) {
            SetPlayerTime(x,hour,minute);
         }
         x++;
    }

    /* Update weather every hour
    if(last_weather_update == 0) {
        UpdateWorldWeather();
    }
    last_weather_update++;
    if(last_weather_update == 60) {
        last_weather_update = 0;
    }*/

}

//--------------------------------------------------

public OnGameModeInit()
{
    // Init our text display
    txtTimeDisp = TextDrawCreate(605.0,25.0,"00:00");
    TextDrawUseBox(txtTimeDisp, 0);
    TextDrawFont(txtTimeDisp, 3);
    TextDrawSetShadow(txtTimeDisp,0); // no shadow
    TextDrawSetOutline(txtTimeDisp,2); // thickness 1
    TextDrawBackgroundColor(txtTimeDisp,0x000000FF);
    TextDrawColor(txtTimeDisp,0xFFFFFFFF);
    TextDrawAlignment(txtTimeDisp,3);
    TextDrawLetterSize(txtTimeDisp,0.5,1.5);
   
    UpdateTimeAndWeather();
    SetTimer("UpdateTimeAndWeather",1000 * 60,1);

    return 1;
}

//--------------------------------------------------

public OnPlayerSpawn(playerid)
{
    TextDrawShowForPlayer(playerid,txtTimeDisp);
   
    gettime(hour, minute);
    SetPlayerTime(playerid,hour,minute);
   
    return 1;
}

//--------------------------------------------------

public OnPlayerDeath(playerid, killerid, reason)
{
    TextDrawHideForPlayer(playerid,txtTimeDisp);
    return 1;
}

//--------------------------------------------------

public OnPlayerConnect(playerid)
{
    gettime(hour, minute);
    SetPlayerTime(playerid,hour,minute);
    return 1;
}

//--------------------------------------------------
Reply
#5

Vou exprimentar, este nao da para mim, pois ja tenho um sitema de mudanзa de climas !
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)