- ShowerManager
- Mesaje : 236
Data de inscriere : 11/10/2015
Varsta: : 31
[Tutorial] Vremea pe server mai realista in timp real!
26/8/2016, 20:05
- In acest tutorial am sa va ofer niste sisteme ingenioase care va pot ajuta sa :
* Setati vremea exact ca in bucuresti , adica daca ploua in bucale ploua si la voi.
* Seteze automat ora pe server. (Worldtime)
Adaugam la inceput in gamemode.
forward GetRealWeather(index, response_code, data[]);
forward ActualizareVreme(); // eu le-am asezat e simplu sa le modificati
Inainte de OnGamemodeInit adaugam urmatoarele functii:
public GetRealWeather(index, response_code, data[])
{
if(response_code == 200)
{
new weathercode[3];
new pos = strfind(data, "icon");
strmid(weathercode, data, pos+6, pos+;
if(weathercode[0] == '0') weathercode[0] = strval(weathercode[1]);
else weathercode[0] = strval(weathercode);
if(weathercode[0] > 4 && weathercode[0] < 12) weathercode[0] -= 4;
else if(weathercode[0] == 13) weathercode[0] = 8;
else if(weathercode[0] == 50) weathercode[0] = 9;
static const weathercodes[] = {
0,
11,
10,
4,
4,
5,
5,
8,
19,
9};
SetWeather(weathercodes[weathercode[0]]);
}
else printf("EROARE: Nu am putut executa GetRealWeather!", response_code);
}
stock SetRealWeather() return HTTP(0, HTTP_GET, "api.openweathermap.org/data/2.5/weather?q=Bucharest&mode=xml&units=metric", "", "GetRealWeather");
public ActualizareVreme()
{
new Hour, Minute;
gettime(Hour, Minute);
if(Hour==0)
{
SetWorldTime(0);
SetRealWeather();
}
if(Hour==1)
{
SetWorldTime(1);
SetRealWeather();
}
if(Hour==2)
{
SetWorldTime(2);
SetRealWeather();
}
if(Hour==3)
{
SetWorldTime(3);
SetRealWeather();
}
if(Hour==4)
{
SetWorldTime(4);
SetRealWeather();
}
if(Hour==5)
{
SetWorldTime(5);
SetRealWeather();
}
if(Hour==6)
{
SetWorldTime(6);
SetRealWeather();
}
if(Hour==7)
{
SetWorldTime(7);
SetRealWeather();
}
if(Hour==
{
SetWorldTime(;
SetRealWeather();
}
if(Hour==9)
{
SetWorldTime(9);
SetRealWeather();
}
if(Hour==10)
{
SetWorldTime(10);
SetRealWeather();
}
if(Hour==11)
{
SetWorldTime(11);
SetRealWeather();
}
if(Hour==12)
{
SetWorldTime(12);
SetRealWeather();
}
if(Hour==13)
{
SetWorldTime(13);
SetRealWeather();
}
if(Hour==14)
{
SetWorldTime(14);
SetRealWeather();
}
if(Hour==15)
{
SetWorldTime(15);
SetRealWeather();
}
if(Hour==16)
{
SetWorldTime(16);
SetRealWeather();
}
if(Hour==17)
{
SetWorldTime(17);
SetRealWeather();
}
if(Hour==18)
{
SetWorldTime(18);
SetRealWeather();
}
if(Hour==20)
{
SetWorldTime(20);
SetRealWeather();
}
if(Hour==21)
{
SetWorldTime(0);
SetRealWeather();
}
if(Hour==22)
{
SetWorldTime(0);
SetRealWeather();
}
if(Hour==23)
{
SetWorldTime(0);
SetWeather(2);
}
return 1;
}
Bun , acum sa va explic cum le folosim.
De fiecare data cand vrem sa actualizam vremea si timpul folosim functia ActualizareVreme();
Exemplu :
public OnGamemodeInit()
{
ActualizareVreme(); // la pornirea gamemodeului
}
Exemplu 2 : (dintr-un gamemode de pe site)
public SyncTime()
{
//new string[64];
new tmphour;
new tmpminute;
new tmpsecond;
gettime(tmphour, tmpminute, tmpsecond);
FixHour(tmphour);
tmphour = shifthour;
if (tmpminute == 00)
{
PayDay();
ActualizareVreme();
}
}
Sper sa apreciati gestul meu sa impart cu voi aceste stockuri , din pacate majoritatea serverelor nici nu folosesc weathers macar q.q doar weather = 0 , peste tot ..
* Setati vremea exact ca in bucuresti , adica daca ploua in bucale ploua si la voi.
* Seteze automat ora pe server. (Worldtime)
Adaugam la inceput in gamemode.
forward GetRealWeather(index, response_code, data[]);
forward ActualizareVreme(); // eu le-am asezat e simplu sa le modificati
Inainte de OnGamemodeInit adaugam urmatoarele functii:
public GetRealWeather(index, response_code, data[])
{
if(response_code == 200)
{
new weathercode[3];
new pos = strfind(data, "icon");
strmid(weathercode, data, pos+6, pos+;
if(weathercode[0] == '0') weathercode[0] = strval(weathercode[1]);
else weathercode[0] = strval(weathercode);
if(weathercode[0] > 4 && weathercode[0] < 12) weathercode[0] -= 4;
else if(weathercode[0] == 13) weathercode[0] = 8;
else if(weathercode[0] == 50) weathercode[0] = 9;
static const weathercodes[] = {
0,
11,
10,
4,
4,
5,
5,
8,
19,
9};
SetWeather(weathercodes[weathercode[0]]);
}
else printf("EROARE: Nu am putut executa GetRealWeather!", response_code);
}
stock SetRealWeather() return HTTP(0, HTTP_GET, "api.openweathermap.org/data/2.5/weather?q=Bucharest&mode=xml&units=metric", "", "GetRealWeather");
public ActualizareVreme()
{
new Hour, Minute;
gettime(Hour, Minute);
if(Hour==0)
{
SetWorldTime(0);
SetRealWeather();
}
if(Hour==1)
{
SetWorldTime(1);
SetRealWeather();
}
if(Hour==2)
{
SetWorldTime(2);
SetRealWeather();
}
if(Hour==3)
{
SetWorldTime(3);
SetRealWeather();
}
if(Hour==4)
{
SetWorldTime(4);
SetRealWeather();
}
if(Hour==5)
{
SetWorldTime(5);
SetRealWeather();
}
if(Hour==6)
{
SetWorldTime(6);
SetRealWeather();
}
if(Hour==7)
{
SetWorldTime(7);
SetRealWeather();
}
if(Hour==
{
SetWorldTime(;
SetRealWeather();
}
if(Hour==9)
{
SetWorldTime(9);
SetRealWeather();
}
if(Hour==10)
{
SetWorldTime(10);
SetRealWeather();
}
if(Hour==11)
{
SetWorldTime(11);
SetRealWeather();
}
if(Hour==12)
{
SetWorldTime(12);
SetRealWeather();
}
if(Hour==13)
{
SetWorldTime(13);
SetRealWeather();
}
if(Hour==14)
{
SetWorldTime(14);
SetRealWeather();
}
if(Hour==15)
{
SetWorldTime(15);
SetRealWeather();
}
if(Hour==16)
{
SetWorldTime(16);
SetRealWeather();
}
if(Hour==17)
{
SetWorldTime(17);
SetRealWeather();
}
if(Hour==18)
{
SetWorldTime(18);
SetRealWeather();
}
if(Hour==20)
{
SetWorldTime(20);
SetRealWeather();
}
if(Hour==21)
{
SetWorldTime(0);
SetRealWeather();
}
if(Hour==22)
{
SetWorldTime(0);
SetRealWeather();
}
if(Hour==23)
{
SetWorldTime(0);
SetWeather(2);
}
return 1;
}
Bun , acum sa va explic cum le folosim.
De fiecare data cand vrem sa actualizam vremea si timpul folosim functia ActualizareVreme();
Exemplu :
public OnGamemodeInit()
{
ActualizareVreme(); // la pornirea gamemodeului
}
Exemplu 2 : (dintr-un gamemode de pe site)
public SyncTime()
{
//new string[64];
new tmphour;
new tmpminute;
new tmpsecond;
gettime(tmphour, tmpminute, tmpsecond);
FixHour(tmphour);
tmphour = shifthour;
if (tmpminute == 00)
{
PayDay();
ActualizareVreme();
}
}
Sper sa apreciati gestul meu sa impart cu voi aceste stockuri , din pacate majoritatea serverelor nici nu folosesc weathers macar q.q doar weather = 0 , peste tot ..
Permisiunile acestui forum:
Nu puteti raspunde la subiectele acestui forum