їEs posible?
#1

Estube creando un script para que muestre la hora de mi host en el server. Y luego se me ocurrio crear un sistema de clima automatico basandome en esa hora. Y tenia una duda:

Codigo:
pawn Код:
public Reloj(playerid)
{
    new string[256];
    new string2[256];
    new year, month, day;
    new hour, minute, second;
    getdate(year, month, day);
    gettime(hour,minute,second);
    new mtext[20];
    getdate(year, month, day);
    if(month == 1) { mtext = "Enero"; }
    else if(month == 2) { mtext = "Febrero"; }
    else if(month == 3) { mtext = "Marzo"; }
    else if(month == 4) { mtext = "Abril"; }
    else if(month == 5) { mtext = "Mayo"; }
    else if(month == 6) { mtext = "Junio"; }
    else if(month == 7) { mtext = "Julio"; }
    else if(month == 8) { mtext = "Augosto"; }
    else if(month == 9) { mtext = "Septiembre"; }
    else if(month == 10) { mtext = "Octubre"; }
    else if(month == 11) { mtext = "Noviembre"; }
    else if(month == 12) { mtext = "Diciembre"; }
    format(string, sizeof(string), "%d %s, %d", day, mtext, year);
    TextDrawSetString(Text:Textdraw99, string);
    format(string2, sizeof(string2), "%d:%d:%d", hour, minute, second);
    TextDrawSetString(Text:Textdraw88, string2);
}
Queria saber si es posible obtener una X hora de ese script para a esa X hora convertir el "Tiempo" o "Clima" a otro, ejemplo:

Al momento que el reloj marque las 21:00:00 el "Tiempo" se establesca a "Noche". Y asн...

Creo que esto se podria hacer con las estaciones, ya que hay 12 meses, seria algo asн:
pawn Код:
public EstacionClima()
{
if(month == 2)
{
 SetWeather(19);
}
}
Verdad?

Yo creo que se puede hacer lo mismo con la hora, pero tardaria mucho mas tiempo escribir las 24 horas los minutos y los segundos
No se si me entienden, espero que aya alguna forma de obtener esa X hora
Reply
#2

Si, es totalmente posible. Puedes usar un timer que realize ese chequeo.
Reply
#3

Quote:
Originally Posted by the_chaoz
Посмотреть сообщение
Si, es totalmente posible. Puedes usar un timer que realize ese chequeo.
Osea, que si quiero que el "Tiempo" cambie a "Noche" a las 21:00 horas, tendria que crear algo asi?:
pawn Код:
public OnGameModeInit()
{
SetTimer("Noche", 1944000000, true);

// Si no me equivoco 1944000000 milisegundos son 9 horas.
}
public Noche()
{
SetWorldTime(); // bueno aca el tiempo que no recuerdo los ids :S
}
Seria algo asн verdad?
Reply
#4

