SA-MP Forums Archive
[Ayuda] їPorque no funciona esto? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: Non-English (https://sampforum.blast.hk/forumdisplay.php?fid=9)
+--- Forum: Languages (https://sampforum.blast.hk/forumdisplay.php?fid=33)
+---- Forum: Español/Spanish (https://sampforum.blast.hk/forumdisplay.php?fid=29)
+---- Thread: [Ayuda] їPorque no funciona esto? (/showthread.php?tid=390727)



[Ayuda] їPorque no funciona esto? [Resuelto] - The_Scope - 07.11.2012

Hola, estoy haciendo un sistema de niveles basandome en el score del jugador y la cosa es que hice esto:

pawn Код:
if(GetPlayerScore(playerid) <= 0 ) { JugadorLVL[playerid] = 0; }
    else if(GetPlayerScore(playerid) <= 10) JugadorLVL[playerid] = 1;
    else if(GetPlayerScore(playerid) <= 20) JugadorLVL[playerid] = 2;
    else if(GetPlayerScore(playerid) <= 30) JugadorLVL[playerid] = 4;
dentro de un callback que se actualiza automaticamente.

Lo que intento hacer es que si por ejemplo el jugador tiene un score mayor a 10 le sete el nivel a 1, y si el jugador tiene un score mayor a 20 le setee lvl 4, etc.

Guardo los datos en MySQL y todo se guarda bien ya que he intentado hacerlo asi:

pawn Код:
if(GetPlayerScore(playerid) == 0 ) { JugadorLVL[playerid] = 0; }
    else if(GetPlayerScore(playerid) == 10) JugadorLVL[playerid] = 1;
    else if(GetPlayerScore(playerid) == 20) JugadorLVL[playerid] = 2;
    else if(GetPlayerScore(playerid) == 30) JugadorLVL[playerid] = 4;
Y ahi si se setea y guarda el LVL del jugador.
Pero la cosa es que solo se setearia si el jugador tubiece un score igual a ese, y que el callback se actualice justo al mismo momento que el jugador tenga ese score :S.

Muchas gracias, The Scope


Respuesta: [Ayuda] їPorque no funciona esto? - Jose_grana - 07.11.2012

Asi seria algo mas optimizado

pawn Код:
switch(GetPlayerScore[playerid])
    {
        case 0: JugadorLVL[playerid] = 0;
        case 10: JugadorLVL[playerid] = 1;
        case 20: JugadorLVL[playerid] = 2;
        case 30: JugadorLVL[playerid] = 3;
    }



Respuesta: [Ayuda] їPorque no funciona esto? - The_Scope - 07.11.2012

Quote:
Originally Posted by Jose_grana
Посмотреть сообщение
Asi seria algo mas optimizado

pawn Код:
switch(GetPlayerScore[playerid])
    {
        case 0: JugadorLVL[playerid] = 0;
        case 10: JugadorLVL[playerid] = 1;
        case 20: JugadorLVL[playerid] = 2;
        case 30: JugadorLVL[playerid] = 3;
    }
Pero si lo hago de esta manera si por ejemplo le seteo el score de un jugador a 31 no le tomara como LVL 3 verdad?

Gracias por responder


Respuesta: [Ayuda] їPorque no funciona esto? - WCrimson - 07.11.2012

pawn Код:
switch(GetPlayerScore[playerid])
    {
        case 0..9: JugadorLVL[playerid] = 0;
        case 10..19: JugadorLVL[playerid] = 1;
        case 20..29: JugadorLVL[playerid] = 2;
        case 30..39: JugadorLVL[playerid] = 3;
    }



Respuesta: [Ayuda] їPorque no funciona esto? - The_Scope - 07.11.2012

Quote:
Originally Posted by WCrimson
Посмотреть сообщение
pawn Код:
switch(GetPlayerScore[playerid])
    {
        case 0..9: JugadorLVL[playerid] = 0;
        case 10..19: JugadorLVL[playerid] = 1;
        case 20..29: JugadorLVL[playerid] = 2;
        case 30..39: JugadorLVL[playerid] = 3;
    }
Muchas gracias


Respuesta: [Ayuda] їPorque no funciona esto? - [J]ulian - 07.11.2012

pawn Код:
JugadorLVL[playerid] = GetPlayerScore(playerid)/10;

// Test de que funciona.
main()
{
    new JugadorLVL[MAX_PLAYERS], playerid = 0;
    for(new i = 0; i < 100; i++)
    {
        JugadorLVL[playerid] = i/10;
        printf("%i", JugadorLVL[playerid]);
    }
}