Que opinan de mi codigo, se podria optimizar?
#2

pawn Код:
new TiempoJugando[MAX_PLAYERS];

SetTimer("PagoDiario", 60000, true);    // 1 minuto

public PagoDiario(playerid)
{
    new hora, minuto, segundo, string[128];
    gettime(hora, minuto, segundo);
   
    for (new i = 0; i < MAX_PLAYERS; i++)
    {
        if (IsPlayerConnected(i) & JugadorLogueado[i] == 1)
        {
            TiempoJugando[i]++;
        }
    }
   
    switch(minuto)
    {
        case 0,1:
        {
            SetWorldTime(hora);
            for (new i = 0; i < MAX_PLAYERS; i++)
            {
                if (IsPlayerConnected(i) & JugadorLogueado[i] == 1)
                {
                    format(string, sizeof(string), "SERVIDOR: Hora de pago.");
                    SendClientMessage(i, COLOR_BLANCO, string);
                    if (TiempoJugando[playerid] >= 20)
                    {
                        TiempoJugando[playerid] = 0;
                        JugadorInfo[playerid][Experiencia]++;
                        GuardarDato_INT(i, "usuarios", "Experiencia", JugadorInfo[playerid][Experiencia]);
                        format(string, sizeof(string), "SERVIDOR: Felicidades, has recibido tu pago diario.");
                        SendClientMessage(i, COLOR_BLANCO, string);
                    }
                    else
                    {
                        TiempoJugando[playerid] = 0;
                        format(string, sizeof(string), "SERVIDOR: No has jugado lo suficiente para recibir tu pago.");
                        SendClientMessage(i, COLOR_BLANCO, string);
                    }
                }
            }
        }
    }
    return 1;
}
Hola mira pues te agrege un switch para remplazar el uso de "||" otra cosa estб de mбs que utilices format en los mensajes y tengas el new de string, porquй? simple porque format se utiliza para agregar parбmetros como el nombre, nъmeros almacenados en variables, etcйtera.

pawn Код:
SendClientMessage(i, COLOR_BLANCO, "SERVIDOR: Hora de pago.");
SendClientMessage(i, COLOR_BLANCO, "SERVIDOR: Felicidades, has recibido tu pago diario.");
SendClientMessage(i, COLOR_BLANCO,"SERVIDOR: No has jugado lo suficiente para recibir tu pago.");
Ahн estбn como debe de ser, ahora sуlo borra el format y remplaza el nuevo mensaje .
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)