o podrias usar un if asi
pawn Код:
if(hour==21)
{
//la funcion que quieras colocar
esto lo pudes colocar en un public y chequearlo, o en donde quieras que se actualize la hora, o donde se aplique la funcion
Reply
#5

Quote:
Originally Posted by davidxxx
Посмотреть сообщение
o podrias usar un if asi
pawn Код:
if(hour==21)
{
//la funcion que quieras colocar
esto lo pudes colocar en un public y chequearlo, o en donde quieras que se actualize la hora, o donde se aplique la funcion
O genial gracias, no sabia que se podia hacer asн "if(hour==x)"
Reply
#6

si tienes una variable si

de nada
Reply
#7

Quote:
Originally Posted by The_Scope
Посмотреть сообщение
Osea, que si quiero que el "Tiempo" cambie a "Noche" a las 21:00 horas, tendria que crear algo asi?:
pawn Код:
public OnGameModeInit()
{
SetTimer("Noche", 1944000000, true);

// Si no me equivoco 1944000000 milisegundos son 9 horas.
}
public Noche()
{
SetWorldTime(); // bueno aca el tiempo que no recuerdo los ids :S
}
Seria algo asн verdad?
no te recomiendo ese metodo, un timer cada hs q chequee la hora actual o 1 cada 12hs segun lo que tengas planeado. y aplicando la comparacion que te dijeron antes.
Reply
#8

Quote:
Originally Posted by the_chaoz
Посмотреть сообщение
no te recomiendo ese metodo, un timer cada hs q chequee la hora actual o 1 cada 12hs segun lo que tengas planeado. y aplicando la comparacion que te dijeron antes.
He creado lo siguiente:
pawn Код:
public OngameModeInit()
{
SetTimer("Clock", 1000, 1); // Reloj actualizado cada 1 segundo

Textdraw99 = TextDrawCreate(450.000000,5.000000, "--");
    Textdraw88 = TextDrawCreate(551.000000,23.000000,"--");
    TextDrawAlignment(Textdraw99,0);
    TextDrawAlignment(Textdraw88,0);
    TextDrawBackgroundColor(Textdraw99,0x00000066);
    TextDrawBackgroundColor(Textdraw88,0x00000066);
    TextDrawFont(Textdraw99,2);
    TextDrawLetterSize(Textdraw99,0.499999,1.500000);
    TextDrawFont(Textdraw88,2);
    TextDrawLetterSize(Textdraw88,0.399999,2.000000);
    TextDrawColor(Textdraw99,0x00ffffff);
    TextDrawColor(Textdraw88,0x00ffffff);
    TextDrawSetOutline(Textdraw99,1);
    TextDrawSetOutline(Textdraw88,1);
    TextDrawSetProportional(Textdraw99,1);
    TextDrawSetProportional(Textdraw88,1);
    TextDrawSetShadow(Textdraw99,1);
    TextDrawSetShadow(Textdraw88,1);
}
public Clock(playerid)
{
    new string[256];
    new string2[256];
    new year, month, day;
    new hour, minute, second;
    getdate(year, month, day);
    gettime(hour,minute,second);
    new mtext[20];
    getdate(year, month, day);
    if(month == 1) { mtext = "Enero"; }
    else if(month == 2) { mtext = "Febrero"; }
    else if(month == 3) { mtext = "Marzo"; }
    else if(month == 4) { mtext = "Abril"; }
    else if(month == 5) { mtext = "Mayo"; }
    else if(month == 6) { mtext = "Junio"; }
    else if(month == 7) { mtext = "Julio"; }
    else if(month == 8) { mtext = "Augosto"; }
    else if(month == 9) { mtext = "Septiembre"; }
    else if(month == 10) { mtext = "Octubre"; }
    else if(month == 11) { mtext = "Noviembre"; }
    else if(month == 12) { mtext = "Diciembre"; }
    format(string, sizeof(string), "%d %s, %d", day, mtext, year);
    TextDrawSetString(Text:Textdraw99, string);
    format(string2, sizeof(string2), "%d:%d:%d", hour, minute, second);
    TextDrawSetString(Text:Textdraw88, string2);
   
    if(hour == 6 && minute == 00 && hour == 7 && minute == 00) { SetWeather(1); } // 6:00 y 7:00 Horas
    if(hour == 8 && minute == 00) { SetWorldTime(8); SetWeather(1); SendClientMessageToAll(COLOR_YELLOW,"SERVER: ЎEl gallo canta! Una nueva jornada comienza!. ЎQue tengas un buen dнa!"); }//8:00 Horas
    if(hour == 9 && minute == 00 && hour == 10 && minute == 00) { SetWeather(2); } // 9:00 y 10:00 Horas
    if(hour == 11 && minute == 00 && hour == 12 && minute == 00) { SetWeather(3); } // 11:00 y 12:00 Horas
    if(hour == 13 && minute == 00) { SetWeather(4); } // 13:00 Horas
    if(hour == 14 && minute == 00) { SetWorldTime(14); SetWeather(4); SendClientMessageToAll(COLOR_YELLOW,"SERVER: ЎUuuy! que Hambre... es un buen momento para ir a comer algo."); }// 14:00 Horas
    if(hour == 15 && minute == 00 && hour == 16 && minute == 00) { SetWeather(7); }// 15:00 y 16:00 Horas
    if(hour == 17 && minute == 00 && hour == 18 && minute == 00) { SetWeather(15); }// 17:00 y 18:00 Horas
    if(hour == 19 && minute == 00) { SetWeather(17); }// 19:00 Horas
    if(hour == 20 && minute == 45) { SetWorldTime(23); SetWeather(33); SendClientMessageToAll(COLOR_YELLOW,"SERVER: La jornada del dia termina, reunete con tu familia y disfruta una rica cena"); }// 20:45 Horas
    if(hour == 21 && minute == 00) { SetWeather(35); }// 21:00 Horas
    if(hour == 22 && minute == 00) { SetWorldTime(0); SetWeather(35); SendClientMessageToAll(COLOR_YELLOW,"SERVER: Ya es tarde, ve a descanzar. Recuerda que andar solo por la noche es peligroso."); }// 22:00 Horas
    if(hour == 23 && minute == 00 && hour == 0 && minute == 00 && hour == 1 && minute == 00 && hour == 2 && minute == 00 && hour == 3 && minute == 00 && hour == 4 && minute == 00 && hour == 5 && minute == 00) { SendRconCommand("weather 38"); }

}
En donde empieza esto:
pawn Код:
if(hour == 20 && minute == 45) { SetWorldTime(23); SetWeather(33); SendClientMessageToAll(COLOR_YELLOW,"SERVER: La jornada del dia termina, reunete con tu familia y disfruta una rica cena"); }// 20:45 Horas
Creo que a las 20 horas y 45 minutos el Clima se cambie al id 33, y el Tiempo (WorldTime) al id 23, y le envie un mensaje a todos los jugadores diciendo: "SERVER: La jornada del dia termina, reunete con tu familia y disfruta una rica cena".

La funcion funciona perfecto, pero el problema es que el el reloj se va actualizando cada 1 segundo para que funcione el "second" de "format(string2, sizeof(string2), "%d:%d:%d", hour, minute, second)" y esto proboca que el mensaje se repita cada 1 segundo cambiando el clima cada 1 segundo y el tiempo cada 1 segundo, probocando un flood que solo se para cuando se cambia de hora el server, volviendo a empezar de nuevo...
Reply
#9

Quote:
Originally Posted by The_Scope
Посмотреть сообщение
He creado lo siguiente:
pawn Код:
public OngameModeInit()
{
SetTimer("Clock", 1000, 1); // Reloj actualizado cada 1 segundo

Textdraw99 = TextDrawCreate(450.000000,5.000000, "--");
    Textdraw88 = TextDrawCreate(551.000000,23.000000,"--");
    TextDrawAlignment(Textdraw99,0);
    TextDrawAlignment(Textdraw88,0);
    TextDrawBackgroundColor(Textdraw99,0x00000066);
    TextDrawBackgroundColor(Textdraw88,0x00000066);
    TextDrawFont(Textdraw99,2);
    TextDrawLetterSize(Textdraw99,0.499999,1.500000);
    TextDrawFont(Textdraw88,2);
    TextDrawLetterSize(Textdraw88,0.399999,2.000000);
    TextDrawColor(Textdraw99,0x00ffffff);
    TextDrawColor(Textdraw88,0x00ffffff);
    TextDrawSetOutline(Textdraw99,1);
    TextDrawSetOutline(Textdraw88,1);
    TextDrawSetProportional(Textdraw99,1);
    TextDrawSetProportional(Textdraw88,1);
    TextDrawSetShadow(Textdraw99,1);
    TextDrawSetShadow(Textdraw88,1);
}
public Clock(playerid)
{
    new string[256];
    new string2[256];
    new year, month, day;
    new hour, minute, second;
    getdate(year, month, day);
    gettime(hour,minute,second);
    new mtext[20];
    getdate(year, month, day);
    if(month == 1) { mtext = "Enero"; }
    else if(month == 2) { mtext = "Febrero"; }
    else if(month == 3) { mtext = "Marzo"; }
    else if(month == 4) { mtext = "Abril"; }
    else if(month == 5) { mtext = "Mayo"; }
    else if(month == 6) { mtext = "Junio"; }
    else if(month == 7) { mtext = "Julio"; }
    else if(month == 8) { mtext = "Augosto"; }
    else if(month == 9) { mtext = "Septiembre"; }
    else if(month == 10) { mtext = "Octubre"; }
    else if(month == 11) { mtext = "Noviembre"; }
    else if(month == 12) { mtext = "Diciembre"; }
    format(string, sizeof(string), "%d %s, %d", day, mtext, year);
    TextDrawSetString(Text:Textdraw99, string);
    format(string2, sizeof(string2), "%d:%d:%d", hour, minute, second);
    TextDrawSetString(Text:Textdraw88, string2);
   
    if(hour == 6 && minute == 00 && hour == 7 && minute == 00) { SetWeather(1); } // 6:00 y 7:00 Horas
    if(hour == 8 && minute == 00) { SetWorldTime(8); SetWeather(1); SendClientMessageToAll(COLOR_YELLOW,"SERVER: ЎEl gallo canta! Una nueva jornada comienza!. ЎQue tengas un buen dнa!"); }//8:00 Horas
    if(hour == 9 && minute == 00 && hour == 10 && minute == 00) { SetWeather(2); } // 9:00 y 10:00 Horas
    if(hour == 11 && minute == 00 && hour == 12 && minute == 00) { SetWeather(3); } // 11:00 y 12:00 Horas
    if(hour == 13 && minute == 00) { SetWeather(4); } // 13:00 Horas
    if(hour == 14 && minute == 00) { SetWorldTime(14); SetWeather(4); SendClientMessageToAll(COLOR_YELLOW,"SERVER: ЎUuuy! que Hambre... es un buen momento para ir a comer algo."); }// 14:00 Horas
    if(hour == 15 && minute == 00 && hour == 16 && minute == 00) { SetWeather(7); }// 15:00 y 16:00 Horas
    if(hour == 17 && minute == 00 && hour == 18 && minute == 00) { SetWeather(15); }// 17:00 y 18:00 Horas
    if(hour == 19 && minute == 00) { SetWeather(17); }// 19:00 Horas
    if(hour == 20 && minute == 45) { SetWorldTime(23); SetWeather(33); SendClientMessageToAll(COLOR_YELLOW,"SERVER: La jornada del dia termina, reunete con tu familia y disfruta una rica cena"); }// 20:45 Horas
    if(hour == 21 && minute == 00) { SetWeather(35); }// 21:00 Horas
    if(hour == 22 && minute == 00) { SetWorldTime(0); SetWeather(35); SendClientMessageToAll(COLOR_YELLOW,"SERVER: Ya es tarde, ve a descanzar. Recuerda que andar solo por la noche es peligroso."); }// 22:00 Horas
    if(hour == 23 && minute == 00 && hour == 0 && minute == 00 && hour == 1 && minute == 00 && hour == 2 && minute == 00 && hour == 3 && minute == 00 && hour == 4 && minute == 00 && hour == 5 && minute == 00) { SendRconCommand("weather 38"); }

}
En donde empieza esto:
pawn Код:
if(hour == 20 && minute == 45) { SetWorldTime(23); SetWeather(33); SendClientMessageToAll(COLOR_YELLOW,"SERVER: La jornada del dia termina, reunete con tu familia y disfruta una rica cena"); }// 20:45 Horas
Creo que a las 20 horas y 45 minutos el Clima se cambie al id 33, y el Tiempo (WorldTime) al id 23, y le envie un mensaje a todos los jugadores diciendo: "SERVER: La jornada del dia termina, reunete con tu familia y disfruta una rica cena".

La funcion funciona perfecto, pero el problema es que el el reloj se va actualizando cada 1 segundo para que funcione el "second" de "format(string2, sizeof(string2), "%d:%d:%d", hour, minute, second)" y esto proboca que el mensaje se repita cada 1 segundo cambiando el clima cada 1 segundo y el tiempo cada 1 segundo, probocando un flood que solo se para cuando se cambia de hora el server, volviendo a empezar de nuevo...
Alguna otra forma o solucion a esto ?
Reply
#10

prueba poniendo un

return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)