[Help] Server Day & Night
#1

Hello , i want to know how to set Day and night in the server or it depends on the place of hosting?
Reply
#2

https://sampwiki.blast.hk/wiki/SetPlayerTime
Reply
#3

Nop, you just need "SetWorldTime".. OR ^^ SetPlayerTime

You can make /day and /night commands using server time.
Reply
#4

This is from my script, it changes day/night automatically according to time:

On top:
PHP код:
new Text:Time;
new 
Tsec;
new 
THrs
Under OnGameModeInit
PHP код:
Time TextDrawCreate(578.00000014.000000"00:00");
    
TextDrawAlignment(Time2);
    
TextDrawFont(Time3);
    
TextDrawLetterSize(Time0.6099993.299998);
    
TextDrawColor(Time, -1);
    
TextDrawSetOutline(Time1);
    
TextDrawSetProportional(Time0);
    
TextDrawSetSelectable(Time0);
    
Tsec0;
    
THrs0;
    
SetTimer("TimeU",60000,true); 
And the callback of timer:
PHP код:
forward TimeU();
public 
TimeU()
{
    new 
string[7];
    
Tsec+=1;
    if(
Tsec==60)
    {
        
Tsec=0;
        
THrs+=1;
    }
    if(
THrs==24)
    {
        
Tsec=0;
        
THrs=0;
    }
    if(
THrs>10)
    {
        if(
Tsec<10)
        {
            
format(string,sizeof(string),"%d:0%d",THrs,Tsec);
        }
        if(
Tsec>9)
        {
               
format(string,sizeof(string),"%d:%d",THrs,Tsec);
        }
    }
    if(
THrs<10)
    {
        if(
Tsec<10)
        {
            
format(string,sizeof(string),"0%d:0%d",THrs,Tsec);
        }
        if(
Tsec>9)
        {
               
format(string,sizeof(string),"0%d:%d",THrs,Tsec);
        }
    }
    for(new 
ii<MAX_PLAYERSi++)
    {
        if(
IsPlayerConnected(i))
        {
            
SetPlayerTime(i,THrs,Tsec);
        }
    }
    
TextDrawSetString(Time,string);

It does everything.
Reply
#5

Is it Possible to Set Day when it is day in my country and set it to night when it is night in my country?
Reply
#6

yes, it is possible.

On top:
PHP код:
new THrs;
new 
Tmin;
new 
Text:Time
OnGameModeInit:
PHP код:
SetTimer("TimeU"30000true);
Time TextDrawCreate(578.00000014.000000"00:00");
    
TextDrawAlignment(Time2);
    
TextDrawFont(Time3);
    
TextDrawLetterSize(Time0.6099993.299998);
    
TextDrawColor(Time, -1);
    
TextDrawSetOutline(Time1);
    
TextDrawSetProportional(Time0);
    
TextDrawSetSelectable(Time0); 
PHP код:
forward TimeU();
public 
TimeU()
{
    new 
string[7], second;
    
gettime(THrsTminsecond);
    if(
THrs>10)
    {
        if(
Tmin<10)
        {
            
format(string,sizeof(string),"%d:0%d",THrs,Tmin;
        }
        if(
Tmin>9)
        {
               
format(string,sizeof(string),"%d:%d",THrs,Tmin);
        }
    }
    if(
THrs<10)
    {
        if(
Tmin<10)
        {
            
format(string,sizeof(string),"0%d:0%d",THrs,Tmin);
        }
        if(
Tmin>9)
        {
               
format(string,sizeof(string),"0%d:%d",THrs,Tmin);
        }
    }
    for(new 
ii<MAX_PLAYERSi++)
    {
        if(
IsPlayerConnected(i))
        {
            
SetPlayerTime(i,THrs,Tmin);
        }
    }
    
TextDrawSetString(Time,string);

Reply
#7

They player's time stop when player is AFK . How to remove the stop function . so that when player is afk (but connected) his time is running same of the other player. e.g. the id 2 is afk so his time stills run and his time matches with mine.
Reply
#8

You can do this with gettime.

Under OnFilterScriptInit() or OnGameModeInit()

pawn Код:
SetTimerEx("Clock", 1000, true, "i", playerid);
pawn Код:
forward Clock(playerid);
public Clock(playerid)
{
    new Hour, Minute, Second;
    gettime(Hour, Minute, Second);
    if(Hour == 12) return SetPlayerTime(playerid, 12, 0);
    if(Hour == 13) return SetPlayerTime(playerid, 13, 0);
    // (.....) you catch idea;
    if(Hour == 20) return SetPlayerTime(playerid, 20, 0);
    //(.....)
    if(Hour == 1) return SetPlayerTime(playerid, 0, 0);
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)