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

Hola estoy haciendo un sistema de pagos diarios y como soy nuevo en pawn me gustaria conocer la opinion de los que mas saben del lenguaje sobre mi codigo.

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]++;
        }
    }
   
    if (minuto == 0 || minuto == 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;
}
Reply
#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
#3

Usa 'foreach' en vez de ese bucle que recorre todos los jugadores.
Reply
#4

Mejor usa y_iterate, es mejor que foreach.
Reply
#5

їCуmo serнa eso Enzo?
Reply
#6

Quote:
Originally Posted by Juance
Посмотреть сообщение
Usa 'foreach' en vez de ese bucle que recorre todos los jugadores.
foreach seria un bucle pero solo para los usuarios online verdad?
Reply
#7

Quote:
Originally Posted by Juance
Посмотреть сообщение
їCуmo serнa eso Enzo?
Y_Iterate es una nueva versiуn de foreach. ademбs forma parte de YSI, me lo ha dicho el mismo ******.
Reply
#8

їHay algъn ejemplo hecho en la web? hay que ponerse al dнa..
Reply
#9

Enzo el chico ha dicho que es nuevo, primero que aprenda bien las cosas originales luego el sabrб si quiere usar includes, y si йl quiere pues ya es su decisiуn pero yo recomendarнa que aprendiera lo normal y despuйs si quiere que use foreach y si aun quiere optimizar mбs el de la libreria de ******...
Reply
#10

Йl dijo optimizar los cуdigos, nunca ha especificado que tipo de forma para optimizar quiere, por lo tanto Enzo le estб dando ejemplos a usar a si como tambiйn yo con el Foreach.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)